diff --git a/jdk/src/macosx/bin/java_md_macosx.c b/jdk/src/macosx/bin/java_md_macosx.c index 14ae5318e33..4fba1ede4b5 100644 --- a/jdk/src/macosx/bin/java_md_macosx.c +++ b/jdk/src/macosx/bin/java_md_macosx.c @@ -906,11 +906,41 @@ SetXDockArgForAWT(const char *arg) { char envVar[80]; if (strstr(arg, "-Xdock:name=") == arg) { + /* + * The APP_NAME_ environment variable is used to pass + * an application name as specified with the -Xdock:name command + * line option from Java launcher code to the AWT code in order + * to assign this name to the app's dock tile on the Mac. + * The _ part is added to avoid collisions with child processes. + * + * WARNING: This environment variable is an implementation detail and + * isn't meant for use outside of the core platform. The mechanism for + * passing this information from Java launcher to other modules may + * change drastically between update release, and it may even be + * removed or replaced with another mechanism. + * + * NOTE: It is used by SWT, and JavaFX. + */ snprintf(envVar, sizeof(envVar), "APP_NAME_%d", getpid()); setenv(envVar, (arg + 12), 1); } if (strstr(arg, "-Xdock:icon=") == arg) { + /* + * The APP_ICON_ environment variable is used to pass + * an application icon as specified with the -Xdock:icon command + * line option from Java launcher code to the AWT code in order + * to assign this icon to the app's dock tile on the Mac. + * The _ part is added to avoid collisions with child processes. + * + * WARNING: This environment variable is an implementation detail and + * isn't meant for use outside of the core platform. The mechanism for + * passing this information from Java launcher to other modules may + * change drastically between update release, and it may even be + * removed or replaced with another mechanism. + * + * NOTE: It is used by SWT, and JavaFX. + */ snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid()); setenv(envVar, (arg + 12), 1); } @@ -931,6 +961,22 @@ SetMainClassForAWT(JNIEnv *env, jclass mainClass) { NULL_CHECK(mainClassName = (*env)->GetStringUTFChars(env, mainClassString, NULL)); char envVar[80]; + /* + * The JAVA_MAIN_CLASS_ environment variable is used to pass + * the name of a Java class whose main() method is invoked by + * the Java launcher code to start the application, to the AWT code + * in order to assign the name to the Apple menu bar when the app + * is active on the Mac. + * The _ part is added to avoid collisions with child processes. + * + * WARNING: This environment variable is an implementation detail and + * isn't meant for use outside of the core platform. The mechanism for + * passing this information from Java launcher to other modules may + * change drastically between update release, and it may even be + * removed or replaced with another mechanism. + * + * NOTE: It is used by SWT, and JavaFX. + */ snprintf(envVar, sizeof(envVar), "JAVA_MAIN_CLASS_%d", getpid()); setenv(envVar, mainClassName, 1); diff --git a/jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java index e71ee173c50..ebe97745d49 100644 --- a/jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java +++ b/jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java @@ -210,6 +210,15 @@ final class LWTextAreaPeer super(); } + @Override + public void replaceSelection(String content) { + getDocument().removeDocumentListener(LWTextAreaPeer.this); + super.replaceSelection(content); + // post only one text event in this case + postTextEvent(); + getDocument().addDocumentListener(LWTextAreaPeer.this); + } + @Override public boolean hasFocus() { return getTarget().hasFocus(); diff --git a/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java index acc2e298b9c..5884b119261 100644 --- a/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java +++ b/jdk/src/macosx/classes/sun/lwawt/LWTextComponentPeer.java @@ -187,7 +187,7 @@ abstract class LWTextComponentPeerJMenuItem for * Actions added to the JPopupMenu. diff --git a/jdk/src/share/classes/javax/swing/JTable.java b/jdk/src/share/classes/javax/swing/JTable.java index 6314cb0a207..17b6b23d135 100644 --- a/jdk/src/share/classes/javax/swing/JTable.java +++ b/jdk/src/share/classes/javax/swing/JTable.java @@ -5470,7 +5470,7 @@ public class JTable extends JComponent implements TableModelListener, Scrollable if (constructor.getDeclaringClass() == String.class) { value = s; } - super.stopCellEditing(); + return super.stopCellEditing(); } try { diff --git a/jdk/src/share/classes/sun/awt/SunToolkit.java b/jdk/src/share/classes/sun/awt/SunToolkit.java index 19cfdf41711..b63403961a6 100644 --- a/jdk/src/share/classes/sun/awt/SunToolkit.java +++ b/jdk/src/share/classes/sun/awt/SunToolkit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -42,6 +42,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; + +import sun.security.util.SecurityConstants; import sun.util.logging.PlatformLogger; import sun.misc.SoftCache; import sun.font.FontDesignMetrics; @@ -1135,6 +1137,26 @@ public abstract class SunToolkit extends Toolkit return ((mods & InputEvent.ALT_MASK) == (mods & InputEvent.CTRL_MASK)); } + /** + * Returns whether popup is allowed to be shown above the task bar. + * This is a default implementation of this method, which checks + * corresponding security permission. + */ + public boolean canPopupOverlapTaskBar() { + boolean result = true; + try { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission( + SecurityConstants.AWT.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION); + } + } catch (SecurityException se) { + // There is no permission to show popups over the task bar + result = false; + } + return result; + } + /** * Returns a new input method window, with behavior as specified in * {@link java.awt.im.spi.InputMethodContext#createInputMethodWindow}. diff --git a/jdk/src/share/classes/sun/util/logging/PlatformLogger.java b/jdk/src/share/classes/sun/util/logging/PlatformLogger.java index df88de5bdd4..30700a06b0b 100644 --- a/jdk/src/share/classes/sun/util/logging/PlatformLogger.java +++ b/jdk/src/share/classes/sun/util/logging/PlatformLogger.java @@ -516,6 +516,9 @@ public class PlatformLogger { } void doLog(int level, String msg, Object... params) { + if (!isLoggable(level)) { + return; + } // only pass String objects to the j.u.l.Logger which may // be created by untrusted code int len = (params != null) ? params.length : 0; diff --git a/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java index 253fa4d1da0..5a08630acdc 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java @@ -657,10 +657,13 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { } - // TODO : fix this duplicate code - class XAWTCaret extends DefaultCaret { + static class XAWTCaret extends DefaultCaret { public void focusGained(FocusEvent e) { super.focusGained(e); + if (getComponent().isEnabled()){ + // Make sure the cursor is visible in case of non-editable TextArea + super.setVisible(true); + } getComponent().repaint(); } diff --git a/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java index 6e3b78d1498..c67a2be1f5f 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java @@ -578,31 +578,7 @@ public class XTextFieldPeer extends XComponentPeer implements TextFieldPeer { } protected Caret createCaret() { - return new XAWTCaret(); - } - } - - class XAWTCaret extends DefaultCaret { - public void focusGained(FocusEvent e) { - super.focusGained(e); - getComponent().repaint(); - } - - public void focusLost(FocusEvent e) { - super.focusLost(e); - getComponent().repaint(); - } - - // Fix for 5100950: textarea.getSelectedText() returns the de-selected text, on XToolkit - // Restoring Motif behaviour - // If the text is unhighlighted then we should sets the selection range to zero - public void setSelectionVisible(boolean vis) { - if (vis){ - super.setSelectionVisible(vis); - }else{ - // In order to de-select the selection - setDot(getDot()); - } + return new XTextAreaPeer.XAWTCaret(); } } diff --git a/jdk/test/java/awt/Frame/FrameStateTest/FrameStateTest.html b/jdk/test/java/awt/Frame/FrameStateTest/FrameStateTest.html new file mode 100644 index 00000000000..5c88ac2d1d8 --- /dev/null +++ b/jdk/test/java/awt/Frame/FrameStateTest/FrameStateTest.html @@ -0,0 +1,50 @@ + + + + + FrameStateTest + + + +

FrameStateTest
Bug ID: 4157271

+

This test checks that when setState(Frame.ICONIFIED) is called before + setVisible(true) the Frame is shown in the proper iconified state. + The problem was that it did not honor the initial iconic state, but + instead was shown in the NORMAL state.

+

See the dialog box (usually in upper left corner) for instructions

+ + + + diff --git a/jdk/test/java/awt/Frame/FrameStateTest/FrameStateTest.java b/jdk/test/java/awt/Frame/FrameStateTest/FrameStateTest.java new file mode 100644 index 00000000000..33ea9b304ff --- /dev/null +++ b/jdk/test/java/awt/Frame/FrameStateTest/FrameStateTest.java @@ -0,0 +1,459 @@ +/* + * 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 4157271 + @summary Checks that when a Frame is created it honors the state it + was set to. The bug was that if setState(Frame.ICONIFIED) was + called before setVisible(true) the Frame would be shown in NORMAL + state instead of ICONIFIED. + @author JTG East Team: area=awt.Frame + @run applet/manual=yesno FrameStateTest.html +*/ + +/** + * FrameStateTest.java + * + * summary: Checks that when setState(Frame.ICONIFIED) is called before + * setVisible(true) the Frame is shown in the proper iconified state. + * The problem was that it did not honor the initial iconic state, but + * instead was shown in the NORMAL state. + */ + +import java.awt.event.*; +import java.awt.*; +import java.lang.*; +import java.applet.Applet; + + +public class FrameStateTest extends Applet implements ActionListener, ItemListener{ + + Button btnCreate = new Button("Create Frame"); + Button btnDispose = new Button("Dispose Frame"); + CheckboxGroup cbgState = new CheckboxGroup(); + CheckboxGroup cbgResize = new CheckboxGroup(); + Checkbox cbIconState = new Checkbox("Frame state ICONIFIED",cbgState,false); + Checkbox cbNormState = new Checkbox("Frame state NORMAL",cbgState,true); + Checkbox cbNonResize = new Checkbox("Frame Nonresizable",cbgResize,false); + Checkbox cbResize = new Checkbox("Frame Resizable",cbgResize,true); + int iState = 0; + boolean bResize = true; + CreateFrame icontst; + + public void init() { + this.setLayout (new BorderLayout ()); + + String[] instructions = + { + "Steps to try to reproduce this problem:", + "When this test is run an Applet Viewer window will display. In the", + "Applet Viewer window select the different options for the Frame (i.e.", + "{Normal, Non-resizalbe}, {Normal, Resizable}, {Iconified, Resizable},", + "{Iconified, Non-resizalbe}). After chosing the Frame's state click the", + "Create Frame button. After the Frame (Frame State Test (Window2)) comes", + "up make sure the proper behavior occurred (Frame shown in proper state).", + "Click the Dispose button to close the Frame. Do the above steps for all", + "the different Frame state combinations available. If you observe the", + "proper behavior the test has passed, Press the Pass button. Otherwise", + "the test has failed, Press the Fail button.", + "Note: In Frame State Test (Window2) you can also chose the different", + "buttons to see different Frame behavior. An example of a problem that", + "has been seen, With the Frame nonresizable you can not iconify the Frame." + }; + Sysout.createDialogWithInstructions( instructions ); + + btnDispose.setEnabled(false); + add(btnCreate, BorderLayout.NORTH); + add(btnDispose, BorderLayout.SOUTH); + + Panel p = new Panel(new GridLayout(0,1)); + p.add(cbIconState); + p.add(cbResize); + add(p, BorderLayout.WEST); + + p = new Panel(new GridLayout(0,1)); + p.add(cbNormState); + p.add(cbNonResize); + add(p, BorderLayout.EAST); + + // Add Listeners + btnDispose.addActionListener(this); + btnCreate.addActionListener(this); + cbNormState.addItemListener(this); + cbResize.addItemListener(this); + cbIconState.addItemListener(this); + cbNonResize.addItemListener(this); + + resize(600, 200); + + }//End init() + + public void actionPerformed(ActionEvent evt) { + + + if (evt.getSource() == btnCreate) { + btnCreate.setEnabled(false); + btnDispose.setEnabled(true); + icontst = new CreateFrame(iState, bResize); + icontst.show(); + } else if (evt.getSource() == btnDispose) { + btnCreate.setEnabled(true); + btnDispose.setEnabled(false); + icontst.dispose(); + } + } + + public void itemStateChanged(ItemEvent evt) { + + if (cbNormState.getState()) iState = 0; + if (cbIconState.getState()) iState = 1; + if (cbResize.getState()) bResize = true; + if (cbNonResize.getState()) bResize = false; + + } + +}// class FrameStateTest + + +class CreateFrame extends Frame implements ActionListener , WindowListener { + + static int e=0; + static int u=0; + static int p=0; + static int i=0; + static int v=0; + + Button b1, b2, b3, b4, b5, b6, b7; + boolean resizable = true; + boolean iconic = false; + String name = "Frame State Test"; + + CreateFrame (int iFrameState, boolean bFrameResizable) { + + setTitle("Frame State Test (Window 2)"); + + if (iFrameState == 1) { + iconic = true; + } + + if (!(bFrameResizable)) { + resizable = false; + } + + System.out.println("CREATING FRAME - Initially "+ + ((iconic) ? "ICONIFIED" : "NORMAL (NON-ICONIFIED)") + " and " + + ((resizable) ? "RESIZABLE" : "NON-RESIZABLE") ); + + Sysout.println("CREATING FRAME - Initially "+ + ((iconic) ? "ICONIFIED" : "NORMAL (NON-ICONIFIED)") + " and " + + ((resizable) ? "RESIZABLE" : "NON-RESIZABLE") ); + + setLayout(new FlowLayout() ); + b1 = new Button("resizable"); + add(b1); + b2 = new Button("resize"); + add(b2); + b3 = new Button("iconify"); + add(b3); + b4 = new Button("iconify and restore"); + add(b4); + b5 = new Button("hide and show"); + add(b5); + b6 = new Button("hide, iconify and show"); + add(b6); + b7 = new Button("hide, iconify, show, and restore"); + add(b7); + b1.addActionListener(this); + b2.addActionListener(this); + b3.addActionListener(this); + b4.addActionListener(this); + b5.addActionListener(this); + b6.addActionListener(this); + b7.addActionListener(this); + addWindowListener(this); + + setBounds(100,2,200, 200); + setState(iconic ? Frame.ICONIFIED: Frame.NORMAL); + setResizable(resizable); + pack(); + setVisible(true); + + } + + public void actionPerformed ( ActionEvent e ) + { + if ( e.getSource() == b2 ) { + Rectangle r = this.getBounds(); + r.width += 10; + System.out.println(" - button pressed - setting bounds on Frame to: "+r); + setBounds(r); + validate(); + } else if ( e.getSource() == b1 ) { + resizable = !resizable; + System.out.println(" - button pressed - setting Resizable to: "+resizable); + ((Frame)(b1.getParent())).setResizable(resizable); + } else if ( e.getSource() == b3 ) { + System.out.println(" - button pressed - setting Iconic: "); + dolog(); + ((Frame)(b1.getParent())).setState(Frame.ICONIFIED); + dolog(); + } else if ( e.getSource() == b4 ) { + System.out.println(" - button pressed - setting Iconic: "); + dolog(); + ((Frame)(b1.getParent())).setState(Frame.ICONIFIED); + dolog(); + try { + Thread.sleep(1000); + } catch (Exception ex) {}; + System.out.println(" - now restoring: "); + ((Frame)(b1.getParent())).setState(Frame.NORMAL); + dolog(); + } else if ( e.getSource() == b5 ) { + System.out.println(" - button pressed - hiding : "); + dolog(); + ((Frame)(b1.getParent())).setVisible(false); + dolog(); + try { + Thread.sleep(1000); + } catch (Exception ex) {}; + System.out.println(" - now reshowing: "); + ((Frame)(b1.getParent())).setVisible(true); + dolog(); + } else if ( e.getSource() == b6 ) { + System.out.println(" - button pressed - hiding : "); + dolog(); + ((Frame)(b1.getParent())).setVisible(false); + dolog(); + try { + Thread.sleep(1000); + } catch (Exception ex) {}; + System.out.println(" - setting Iconic: "); + dolog(); + ((Frame)(b1.getParent())).setState(Frame.ICONIFIED); + try { + Thread.sleep(1000); + } catch (Exception ex) {}; + System.out.println(" - now reshowing: "); + ((Frame)(b1.getParent())).setVisible(true); + dolog(); + } else if ( e.getSource() == b7 ) { + System.out.println(" - button pressed - hiding : "); + dolog(); + ((Frame)(b1.getParent())).setVisible(false); + dolog(); + try { + Thread.sleep(1000); + } catch (Exception ex) {}; + System.out.println(" - setting Iconic: "); + dolog(); + ((Frame)(b1.getParent())).setState(Frame.ICONIFIED); + try { + Thread.sleep(1000); + } catch (Exception ex) {}; + System.out.println(" - now reshowing: "); + ((Frame)(b1.getParent())).setVisible(true); + dolog(); + try { + Thread.sleep(1000); + } catch (Exception ex) {}; + System.out.println(" - now restoring: "); + ((Frame)(b1.getParent())).setState(Frame.NORMAL); + dolog(); + } + } + + public void windowActivated(WindowEvent e) { + System.out.println(name + " Activated"); + dolog(); + } + public void windowClosed(WindowEvent e) { + System.out.println(name + " Closed"); + dolog(); + } + public void windowClosing(WindowEvent e) { + ((Window)(e.getSource())).dispose(); + System.out.println(name + " Closing"); + dolog(); + } + public void windowDeactivated(WindowEvent e) { + System.out.println(name + " Deactivated"); + dolog(); + } + public void windowDeiconified(WindowEvent e) { + System.out.println(name + " Deiconified"); + dolog(); + } + public void windowIconified(WindowEvent e) { + System.out.println(name + " Iconified"); + dolog(); + } + public void windowOpened(WindowEvent e) { + System.out.println(name + " Opened"); + dolog(); + } + + public void dolog() { + System.out.println(" getState returns: "+getState()); + } +} + +// }// class FrameStateTest + +/**************************************************** + Standard Test Machinery + DO NOT modify anything below -- it's a standard + chunk of code whose purpose is to make user + interaction uniform, and thereby make it simpler + to read and understand someone else's test. + ****************************************************/ + +/** + This is part of the standard test machinery. + It creates a dialog (with the instructions), and is the interface + for sending text messages to the user. + To print the instructions, send an array of strings to Sysout.createDialog + WithInstructions method. Put one line of instructions per array entry. + To display a message for the tester to see, simply call Sysout.println + with the string to be displayed. + This mimics System.out.println but works within the test harness as well + as standalone. + */ + +class Sysout + { + private static TestDialog dialog; + + public static void createDialogWithInstructions( String[] instructions ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + dialog.printInstructions( instructions ); + dialog.show(); + println( "Any messages for the tester will display here." ); + } + + public static void createDialog( ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + String[] defInstr = { "Instructions will appear here. ", "" } ; + dialog.printInstructions( defInstr ); + dialog.show(); + println( "Any messages for the tester will display here." ); + } + + + public static void printInstructions( String[] instructions ) + { + dialog.printInstructions( instructions ); + } + + + public static void println( String messageIn ) + { + dialog.displayMessage( messageIn ); + } + + }// Sysout class + +/** + This is part of the standard test machinery. It provides a place for the + test instructions to be displayed, and a place for interactive messages + to the user to be displayed. + To have the test instructions displayed, see Sysout. + To have a message to the user be displayed, see Sysout. + Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog + { + + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog( Frame frame, String name ) + { + super( frame, name ); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + int scrollNone = TextArea.SCROLLBARS_NONE; + instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); + add( "North", instructionsText ); + + messageText = new TextArea( "", 10, maxStringLength, scrollBoth ); + add("South", messageText); + + pack(); + + show(); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions( String[] instructions ) + { + //Clear out any current instructions + instructionsText.setText( "" ); + + //Go down array of instruction strings + + String printStr, remainingStr; + for( int i=0; i < instructions.length; i++ ) + { + //chop up each into pieces maxSringLength long + remainingStr = instructions[ i ]; + while( remainingStr.length() > 0 ) + { + //if longer than max then chop off first max chars to print + if( remainingStr.length() >= maxStringLength ) + { + //Try to chop on a word boundary + int posOfSpace = remainingStr. + lastIndexOf( ' ', maxStringLength - 1 ); + + if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; + + printStr = remainingStr.substring( 0, posOfSpace + 1 ); + remainingStr = remainingStr.substring( posOfSpace + 1 ); + } + //else just print + else + { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append( printStr + "\n" ); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage( String messageIn ) + { + messageText.append( messageIn + "\n" ); + } + + + }// TestDialog class diff --git a/jdk/test/java/awt/Mouse/EnterExitEvents/DragWindowOutOfFrameTest.java b/jdk/test/java/awt/Mouse/EnterExitEvents/DragWindowOutOfFrameTest.java new file mode 100644 index 00000000000..57637710a16 --- /dev/null +++ b/jdk/test/java/awt/Mouse/EnterExitEvents/DragWindowOutOfFrameTest.java @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2005, 2006, 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 7154048 + * @summary Window created under a mouse does not receive mouse enter event. + * Mouse Entered/Exited events should be generated during dragging the window + * out of the frame and to the frame. + * @library ../../regtesthelpers + * @build Util + * @author alexandr.scherbatiy area=awt.event + * @run main DragWindowOutOfFrameTest + */ +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import java.util.concurrent.*; +import sun.awt.SunToolkit; + +import test.java.awt.regtesthelpers.Util; + +public class DragWindowOutOfFrameTest { + + private static volatile int dragWindowMouseEnteredCount = 0; + private static volatile int dragWindowMouseExitedCount = 0; + private static volatile int dragWindowMouseReleasedCount = 0; + private static volatile int buttonMouseEnteredCount = 0; + private static volatile int buttonMouseExitedCount = 0; + private static volatile int labelMouseEnteredCount = 0; + private static volatile int labelMouseExitedCount = 0; + private static volatile int labelMouseReleasedCount = 0; + private static MyDragWindow dragWindow; + private static JLabel label; + private static JButton button; + + public static void main(String[] args) throws Exception { + + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + Point pointToClick = Util.invokeOnEDT(new Callable() { + + @Override + public Point call() throws Exception { + return getCenterPoint(label); + } + }); + + + robot.mouseMove(pointToClick.x, pointToClick.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + toolkit.realSync(); + + if (dragWindowMouseEnteredCount != 1 && dragWindowMouseExitedCount != 0) { + throw new RuntimeException( + "Wrong number mouse Entered/Exited events on Drag Window!"); + } + + Point pointToDrag = Util.invokeOnEDT(new Callable() { + + @Override + public Point call() throws Exception { + label.addMouseListener(new LabelMouseListener()); + button.addMouseListener(new ButtonMouseListener()); + return getCenterPoint(button); + } + }); + + robot.mouseMove(450, pointToClick.y); + toolkit.realSync(); + + if (labelMouseEnteredCount != 0 && labelMouseExitedCount != 1) { + throw new RuntimeException( + "Wrong number Mouse Entered/Exited events on label!"); + } + + robot.mouseMove(450, pointToDrag.y); + toolkit.realSync(); + + if (labelMouseEnteredCount != 0 && labelMouseExitedCount != 1) { + throw new RuntimeException( + "Wrong number Mouse Entered/Exited events on label!"); + } + + if (buttonMouseEnteredCount != 0 && buttonMouseExitedCount != 0) { + throw new RuntimeException( + "Wrong number Mouse Entered/Exited events on button!"); + } + + robot.mouseMove(pointToDrag.y, pointToDrag.y); + toolkit.realSync(); + + if (buttonMouseEnteredCount != 1 && buttonMouseExitedCount != 0) { + throw new RuntimeException( + "Wrong number Mouse Entered/Exited events on button!"); + } + + robot.mouseRelease(InputEvent.BUTTON1_MASK); + toolkit.realSync(); + + if (labelMouseReleasedCount != 1) { + throw new RuntimeException("No MouseReleased event on label!"); + } + } + + private static Point getCenterPoint(Component comp) { + Point p = comp.getLocationOnScreen(); + Rectangle rect = comp.getBounds(); + return new Point(p.x + rect.width / 2, p.y + rect.height / 2); + } + + private static void createAndShowGUI() { + + JFrame frame = new JFrame("Main Frame"); + frame.setLocation(100, 100); + frame.setSize(300, 200); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + label = new JLabel("Label"); + + DragWindowCreationMouseListener listener = new DragWindowCreationMouseListener(frame); + label.addMouseListener(listener); + label.addMouseMotionListener(listener); + + button = new JButton("Button"); + Panel panel = new Panel(new BorderLayout()); + + panel.add(label, BorderLayout.NORTH); + panel.add(button, BorderLayout.CENTER); + + frame.getContentPane().add(panel); + frame.setVisible(true); + + } + + private static Point getAbsoluteLocation(MouseEvent e) { + return new Point(e.getXOnScreen(), e.getYOnScreen()); + } + + static class MyDragWindow extends Window { + + public MyDragWindow(Window parent, Point location) { + super(parent); + setSize(500, 300); + setVisible(true); + JPanel panel = new JPanel(); + add(panel); + setLocation(location.x - 250, location.y - 150); + addMouseListener(new DragWindowMouseListener()); + } + + void dragTo(Point point) { + setLocation(point.x - 250, point.y - 150); + } + } + + static class DragWindowCreationMouseListener extends MouseAdapter { + + Point origin; + Window parent; + + public DragWindowCreationMouseListener(Window parent) { + this.parent = parent; + } + + @Override + public void mousePressed(MouseEvent e) { + if (dragWindow == null) { + dragWindow = new MyDragWindow(parent, getAbsoluteLocation(e)); + } else { + dragWindow.setVisible(true); + dragWindow.dragTo(getAbsoluteLocation(e)); + } + } + + @Override + public void mouseReleased(MouseEvent e) { + labelMouseReleasedCount++; + if (dragWindow != null) { + dragWindow.setVisible(false); + } + } + + public void mouseDragged(MouseEvent e) { + if (dragWindow != null) { + dragWindow.dragTo(getAbsoluteLocation(e)); + } + } + } + + static class DragWindowMouseListener extends MouseAdapter { + + @Override + public void mouseEntered(MouseEvent e) { + dragWindowMouseEnteredCount++; + } + + @Override + public void mouseExited(MouseEvent e) { + dragWindowMouseExitedCount++; + } + + @Override + public void mouseReleased(MouseEvent e) { + dragWindowMouseReleasedCount++; + } + } + + static class LabelMouseListener extends MouseAdapter { + + @Override + public void mouseEntered(MouseEvent e) { + labelMouseEnteredCount++; + } + + @Override + public void mouseExited(MouseEvent e) { + labelMouseExitedCount++; + } + } + + static class ButtonMouseListener extends MouseAdapter { + + @Override + public void mouseEntered(MouseEvent e) { + buttonMouseEnteredCount++; + } + + @Override + public void mouseExited(MouseEvent e) { + buttonMouseExitedCount++; + } + } +} diff --git a/jdk/test/java/awt/Mouse/EnterExitEvents/DragWindowTest.java b/jdk/test/java/awt/Mouse/EnterExitEvents/DragWindowTest.java new file mode 100644 index 00000000000..ccba2bcb7b0 --- /dev/null +++ b/jdk/test/java/awt/Mouse/EnterExitEvents/DragWindowTest.java @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2005, 2006, 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 7154048 + * @summary Window created under a mouse does not receive mouse enter event. + * Mouse Entered/Exited events are wrongly generated during dragging the window + * from one component to another + * @library ../../regtesthelpers + * @build Util + * @author alexandr.scherbatiy area=awt.event + * @run main DragWindowTest + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +import java.util.concurrent.*; +import sun.awt.SunToolkit; + +import test.java.awt.regtesthelpers.Util; + +public class DragWindowTest { + + private static volatile int dragWindowMouseEnteredCount = 0; + private static volatile int dragWindowMouseReleasedCount = 0; + private static volatile int buttonMouseEnteredCount = 0; + private static volatile int labelMouseReleasedCount = 0; + private static MyDragWindow dragWindow; + private static JLabel label; + private static JButton button; + + public static void main(String[] args) throws Exception { + + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + Point pointToClick = Util.invokeOnEDT(new Callable() { + + @Override + public Point call() throws Exception { + return getCenterPoint(label); + } + }); + + + robot.mouseMove(pointToClick.x, pointToClick.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + toolkit.realSync(); + + if (dragWindowMouseEnteredCount != 1) { + throw new RuntimeException("No MouseEntered event on Drag Window!"); + } + + Point pointToDrag = Util.invokeOnEDT(new Callable() { + + @Override + public Point call() throws Exception { + button.addMouseListener(new ButtonMouseListener()); + return getCenterPoint(button); + } + }); + + robot.mouseMove(pointToDrag.x, pointToDrag.y); + toolkit.realSync(); + + if (buttonMouseEnteredCount != 0) { + throw new RuntimeException("Extra MouseEntered event on button!"); + } + + robot.mouseRelease(InputEvent.BUTTON1_MASK); + toolkit.realSync(); + + if (labelMouseReleasedCount != 1) { + throw new RuntimeException("No MouseReleased event on label!"); + } + + } + + private static Point getCenterPoint(Component comp) { + Point p = comp.getLocationOnScreen(); + Rectangle rect = comp.getBounds(); + return new Point(p.x + rect.width / 2, p.y + rect.height / 2); + } + + private static void createAndShowGUI() { + + JFrame frame = new JFrame("Main Frame"); + frame.setSize(300, 200); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + label = new JLabel("Label"); + + LabelMouseListener listener = new LabelMouseListener(frame); + label.addMouseListener(listener); + label.addMouseMotionListener(listener); + + button = new JButton("Button"); + Panel panel = new Panel(new BorderLayout()); + + panel.add(label, BorderLayout.NORTH); + panel.add(button, BorderLayout.CENTER); + + frame.getContentPane().add(panel); + frame.setVisible(true); + + } + + private static Point getAbsoluteLocation(MouseEvent e) { + return new Point(e.getXOnScreen(), e.getYOnScreen()); + } + + static class MyDragWindow extends Window { + + static int d = 30; + + public MyDragWindow(Window parent, Point location) { + super(parent); + setSize(150, 150); + setVisible(true); + JPanel panel = new JPanel(); + add(panel); + setLocation(location.x - d, location.y - d); + addMouseListener(new DragWindowMouseListener()); + } + + void dragTo(Point point) { + setLocation(point.x - d, point.y - d); + } + } + + static class LabelMouseListener extends MouseAdapter { + + Point origin; + Window parent; + + public LabelMouseListener(Window parent) { + this.parent = parent; + } + + @Override + public void mousePressed(MouseEvent e) { + if (dragWindow == null) { + dragWindow = new MyDragWindow(parent, getAbsoluteLocation(e)); + } else { + dragWindow.setVisible(true); + dragWindow.dragTo(getAbsoluteLocation(e)); + } + } + + @Override + public void mouseReleased(MouseEvent e) { + labelMouseReleasedCount++; + if (dragWindow != null) { + dragWindow.setVisible(false); + } + } + + public void mouseDragged(MouseEvent e) { + if (dragWindow != null) { + dragWindow.dragTo(getAbsoluteLocation(e)); + } + } + } + + static class DragWindowMouseListener extends MouseAdapter { + + @Override + public void mouseEntered(MouseEvent e) { + dragWindowMouseEnteredCount++; + } + + @Override + public void mouseReleased(MouseEvent e) { + dragWindowMouseReleasedCount++; + } + } + + static class ButtonMouseListener extends MouseAdapter { + + @Override + public void mouseEntered(MouseEvent e) { + buttonMouseEnteredCount++; + } + } +} diff --git a/jdk/test/java/awt/Mouse/EnterExitEvents/ResizingFrameTest.java b/jdk/test/java/awt/Mouse/EnterExitEvents/ResizingFrameTest.java new file mode 100644 index 00000000000..9a9042b1a70 --- /dev/null +++ b/jdk/test/java/awt/Mouse/EnterExitEvents/ResizingFrameTest.java @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2005, 2006, 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 7154048 + * @summary Programmatically resized window does not receive mouse entered/exited events + * @author alexandr.scherbatiy area=awt.event + * @run main ResizingFrameTest + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import sun.awt.SunToolkit; + +public class ResizingFrameTest { + + private static volatile int mouseEnteredCount = 0; + private static volatile int mouseExitedCount = 0; + private static JFrame frame; + + public static void main(String[] args) throws Exception { + + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(50); + robot.mouseMove(100, 100); + + // create a frame under the mouse cursor + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + createAndShowGUI(); + } + }); + + + toolkit.realSync(); + + if (mouseEnteredCount != 1 || mouseExitedCount != 0) { + throw new RuntimeException("No Mouse Entered/Exited events!"); + } + + // iconify frame + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + frame.setExtendedState(Frame.ICONIFIED); + } + }); + + toolkit.realSync(); + robot.delay(200); + + if (mouseEnteredCount != 1 || mouseExitedCount != 1) { + throw new RuntimeException("No Mouse Entered/Exited events!"); + } + + // deiconify frame + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + frame.setExtendedState(Frame.NORMAL); + } + }); + + toolkit.realSync(); + robot.delay(200); + + if (mouseEnteredCount != 2 || mouseExitedCount != 1) { + throw new RuntimeException("No Mouse Entered/Exited events!"); + } + + // move the mouse out of the frame + robot.mouseMove(500, 500); + toolkit.realSync(); + robot.delay(200); + + if (mouseEnteredCount != 2 || mouseExitedCount != 2) { + throw new RuntimeException("No Mouse Entered/Exited events!"); + } + + // maximize the frame + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + frame.setExtendedState(Frame.MAXIMIZED_BOTH); + } + }); + + toolkit.realSync(); + robot.delay(200); + + if (mouseEnteredCount != 3 || mouseExitedCount != 2) { + throw new RuntimeException("No Mouse Entered/Exited events!"); + } + + + // demaximize the frame + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + frame.setExtendedState(Frame.NORMAL); + } + }); + + toolkit.realSync(); + robot.delay(200); + + if (mouseEnteredCount != 3 || mouseExitedCount != 3) { + throw new RuntimeException("No Mouse Entered/Exited events!"); + + } + + // move the frame under the mouse + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + frame.setLocation(400, 400); + } + }); + + toolkit.realSync(); + robot.delay(200); + + if (mouseEnteredCount != 4 || mouseExitedCount != 3) { + throw new RuntimeException("No Mouse Entered/Exited events!"); + } + + // move the frame out of the mouse + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + frame.setLocation(100, 100); + } + }); + + toolkit.realSync(); + robot.delay(400); + + if (mouseEnteredCount != 4 || mouseExitedCount != 4) { + throw new RuntimeException("No Mouse Entered/Exited events!"); + } + + // enlarge the frame bounds + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + frame.setBounds(100, 100, 800, 800); + } + }); + + toolkit.realSync(); + robot.delay(200); + + if (mouseEnteredCount != 5 || mouseExitedCount != 4) { + throw new RuntimeException("No Mouse Entered/Exited events!"); + } + + // make the frame bounds smaller + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + frame.setBounds(100, 100, 200, 300); + } + }); + + toolkit.realSync(); + robot.delay(400); + + + if (mouseEnteredCount != 5 || mouseExitedCount != 5) { + throw new RuntimeException("No Mouse Entered/Exited events!"); + } + } + + private static void createAndShowGUI() { + + frame = new JFrame("Main Frame"); + frame.setSize(300, 200); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + frame.addMouseListener(new MouseAdapter() { + + @Override + public void mouseEntered(MouseEvent e) { + mouseEnteredCount++; + } + + @Override + public void mouseExited(MouseEvent e) { + mouseExitedCount++; + } + }); + + frame.setVisible(true); + } +} \ No newline at end of file diff --git a/jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java b/jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java new file mode 100644 index 00000000000..188cd3fde86 --- /dev/null +++ b/jdk/test/java/awt/TextArea/TextAreaCaretVisibilityTest/bug7129742.java @@ -0,0 +1,113 @@ +/* + * 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. + */ + +/* + * Portions Copyright (c) 2012 IBM Corporation + */ + + +/* @test + * @bug 7129742 + * @summary Focus in non-editable TextArea is not shown on Linux. + * @author Sean Chou + */ + +import java.awt.FlowLayout; +import java.awt.TextArea; +import java.awt.Toolkit; +import java.lang.reflect.Field; + +import javax.swing.JFrame; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; +import javax.swing.text.DefaultCaret; + +import sun.awt.SunToolkit; + +public class bug7129742 { + + public static DefaultCaret caret = null; + public static JFrame frame = null; + public static boolean fastreturn = false; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + frame = new JFrame("Test"); + TextArea textArea = new TextArea("Non-editable textArea"); + textArea.setEditable(false); + frame.setLayout(new FlowLayout()); + frame.add(textArea); + frame.pack(); + frame.setVisible(true); + + try { + Class XTextAreaPeerClzz = textArea.getPeer().getClass(); + System.out.println(XTextAreaPeerClzz.getName()); + if (!XTextAreaPeerClzz.getName().equals("sun.awt.X11.XTextAreaPeer")) { + fastreturn = true; + return; + } + + Field jtextField = XTextAreaPeerClzz.getDeclaredField("jtext"); + jtextField.setAccessible(true); + JTextArea jtext = (JTextArea)jtextField.get(textArea.getPeer()); + caret = (DefaultCaret) jtext.getCaret(); + + textArea.requestFocusInWindow(); + } catch (NoSuchFieldException | SecurityException + | IllegalArgumentException | IllegalAccessException e) { + /* These exceptions mean the implementation of XTextAreaPeer is + * changed, this testcase is not valid any more, fix it or remove. + */ + frame.dispose(); + throw new RuntimeException("This testcase is not valid any more!"); + } + } + }); + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + try{ + if (fastreturn) { + return; + } + boolean passed = caret.isActive(); + System.out.println("is caret visible : " + passed); + + if (!passed) { + throw new RuntimeException("The test for bug 71297422 failed"); + } + } finally { + frame.dispose(); + } + } + }); + } + +} diff --git a/jdk/test/java/awt/regtesthelpers/Util.java b/jdk/test/java/awt/regtesthelpers/Util.java index 5774e0bb732..42be600eef1 100644 --- a/jdk/test/java/awt/regtesthelpers/Util.java +++ b/jdk/test/java/awt/regtesthelpers/Util.java @@ -600,4 +600,34 @@ public final class Util { time, printEvent); } + + + /** + * Invokes the task on the EDT thread. + * + * @return result of the task + */ + public static T invokeOnEDT(final java.util.concurrent.Callable task) throws Exception { + final java.util.List result = new java.util.ArrayList(1); + final Exception[] exception = new Exception[1]; + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + try { + result.add(task.call()); + } catch (Exception e) { + exception[0] = e; + } + } + }); + + if (exception[0] != null) { + throw exception[0]; + } + + return result.get(0); + } + } diff --git a/jdk/test/javax/swing/JComponent/7154030/bug7154030.java b/jdk/test/javax/swing/JComponent/7154030/bug7154030.java new file mode 100644 index 00000000000..50007435b55 --- /dev/null +++ b/jdk/test/javax/swing/JComponent/7154030/bug7154030.java @@ -0,0 +1,169 @@ +/* + * 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. + */ + +/* + * Portions Copyright (c) 2012 IBM Corporation + */ + +import javax.swing.JButton; +import javax.swing.JDesktopPane; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import sun.awt.SunToolkit; + +import java.awt.AWTException; +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.image.BufferedImage; + +/* @test 1.1 2012/04/12 + * @bug 7154030 + * @summary Swing components fail to hide after calling hide() + * @author Jonathan Lu + * @library ../../regtesthelpers/ + * @build Util + * @run main bug7154030 + */ + +public class bug7154030 { + + private static JButton button = null; + + public static void main(String[] args) throws Exception { + BufferedImage imageInit = null; + + BufferedImage imageShow = null; + + BufferedImage imageHide = null; + + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + + Robot robot = new Robot(); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + JDesktopPane desktop = new JDesktopPane(); + button = new JButton("button"); + JFrame frame = new JFrame(); + + button.setSize(200, 200); + button.setLocation(100, 100); + button.setForeground(Color.RED); + button.setBackground(Color.RED); + button.setOpaque(true); + button.setVisible(false); + desktop.add(button); + + frame.setContentPane(desktop); + frame.setSize(300, 300); + frame.setLocation(0, 0); + frame.setVisible(true); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + } + }); + + toolkit.realSync(); + imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + button.show(); + } + }); + + toolkit.realSync(); + imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); + if (Util.compareBufferedImages(imageInit, imageShow)) { + throw new Exception("Failed to show opaque button"); + } + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + button.hide(); + } + }); + + toolkit.realSync(); + imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); + + if (!Util.compareBufferedImages(imageInit, imageHide)) { + throw new Exception("Failed to hide opaque button"); + } + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + button.setOpaque(false); + button.setBackground(new Color(128, 128, 0)); + button.setVisible(false); + } + }); + + toolkit.realSync(); + imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + button.show(); + } + }); + + toolkit.realSync(); + imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + button.hide(); + } + }); + + if (Util.compareBufferedImages(imageInit, imageShow)) { + throw new Exception("Failed to show non-opaque button"); + } + + toolkit.realSync(); + imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300)); + + if (!Util.compareBufferedImages(imageInit, imageHide)) { + throw new Exception("Failed to hide non-opaque button"); + } + } +} diff --git a/jdk/test/javax/swing/JTable/7055065/bug7055065.java b/jdk/test/javax/swing/JTable/7055065/bug7055065.java new file mode 100644 index 00000000000..119d9a57654 --- /dev/null +++ b/jdk/test/javax/swing/JTable/7055065/bug7055065.java @@ -0,0 +1,178 @@ +/* + * 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. + */ + +/* + * Portions Copyright (c) 2012 IBM Corporation + */ + +/* @test 1.1 2012/04/19 + * @bug 7055065 + * @summary NullPointerException when sorting JTable with empty cell + * @author Jonathan Lu + * @library ../../regtesthelpers/ + * @build Util + * @run main bug7055065 + */ + +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.SwingUtilities; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableModel; +import javax.swing.table.TableRowSorter; +import sun.awt.SunToolkit; +import java.util.concurrent.Callable; + +public class bug7055065 { + + private static JTable table; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + createAndShowUI(); + } + }); + + toolkit.realSync(); + clickCell(robot, 1, 1); + Util.hitKeys(robot, KeyEvent.VK_BACK_SPACE, KeyEvent.VK_BACK_SPACE, + KeyEvent.VK_BACK_SPACE); + + toolkit.realSync(); + clickColumnHeader(robot, 1); + + toolkit.realSync(); + clickColumnHeader(robot, 1); + } + + private static void clickCell(Robot robot, final int row, final int column) + throws Exception { + Point point = Util.invokeOnEDT(new Callable() { + @Override + public Point call() throws Exception { + Rectangle rect = table.getCellRect(row, column, false); + Point point = new Point(rect.x + rect.width / 2, rect.y + + rect.height / 2); + SwingUtilities.convertPointToScreen(point, table); + return point; + } + }); + + robot.mouseMove(point.x, point.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + + private static void clickColumnHeader(Robot robot, final int column) + throws Exception { + Point point = Util.invokeOnEDT(new Callable() { + @Override + public Point call() throws Exception { + Rectangle rect = table.getCellRect(0, column, false); + int headerHeight = table.getTableHeader().getHeight(); + Point point = new Point(rect.x + rect.width / 2, rect.y + - headerHeight / 2); + SwingUtilities.convertPointToScreen(point, table); + return point; + } + }); + + robot.mouseMove(point.x, point.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + + private static void createAndShowUI() { + JFrame frame = new JFrame("SimpleTableDemo"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JPanel newContentPane = new JPanel(); + newContentPane.setOpaque(true); + frame.setContentPane(newContentPane); + + final String[] columnNames = { "String", "Number" }; + final Object[][] data = { { "aaaa", new Integer(1) }, + { "bbbb", new Integer(3) }, { "cccc", new Integer(2) }, + { "dddd", new Integer(4) }, { "eeee", new Integer(5) } }; + table = new JTable(data, columnNames); + + table.setPreferredScrollableViewportSize(new Dimension(500, 400)); + table.setFillsViewportHeight(true); + + TableModel dataModel = new AbstractTableModel() { + + public int getColumnCount() { + return columnNames.length; + } + + public int getRowCount() { + return data.length; + } + + public Object getValueAt(int row, int col) { + return data[row][col]; + } + + public String getColumnName(int column) { + return columnNames[column]; + } + + public Class getColumnClass(int c) { + return getValueAt(0, c).getClass(); + } + + public boolean isCellEditable(int row, int col) { + return col != 5; + } + + public void setValueAt(Object aValue, int row, int column) { + data[row][column] = aValue; + } + }; + table.setModel(dataModel); + TableRowSorter sorter = new TableRowSorter( + dataModel); + table.setRowSorter(sorter); + + JScrollPane scrollPane = new JScrollPane(table); + newContentPane.add(scrollPane); + + frame.pack(); + frame.setLocation(0, 0); + frame.setVisible(true); + } +} diff --git a/jdk/test/javax/swing/JTree/4908142/bug4908142.java b/jdk/test/javax/swing/JTree/4908142/bug4908142.java new file mode 100644 index 00000000000..58cb1ea86f5 --- /dev/null +++ b/jdk/test/javax/swing/JTree/4908142/bug4908142.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2009, 2010, 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 4908142 + * @summary JList doesn't handle search function appropriately + * @author Andrey Pikalev + * @library ../../regtesthelpers + * @build Util + * @run main bug4908142 + */ +import javax.swing.*; +import javax.swing.tree.*; +import java.awt.*; +import java.awt.event.*; +import java.util.concurrent.Callable; +import sun.awt.SunToolkit; + +public class bug4908142 { + + private static JTree tree; + + public static void main(String[] args) throws Exception { + + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(50); + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + tree.requestFocus(); + tree.setSelectionRow(0); + } + }); + + toolkit.realSync(); + + + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_A); + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_A); + robot.keyPress(KeyEvent.VK_D); + robot.keyRelease(KeyEvent.VK_D); + toolkit.realSync(); + + + String sel = Util.invokeOnEDT(new Callable() { + + @Override + public String call() throws Exception { + return tree.getLastSelectedPathComponent().toString(); + } + }); + + if (!"aad".equals(sel)) { + throw new Error("The selected index should be \"aad\", but not " + sel); + } + } + + private static void createAndShowGUI() { + JFrame fr = new JFrame("Test"); + fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + String[] data = {"aaa", "aab", "aac", "aad", "ade", "bba"}; + final DefaultMutableTreeNode root = new DefaultMutableTreeNode(data[0]); + for (int i = 1; i < data.length; i++) { + DefaultMutableTreeNode node = new DefaultMutableTreeNode(data[i]); + root.add(node); + } + + tree = new JTree(root); + + JScrollPane sp = new JScrollPane(tree); + fr.getContentPane().add(sp); + fr.setSize(200, 200); + fr.setVisible(true); + } +} diff --git a/jdk/test/tools/launcher/EnvironmentVariables.java b/jdk/test/tools/launcher/EnvironmentVariables.java new file mode 100644 index 00000000000..06ae701a6c2 --- /dev/null +++ b/jdk/test/tools/launcher/EnvironmentVariables.java @@ -0,0 +1,79 @@ +/* + * 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. + */ + +/* + * see TestSpecialArgs.java + * bug 7131021 + * summary Checks for environment variables set by the launcher + * author anthony.petrov@oracle.com: area=launcher + */ + +public class EnvironmentVariables { + public static void main(String[] args) { + if (args.length != 2) { + throw new RuntimeException("ERROR: two command line arguments expected"); + } + + String name = args[0]; + String expect = args[1]; + String key = null; + + if (!name.endsWith("*")) { + key = name; + } else { + name = name.split("\\*")[0]; + + for (String s : System.getenv().keySet()) { + if (s.startsWith(name)) { + if (key == null) { + key = s; + } else { + System.err.println("WARNING: more variables match: " + s); + } + } + } + + if (key == null) { + throw new RuntimeException("ERROR: unable to find a match for: " + name); + } + } + + System.err.println("Will check the variable named: '" + key + + "' expecting the value: '" + expect + "'"); + + if (!System.getenv().containsKey(key)) { + throw new RuntimeException("ERROR: the variable '" + key + + "' is not present in the environment"); + } + + if (!expect.equals(System.getenv().get(key))) { + throw new RuntimeException("ERROR: expected: '" + expect + + "', got: '" + System.getenv().get(key) + "'"); + } + for (String x : args) { + System.err.print(x + " "); + } + System.err.println("-----> Passed!"); + } +} + diff --git a/jdk/test/tools/launcher/TestHelper.java b/jdk/test/tools/launcher/TestHelper.java index 445efcec3a6..1fdfb431e42 100644 --- a/jdk/test/tools/launcher/TestHelper.java +++ b/jdk/test/tools/launcher/TestHelper.java @@ -21,6 +21,7 @@ * questions. */ +import java.util.Set; import java.io.BufferedReader; import java.io.File; import java.io.FileFilter; @@ -316,19 +317,28 @@ public class TestHelper { } static TestResult doExec(String...cmds) { - return doExec(null, cmds); + return doExec(null, null, cmds); } + static TestResult doExec(Map envToSet, String...cmds) { + return doExec(envToSet, null, cmds); + } /* * A method which executes a java cmd and returns the results in a container */ - static TestResult doExec(Map envToSet, String...cmds) { + static TestResult doExec(Map envToSet, + Set envToRemove, String...cmds) { String cmdStr = ""; for (String x : cmds) { cmdStr = cmdStr.concat(x + " "); } ProcessBuilder pb = new ProcessBuilder(cmds); Map env = pb.environment(); + if (envToRemove != null) { + for (String key : envToRemove) { + env.remove(key); + } + } if (envToSet != null) { env.putAll(envToSet); } diff --git a/jdk/test/tools/launcher/TestSpecialArgs.java b/jdk/test/tools/launcher/TestSpecialArgs.java new file mode 100644 index 00000000000..344869bfbae --- /dev/null +++ b/jdk/test/tools/launcher/TestSpecialArgs.java @@ -0,0 +1,104 @@ +/* + * 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 7124089 7131021 + * @summary Checks for MacOSX specific flags are accepted or rejected, and + * MacOSX platforms specific environment is consistent. + * @compile -XDignore.symbol.file TestSpecialArgs.java EnvironmentVariables.java + * @run main TestSpecialArgs + */ +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class TestSpecialArgs extends TestHelper { + + public static void main(String... args) { + final Map envMap = new HashMap<>(); + envMap.put("_JAVA_LAUNCHER_DEBUG", "true"); + + TestResult tr = doExec(envMap, javaCmd, "-XstartOnFirstThread", "-version"); + if (isMacOSX) { + if (!tr.contains("In same thread")) { + System.out.println(tr); + throw new RuntimeException("Error: not running in the same thread ?"); + } + if (!tr.isOK()) { + System.out.println(tr); + throw new RuntimeException("Error: arg was rejected ????"); + } + } else { + if (tr.isOK()) { + System.out.println(tr); + throw new RuntimeException("Error: argument was accepted ????"); + } + } + + tr = doExec(javaCmd, "-Xdock:/tmp/not-available", "-version"); + if (isMacOSX) { + if (!tr.isOK()) { + System.out.println(tr); + throw new RuntimeException("Error: arg was rejected ????"); + } + } else { + if (tr.isOK()) { + System.out.println(tr); + throw new RuntimeException("Error: argument was accepted ????"); + } + } + // MacOSX specific tests ensue...... + if (!isMacOSX) + return; + Set envToRemove = new HashSet<>(); + Map map = System.getenv(); + for (String s : map.keySet()) { + if (s.startsWith("JAVA_MAIN_CLASS_") + || s.startsWith("APP_NAME_") + || s.startsWith("APP_ICON_")) { + envToRemove.add(s); + } + } + runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(), + "EnvironmentVariables", "JAVA_MAIN_CLASS_*", + "EnvironmentVariables"); + + runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(), + "-Xdock:name=TestAppName", "EnvironmentVariables", + "APP_NAME_*", "TestAppName"); + + runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(), + "-Xdock:icon=TestAppIcon", "EnvironmentVariables", + "APP_ICON_*", "TestAppIcon"); + } + + static void runTest(Set envToRemove, String... args) { + TestResult tr = doExec(null, envToRemove, args); + if (!tr.isOK()) { + System.err.println(tr.toString()); + throw new RuntimeException("Test Fails"); + } + } +}