diff --git a/src/share/classes/java/awt/Window.java b/src/share/classes/java/awt/Window.java index d84049ac0d17216af7ea0f77bf3ab8a882a4c857..5d8f1e6695d81e31e5f7fa37055ef87f7a5b240a 100644 --- a/src/share/classes/java/awt/Window.java +++ b/src/share/classes/java/awt/Window.java @@ -504,6 +504,8 @@ public class Window extends Container implements Accessible { } modalExclusionType = Dialog.ModalExclusionType.NO_EXCLUDE; + + SunToolkit.checkAndSetPolicy(this, false); } /** diff --git a/src/share/classes/java/awt/doc-files/FocusSpec.html b/src/share/classes/java/awt/doc-files/FocusSpec.html index d233019cdd4e0b32986e0df93e7425393a73c907..da27abe8ad04ec411dedbf2675cd16ee0324e65c 100644 --- a/src/share/classes/java/awt/doc-files/FocusSpec.html +++ b/src/share/classes/java/awt/doc-files/FocusSpec.html @@ -894,8 +894,7 @@ not the focused Window and the platform does not support requesting focus across Windows. If the request is denied for this reason, the request is remembered and will be granted when the Window is later focused by the user. Otherwise, the focus change request changes the -focused Window as well. Currently, Microsoft Windows supports cross-Window -focus transfers while Solaris does not. +focused Window as well.

There is no way to determine synchronously whether a focus change request has been granted. Instead, client code must install a diff --git a/src/solaris/classes/sun/awt/X11/XComponentPeer.java b/src/solaris/classes/sun/awt/X11/XComponentPeer.java index a369a7f68310fe9b0316b1cc705d8608940a0e71..6e425513c1c40a13fec3d9ebe2b07582fa095830 100644 --- a/src/solaris/classes/sun/awt/X11/XComponentPeer.java +++ b/src/solaris/classes/sun/awt/X11/XComponentPeer.java @@ -725,7 +725,21 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget XGlobalCursorManager.getCursorManager().updateCursorImmediately(); } - public void pSetCursor(Cursor cursor) { + public final void pSetCursor(Cursor cursor) { + this.pSetCursor(cursor, true); + } + + /* + * The method changes the cursor. + * @param cursor - a new cursor to change to. + * @param ignoreSubComponents - if {@code true} is passed then + * the new cursor will be installed on window. + * if {@code false} is passed then + * subsequent components will try to handle + * this request and install their cursor. + */ + //ignoreSubComponents not used here + public void pSetCursor(Cursor cursor, boolean ignoreSubComponents) { XToolkit.awtLock(); try { long xcursor = XGlobalCursorManager.getCursor(cursor); diff --git a/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java b/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java index 579586ae047b628694176a8d5c85fddc921f1362..c28d9d03e1174226be08fcb6b4c36b0a51a0a567 100644 --- a/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java +++ b/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java @@ -104,7 +104,9 @@ public final class XGlobalCursorManager extends GlobalCursorManager { nativeContainer = new WeakReference(nc); } - ((XComponentPeer)nc_peer).pSetCursor(cur); + //6431076. A subcomponents (a XTextArea in particular) + //may want to override the cursor over some of their parts. + ((XComponentPeer)nc_peer).pSetCursor(cur, false); // in case of grab we do for Swing we need to update keep cursor updated // (we don't need this in case of AWT menus). Window Manager consider // the grabber as a current window and use its cursor. So we need to diff --git a/src/solaris/classes/sun/awt/X11/XSelection.java b/src/solaris/classes/sun/awt/X11/XSelection.java index ea055bf4b64b4471c0f4b23c2146383341408cbb..1ffd1346361e188681ad60a8ebd35c725a107658 100644 --- a/src/solaris/classes/sun/awt/X11/XSelection.java +++ b/src/solaris/classes/sun/awt/X11/XSelection.java @@ -301,13 +301,8 @@ public final class XSelection { } finally { XToolkit.awtUnlock(); } - if (!dataGetter.isExecuted()) { - throw new IOException("Owner timed out"); - } - if (dataGetter.isDisposed()) { - throw new IOException("Owner failed to convert data"); - } + validateDataGetter(dataGetter); // Handle incremental transfer. if (dataGetter.getActualType() == @@ -380,14 +375,7 @@ public final class XSelection { XToolkit.awtUnlock(); } - // The owner didn't respond - terminate the transfer. - if (!incrDataGetter.isExecuted()) { - throw new IOException("Owner timed out"); - } - - if (incrDataGetter.isDisposed()) { - throw new IOException("Owner failed to convert data"); - } + validateDataGetter(dataGetter); if (incrDataGetter.getActualFormat() != 8) { throw new IOException("Unsupported data format: " + @@ -445,6 +433,23 @@ public final class XSelection { return data != null ? data : new byte[0]; } + void validateDataGetter(WindowPropertyGetter propertyGetter) + throws IOException + { + // The order of checks is important because a property getter + // has not been executed in case of timeout as well as in case of + // changed selection owner. + + if (propertyGetter.isDisposed()) { + throw new IOException("Owner failed to convert data"); + } + + // The owner didn't respond - terminate the transfer. + if (!propertyGetter.isExecuted()) { + throw new IOException("Owner timed out"); + } + } + // To be MT-safe this method should be called under awtLock. boolean isOwner() { return isOwner; diff --git a/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java b/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java index 4cbca44224dac76917aa2687a00faa00015955b6..d9cc3033a3b9cc636584e9a3c198bf9603af48d2 100644 --- a/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java +++ b/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java @@ -175,6 +175,34 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { super.dispose(); } + + /* + * The method overrides one from XComponentPeer + * If ignoreSubComponents=={@code true} it calls super. + * If ignoreSubComponents=={@code false} it uses the XTextArea machinery + * to change cursor appropriately. In particular it changes the cursor to + * default if over scrollbars. + */ + @Override + public void pSetCursor(Cursor cursor, boolean ignoreSubComponents) { + Point onScreen = getLocationOnScreen(); + if (ignoreSubComponents || + javaMouseEventHandler == null || + onScreen == null) + { + super.pSetCursor(cursor, true); + return; + } + + Point cursorPos = new Point(); + ((XGlobalCursorManager)XGlobalCursorManager.getCursorManager()).getCursorPos(cursorPos); + + Point localPoint = new Point(cursorPos.x - onScreen.x, cursorPos.y - onScreen.y ); + + javaMouseEventHandler.setPointerToUnderPoint(localPoint); + javaMouseEventHandler.setCursor(); + } + void setScrollBarVisibility() { int visibility = ((TextArea)target).getScrollbarVisibility(); jtext.setLineWrap(false); @@ -1264,13 +1292,13 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { void handle( MouseEvent event ) { if ( ! grabbed ) { // dispatch() needs up-to-date pointer in ungrabbed case. - setPointerToUnderEventPoint( event ); + setPointerToUnderPoint( event.getPoint() ); } dispatch( event ); boolean wasGrabbed = grabbed; grabbed_update( event ); if ( wasGrabbed && ! grabbed ) { - setPointerToUnderEventPoint( event ); + setPointerToUnderPoint( event.getPoint() ); } setCursor(); } @@ -1338,7 +1366,7 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { // 'target.getCursor()' is also applied from elsewhere // (at least now), but only when mouse "entered", and // before 'XTextAreaPeer.handleJavaMouseEvent' is invoked. - outer.pSetCursor( outer.target.getCursor() ); + outer.pSetCursor( outer.target.getCursor(), true ); } else { // We can write here a more intelligent cursor selection @@ -1346,7 +1374,7 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { // However, I see no point in doing so now. But if you feel // like implementing it, you'll probably need to introduce // 'Pointer.Type.PANEL'. - outer.pSetCursor( outer.textPane.getCursor() ); + outer.pSetCursor( outer.textPane.getCursor(), true ); } } @@ -1391,8 +1419,7 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { return l; } - private void setPointerToUnderEventPoint( MouseEvent event ) { - Point point = event.getPoint(); + private void setPointerToUnderPoint( Point point ) { if ( outer.textPane.getViewport().getBounds().contains( point ) ) { current.setText(); } diff --git a/test/java/awt/Container/CheckZOrderChange/CheckZOrderChange.java b/test/java/awt/Container/CheckZOrderChange/CheckZOrderChange.java index 0814b52b25d383d5ef9ed3cdaf504a0099672102..3c06a523b292d7e38a8c8dc0fdd100ccacbb9b5d 100644 --- a/test/java/awt/Container/CheckZOrderChange/CheckZOrderChange.java +++ b/test/java/awt/Container/CheckZOrderChange/CheckZOrderChange.java @@ -1,3 +1,26 @@ +/* + * Copyright (c) 2008, 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 %I% %E% @bug 2161766 diff --git a/test/java/awt/KeyboardFocusmanager/DefaultPolicyChange/DefaultPolicyChange_AWT.java b/test/java/awt/KeyboardFocusmanager/DefaultPolicyChange/DefaultPolicyChange_AWT.java new file mode 100644 index 0000000000000000000000000000000000000000..34b52f0bea0725dd755030c80503d76edb925689 --- /dev/null +++ b/test/java/awt/KeyboardFocusmanager/DefaultPolicyChange/DefaultPolicyChange_AWT.java @@ -0,0 +1,44 @@ +/* + @test + @bug 6741526 + @summary KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy) affects created components + @library ../../regtesthelpers + @build Sysout + @author Andrei Dmitriev : area=awt-focus + @run main DefaultPolicyChange_AWT +*/ + +import java.awt.*; +import test.java.awt.regtesthelpers.Sysout; + +public class DefaultPolicyChange_AWT { + public static void main(String []s) { + DefaultPolicyChange_AWT.runTestAWT(); + } + + private static void runTestAWT(){ + KeyboardFocusManager currentKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + FocusTraversalPolicy defaultFTP = currentKFM.getDefaultFocusTraversalPolicy(); + ContainerOrderFocusTraversalPolicy newFTP = new ContainerOrderFocusTraversalPolicy(); + + Frame frame = new Frame(); + Window window = new Window(frame); + + FocusTraversalPolicy resultFTP = window.getFocusTraversalPolicy(); + Sysout.println("FocusTraversalPolicy on window = " + resultFTP); + /** + * Note: this call doesn't affect already created components as they have + * their policy initialized. Only new components will use this policy as + * their default policy. + **/ + Sysout.println("Now will set another policy."); + currentKFM.setDefaultFocusTraversalPolicy(newFTP); + resultFTP = window.getFocusTraversalPolicy(); + if (!resultFTP.equals(defaultFTP)) { + Sysout.println("Failure! FocusTraversalPolicy should not change"); + Sysout.println("Was: " + defaultFTP); + Sysout.println("Become: " + resultFTP); + throw new RuntimeException("Failure! FocusTraversalPolicy should not change"); + } + } +} diff --git a/test/java/awt/KeyboardFocusmanager/DefaultPolicyChange/DefaultPolicyChange_Swing.java b/test/java/awt/KeyboardFocusmanager/DefaultPolicyChange/DefaultPolicyChange_Swing.java new file mode 100644 index 0000000000000000000000000000000000000000..f0680433644a415df6501670028816e885a19efe --- /dev/null +++ b/test/java/awt/KeyboardFocusmanager/DefaultPolicyChange/DefaultPolicyChange_Swing.java @@ -0,0 +1,69 @@ +/* + @test + @bug 6741526 + @summary KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy) affects created components + @library ../../regtesthelpers + @build Sysout + @author Andrei Dmitriev : area=awt-focus + @run main DefaultPolicyChange_Swing +*/ + +import java.awt.*; +import javax.swing.*; +import javax.swing.table.DefaultTableModel; +import test.java.awt.regtesthelpers.Sysout; + +public class DefaultPolicyChange_Swing { + public static void main(String []s) { + EventQueue.invokeLater(new Runnable(){ + public void run (){ + DefaultPolicyChange_Swing.runTestSwing(); + } + }); + } + private static void runTestSwing(){ + KeyboardFocusManager currentKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + FocusTraversalPolicy defaultFTP = currentKFM.getDefaultFocusTraversalPolicy(); + ContainerOrderFocusTraversalPolicy newFTP = new ContainerOrderFocusTraversalPolicy(); + + + JFrame jf = new JFrame("Test1"); + JWindow jw = new JWindow(jf); + JDialog jd = new JDialog(jf); + JPanel jp1 = new JPanel(); + JButton jb1 = new JButton("jb1"); + JTable jt1 = new JTable(new DefaultTableModel()); + + jf.add(jb1); + jf.add(jt1); + jf.add(jp1); + System.out.println("FTP current on jf= " + jf.getFocusTraversalPolicy()); + System.out.println("FTP current on jw= " + jw.getFocusTraversalPolicy()); + System.out.println("FTP current on jd= " + jd.getFocusTraversalPolicy()); + + if (!(jf.getFocusTraversalPolicy() instanceof LayoutFocusTraversalPolicy) || + !(jw.getFocusTraversalPolicy() instanceof LayoutFocusTraversalPolicy) || + !(jd.getFocusTraversalPolicy() instanceof LayoutFocusTraversalPolicy)) + { + throw new RuntimeException("Failure! Swing toplevel must have LayoutFocusTraversalPolicy installed"); + } + + jf.setVisible(true); + + System.out.println("Now will set another policy."); + currentKFM.setDefaultFocusTraversalPolicy(newFTP); + + FocusTraversalPolicy resultFTP = jw.getFocusTraversalPolicy(); + + System.out.println("FTP current on jf= " + jf.getFocusTraversalPolicy()); + System.out.println("FTP current on jw= " + jw.getFocusTraversalPolicy()); + System.out.println("FTP current on jd= " + jd.getFocusTraversalPolicy()); + + if (!resultFTP.equals(defaultFTP)) { + Sysout.println("Failure! FocusTraversalPolicy should not change"); + Sysout.println("Was: " + defaultFTP); + Sysout.println("Become: " + resultFTP); + throw new RuntimeException("Failure! FocusTraversalPolicy should not change"); + } + } +} diff --git a/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test.java b/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test.java new file mode 100644 index 0000000000000000000000000000000000000000..098fdac7e8cc74fbbd07221e0209b5ca7b0b6157 --- /dev/null +++ b/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test.java @@ -0,0 +1,385 @@ +/* + @test + @bug 6431076 + @summary Mouse cursor must remain DEFAULT over scrollbar when text is typed + @author Andrei Dmitriev: area=TextArea + @run main/manual Test +*/ + +import java.awt.*; +import java.awt.event.*; + +public class Test { + private static void init() { + Frame f = new Frame("Test for cursor"); + final int dim = 100; + String line = ""; + for( int i=0; i 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" ); + System.out.println(messageIn); + } + + //catch presses of the passed and failed buttons. + //simply call the standard pass() or fail() static methods of + //ManualMainTest + public void actionPerformed( ActionEvent e ) + { + if( e.getActionCommand() == "pass" ) + { + Test.pass(); + } + else + { + Test.fail(); + } + } + +}// TestDialog class diff --git a/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test1.java b/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test1.java new file mode 100644 index 0000000000000000000000000000000000000000..24d0670b4c2394c5e0206997c4ba4f4c06f4e721 --- /dev/null +++ b/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test1.java @@ -0,0 +1,386 @@ +/* + @test + @bug 6431076 + @summary Mouse cursor must remain DEFAULT over scrollbar when text is typed + @author Andrei Dmitriev: area=TextArea + @run main/manual Test1 +*/ + +import java.awt.*; +import java.awt.event.*; + +public class Test1 { + private static void init() { + Frame f = new Frame("Test1 for cursor"); + final int dim = 100; + String line = ""; + for( int i=0; i 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" ); + System.out.println(messageIn); + } + + //catch presses of the passed and failed buttons. + //simply call the standard pass() or fail() static methods of + //ManualMainTest + public void actionPerformed( ActionEvent e ) + { + if( e.getActionCommand() == "pass" ) + { + Test1.pass(); + } + else + { + Test1.fail(); + } + } + +}// TestDialog class