changeset 4382:52a9555dbbb1

Merge
author lana
date Mon, 16 May 2011 18:15:42 -0700
parents 59aadf63f2a7 0b7f41c14605
children 2a580e14e428
files
diffstat 15 files changed, 425 insertions(+), 179 deletions(-) [+]
line wrap: on
line diff
--- a/make/sun/xawt/mapfile-vers	Mon May 16 15:38:56 2011 -0700
+++ b/make/sun/xawt/mapfile-vers	Mon May 16 18:15:42 2011 -0700
@@ -158,7 +158,6 @@
         Java_sun_awt_X11_XRobotPeer_mouseReleaseImpl;
         Java_sun_awt_X11_XRobotPeer_mouseWheelImpl;
         Java_sun_awt_X11_XRobotPeer_setup;
-        Java_sun_awt_X11_XRobotPeer__1dispose;
         Java_sun_awt_X11_XToolkit_getNumberOfButtonsImpl;
         Java_java_awt_Component_initIDs;
         Java_java_awt_Container_initIDs;
--- a/src/share/classes/java/awt/Component.java	Mon May 16 15:38:56 2011 -0700
+++ b/src/share/classes/java/awt/Component.java	Mon May 16 18:15:42 2011 -0700
@@ -2887,11 +2887,12 @@
     /**
      * Invalidates this component and its ancestors.
      * <p>
-     * All the ancestors of this component up to the nearest validate root are
-     * marked invalid also. If there is no a validate root container for this
-     * component, all of its ancestors up to the root of the hierarchy are
-     * marked invalid as well. Marking a container <i>invalid</i> indicates
-     * that the container needs to be laid out.
+     * By default, all the ancestors of the component up to the top-most
+     * container of the hierarchy are marked invalid. If the {@code
+     * java.awt.smartInvalidate} system property is set to {@code true},
+     * invalidation stops on the nearest validate root of this component.
+     * Marking a container <i>invalid</i> indicates that the container needs to
+     * be laid out.
      * <p>
      * This method is called automatically when any layout-related information
      * changes (e.g. setting the bounds of the component, or adding the
--- a/src/share/classes/java/awt/Container.java	Mon May 16 15:38:56 2011 -0700
+++ b/src/share/classes/java/awt/Container.java	Mon May 16 18:15:42 2011 -0700
@@ -41,6 +41,8 @@
 import java.io.PrintStream;
 import java.io.PrintWriter;
 
+import java.security.AccessController;
+
 import java.util.Arrays;
 import java.util.EventListener;
 import java.util.HashSet;
@@ -60,6 +62,8 @@
 
 import sun.java2d.pipe.Region;
 
+import sun.security.action.GetBooleanAction;
+
 /**
  * A generic Abstract Window Toolkit(AWT) container object is a component
  * that can contain other AWT components.
@@ -1506,12 +1510,18 @@
      * Layout-related changes, such as bounds of the validate root descendants,
      * do not affect the layout of the validate root parent. This peculiarity
      * enables the {@code invalidate()} method to stop invalidating the
-     * component hierarchy when the method encounters a validate root.
+     * component hierarchy when the method encounters a validate root. However,
+     * to preserve backward compatibility this new optimized behavior is
+     * enabled only when the {@code java.awt.smartInvalidate} system property
+     * value is set to {@code true}.
      * <p>
-     * If a component hierarchy contains validate roots, the {@code validate()}
-     * method must be invoked on the validate root of a previously invalidated
-     * component, rather than on the top-level container (such as a {@code
-     * Frame} object) to restore the validity of the hierarchy later.
+     * If a component hierarchy contains validate roots and the new optimized
+     * {@code invalidate()} behavior is enabled, the {@code validate()} method
+     * must be invoked on the validate root of a previously invalidated
+     * component to restore the validity of the hierarchy later. Otherwise,
+     * calling the {@code validate()} method on the top-level container (such
+     * as a {@code Frame} object) should be used to restore the validity of the
+     * component hierarchy.
      * <p>
      * The {@code Window} class and the {@code Applet} class are the validate
      * roots in AWT.  Swing introduces more validate roots.
@@ -1527,13 +1537,20 @@
         return false;
     }
 
+    private static final boolean isJavaAwtSmartInvalidate;
+    static {
+        // Don't lazy-read because every app uses invalidate()
+        isJavaAwtSmartInvalidate = AccessController.doPrivileged(
+                new GetBooleanAction("java.awt.smartInvalidate"));
+    }
+
     /**
      * Invalidates the parent of the container unless the container
      * is a validate root.
      */
     @Override
     void invalidateParent() {
-        if (!isValidateRoot()) {
+        if (!isJavaAwtSmartInvalidate || !isValidateRoot()) {
             super.invalidateParent();
         }
     }
@@ -1572,9 +1589,8 @@
      * automatically.  Note that the ancestors of the container may be
      * invalidated also (see {@link Component#invalidate} for details.)
      * Therefore, to restore the validity of the hierarchy, the {@code
-     * validate()} method should be invoked on a validate root of an
-     * invalidated component, or on the top-most container if the hierarchy
-     * does not contain validate roots.
+     * validate()} method should be invoked on the top-most invalid
+     * container of the hierarchy.
      * <p>
      * Validating the container may be a quite time-consuming operation. For
      * performance reasons a developer may postpone the validation of the
--- a/src/share/classes/java/awt/Toolkit.java	Mon May 16 15:38:56 2011 -0700
+++ b/src/share/classes/java/awt/Toolkit.java	Mon May 16 18:15:42 2011 -0700
@@ -466,10 +466,7 @@
      */
     protected void loadSystemColors(int[] systemColors)
         throws HeadlessException {
-        if (GraphicsEnvironment.isHeadless()){
-            throw new HeadlessException();
-        }
-
+        GraphicsEnvironment.checkHeadless();
     }
 
 /**
@@ -504,10 +501,7 @@
      */
     public void setDynamicLayout(boolean dynamic)
         throws HeadlessException {
-        if (GraphicsEnvironment.isHeadless()){
-            throw new HeadlessException();
-        }
-
+        GraphicsEnvironment.checkHeadless();
     }
 
     /**
@@ -531,9 +525,8 @@
      */
     protected boolean isDynamicLayoutSet()
         throws HeadlessException {
-        if (GraphicsEnvironment.isHeadless()){
-            throw new HeadlessException();
-        }
+        GraphicsEnvironment.checkHeadless();
+
         if (this != Toolkit.getDefaultToolkit()) {
             return Toolkit.getDefaultToolkit().isDynamicLayoutSet();
         } else {
@@ -569,9 +562,8 @@
      */
     public boolean isDynamicLayoutActive()
         throws HeadlessException {
-        if (GraphicsEnvironment.isHeadless()){
-            throw new HeadlessException();
-        }
+        GraphicsEnvironment.checkHeadless();
+
         if (this != Toolkit.getDefaultToolkit()) {
             return Toolkit.getDefaultToolkit().isDynamicLayoutActive();
         } else {
@@ -615,9 +607,7 @@
      */
     public Insets getScreenInsets(GraphicsConfiguration gc)
         throws HeadlessException {
-        if (GraphicsEnvironment.isHeadless()){
-            throw new HeadlessException();
-        }
+        GraphicsEnvironment.checkHeadless();
         if (this != Toolkit.getDefaultToolkit()) {
             return Toolkit.getDefaultToolkit().getScreenInsets(gc);
         } else {
@@ -1200,10 +1190,7 @@
      * security manager's <code>checkPermission</code> method with a <code>
      * RuntimePermission("queuePrintJob")</code> permission.
      *
-     * @param   frame the parent of the print dialog. May be null if and only
-     *          if jobAttributes is not null and jobAttributes.getDialog()
-     *          returns JobAttributes.DialogType.NONE or
-     *          JobAttributes.DialogType.COMMON.
+     * @param   frame the parent of the print dialog. May not be null.
      * @param   jobtitle the title of the PrintJob. A null title is equivalent
      *          to "".
      * @param   jobAttributes a set of job attributes which will control the
@@ -1359,9 +1346,8 @@
      * @since 1.4
      */
     public Clipboard getSystemSelection() throws HeadlessException {
-        if (GraphicsEnvironment.isHeadless()){
-            throw new HeadlessException();
-        }
+        GraphicsEnvironment.checkHeadless();
+
         if (this != Toolkit.getDefaultToolkit()) {
             return Toolkit.getDefaultToolkit().getSystemSelection();
         } else {
@@ -1391,9 +1377,7 @@
      * @since     JDK1.1
      */
     public int getMenuShortcutKeyMask() throws HeadlessException {
-        if (GraphicsEnvironment.isHeadless()){
-            throw new HeadlessException();
-        }
+        GraphicsEnvironment.checkHeadless();
 
         return Event.CTRL_MASK;
     }
@@ -1418,7 +1402,10 @@
      * @since 1.3
      */
     public boolean getLockingKeyState(int keyCode)
-        throws UnsupportedOperationException {
+        throws UnsupportedOperationException
+    {
+        GraphicsEnvironment.checkHeadless();
+
         if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK ||
                keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) {
             throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
@@ -1449,7 +1436,10 @@
      * @since 1.3
      */
     public void setLockingKeyState(int keyCode, boolean on)
-        throws UnsupportedOperationException {
+        throws UnsupportedOperationException
+    {
+        GraphicsEnvironment.checkHeadless();
+
         if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK ||
                keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) {
             throw new IllegalArgumentException("invalid key for Toolkit.setLockingKeyState");
@@ -1523,9 +1513,8 @@
      */
     public Dimension getBestCursorSize(int preferredWidth,
         int preferredHeight) throws HeadlessException {
-        if (GraphicsEnvironment.isHeadless()){
-            throw new HeadlessException();
-        }
+        GraphicsEnvironment.checkHeadless();
+
         // Override to implement custom cursor support.
         if (this != Toolkit.getDefaultToolkit()) {
             return Toolkit.getDefaultToolkit().
@@ -1553,9 +1542,8 @@
      * @since     1.2
      */
     public int getMaximumCursorColors() throws HeadlessException {
-        if (GraphicsEnvironment.isHeadless()){
-            throw new HeadlessException();
-        }
+        GraphicsEnvironment.checkHeadless();
+
         // Override to implement custom cursor support.
         if (this != Toolkit.getDefaultToolkit()) {
             return Toolkit.getDefaultToolkit().getMaximumCursorColors();
@@ -1605,9 +1593,8 @@
     public boolean isFrameStateSupported(int state)
         throws HeadlessException
     {
-        if (GraphicsEnvironment.isHeadless()){
-            throw new HeadlessException();
-        }
+        GraphicsEnvironment.checkHeadless();
+
         if (this != Toolkit.getDefaultToolkit()) {
             return Toolkit.getDefaultToolkit().
                 isFrameStateSupported(state);
@@ -2614,9 +2601,8 @@
     * @since 1.7
      */
     public boolean areExtraMouseButtonsEnabled() throws HeadlessException {
-        if (GraphicsEnvironment.isHeadless()){
-            throw new HeadlessException();
-        }
+        GraphicsEnvironment.checkHeadless();
+
         return Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled();
     }
 }
--- a/src/solaris/classes/sun/awt/X11/XRobotPeer.java	Mon May 16 15:38:56 2011 -0700
+++ b/src/solaris/classes/sun/awt/X11/XRobotPeer.java	Mon May 16 18:15:42 2011 -0700
@@ -48,7 +48,7 @@
     }
 
     public void dispose() {
-        _dispose();
+        // does nothing
     }
 
     public void mouseMove(int x, int y) {
@@ -88,7 +88,6 @@
     }
 
     private static native synchronized void setup(int numberOfButtons, int[] buttonDownMasks);
-    private static native synchronized void _dispose();
 
     private static native synchronized void mouseMoveImpl(X11GraphicsConfig xgc, int x, int y);
     private static native synchronized void mousePressImpl(int buttons);
--- a/src/solaris/native/sun/awt/awt_Robot.c	Mon May 16 15:38:56 2011 -0700
+++ b/src/solaris/native/sun/awt/awt_Robot.c	Mon May 16 18:15:42 2011 -0700
@@ -48,28 +48,12 @@
 #ifdef __linux__
 #include <sys/socket.h>
 #endif
-#include <dlfcn.h>
 
 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
 
 static jint * masks;
 static jint num_buttons;
 
-static unsigned int s_robotInstanceCounter = 0;
-
-static void* xcompositeLibHandle = NULL;
-static Bool xcompositeExtAvailable = False;
-static Bool xcompositeExtTested = False;
-
-typedef Status (*T_XCompositeQueryVersion)(Display *dpy, int *major_versionp, int *minor_versionp);
-typedef Window (*T_XCompositeGetOverlayWindow)(Display *dpy, Window window);
-typedef void (*T_XCompositeReleaseOverlayWindow)(Display *dpy, Window window);
-
-static T_XCompositeQueryVersion XCompositeQueryVersion = NULL;
-static T_XCompositeGetOverlayWindow XCompositeGetOverlayWindow = NULL;
-static T_XCompositeReleaseOverlayWindow XCompositeReleaseOverlayWindow = NULL;
-
-
 static int32_t isXTestAvailable() {
     int32_t major_opcode, first_event, first_error;
     int32_t  event_basep, error_basep, majorp, minorp;
@@ -210,80 +194,8 @@
     }
 
     AWT_UNLOCK();
-
-    s_robotInstanceCounter++;
 }
 
-JNIEXPORT void JNICALL
-Java_sun_awt_X11_XRobotPeer__1dispose (JNIEnv * env, jclass cls)
-{
-    if (--s_robotInstanceCounter) {
-        return;
-    }
-
-    // This is the last instance of the XRobotPeer being released
-
-    if (xcompositeExtTested && xcompositeExtAvailable && xcompositeLibHandle) {
-        // The lib is loaded in IsXCompositeAvailable(). Unload under AWT_LOCK
-        // so that the shutdown function of the lib behaves correctly.
-        AWT_LOCK();
-        dlclose(xcompositeLibHandle);
-        AWT_UNLOCK();
-    }
-
-    xcompositeExtTested = False;
-    xcompositeExtAvailable = False;
-    xcompositeLibHandle = NULL;
-}
-
-/*
- * Returns True only if XCOMPOSITE is of version 0.3 or higher.
- * The functions that we need are available since that version.
- *
- * Must be invoked under AWT_LOCK.
- *
- * Leaves the library loaded if the version is correct.
- */
-static Bool IsXCompositeAvailable()
-{
-    if (!xcompositeExtTested) {
-        int opcode, eventb, errorb;
-
-        if (XQueryExtension(awt_display, "Composite", &opcode, &eventb, &errorb)) {
-            xcompositeLibHandle = dlopen("libXcomposite.so.1", RTLD_LAZY | RTLD_GLOBAL);
-#ifndef __linux__ /* SOLARIS */
-            if (xcompositeLibHandle == NULL) {
-                xcompositeLibHandle = dlopen("/usr/sfw/lib/libXcomposite.so.1",
-                        RTLD_LAZY | RTLD_GLOBAL);
-            }
-#endif
-
-            if (xcompositeLibHandle) {
-                int major, minor;
-                XCompositeQueryVersion = (T_XCompositeQueryVersion)dlsym(xcompositeLibHandle, "XCompositeQueryVersion");
-
-                if (XCompositeQueryVersion && XCompositeQueryVersion(awt_display, &major, &minor)) {
-                    if (major >= 0 && minor >= 3) {
-                        XCompositeGetOverlayWindow = (T_XCompositeGetOverlayWindow)dlsym(xcompositeLibHandle, "XCompositeGetOverlayWindow");
-                        XCompositeReleaseOverlayWindow = (T_XCompositeReleaseOverlayWindow)dlsym(xcompositeLibHandle, "XCompositeReleaseOverlayWindow");
-
-                        if (XCompositeGetOverlayWindow && XCompositeReleaseOverlayWindow) {
-                            xcompositeExtAvailable = True;
-                        }
-                    }
-                }
-
-                if (!xcompositeExtAvailable) {
-                    dlclose(xcompositeLibHandle);
-                } /* else the lib is unloaded in _dispose() */
-            }
-        }
-
-        xcompositeExtTested = True;
-    }
-
-    return xcompositeExtAvailable;
-}
 
 JNIEXPORT void JNICALL
 Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
@@ -299,7 +211,7 @@
     jint *ary;               /* Array of jints for sending pixel values back
                               * to parent process.
                               */
-    Window window;
+    Window rootWindow;
     AwtGraphicsConfigDataPtr adata;
 
     DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, x, y, width, height, pixelArray);
@@ -316,24 +228,14 @@
     adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
     DASSERT(adata != NULL);
 
-    window = XRootWindow(awt_display, adata->awt_visInfo.screen);
-
-    if (IsXCompositeAvailable()) {
-        // Use 'composite overlay window' instead of the root window.
-        // See 6903034 for details.
-        window = XCompositeGetOverlayWindow(awt_display, window);
-    }
-
-    image = getWindowImage(awt_display, window, x, y, width, height);
+    rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
+    image = getWindowImage(awt_display, rootWindow, x, y, width, height);
 
     /* Array to use to crunch around the pixel values */
     ary = (jint *) malloc(width * height * sizeof (jint));
     if (ary == NULL) {
         JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
         XDestroyImage(image);
-        if (IsXCompositeAvailable()) {
-            XCompositeReleaseOverlayWindow(awt_display, window);
-        }
         AWT_UNLOCK();
         return;
     }
@@ -354,9 +256,6 @@
     free(ary);
 
     XDestroyImage(image);
-    if (IsXCompositeAvailable()) {
-        XCompositeReleaseOverlayWindow(awt_display, window);
-    }
 
     AWT_UNLOCK();
 }
--- a/src/windows/classes/sun/awt/windows/WFramePeer.java	Mon May 16 15:38:56 2011 -0700
+++ b/src/windows/classes/sun/awt/windows/WFramePeer.java	Mon May 16 18:15:42 2011 -0700
@@ -107,8 +107,16 @@
             Rectangle currentDevBounds = currentDevGC.getBounds();
             Rectangle primaryDevBounds = primaryDevGC.getBounds();
 
-            b.width -= (currentDevBounds.width - primaryDevBounds.width);
-            b.height -= (currentDevBounds.height - primaryDevBounds.height);
+            boolean isCurrentDevLarger =
+                ((currentDevBounds.width - primaryDevBounds.width > 0) ||
+                 (currentDevBounds.height - primaryDevBounds.height > 0));
+
+            // the window manager doesn't seem to compensate for differences when
+            // the primary monitor is larger than the monitor that display the window
+            if (isCurrentDevLarger) {
+                b.width -= (currentDevBounds.width - primaryDevBounds.width);
+                b.height -= (currentDevBounds.height - primaryDevBounds.height);
+            }
         }
     }
 
--- a/src/windows/native/sun/java2d/d3d/D3DPipelineManager.cpp	Mon May 16 15:38:56 2011 -0700
+++ b/src/windows/native/sun/java2d/d3d/D3DPipelineManager.cpp	Mon May 16 18:15:42 2011 -0700
@@ -192,6 +192,14 @@
     pMgr = D3DPipelineManager::GetInstance();
     RETURN_IF_NULL(pMgr);
     hMon = pMgr->pd3d9->GetAdapterMonitor(adapter);
+
+    /*
+     * If we don't have devices initialized yet, no sense to clear them.
+     */
+    if (!Devices::GetInstance()){
+         return;
+    }
+
     gdiScreen = AwtWin32GraphicsDevice::GetScreenFromHMONITOR(hMon);
 
     JNU_CallStaticMethodByName(env, NULL,
--- a/src/windows/native/sun/windows/Devices.h	Mon May 16 15:38:56 2011 -0700
+++ b/src/windows/native/sun/windows/Devices.h	Mon May 16 18:15:42 2011 -0700
@@ -36,6 +36,7 @@
 class Devices {
 
 public:
+static Devices*                 GetInstance();
 static BOOL                     UpdateInstance(JNIEnv *env);
        int                      GetNumDevices() { return numDevices; }
        AwtWin32GraphicsDevice*  GetDeviceReference(int index, BOOL adjust = TRUE);
@@ -59,7 +60,6 @@
 private:
                                 Devices(int numElements);
        void                     AddReference();
-static Devices*                 GetInstance();
 
        AwtWin32GraphicsDevice** devices;
        int                      refCount;
--- a/src/windows/native/sun/windows/awt_Choice.cpp	Mon May 16 15:38:56 2011 -0700
+++ b/src/windows/native/sun/windows/awt_Choice.cpp	Mon May 16 18:15:42 2011 -0700
@@ -396,6 +396,12 @@
 
     DASSERT(::IsWindow(hwnd));
 
+    // This branch is required for the proper work of AwtComponent::GetComponent() method
+    // while hovering drop-down list
+    if (message == WmAwtIsComponent) {
+        return (LRESULT)TRUE;
+    }
+
     switch (message) {
         case WM_LBUTTONDOWN: {
             DWORD curPos = ::GetMessagePos();
--- a/src/windows/native/sun/windows/awt_Component.cpp	Mon May 16 15:38:56 2011 -0700
+++ b/src/windows/native/sun/windows/awt_Component.cpp	Mon May 16 18:15:42 2011 -0700
@@ -364,7 +364,6 @@
     AwtComponent *component =
         (AwtComponent *)::GetWindowLongPtr(hWnd, GWLP_USERDATA);
     DASSERT(!component || !IsBadReadPtr(component, sizeof(AwtComponent)) );
-    DASSERT(!component || component->GetHWnd() == hWnd );
     return component;
 }
 
--- a/src/windows/native/sun/windows/awt_Frame.cpp	Mon May 16 15:38:56 2011 -0700
+++ b/src/windows/native/sun/windows/awt_Frame.cpp	Mon May 16 18:15:42 2011 -0700
@@ -344,17 +344,6 @@
                 SetImeTargetComponent(NULL);
             }
             break;
-        // TODO: when a Choice's list is dropped down and we're scrolling in
-        // the list WM_MOUSEWHEEL messages come to the poxy, not to the list. Why?
-        case WM_MOUSEWHEEL:
-            focusOwner = AwtComponent::GetComponent(sm_focusOwner);
-            if  (focusOwner != NULL &&
-                 focusOwner != this) // avoid recursive calls
-            {
-                 retValue = focusOwner->WindowProc(message, wParam, lParam);
-                 mr = mrConsume;
-            }
-            break;
         case WM_SETFOCUS:
             if (sm_inSynthesizeFocus) break; // pass it up the WindowProc chain
 
--- a/test/java/awt/Component/Revalidate/Revalidate.java	Mon May 16 15:38:56 2011 -0700
+++ b/test/java/awt/Component/Revalidate/Revalidate.java	Mon May 16 18:15:42 2011 -0700
@@ -26,7 +26,7 @@
   @bug 7036669
   @summary Test Component.revalidate() method
   @author anthony.petrov@oracle.com: area=awt.component
-  @run main Revalidate
+  @run main/othervm -Djava.awt.smartInvalidate=true Revalidate
 */
 
 import java.awt.*;
--- a/test/java/awt/Container/ValidateRoot/InvalidateMustRespectValidateRoots.java	Mon May 16 15:38:56 2011 -0700
+++ b/test/java/awt/Container/ValidateRoot/InvalidateMustRespectValidateRoots.java	Mon May 16 18:15:42 2011 -0700
@@ -26,7 +26,7 @@
   @bug 6852592
   @summary invalidate() must stop when it encounters a validate root
   @author anthony.petrov@sun.com
-  @run main InvalidateMustRespectValidateRoots
+  @run main/othervm -Djava.awt.smartInvalidate=true InvalidateMustRespectValidateRoots
 */
 
 import javax.swing.*;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/Toolkit/Headless/ExceptionContract/ExceptionContract.java	Mon May 16 18:15:42 2011 -0700
@@ -0,0 +1,336 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+  @test
+  @bug 7040577
+  @library ../../../regtesthelpers
+  @build Sysout
+  @summary Default implementation of Toolkit.loadSystemColors(int[]) and many others doesn't throw HE in hl env
+  @author andrei dmitriev: area=awt.headless
+  @run main/othervm -Djava.awt.headless=true ExceptionContract
+*/
+
+import java.awt.*;
+import java.util.Properties;
+import test.java.awt.regtesthelpers.Sysout;
+
+import java.awt.datatransfer.Clipboard;
+import java.awt.dnd.*;
+import java.awt.dnd.peer.DragSourceContextPeer;
+import java.awt.font.TextAttribute;
+import java.awt.im.InputMethodHighlight;
+import java.awt.image.*;
+import java.awt.peer.*;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+
+public class ExceptionContract {
+
+    private static boolean passed = false;
+    public static void main(String[] args)  {
+        //Case1
+        try{
+            new _Toolkit().getLockingKeyState(1);
+        } catch (HeadlessException he){
+            passed = true;
+        }
+        if (!passed){
+            throw new RuntimeException("Tk.getLockingKeyState() didn't throw HeadlessException while in the headless mode.");
+        }
+
+        passed = false;
+        //Case2
+        try{
+            new _Toolkit().setLockingKeyState(1, true);
+        } catch (HeadlessException he){
+            passed = true;
+        }
+        if (!passed){
+            throw new RuntimeException("Tk.setLockingKeyState() didn't throw HeadlessException while in the headless mode.");
+        }
+
+        passed = false;
+        //Case3
+        try{
+            new _Toolkit().createCustomCursor(new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB), new Point(0,0), "Custom cursor");
+        } catch (HeadlessException he){
+            he.printStackTrace();
+            passed = true;
+        }
+        if (!passed){
+            throw new RuntimeException("Tk.createCustomCursor(args) didn't throw HeadlessException while in the headless mode.");
+        }
+
+    }
+
+    static class _Toolkit extends Toolkit {
+
+        @Override
+        public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
+            throws IndexOutOfBoundsException, HeadlessException
+        {
+            return super.createCustomCursor(cursor, hotSpot, name);
+        }
+
+
+        @Override
+        public void setLockingKeyState(int keyCode, boolean on) throws UnsupportedOperationException {
+            super.setLockingKeyState(keyCode, on);
+        }
+
+        @Override
+        public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException {
+            return super.getLockingKeyState(keyCode);
+        }
+
+
+        @Override
+        public void loadSystemColors(int[] systemColors) throws HeadlessException {
+            return;
+        }
+
+        @Override
+        protected DesktopPeer createDesktopPeer(Desktop target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected ButtonPeer createButton(Button target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected TextFieldPeer createTextField(TextField target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected LabelPeer createLabel(Label target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected ListPeer createList(List target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected CheckboxPeer createCheckbox(Checkbox target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected ScrollbarPeer createScrollbar(Scrollbar target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected ScrollPanePeer createScrollPane(ScrollPane target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected TextAreaPeer createTextArea(TextArea target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected ChoicePeer createChoice(Choice target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected FramePeer createFrame(Frame target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected CanvasPeer createCanvas(Canvas target) {
+            return null;
+        }
+
+        @Override
+        protected PanelPeer createPanel(Panel target) {
+            return null;
+        }
+
+        @Override
+        protected WindowPeer createWindow(Window target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected DialogPeer createDialog(Dialog target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected MenuBarPeer createMenuBar(MenuBar target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected MenuPeer createMenu(Menu target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected PopupMenuPeer createPopupMenu(PopupMenu target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected MenuItemPeer createMenuItem(MenuItem target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected FileDialogPeer createFileDialog(FileDialog target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected FontPeer getFontPeer(String name, int style) {
+            return null;
+        }
+
+        @Override
+        public Dimension getScreenSize() throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        public int getScreenResolution() throws HeadlessException {
+            return 0;
+        }
+
+        @Override
+        public ColorModel getColorModel() throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        public String[] getFontList() {
+            return new String[0];
+        }
+
+        @Override
+        public FontMetrics getFontMetrics(Font font) {
+            return null;
+        }
+
+        @Override
+        public void sync() {
+
+        }
+
+        @Override
+        public Image getImage(String filename) {
+            return null;
+        }
+
+        @Override
+        public Image getImage(URL url) {
+            return null;
+        }
+
+        @Override
+        public Image createImage(String filename) {
+            return null;
+        }
+
+        @Override
+        public Image createImage(URL url) {
+            return null;
+        }
+
+        @Override
+        public boolean prepareImage(Image image, int width, int height, ImageObserver observer) {
+            return false;
+        }
+
+        @Override
+        public int checkImage(Image image, int width, int height, ImageObserver observer) {
+            return 0;
+        }
+
+        @Override
+        public Image createImage(ImageProducer producer) {
+            return null;
+        }
+
+        @Override
+        public Image createImage(byte[] imagedata, int imageoffset, int imagelength) {
+            return null;
+        }
+
+        @Override
+        public PrintJob getPrintJob(Frame frame, String jobtitle, Properties props) {
+            return null;
+        }
+
+        @Override
+        public void beep() {
+
+        }
+
+        @Override
+        public Clipboard getSystemClipboard() throws HeadlessException {
+            return null;
+        }
+
+        @Override
+        protected EventQueue getSystemEventQueueImpl() {
+            return null;
+        }
+
+        @Override
+        public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
+            return null;
+        }
+
+        @Override
+        public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
+            return false;
+        }
+
+        @Override
+        public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType modalExclusionType) {
+            return false;
+        }
+
+        @Override
+        public Map<TextAttribute, ?> mapInputMethodHighlight(InputMethodHighlight highlight) throws HeadlessException {
+            return null;
+        }
+    }
+}