--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java Fri Dec 28 18:30:56 2012 -0800
@@ -119,7 +119,9 @@
public void handleWindowFocusEvent(boolean parentWindowActive) {
this.parentWindowActive = parentWindowActive;
- if (focused) {
+ // ignore focus "lost" native request as it may mistakenly
+ // deactivate active window (see 8001161)
+ if (focused && parentWindowActive) {
responder.handleWindowFocusEvent(parentWindowActive, null);
}
}
--- a/jdk/src/share/classes/java/beans/DefaultPersistenceDelegate.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/src/share/classes/java/beans/DefaultPersistenceDelegate.java Fri Dec 28 18:30:56 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2012, 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
@@ -58,7 +58,8 @@
*/
public class DefaultPersistenceDelegate extends PersistenceDelegate {
- private String[] constructor;
+ private static final String[] EMPTY = {};
+ private final String[] constructor;
private Boolean definesEquals;
/**
@@ -67,7 +68,7 @@
* @see #DefaultPersistenceDelegate(java.lang.String[])
*/
public DefaultPersistenceDelegate() {
- this(new String[0]);
+ this.constructor = EMPTY;
}
/**
@@ -92,7 +93,7 @@
* @see #instantiate
*/
public DefaultPersistenceDelegate(String[] constructorPropertyNames) {
- this.constructor = constructorPropertyNames;
+ this.constructor = (constructorPropertyNames == null) ? EMPTY : constructorPropertyNames.clone();
}
private static boolean definesEquals(Class<?> type) {
--- a/jdk/src/share/classes/java/beans/EventSetDescriptor.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/src/share/classes/java/beans/EventSetDescriptor.java Fri Dec 28 18:30:56 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2012, 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
@@ -277,7 +277,9 @@
Method removeListenerMethod)
throws IntrospectionException {
setName(eventSetName);
- this.listenerMethodDescriptors = listenerMethodDescriptors;
+ this.listenerMethodDescriptors = (listenerMethodDescriptors != null)
+ ? listenerMethodDescriptors.clone()
+ : null;
setAddListenerMethod(addListenerMethod);
setRemoveListenerMethod(removeListenerMethod);
setListenerType(listenerType);
@@ -347,7 +349,9 @@
* events are fired.
*/
public synchronized MethodDescriptor[] getListenerMethodDescriptors() {
- return listenerMethodDescriptors;
+ return (this.listenerMethodDescriptors != null)
+ ? this.listenerMethodDescriptors.clone()
+ : null;
}
/**
--- a/jdk/src/share/classes/java/beans/MethodDescriptor.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/src/share/classes/java/beans/MethodDescriptor.java Fri Dec 28 18:30:56 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2012, 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
@@ -70,7 +70,9 @@
ParameterDescriptor parameterDescriptors[]) {
setName(method.getName());
setMethod(method);
- this.parameterDescriptors = parameterDescriptors;
+ this.parameterDescriptors = (parameterDescriptors != null)
+ ? parameterDescriptors.clone()
+ : null;
}
/**
@@ -161,7 +163,9 @@
* a null array if the parameter names aren't known.
*/
public ParameterDescriptor[] getParameterDescriptors() {
- return parameterDescriptors;
+ return (this.parameterDescriptors != null)
+ ? this.parameterDescriptors.clone()
+ : null;
}
/*
--- a/jdk/src/share/classes/java/beans/Statement.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/src/share/classes/java/beans/Statement.java Fri Dec 28 18:30:56 2012 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2012, 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
@@ -92,7 +92,7 @@
public Statement(Object target, String methodName, Object[] arguments) {
this.target = target;
this.methodName = methodName;
- this.arguments = (arguments == null) ? emptyArray : arguments;
+ this.arguments = (arguments == null) ? emptyArray : arguments.clone();
}
/**
@@ -128,7 +128,7 @@
* @return the array of arguments
*/
public Object[] getArguments() {
- return arguments;
+ return this.arguments.clone();
}
/**
--- a/jdk/src/solaris/classes/sun/awt/X11/XBaseWindow.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/src/solaris/classes/sun/awt/X11/XBaseWindow.java Fri Dec 28 18:30:56 2012 -0800
@@ -994,10 +994,7 @@
return;
}
int buttonState = 0;
- final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
- for (int i = 0; i<buttonsNumber; i++){
- buttonState |= (xbe.get_state() & XConstants.buttonsMask[i]);
- }
+ buttonState = xbe.get_state() & XConstants.ALL_BUTTONS_MASK;
switch (xev.get_type()) {
case XConstants.ButtonPress:
if (buttonState == 0) {
@@ -1034,12 +1031,12 @@
* Checks ButtonRelease released all Mouse buttons
*/
static boolean isFullRelease(int buttonState, int button) {
- final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
+ final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
if (button < 0 || button > buttonsNumber) {
return buttonState == 0;
} else {
- return buttonState == XConstants.buttonsMask[button - 1];
+ return buttonState == XlibUtil.getButtonMask(button);
}
}
--- a/jdk/src/solaris/classes/sun/awt/X11/XConstants.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/src/solaris/classes/sun/awt/X11/XConstants.java Fri Dec 28 18:30:56 2012 -0800
@@ -130,6 +130,9 @@
public static final long ColormapChangeMask = (1L<<23) ;
public static final long OwnerGrabButtonMask = (1L<<24) ;
+ public static final int MAX_BUTTONS = 5;
+ public static final int ALL_BUTTONS_MASK = (int) (Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask);
+
/* Event names. Used in "type" field in XEvent structures. Not to be
confused with event masks above. They start from 2 because 0 and 1
are reserved in the protocol for errors and replies. */
@@ -194,34 +197,6 @@
public static final int Mod4MapIndex = 6 ;
public static final int Mod5MapIndex = 7 ;
-
- /* button masks. Used in same manner as Key masks above. Not to be confused
- with button names below. */
- public static final int [] buttonsMask = new int []{ 1<<8,
- 1<<9,
- 1<<10,
- 1<<11,
- 1<<12,
- 1<<13,
- 1<<14,
- 1<<15,
- 1<<16,
- 1<<17,
- 1<<18,
- 1<<19,
- 1<<20,
- 1<<21,
- 1<<22,
- 1<<23,
- 1<<24,
- 1<<25,
- 1<<26,
- 1<<27,
- 1<<28,
- 1<<29,
- 1<<30,
- 1<<31 };
-
public static final int AnyModifier = (1<<15) ; /* used in GrabButton, GrabKey */
--- a/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/src/solaris/classes/sun/awt/X11/XToolkit.java Fri Dec 28 18:30:56 2012 -0800
@@ -1543,6 +1543,10 @@
}
}
+ static int getNumberOfButtonsForMask() {
+ return Math.min(XConstants.MAX_BUTTONS, ((SunToolkit) (Toolkit.getDefaultToolkit())).getNumberOfButtons());
+ }
+
private final static String prefix = "DnD.Cursor.";
private final static String postfix = ".32x32";
private static final String dndPrefix = "DnD.";
--- a/jdk/src/solaris/classes/sun/awt/X11/XWindow.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWindow.java Fri Dec 28 18:30:56 2012 -0800
@@ -596,12 +596,12 @@
/* this is an attempt to refactor button IDs in : MouseEvent, InputEvent, XlibWrapper and XWindow.*/
//reflects a button number similar to MouseEvent.BUTTON1, 2, 3 etc.
- for (int i = 0; i < XConstants.buttonsMask.length; i ++){
+ for (int i = 0; i < XConstants.buttons.length; i ++){
//modifier should be added if :
// 1) current button is now still in PRESSED state (means that user just pressed mouse but not released yet) or
// 2) if Xsystem reports that "state" represents that button was just released. This only happens on RELEASE with 1,2,3 buttons.
// ONLY one of these conditions should be TRUE to add that modifier.
- if (((state & XConstants.buttonsMask[i]) != 0) != (button == XConstants.buttons[i])){
+ if (((state & XlibUtil.getButtonMask(i + 1)) != 0) != (button == XConstants.buttons[i])){
//exclude wheel buttons from adding their numbers as modifiers
if (!wheel_mouse) {
modifiers |= InputEvent.getMaskForButton(i+1);
@@ -689,7 +689,7 @@
if (type == XConstants.ButtonPress) {
//Allow this mouse button to generate CLICK event on next ButtonRelease
- mouseButtonClickAllowed |= XConstants.buttonsMask[lbutton];
+ mouseButtonClickAllowed |= XlibUtil.getButtonMask(lbutton);
XWindow lastWindow = (lastWindowRef != null) ? ((XWindow)lastWindowRef.get()):(null);
/*
multiclick checking
@@ -747,7 +747,7 @@
postEventToEventQueue(me);
if ((type == XConstants.ButtonRelease) &&
- ((mouseButtonClickAllowed & XConstants.buttonsMask[lbutton]) != 0) ) // No up-button in the drag-state
+ ((mouseButtonClickAllowed & XlibUtil.getButtonMask(lbutton)) != 0) ) // No up-button in the drag-state
{
postEventToEventQueue(me = new MouseEvent((Component)getEventSource(),
MouseEvent.MOUSE_CLICKED,
@@ -777,7 +777,7 @@
/* Update the state variable AFTER the CLICKED event post. */
if (type == XConstants.ButtonRelease) {
/* Exclude this mouse button from allowed list.*/
- mouseButtonClickAllowed &= ~XConstants.buttonsMask[lbutton];
+ mouseButtonClickAllowed &= ~ XlibUtil.getButtonMask(lbutton);
}
}
@@ -793,12 +793,12 @@
//this doesn't work for extra buttons because Xsystem is sending state==0 for every extra button event.
// we can't correct it in MouseEvent class as we done it with modifiers, because exact type (DRAG|MOVE)
// should be passed from XWindow.
- final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
+ final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
for (int i = 0; i < buttonsNumber; i++){
// TODO : here is the bug in WM: extra buttons doesn't have state!=0 as they should.
if ((i != 4) && (i != 5)) {
- mouseKeyState = mouseKeyState | (xme.get_state() & XConstants.buttonsMask[i]);
+ mouseKeyState = mouseKeyState | (xme.get_state() & XlibUtil.getButtonMask(i + 1));
}
}
--- a/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java Fri Dec 28 18:30:56 2012 -0800
@@ -2070,12 +2070,12 @@
}
if (isGrabbed()) {
boolean dragging = false;
- final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
+ final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
for (int i = 0; i < buttonsNumber; i++){
// here is the bug in WM: extra buttons doesn't have state!=0 as they should.
if ((i != 4) && (i != 5)){
- dragging = dragging || ((xme.get_state() & XConstants.buttonsMask[i]) != 0);
+ dragging = dragging || ((xme.get_state() & XlibUtil.getButtonMask(i + 1)) != 0);
}
}
// When window is grabbed, all events are dispatched to
--- a/jdk/src/solaris/classes/sun/awt/X11/XlibUtil.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/src/solaris/classes/sun/awt/X11/XlibUtil.java Fri Dec 28 18:30:56 2012 -0800
@@ -396,4 +396,14 @@
return isShapingSupported.booleanValue();
}
+ static int getButtonMask(int button) {
+ // Button indices start with 1. The first bit in the button mask is the 8th.
+ // The state mask does not support button indicies > 5, so we need to
+ // cut there.
+ if (button <= 0 || button > XConstants.MAX_BUTTONS) {
+ return 0;
+ } else {
+ return 1 << (7 + button);
+ }
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/beans/Introspector/Test8005065.java Fri Dec 28 18:30:56 2012 -0800
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2012, 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.
+ *
+ * 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 8005065
+ * @summary Tests that all arrays in JavaBeans are guarded
+ * @author Sergey Malenkov
+ */
+
+import java.beans.DefaultPersistenceDelegate;
+import java.beans.Encoder;
+import java.beans.EventSetDescriptor;
+import java.beans.ExceptionListener;
+import java.beans.Expression;
+import java.beans.Statement;
+import java.beans.MethodDescriptor;
+import java.beans.ParameterDescriptor;
+
+public class Test8005065 {
+
+ public static void main(String[] args) {
+ testDefaultPersistenceDelegate();
+ testEventSetDescriptor();
+ testMethodDescriptor();
+ testStatement();
+ }
+
+ private static void testDefaultPersistenceDelegate() {
+ Encoder encoder = new Encoder();
+ String[] array = { "array" };
+ MyDPD dpd = new MyDPD(array);
+ dpd.instantiate(dpd, encoder);
+ array[0] = null;
+ dpd.instantiate(dpd, encoder);
+ }
+
+ private static void testEventSetDescriptor() {
+ try {
+ MethodDescriptor[] array = { new MethodDescriptor(MyDPD.class.getMethod("getArray")) };
+ EventSetDescriptor descriptor = new EventSetDescriptor(null, null, array, null, null);
+ test(descriptor.getListenerMethodDescriptors());
+ array[0] = null;
+ test(descriptor.getListenerMethodDescriptors());
+ descriptor.getListenerMethodDescriptors()[0] = null;
+ test(descriptor.getListenerMethodDescriptors());
+ }
+ catch (Exception exception) {
+ throw new Error("unexpected error", exception);
+ }
+ }
+
+ private static void testMethodDescriptor() {
+ try {
+ ParameterDescriptor[] array = { new ParameterDescriptor() };
+ MethodDescriptor descriptor = new MethodDescriptor(MyDPD.class.getMethod("getArray"), array);
+ test(descriptor.getParameterDescriptors());
+ array[0] = null;
+ test(descriptor.getParameterDescriptors());
+ descriptor.getParameterDescriptors()[0] = null;
+ test(descriptor.getParameterDescriptors());
+ }
+ catch (Exception exception) {
+ throw new Error("unexpected error", exception);
+ }
+ }
+
+ private static void testStatement() {
+ Object[] array = { new Object() };
+ Statement statement = new Statement(null, null, array);
+ test(statement.getArguments());
+ array[0] = null;
+ test(statement.getArguments());
+ statement.getArguments()[0] = null;
+ test(statement.getArguments());
+ }
+
+ private static <T> void test(T[] array) {
+ if (array.length != 1) {
+ throw new Error("unexpected array length");
+ }
+ if (array[0] == null) {
+ throw new Error("unexpected array content");
+ }
+ }
+
+ public static class MyDPD
+ extends DefaultPersistenceDelegate
+ implements ExceptionListener {
+
+ private final String[] array;
+
+ public MyDPD(String[] array) {
+ super(array);
+ this.array = array;
+ }
+
+ public Expression instantiate(Object instance, Encoder encoder) {
+ encoder.setExceptionListener(this);
+ return super.instantiate(instance, encoder);
+ }
+
+ public String[] getArray() {
+ return this.array;
+ }
+
+ public void exceptionThrown(Exception exception) {
+ throw new Error("unexpected error", exception);
+ }
+ }
+}
--- a/jdk/test/javax/swing/AncestorNotifier/7193219/bug7193219.java Fri Dec 28 18:28:39 2012 -0800
+++ b/jdk/test/javax/swing/AncestorNotifier/7193219/bug7193219.java Fri Dec 28 18:30:56 2012 -0800
@@ -30,6 +30,7 @@
import java.io.*;
import javax.swing.*;
+import javax.swing.plaf.metal.*;
public class bug7193219 {
private static byte[] serializeGUI() {
@@ -73,6 +74,7 @@
}
public static void main(String[] args) throws Exception {
+ UIManager.setLookAndFeel(new MetalLookAndFeel());
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JFrame/4962534/bug4962534.html Fri Dec 28 18:30:56 2012 -0800
@@ -0,0 +1,43 @@
+<html>
+<!--
+ Copyright (c) 2012, 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.
+
+ 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 4962534
+ @summary JFrame dances very badly
+ @author dav@sparc.spb.su area=
+ @run applet bug4962534.html
+ -->
+<head>
+<title> </title>
+</head>
+<body>
+
+<h1>bug4962534<br>Bug ID: 4962534 </h1>
+
+<p> This is an AUTOMATIC test, simply wait for completion </p>
+
+<APPLET CODE="bug4962534.class" WIDTH=200 HEIGHT=200></APPLET>
+</body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JFrame/4962534/bug4962534.java Fri Dec 28 18:30:56 2012 -0800
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 2012, 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.
+ *
+ * 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 4962534 7104594
+ @summary JFrame dances very badly
+ @author dav@sparc.spb.su area=
+ @run applet bug4962534.html
+ */
+import java.applet.Applet;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.Random;
+import javax.swing.*;
+import sun.awt.SunToolkit;
+
+public class bug4962534 extends Applet {
+
+ Robot robot;
+ volatile Point framePosition;
+ volatile Point newFrameLocation;
+ JFrame frame;
+ Rectangle gcBounds;
+ Component titleComponent;
+ JLayeredPane lPane;
+ volatile boolean titleFound = false;
+ SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+ public static Object LOCK = new Object();
+
+ @Override
+ public void init() {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ createAndShowGUI();
+ }
+ });
+ } catch (Exception ex) {
+ throw new RuntimeException("Init failed. " + ex.getMessage());
+ }
+ }//End init()
+
+ @Override
+ public void start() {
+ validate();
+
+ try {
+ setJLayeredPaneEDT();
+ setTitleComponentEDT();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new RuntimeException("Test failed. " + ex.getMessage());
+ }
+
+ if (!titleFound) {
+ throw new RuntimeException("Test Failed. Unable to determine title's size.");
+ }
+
+ Random r = new Random();
+
+ for (int iteration = 0; iteration < 10; iteration++) {
+ try {
+ setFramePosEDT();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new RuntimeException("Test failed.");
+ }
+ try {
+ robot = new Robot();
+ robot.setAutoDelay(70);
+
+ toolkit.realSync();
+
+ robot.mouseMove(framePosition.x + getJFrameWidthEDT() / 2,
+ framePosition.y + titleComponent.getHeight() / 2);
+ robot.mousePress(InputEvent.BUTTON1_MASK);
+
+ toolkit.realSync();
+
+ gcBounds =
+ GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getConfigurations()[0].getBounds();
+
+ robot.mouseMove(framePosition.x + getJFrameWidthEDT() / 2,
+ framePosition.y + titleComponent.getHeight() / 2);
+
+ toolkit.realSync();
+
+ int multier = gcBounds.height / 2 - 10; //we will not go out the borders
+ for (int i = 0; i < 10; i++) {
+ robot.mouseMove(gcBounds.width / 2 - (int) (r.nextDouble() * multier), gcBounds.height / 2 - (int) (r.nextDouble() * multier));
+ }
+ robot.mouseRelease(InputEvent.BUTTON1_MASK);
+
+ toolkit.realSync();
+
+ } catch (AWTException e) {
+ throw new RuntimeException("Test Failed. AWTException thrown." + e.getMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException("Test Failed.");
+ }
+ System.out.println("Mouse lies in " + MouseInfo.getPointerInfo().getLocation());
+ boolean frameIsOutOfScreen = false;
+ try {
+ setNewFrameLocationEDT();
+ System.out.println("Now Frame lies in " + newFrameLocation);
+ frameIsOutOfScreen = checkFrameIsOutOfScreenEDT();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new RuntimeException("Test Failed.");
+ }
+
+ if (frameIsOutOfScreen) {
+ throw new RuntimeException("Test failed. JFrame is out of screen.");
+ }
+
+ } //for iteration
+ System.out.println("Test passed.");
+ }// start()
+
+ private void createAndShowGUI() {
+ try {
+ UIManager.setLookAndFeel(
+ "javax.swing.plaf.metal.MetalLookAndFeel");
+ } catch (Exception ex) {
+ throw new RuntimeException(ex.getMessage());
+ }
+ JFrame.setDefaultLookAndFeelDecorated(true);
+ frame = new JFrame("JFrame Dance Test");
+ frame.pack();
+ frame.setSize(450, 260);
+ frame.setVisible(true);
+ }
+
+ private void setJLayeredPaneEDT() throws Exception {
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ lPane = frame.getLayeredPane();
+ System.out.println("JFrame's LayeredPane " + lPane);
+ }
+ });
+ }
+
+ private void setTitleComponentEDT() throws Exception {
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ for (int j = 0; j < lPane.getComponentsInLayer(JLayeredPane.FRAME_CONTENT_LAYER.intValue()).length; j++) {
+ titleComponent = lPane.getComponentsInLayer(JLayeredPane.FRAME_CONTENT_LAYER.intValue())[j];
+ if (titleComponent.getClass().getName().equals("javax.swing.plaf.metal.MetalTitlePane")) {
+ titleFound = true;
+ break;
+ }
+ }
+ }
+ });
+ }
+
+ private void setFramePosEDT() throws Exception {
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ framePosition = frame.getLocationOnScreen();
+ }
+ });
+ }
+
+ private boolean checkFrameIsOutOfScreenEDT() throws Exception {
+
+ final boolean[] result = new boolean[1];
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ if (newFrameLocation.x > gcBounds.width || newFrameLocation.x < 0
+ || newFrameLocation.y > gcBounds.height || newFrameLocation.y
+ < 0) {
+ result[0] = true;
+ }
+ }
+ });
+ return result[0];
+ }
+
+ private void setNewFrameLocationEDT() throws Exception {
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ newFrameLocation = new Point(frame.getLocationOnScreen().x
+ + frame.getWidth() / 2, frame.getLocationOnScreen().y + titleComponent.getHeight() / 2);
+ }
+ });
+ }
+
+ private int getJFrameWidthEDT() throws Exception {
+
+ final int[] result = new int[1];
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ result[0] = frame.getWidth();
+ }
+ });
+
+ return result[0];
+ }
+}// class