--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPrinterJob.java Wed Feb 13 17:55:44 2013 -0800
@@ -30,6 +30,8 @@
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.print.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import javax.print.*;
import javax.print.attribute.PrintRequestAttributeSet;
@@ -47,6 +49,8 @@
private static String sShouldNotReachHere = "Should not reach here.";
+ private volatile SecondaryLoop printingLoop;
+
private boolean noDefaultPrinter = false;
private static Font defaultFont;
@@ -160,11 +164,22 @@
volatile boolean onEventThread;
+ @Override
+ protected void cancelDoc() throws PrinterAbortException {
+ super.cancelDoc();
+ if (printingLoop != null) {
+ printingLoop.exit();
+ }
+ }
+
private void completePrintLoop() {
Runnable r = new Runnable() { public void run() {
synchronized(this) {
performingPrinting = false;
}
+ if (printingLoop != null) {
+ printingLoop.exit();
+ }
}};
if (onEventThread) {
@@ -219,17 +234,21 @@
onEventThread = true;
+ printingLoop = AccessController.doPrivileged(new PrivilegedAction<SecondaryLoop>() {
+ @Override
+ public SecondaryLoop run() {
+ return Toolkit.getDefaultToolkit()
+ .getSystemEventQueue()
+ .createSecondaryLoop();
+ }
+ });
+
try {
// Fire off the print rendering loop on the AppKit thread, and don't have
// it wait and block this thread.
if (printLoop(false, firstPage, lastPage)) {
- // Fire off the EventConditional that will what until the condition is met,
- // but will still process AWTEvent's as they occur.
- new EventDispatchAccess() {
- public boolean evaluate() {
- return performingPrinting;
- }
- }.pumpEventsAndWait();
+ // Start a secondary loop on EDT until printing operation is finished or cancelled
+ printingLoop.enter();
}
} catch (Exception e) {
e.printStackTrace();
@@ -253,6 +272,9 @@
performingPrinting = false;
notify();
}
+ if (printingLoop != null) {
+ printingLoop.exit();
+ }
}
// Normalize the collated, # copies, numPages, first/last pages. Need to
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/EventDispatchAccess.java Wed Feb 13 15:06:47 2013 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-/*
- * 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.
- */
-
-package sun.lwawt.macosx;
-
-// This exists strictly to work around the fact that java.awt.Conditional isn't a public class.
-// It uses java reflection to get the EventDispatchThread class and call a MacOSX only
-// method on it.
-//
-// NOTE: This uses reflection in its implementation, so it is not for performance critical code.
-//
-// See java.awt.EventDispatchThread and apple.awt.CPrintJob for more.
-//
-public abstract class EventDispatchAccess {
- public native void pumpEventsAndWait();
- public abstract boolean evaluate();
-}
--- a/jdk/src/macosx/lib/flavormap.properties Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/src/macosx/lib/flavormap.properties Wed Feb 13 17:55:44 2013 -0800
@@ -1,7 +1,7 @@
#
# This properties file is used to initialize the default
-# java.awt.datatransfer.SystemFlavorMap. It contains the X11 platform-specific,
-# default mappings between common X11 selection atoms and platform-independent
+# java.awt.datatransfer.SystemFlavorMap. It contains the Mac OS X platform-specific,
+# default mappings between common Mac OS X selection atoms and platform-independent
# MIME type strings, which will be converted into
# java.awt.datatransfer.DataFlavors.
#
@@ -76,3 +76,5 @@
text/uri-list=application/x-java-file-list;class=java.util.List
PNG=image/x-java-image;class=java.awt.Image
JFIF=image/x-java-image;class=java.awt.Image
+RICH_TEXT=text/rtf
+HTML=text/html;charset=utf-8;eoln="\r\n";terminators=1
--- a/jdk/src/macosx/native/sun/awt/CPrinterJob.m Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/src/macosx/native/sun/awt/CPrinterJob.m Wed Feb 13 17:55:44 2013 -0800
@@ -384,31 +384,6 @@
}
/*
- * Class: sun_lwawt_macosx_EventDispatchAccess
- * Method: pumpEventsAndWait
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_sun_lwawt_macosx_EventDispatchAccess_pumpEventsAndWait
-(JNIEnv *env, jobject eda)
-{
- static JNF_CLASS_CACHE(jc_Thread, "java/lang/Thread");
- static JNF_STATIC_MEMBER_CACHE(jm_currentThread, jc_Thread, "currentThread", "()Ljava/lang/Thread;");
- static JNF_CLASS_CACHE(jc_EventDispatchThread, "java/awt/EventDispatchThread");
- static JNF_MEMBER_CACHE(jm_macosxGetConditional, jc_EventDispatchThread, "_macosxGetConditional", "(Ljava/lang/Object;)Ljava/awt/Conditional;");
- static JNF_MEMBER_CACHE(jm_pumpEvents, jc_EventDispatchThread, "pumpEvents", "(Ljava/awt/Conditional;)V");
-
-JNF_COCOA_DURING(env);
-
- jobject thread = JNFCallStaticObjectMethod(env, jm_currentThread);
- jobject conditional = JNFCallObjectMethod(env, thread, jm_macosxGetConditional, eda);
- if (conditional != NULL) {
- JNFCallVoidMethod(env, thread, jm_pumpEvents, conditional);
- }
-
-JNF_COCOA_HANDLE(env);
-}
-
-/*
* Class: sun_lwawt_macosx_CPrinterJob
* Method: abortDoc
* Signature: ()V
--- a/jdk/src/share/classes/java/awt/EventDispatchThread.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/src/share/classes/java/awt/EventDispatchThread.java Wed Feb 13 17:55:44 2013 -0800
@@ -107,34 +107,6 @@
}
}
- // MacOSX change:
- // This was added because this class (and java.awt.Conditional) are package private.
- // There are certain instances where classes in other packages need to block the
- // AWTEventQueue while still allowing it to process events. This uses reflection
- // to call back into the caller in order to remove dependencies.
- //
- // NOTE: This uses reflection in its implementation, so it is not for performance critical code.
- //
- // cond is an instance of sun.lwawt.macosx.EventDispatchAccess
- //
- private Conditional _macosxGetConditional(final Object cond) {
- try {
- return new Conditional() {
- final Method evaluateMethod = Class.forName("sun.lwawt.macosx.EventDispatchAccess").getMethod("evaluate", null);
- public boolean evaluate() {
- try {
- return ((Boolean)evaluateMethod.invoke(cond, null)).booleanValue();
- } catch (Exception e) {
- return false;
- }
- }
- };
- } catch (Exception e) {
- return new Conditional() { public boolean evaluate() { return false; } };
- }
- }
-
-
void pumpEvents(Conditional cond) {
pumpEvents(ANY_EVENT, cond);
}
--- a/jdk/src/share/classes/javax/swing/JMenuBar.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/src/share/classes/javax/swing/JMenuBar.java Wed Feb 13 17:55:44 2013 -0800
@@ -70,7 +70,14 @@
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
- *
+ * <p>
+ * <strong>Warning:</strong>
+ * By default, pressing the Tab key does not transfer focus from a <code>
+ * JMenuBar</code> which is added to a container together with other Swing
+ * components, because the <code>focusTraversalKeysEnabled</code> property
+ * of <code>JMenuBar</code> is set to <code>false</code>. To resolve this,
+ * you should call the <code>JMenuBar.setFocusTraversalKeysEnabled(true)</code>
+ * method.
* @beaninfo
* attribute: isContainer true
* description: A container for holding and displaying menus.
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java Wed Feb 13 17:55:44 2013 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, 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
@@ -1120,7 +1120,9 @@
listBox.setSelectedIndex( si + 1 );
listBox.ensureIndexIsVisible( si + 1 );
if ( !isTableCellEditor ) {
- comboBox.setSelectedIndex(si+1);
+ if (!(UIManager.getBoolean("ComboBox.noActionOnKeyNavigation") && comboBox.isPopupVisible())) {
+ comboBox.setSelectedIndex(si+1);
+ }
}
comboBox.repaint();
}
@@ -1144,7 +1146,9 @@
listBox.setSelectedIndex( si - 1 );
listBox.ensureIndexIsVisible( si - 1 );
if ( !isTableCellEditor ) {
- comboBox.setSelectedIndex(si-1);
+ if (!(UIManager.getBoolean("ComboBox.noActionOnKeyNavigation") && comboBox.isPopupVisible())) {
+ comboBox.setSelectedIndex(si-1);
+ }
}
comboBox.repaint();
}
@@ -1490,7 +1494,13 @@
key == HOME || key == END) {
int index = getNextIndex(comboBox, key);
if (index >= 0 && index < comboBox.getItemCount()) {
- comboBox.setSelectedIndex(index);
+ if (UIManager.getBoolean("ComboBox.noActionOnKeyNavigation") && comboBox.isPopupVisible()) {
+ ui.listBox.setSelectedIndex(index);
+ ui.listBox.ensureIndexIsVisible(index);
+ comboBox.repaint();
+ } else {
+ comboBox.setSelectedIndex(index);
+ }
}
}
else if (key == DOWN) {
@@ -1558,22 +1568,33 @@
else if (key == ENTER) {
if (comboBox.isPopupVisible()) {
- // Forces the selection of the list item
- boolean isEnterSelectablePopup =
- UIManager.getBoolean("ComboBox.isEnterSelectablePopup");
- if (!comboBox.isEditable() || isEnterSelectablePopup
- || ui.isTableCellEditor) {
+ // If ComboBox.noActionOnKeyNavigation is set,
+ // forse selection of list item
+ if (UIManager.getBoolean("ComboBox.noActionOnKeyNavigation")) {
Object listItem = ui.popup.getList().getSelectedValue();
if (listItem != null) {
- // Use the selected value from popup
- // to set the selected item in combo box,
- // but ensure before that JComboBox.actionPerformed()
- // won't use editor's value to set the selected item
comboBox.getEditor().setItem(listItem);
comboBox.setSelectedItem(listItem);
}
+ comboBox.setPopupVisible(false);
+ } else {
+ // Forces the selection of the list item
+ boolean isEnterSelectablePopup =
+ UIManager.getBoolean("ComboBox.isEnterSelectablePopup");
+ if (!comboBox.isEditable() || isEnterSelectablePopup
+ || ui.isTableCellEditor) {
+ Object listItem = ui.popup.getList().getSelectedValue();
+ if (listItem != null) {
+ // Use the selected value from popup
+ // to set the selected item in combo box,
+ // but ensure before that JComboBox.actionPerformed()
+ // won't use editor's value to set the selected item
+ comboBox.getEditor().setItem(listItem);
+ comboBox.setSelectedItem(listItem);
+ }
+ }
+ comboBox.setPopupVisible(false);
}
- comboBox.setPopupVisible(false);
}
else {
// Hide combo box if it is a table cell editor
@@ -1604,14 +1625,20 @@
}
private int getNextIndex(JComboBox comboBox, String key) {
+ int listHeight = comboBox.getMaximumRowCount();
+
+ int selectedIndex = comboBox.getSelectedIndex();
+ if (UIManager.getBoolean("ComboBox.noActionOnKeyNavigation")
+ && (comboBox.getUI() instanceof BasicComboBoxUI)) {
+ selectedIndex = ((BasicComboBoxUI) comboBox.getUI()).listBox.getSelectedIndex();
+ }
+
if (key == PAGE_UP) {
- int listHeight = comboBox.getMaximumRowCount();
- int index = comboBox.getSelectedIndex() - listHeight;
+ int index = selectedIndex - listHeight;
return (index < 0 ? 0: index);
}
else if (key == PAGE_DOWN) {
- int listHeight = comboBox.getMaximumRowCount();
- int index = comboBox.getSelectedIndex() + listHeight;
+ int index = selectedIndex + listHeight;
int max = comboBox.getItemCount();
return (index < max ? index: max-1);
}
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java Wed Feb 13 17:55:44 2013 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, 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
@@ -861,6 +861,7 @@
"END", "endPassThrough",
"ENTER", "enterPressed"
}),
+ "ComboBox.noActionOnKeyNavigation", Boolean.FALSE,
// *** FileChooser
--- a/jdk/src/share/classes/sun/awt/im/CompositionAreaHandler.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/src/share/classes/sun/awt/im/CompositionAreaHandler.java Wed Feb 13 17:55:44 2013 -0800
@@ -33,6 +33,7 @@
import java.awt.font.TextAttribute;
import java.awt.font.TextHitInfo;
import java.awt.im.InputMethodRequests;
+import java.lang.ref.WeakReference;
import java.text.AttributedCharacterIterator;
import java.text.AttributedCharacterIterator.Attribute;
import java.text.AttributedString;
@@ -55,7 +56,7 @@
private AttributedCharacterIterator composedText;
private TextHitInfo caret = null;
- private Component clientComponent = null;
+ private WeakReference<Component> clientComponent = new WeakReference<>(null);
private InputMethodContext inputMethodContext;
/**
@@ -76,8 +77,9 @@
}
// If the client component is an active client using below-the-spot style, then
// make the composition window undecorated without a title bar.
- if(clientComponent!=null){
- InputMethodRequests req = clientComponent.getInputMethodRequests();
+ Component client = clientComponent.get();
+ if(client != null){
+ InputMethodRequests req = client.getInputMethodRequests();
if (req != null && inputMethodContext.useBelowTheSpotInput()) {
setCompositionAreaUndecorated(true);
}
@@ -86,7 +88,7 @@
}
void setClientComponent(Component clientComponent) {
- this.clientComponent = clientComponent;
+ this.clientComponent = new WeakReference<>(clientComponent);
}
/**
@@ -256,8 +258,9 @@
* the composed text are forwarded to the client component.
*/
InputMethodRequests getClientInputMethodRequests() {
- if (clientComponent != null) {
- return clientComponent.getInputMethodRequests();
+ Component client = clientComponent.get();
+ if (client != null) {
+ return client.getInputMethodRequests();
}
return null;
--- a/jdk/src/solaris/classes/sun/awt/X11/XIconWindow.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/src/solaris/classes/sun/awt/X11/XIconWindow.java Wed Feb 13 17:55:44 2013 -0800
@@ -92,7 +92,7 @@
}
XIconSize[] sizeList = getIconSizes();
- log.finest("Icon sizes: {0}", sizeList);
+ log.finest("Icon sizes: {0}", (Object[]) sizeList);
if (sizeList == null) {
// No icon sizes so we simply fall back to 16x16
return new Dimension(16, 16);
--- a/jdk/src/solaris/classes/sun/awt/X11InputMethod.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/src/solaris/classes/sun/awt/X11InputMethod.java Wed Feb 13 17:55:44 2013 -0800
@@ -57,6 +57,7 @@
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
+import java.lang.ref.WeakReference;
import sun.util.logging.PlatformLogger;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
@@ -104,7 +105,7 @@
//reset the XIC if necessary
private boolean needResetXIC = false;
- private Component needResetXICClient = null;
+ private WeakReference<Component> needResetXICClient = new WeakReference<>(null);
// The use of compositionEnableSupported is to reduce unnecessary
// native calls if set/isCompositionEnabled
@@ -272,14 +273,14 @@
called on the passive client when endComposition is called.
*/
if (needResetXIC && haveActiveClient() &&
- getClientComponent() != needResetXICClient){
+ getClientComponent() != needResetXICClient.get()){
resetXIC();
// needs to reset the last xic focussed component.
lastXICFocussedComponent = null;
isLastXICActive = false;
- needResetXICClient = null;
+ needResetXICClient.clear();
needResetXIC = false;
}
}
@@ -417,7 +418,7 @@
isLastXICActive = false;
resetXIC();
- needResetXICClient = null;
+ needResetXICClient.clear();
needResetXIC = false;
}
}
@@ -478,7 +479,7 @@
disableInputMethod();
if (needResetXIC) {
resetXIC();
- needResetXICClient = null;
+ needResetXICClient.clear();
needResetXIC = false;
}
}
@@ -877,7 +878,7 @@
boolean active = haveActiveClient();
if (active && composedText == null && committedText == null){
needResetXIC = true;
- needResetXICClient = getClientComponent();
+ needResetXICClient = new WeakReference<>(getClientComponent());
return;
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/AbsoluteComponentCenterCalculator.java Wed Feb 13 17:55:44 2013 -0800
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+import java.awt.*;
+
+class AbsoluteComponentCenterCalculator {
+ private AbsoluteComponentCenterCalculator() {
+ }
+
+ public static int calculateXCenterCoordinate(Component component) {
+ return (int) component.getLocationOnScreen().getX() + (component.getWidth() / 2);
+ }
+
+ public static int calculateYCenterCoordinate(Component component) {
+ return (int) component.getLocationOnScreen().getY() + (component.getHeight() / 2);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/DataFlavorSearcher.java Wed Feb 13 17:55:44 2013 -0800
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.FlavorTable;
+import java.awt.datatransfer.SystemFlavorMap;
+import java.util.Arrays;
+
+public class DataFlavorSearcher {
+ static public String[] HTML_NAMES = new String[]{"HTML", "HTML Format"};
+ static public String[] RICH_TEXT_NAMES = new String[]{"RICH_TEXT", "Rich Text Format"};
+
+ static public DataFlavor getByteDataFlavorForNative(String[] nats) {
+ FlavorTable flavorTable = (FlavorTable) SystemFlavorMap.getDefaultFlavorMap();
+
+ for (String nat : nats) {
+ java.util.List<DataFlavor> flavors = flavorTable.getFlavorsForNative(nat);
+ for (DataFlavor flavor : flavors) {
+ if (flavor != null
+ && flavor.getRepresentationClass().equals(byte[].class)) {
+ return flavor;
+ }
+ }
+ }
+ throw new RuntimeException("No data flavor was found for natives: " + Arrays.toString(nats));
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/InterprocessMessages.java Wed Feb 13 17:55:44 2013 -0800
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+interface InterprocessMessages {
+ final static int EXECUTION_IS_SUCCESSFULL = 0;
+ final static int DATA_IS_CORRUPTED = 212;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug.html Wed Feb 13 17:55:44 2013 -0800
@@ -0,0 +1,27 @@
+<html>
+<!--
+
+ @test
+ @bug 8005932
+ @summary Java 7 on mac os x only provides text clipboard formats
+ @author mikhail.cherkasov@oracle.com
+ @library ../../regtesthelpers
+ @library ../../regtesthelpers/process
+ @build Util
+ @build ProcessResults ProcessCommunicator
+
+
+ @run applet/othervm MissedHtmlAndRtfBug.html
+*/>
+<head>
+ <title>Java 7 on mac os x only provides text clipboard formats</title>
+</head>
+<body>
+
+<h1> MissedHtmlAndRtfBug <br>Bug ID: 8005932 </h1>
+
+<p> This is an AUTOMATIC test, simply wait for completion </p>
+
+<APPLET CODE="MissedHtmlAndRtfBug.class" WIDTH=200 HEIGHT=200></APPLET>
+</body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/MissedHtmlAndRtfBug.java Wed Feb 13 17:55:44 2013 -0800
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2013, 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 8005932
+ @summary Java 7 on mac os x only provides text clipboard formats
+ @author mikhail.cherkasov@oracle.com
+ @library ../../regtesthelpers
+ @library ../../regtesthelpers/process
+ @build Util
+ @build ProcessResults ProcessCommunicator
+
+
+ @run applet/othervm MissedHtmlAndRtfBug.html
+*/
+import java.awt.*;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.event.*;
+import java.applet.Applet;
+import java.io.File;
+import java.util.ArrayList;
+
+import test.java.awt.regtesthelpers.process.ProcessCommunicator;
+import test.java.awt.regtesthelpers.process.ProcessResults;
+import test.java.awt.regtesthelpers.Util;
+import sun.awt.OSInfo;
+
+import static java.lang.Thread.sleep;
+
+public class MissedHtmlAndRtfBug extends Applet {
+ public void init() {
+ setLayout(new BorderLayout());
+ }//End init()
+
+ public void start() {
+ if (OSInfo.getOSType() != OSInfo.OSType.MACOSX
+ && OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
+ System.out.println("This test is for Windows and Mac only. Passed.");
+ return;
+ }
+
+ final Frame sourceFrame = new Frame("Source frame");
+ final SourcePanel sourcePanel = new SourcePanel();
+ sourceFrame.add(sourcePanel);
+ sourceFrame.pack();
+ sourceFrame.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ sourceFrame.dispose();
+ }
+ });
+ sourceFrame.setVisible(true);
+
+ Util.waitForIdle(null);
+
+ NextFramePositionCalculator positionCalculator = new NextFramePositionCalculator(sourceFrame);
+
+ ArrayList<String> args = new ArrayList<String>(5);
+ args.add(String.valueOf(positionCalculator.getNextLocationX()));
+ args.add(String.valueOf(positionCalculator.getNextLocationY()));
+ args.add(String.valueOf(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(sourcePanel)));
+ args.add(String.valueOf(AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(sourcePanel)));
+ args.add(concatStrings(DataFlavorSearcher.RICH_TEXT_NAMES));
+
+ ProcessResults processResults =
+// ProcessCommunicator.executeChildProcess(this.getClass(), "/Users/mcherkasov/ws/clipboard/DataFlover/out/production/DataFlover" +
+// " -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 ",
+// args.toArray(new String[0]));
+ ProcessCommunicator.executeChildProcess(this.getClass(),
+ "." + File.separator + System.getProperty("java.class.path"), args.toArray(new String[]{}));
+
+ verifyTestResults(processResults);
+
+ args.set(args.size() - 1, concatStrings(DataFlavorSearcher.HTML_NAMES));
+
+ ProcessCommunicator.executeChildProcess(this.getClass(),
+ "." + File.separator + System.getProperty("java.class.path"), args.toArray(new String[]{}));
+ verifyTestResults(processResults);
+
+
+ }// start()
+
+ private String concatStrings(String[] strings) {
+ StringBuffer result = new StringBuffer("\"");
+ for (int i = 0; i < strings.length; i++) {
+ result.append(strings[i]);
+ result.append(",");
+ }
+ result.append("\"");
+ return result.toString();
+ }
+
+
+ private static void verifyTestResults(ProcessResults processResults) {
+ if (InterprocessMessages.DATA_IS_CORRUPTED ==
+ processResults.getExitValue()) {
+ processResults.printProcessErrorOutput(System.err);
+ throw new RuntimeException("TEST IS FAILED: Target has received" +
+ " corrupted data.");
+ }
+ processResults.verifyStdErr(System.err);
+ processResults.verifyProcessExitValue(System.err);
+ processResults.printProcessStandartOutput(System.out);
+ }
+
+ //We cannot make an instance of the applet without the default constructor
+ public MissedHtmlAndRtfBug() {
+ super();
+ }
+
+ //We need in this constructor to pass frame position between JVMs
+ public MissedHtmlAndRtfBug(Point targetFrameLocation, Point dragSourcePoint, DataFlavor df)
+ throws InterruptedException {
+ final Frame targetFrame = new Frame("Target frame");
+ final TargetPanel targetPanel = new TargetPanel(targetFrame, df);
+ targetFrame.add(targetPanel);
+ targetFrame.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ targetFrame.dispose();
+ }
+ });
+ targetFrame.setLocation(targetFrameLocation);
+ targetFrame.pack();
+ targetFrame.setVisible(true);
+
+ doTest(dragSourcePoint, targetPanel);
+ }
+
+ private void doTest(Point dragSourcePoint, TargetPanel targetPanel) {
+ Util.waitForIdle(null);
+
+ final Robot robot = Util.createRobot();
+
+ robot.mouseMove((int) dragSourcePoint.getX(), (int) dragSourcePoint.getY());
+ try {
+ sleep(100);
+ robot.mousePress(InputEvent.BUTTON1_MASK);
+ sleep(100);
+ robot.mouseRelease(InputEvent.BUTTON1_MASK);
+ sleep(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ Util.drag(robot, dragSourcePoint, new Point(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(targetPanel),
+ AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(targetPanel)),
+ InputEvent.BUTTON1_MASK);
+ }
+
+
+ enum InterprocessArguments {
+ TARGET_FRAME_X_POSITION_ARGUMENT,
+ TARGET_FRAME_Y_POSITION_ARGUMENT,
+ DRAG_SOURCE_POINT_X_ARGUMENT,
+ DRAG_SOURCE_POINT_Y_ARGUMENT,
+ DATA_FLAVOR_NAMES;
+
+ int extractInt(String[] args) {
+ return Integer.parseInt(args[this.ordinal()]);
+ }
+
+ String[] extractStringArray(String[] args) {
+ return args[this.ordinal()].replaceAll("\"", "").split(",");
+ }
+ }
+
+ public static void main(String[] args) {
+ Point dragSourcePoint = new Point(InterprocessArguments.DRAG_SOURCE_POINT_X_ARGUMENT.extractInt(args),
+ InterprocessArguments.DRAG_SOURCE_POINT_Y_ARGUMENT.extractInt(args));
+ Point targetFrameLocation = new Point(InterprocessArguments.TARGET_FRAME_X_POSITION_ARGUMENT.extractInt(args),
+ InterprocessArguments.TARGET_FRAME_Y_POSITION_ARGUMENT.extractInt(args));
+ String[] names = InterprocessArguments.DATA_FLAVOR_NAMES.extractStringArray(args);
+
+ DataFlavor df = DataFlavorSearcher.getByteDataFlavorForNative(names);
+ try {
+ new MissedHtmlAndRtfBug(targetFrameLocation, dragSourcePoint, df);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/MyTransferable.java Wed Feb 13 17:55:44 2013 -0800
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+import java.awt.datatransfer.*;
+import java.io.IOException;
+
+class MyTransferable implements Transferable {
+
+ public static final String TEST_DATA = "<b>Test</b>";
+ private DataFlavor[] dataFlavors;
+
+ public MyTransferable() {
+ dataFlavors = new DataFlavor[]{DataFlavorSearcher.getByteDataFlavorForNative(DataFlavorSearcher.HTML_NAMES),
+ DataFlavorSearcher.getByteDataFlavorForNative(DataFlavorSearcher.RICH_TEXT_NAMES)};
+ }
+
+
+ @Override
+ public DataFlavor[] getTransferDataFlavors() {
+ return dataFlavors;
+ }
+
+ @Override
+ public boolean isDataFlavorSupported(DataFlavor flavor) {
+ for (DataFlavor f : dataFlavors) {
+ if (f.equals(flavor)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public Object getTransferData(DataFlavor flavor)
+ throws UnsupportedFlavorException, IOException {
+ if (isDataFlavorSupported(flavor)) {
+ return TEST_DATA.getBytes("UTF-16");
+ } else {
+ throw new UnsupportedFlavorException(flavor);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/NextFramePositionCalculator.java Wed Feb 13 17:55:44 2013 -0800
@@ -0,0 +1,20 @@
+import java.awt.*;
+
+
+class NextFramePositionCalculator {
+
+ private final Frame currentFrame;
+
+ public NextFramePositionCalculator(Frame currentFrame) {
+ this.currentFrame = currentFrame;
+ }
+
+ public int getNextLocationX() {
+ return currentFrame.getX() + currentFrame.getWidth();
+ }
+
+ public int getNextLocationY() {
+ return currentFrame.getY();
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/SourcePanel.java Wed Feb 13 17:55:44 2013 -0800
@@ -0,0 +1,26 @@
+import java.awt.dnd.DragSource;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.*;
+
+public class SourcePanel extends Panel {
+
+ private final MyDragGestureListener dragGestureListener =
+ new MyDragGestureListener();
+
+ public SourcePanel() {
+ setPreferredSize(new Dimension(200, 200));
+ DragSource defaultDragSource =
+ DragSource.getDefaultDragSource();
+ defaultDragSource.createDefaultDragGestureRecognizer(this,
+ DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
+ setBackground(Color.RED);
+ }
+
+ private class MyDragGestureListener implements DragGestureListener {
+ public void dragGestureRecognized(DragGestureEvent dge) {
+ dge.startDrag(null, new MyTransferable());
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/DataFlavor/MissedHtmlAndRtfBug/TargetPanel.java Wed Feb 13 17:55:44 2013 -0800
@@ -0,0 +1,83 @@
+import java.awt.datatransfer.Transferable;
+import java.awt.dnd.*;
+import java.awt.*;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.IOException;
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class TargetPanel extends Panel implements DropTargetListener {
+
+
+ //private final CustomDropTargetListener dropTargetListener = new CustomDropTargetListener();
+
+ private Frame frame;
+ DataFlavor dataFlavor;
+
+ public TargetPanel(Frame frame, DataFlavor dataFlavor) {
+ this.dataFlavor = dataFlavor;
+ this.frame = frame;
+ setBackground(Color.DARK_GRAY);
+ setPreferredSize(new Dimension(200, 200));
+ setDropTarget(new DropTarget(this, this));
+ }
+
+ public void dragEnter(DropTargetDragEvent dtde) {
+ if (dtde.isDataFlavorSupported(dataFlavor)) {
+ dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
+ }
+ }
+
+ public void dragOver(DropTargetDragEvent dtde) {
+ if (dtde.isDataFlavorSupported(dataFlavor)) {
+ dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
+ }
+ }
+
+ public void dropActionChanged(DropTargetDragEvent dtde) {
+ if (dtde.isDataFlavorSupported(dataFlavor)) {
+ dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
+ }
+ }
+
+ public void dragExit(DropTargetEvent dte) {
+
+ }
+
+ public void drop(DropTargetDropEvent dtde) {
+ dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
+ if (dtde.isDataFlavorSupported(dataFlavor)) {
+ String result = null;
+ try {
+ Transferable t = dtde.getTransferable();
+ byte[] data = (byte[]) dtde.getTransferable().getTransferData(dataFlavor);
+ result = new String(data, "UTF-16");
+ repaint();
+ } catch (UnsupportedFlavorException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ dtde.dropComplete(true);
+
+
+ if (result != null && result.contains(MyTransferable.TEST_DATA)) {
+ System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL);
+ Timer t = new Timer();
+ t.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ System.exit(0);
+ }
+ }, 2000);
+ return;
+
+ }
+ }
+ dtde.rejectDrop();
+ System.err.println(InterprocessMessages.DATA_IS_CORRUPTED);
+ System.exit(InterprocessMessages.DATA_IS_CORRUPTED);
+ }
+
+}
--- a/jdk/test/java/awt/Frame/WindowDragTest/WindowDragTest.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/test/java/awt/Frame/WindowDragTest/WindowDragTest.java Wed Feb 13 17:55:44 2013 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, 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
@@ -23,10 +23,11 @@
/*
@test
- @bug 7128738
+ @bug 7128738 7161759
@summary dragged dialog freezes system on dispose
@author Oleg Pekhovskiy: area=awt.toplevel
@library ../../regtesthelpers
+ @build Util
@run main WindowDragTest
*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/im/memoryleak/InputContextMemoryLeakTest.java Wed Feb 13 17:55:44 2013 -0800
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+import java.awt.FlowLayout;
+import java.awt.Robot;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+import test.java.awt.regtesthelpers.Util;
+
+/*
+ @test
+ @bug 7079260
+ @summary XInputContext leaks memory by needRecetXXIClient field
+ @author Petr Pchelko
+ @library ../../regtesthelpers
+ @build Util
+ @compile InputContextMemoryLeakTest.java
+ @run main/othervm -Xmx20M InputContextMemoryLeakTest
+ */
+public class InputContextMemoryLeakTest {
+
+ private static JFrame frame;
+ private static WeakReference<JTextField> text;
+ private static WeakReference<JPanel> p;
+ private static JButton button;
+
+ public static void init() throws Throwable {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ frame = new JFrame();
+ frame.setLayout(new FlowLayout());
+ JPanel p1 = new JPanel();
+ button = new JButton("Test");
+ p1.add(button);
+ frame.add(p1);
+ text = new WeakReference<JTextField>(new JTextField("Text"));
+ p = new WeakReference<JPanel>(new JPanel(new FlowLayout()));
+ p.get().add(text.get());
+ frame.add(p.get());
+ frame.setBounds(500, 400, 200, 200);
+ frame.setVisible(true);
+ }
+ });
+
+ Util.focusComponent(text.get(), 500);
+ Util.clickOnComp(button, new Robot());
+ //References to objects testes for memory leak are stored in Util.
+ //Need to clean them
+ Util.cleanUp();
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ frame.remove(p.get());
+ }
+ });
+
+ Util.waitForIdle(null);
+ //After the next caret blink it automatically TextField references
+ Thread.sleep(text.get().getCaret().getBlinkRate() * 2);
+ Util.waitForIdle(null);
+ assertGC();
+ }
+
+ public static void assertGC() throws Throwable {
+ List<byte[]> alloc = new ArrayList<byte[]>();
+ int size = 1024 * 10;
+ while (true) {
+ try {
+ alloc.add(new byte[size]);
+ } catch (OutOfMemoryError err) {
+ break;
+ }
+ }
+ alloc = null;
+ if (text.get() != null) {
+ throw new Exception("Test failed: JTextField was not collected");
+ }
+ }
+
+ public static void main(String args[]) throws Throwable {
+ init();
+ }
+}
--- a/jdk/test/java/awt/regtesthelpers/Util.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/test/java/awt/regtesthelpers/Util.java Wed Feb 13 17:55:44 2013 -0800
@@ -463,6 +463,13 @@
return -1;
}
+ //Cleans all the references
+ public static void cleanUp() {
+ apListener = null;
+ fgListener = null;
+ wgfListener = null;
+ }
+
////////////////////////////
// Some stuff to test focus.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JComboBox/4199622/bug4199622.java Wed Feb 13 17:55:44 2013 -0800
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2013, 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 4199622
+ @summary RFE: JComboBox shouldn't send ActionEvents for keyboard navigation
+ @author Vladislav Karnaukhov
+ @run main bug4199622
+*/
+
+import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
+import sun.awt.OSInfo;
+import sun.awt.SunToolkit;
+
+import javax.swing.*;
+import javax.swing.plaf.metal.MetalLookAndFeel;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.lang.reflect.InvocationTargetException;
+
+public class bug4199622 extends JFrame implements ActionListener {
+
+ static final int nElems = 20;
+ static JComboBox<String> cb = null;
+
+ bug4199622(LookAndFeel laf) {
+ super();
+
+ try {
+ UIManager.setLookAndFeel(laf);
+ } catch (UnsupportedLookAndFeelException e) {
+ throw new RuntimeException("Test failed", e);
+ }
+
+ setDefaultCloseOperation(DISPOSE_ON_CLOSE);
+ cb = new JComboBox<>();
+ for (int i = 0; i < nElems; i++) {
+ cb.addItem(String.valueOf(i + 1));
+ }
+ cb.addActionListener(this);
+ add(cb);
+
+ setSize(300, 300);
+ pack();
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (UIManager.getBoolean("ComboBox.noActionOnKeyNavigation") && cb.isPopupVisible()) {
+ throw new RuntimeException("Test failed. actionPerformed generated");
+ }
+ }
+
+ static Robot robot = null;
+ static SunToolkit toolkit = null;
+
+ static void doTest() {
+ if (robot == null) {
+ try {
+ robot = new Robot();
+ robot.setAutoDelay(20);
+ } catch (AWTException e) {
+ throw new RuntimeException("Can't create robot. Test failed", e);
+ }
+ }
+
+ toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+ if (toolkit == null) {
+ throw new RuntimeException("Can't get the toolkit. Test failed");
+ }
+ toolkit.realSync();
+
+ doActualTest();
+
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ cb.hidePopup();
+ cb.setEditable(true);
+ cb.updateUI();
+ }
+ });
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Test failed", e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Test failed", e);
+ }
+
+ toolkit.realSync();
+ doActualTest();
+ }
+
+ static void doActualTest() {
+ UIManager.put("ComboBox.noActionOnKeyNavigation", true);
+ doTestUpDown();
+ UIManager.put("ComboBox.noActionOnKeyNavigation", false);
+ doTestUpDown();
+
+ UIManager.put("ComboBox.noActionOnKeyNavigation", true);
+ doTestPgUpDown();
+ UIManager.put("ComboBox.noActionOnKeyNavigation", false);
+ doTestPgUpDown();
+
+ UIManager.put("ComboBox.noActionOnKeyNavigation", true);
+ doTestHomeEnd();
+ UIManager.put("ComboBox.noActionOnKeyNavigation", false);
+ doTestHomeEnd();
+ }
+
+ static void doTestHomeEnd() {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ cb.hidePopup();
+ cb.setSelectedIndex(0);
+ }
+ });
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Test failed", e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Test failed", e);
+ }
+ toolkit.realSync();
+
+ robot.keyPress(KeyEvent.VK_END);
+ toolkit.realSync();
+ robot.keyPress(KeyEvent.VK_HOME);
+ toolkit.realSync();
+ }
+
+ static void doTestUpDown() {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ cb.hidePopup();
+ cb.setSelectedIndex(0);
+ }
+ });
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Test failed", e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Test failed", e);
+ }
+ toolkit.realSync();
+
+ for (int i = 0; i < nElems; i++) {
+ robot.keyPress(KeyEvent.VK_DOWN);
+ toolkit.realSync();
+ }
+
+ for (int i = 0; i < nElems; i++) {
+ robot.keyPress(KeyEvent.VK_UP);
+ toolkit.realSync();
+ }
+ }
+
+ static void doTestPgUpDown() {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ cb.hidePopup();
+ cb.setSelectedIndex(0);
+ }
+ });
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Test failed", e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Test failed", e);
+ }
+ toolkit.realSync();
+
+ int listHeight = cb.getMaximumRowCount();
+ for (int i = 0; i < nElems; i += listHeight) {
+ robot.keyPress(KeyEvent.VK_PAGE_DOWN);
+ toolkit.realSync();
+ }
+
+ for (int i = 0; i < nElems; i += listHeight) {
+ robot.keyPress(KeyEvent.VK_PAGE_UP);
+ toolkit.realSync();
+ }
+ }
+
+ public static void main(String[] args) {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ bug4199622 test = new bug4199622(new MetalLookAndFeel());
+ test.setVisible(true);
+ }
+ });
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Test failed", e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Test failed", e);
+ }
+ doTest();
+
+ if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ bug4199622 test = new bug4199622(new WindowsLookAndFeel());
+ test.setVisible(true);
+ }
+ });
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Test failed", e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException("Test failed", e);
+ }
+ doTest();
+ }
+ }
+}
--- a/jdk/test/javax/swing/JLabel/6596966/bug6596966.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/test/javax/swing/JLabel/6596966/bug6596966.java Wed Feb 13 17:55:44 2013 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, 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
@@ -24,16 +24,17 @@
/* @test
@bug 6596966
@summary Some JFileChooser mnemonics do not work with sticky keys
+ @library ../../regtesthelpers
+ @build Util
@run main bug6596966
@author Pavel Porvatov
*/
-
-import sun.awt.SunToolkit;
-
-import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
+import java.util.ArrayList;
+import javax.swing.*;
+import sun.awt.SunToolkit;
public class bug6596966 {
private static JFrame frame;
@@ -71,11 +72,14 @@
toolkit.realSync();
- robot.keyPress(KeyEvent.VK_ALT);
+ ArrayList<Integer> keys = Util.getSystemMnemonicKeyCodes();
+ for (int i = 0; i < keys.size(); ++i) {
+ robot.keyPress(keys.get(i));
+ }
+
robot.keyPress(KeyEvent.VK_L);
toolkit.realSync();
-
toolkit.getSystemEventQueue().postEvent(new KeyEvent(label, KeyEvent.KEY_RELEASED,
EventQueue.getMostRecentEventTime(), 0, KeyEvent.VK_L, 'L'));
@@ -90,7 +94,11 @@
}
});
} finally {
- robot.keyRelease(KeyEvent.VK_ALT);
+ robot.keyRelease(KeyEvent.VK_L);
+ for (int i = 0; i < keys.size(); ++i) {
+ robot.keyRelease(keys.get(i));
+ }
+ toolkit.realSync();
}
}
}
--- a/jdk/test/javax/swing/regtesthelpers/Util.java Wed Feb 13 15:06:47 2013 -0800
+++ b/jdk/test/javax/swing/regtesthelpers/Util.java Wed Feb 13 17:55:44 2013 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, 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
@@ -23,11 +23,13 @@
import javax.swing.*;
import java.awt.*;
+import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
+import sun.swing.*;
/**
* <p>This class contains utilities useful for regression testing.
@@ -212,4 +214,33 @@
return result.get(0);
}
+ /**
+ * Gets key codes from system mnemonic key mask
+ * @return key codes list
+ */
+ public static ArrayList<Integer> getSystemMnemonicKeyCodes() {
+ return Util.getKeyCodesFromKeyMask(SwingUtilities2.getSystemMnemonicKeyMask());
+ }
+
+ /**
+ * Gets the key codes list from modifiers
+ * @param modifiers an integer combination of the modifier constants
+ * @return key codes list
+ */
+ public static ArrayList<Integer> getKeyCodesFromKeyMask(int modifiers) {
+ ArrayList<Integer> result = new ArrayList<>();
+ if ((modifiers & InputEvent.CTRL_MASK) != 0) {
+ result.add(KeyEvent.VK_CONTROL);
+ }
+ if ((modifiers & InputEvent.ALT_MASK) != 0) {
+ result.add(KeyEvent.VK_ALT);
+ }
+ if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
+ result.add(KeyEvent.VK_SHIFT);
+ }
+ if ((modifiers & InputEvent.META_MASK) != 0) {
+ result.add(KeyEvent.VK_META);
+ }
+ return result;
+ }
}