From 40d87232e689137e2b4f8e764772f0291ca667cf Mon Sep 17 00:00:00 2001 From: Sean Chou Date: Thu, 16 Feb 2012 17:42:09 +0400 Subject: [PATCH 1/8] 7089914: Focus on image icons are not visible in javaws cache with high contrast mode Reviewed-by: rupashka --- .../plaf/windows/WindowsLookAndFeel.java | 23 +++++- .../plaf/windows/WindowsRadioButtonUI.java | 5 ++ .../7089914/bug7089914.java | 77 +++++++++++++++++++ 3 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 jdk/test/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI/7089914/bug7089914.java diff --git a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java index b8723035a32..6fe38ab7592 100644 --- a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java +++ b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java @@ -55,7 +55,6 @@ import javax.swing.text.DefaultEditorKit; import java.awt.Font; import java.awt.Color; -import java.awt.event.KeyEvent; import java.awt.event.ActionEvent; import java.security.AccessController; @@ -523,6 +522,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel Object ScrollbarBackgroundColor = new DesktopProperty( "win.scrollbar.backgroundColor", table.get("scrollbar")); + Object buttonFocusColor = new FocusColorProperty(); Object TextBackground = new XPColorValue(Part.EP_EDIT, null, Prop.FILLCOLOR, WindowBackgroundColor); @@ -629,7 +629,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel "Button.highlight", ControlHighlightColor, "Button.disabledForeground", InactiveTextColor, "Button.disabledShadow", ControlHighlightColor, - "Button.focus", black, + "Button.focus", buttonFocusColor, "Button.dashedRectGapX", new XPValue(Integer.valueOf(3), Integer.valueOf(5)), "Button.dashedRectGapY", new XPValue(Integer.valueOf(3), Integer.valueOf(4)), "Button.dashedRectGapWidth", new XPValue(Integer.valueOf(6), Integer.valueOf(10)), @@ -652,7 +652,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel "CheckBox.darkShadow", ControlDarkShadowColor, "CheckBox.light", ControlLightColor, "CheckBox.highlight", ControlHighlightColor, - "CheckBox.focus", black, + "CheckBox.focus", buttonFocusColor, "CheckBox.focusInputMap", new UIDefaults.LazyInputMap(new Object[] { "SPACE", "pressed", @@ -1007,7 +1007,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel "RadioButton.darkShadow", ControlDarkShadowColor, "RadioButton.light", ControlLightColor, "RadioButton.highlight", ControlHighlightColor, - "RadioButton.focus", black, + "RadioButton.focus", buttonFocusColor, "RadioButton.focusInputMap", new UIDefaults.LazyInputMap(new Object[] { "SPACE", "pressed", @@ -2614,4 +2614,19 @@ public class WindowsLookAndFeel extends BasicLookAndFeel } } + private static class FocusColorProperty extends DesktopProperty { + public FocusColorProperty () { + // Fallback value is never used bacause of the configureValue method doesn't return null + super("win.3d.backgroundColor", Color.BLACK); + } + + @Override + protected Object configureValue(Object value) { + if (! ((Boolean)Toolkit.getDefaultToolkit().getDesktopProperty("win.highContrast.on")).booleanValue()){ + return Color.BLACK; + } + return Color.BLACK.equals(value) ? Color.WHITE : Color.BLACK; + } + } + } diff --git a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI.java b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI.java index 56214ac6db4..81c97f4a334 100644 --- a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI.java +++ b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI.java @@ -89,6 +89,11 @@ public class WindowsRadioButtonUI extends BasicRadioButtonUI } } + protected void uninstallDefaults(AbstractButton b) { + super.uninstallDefaults(b); + initialized = false; + } + protected Color getFocusColor() { return focusColor; } diff --git a/jdk/test/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI/7089914/bug7089914.java b/jdk/test/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI/7089914/bug7089914.java new file mode 100644 index 00000000000..3354f286fd2 --- /dev/null +++ b/jdk/test/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI/7089914/bug7089914.java @@ -0,0 +1,77 @@ +/* + * 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 7089914 + * @summary Focus on image icons are not visible in javaws cache with high contrast mode + * @author Sean Chou + */ + +import javax.swing.*; +import java.lang.reflect.Field; + +public class bug7089914 { + + public static void main(String[] args) throws Exception { + try { + UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); + } catch (Exception e) { + System.out.println("Not WindowsLookAndFeel, test skipped"); + + return; + } + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + + JRadioButton rb = new JRadioButton(); + + if (!"com.sun.java.swing.plaf.windows.WindowsRadioButtonUI".equals(rb.getUI().getClass().getName())) { + throw new RuntimeException("Unexpected UI class of JRadioButton"); + } + + try { + Field initializedField = rb.getUI().getClass().getDeclaredField("initialized"); + initializedField.setAccessible(true); + + if (!initializedField.getBoolean(rb.getUI())) { + throw new RuntimeException("initialized is false"); + } + + rb.getUI().uninstallUI(rb); + + if (initializedField.getBoolean(rb.getUI())) { + throw new RuntimeException("initialized is true"); + } + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + }); + } +} From 8326ba32356f977b48f8a2da051c086da82a5ec6 Mon Sep 17 00:00:00 2001 From: Alexander Scherbatiy Date: Tue, 21 Feb 2012 14:19:21 +0400 Subject: [PATCH 2/8] 7133566: [macosx] closed/javax/swing/JTable/4220171/bug4220171.java fails on MacOS Reviewed-by: alexp --- .../swing/JTable/4220171/bug4220171.java | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 jdk/test/javax/swing/JTable/4220171/bug4220171.java diff --git a/jdk/test/javax/swing/JTable/4220171/bug4220171.java b/jdk/test/javax/swing/JTable/4220171/bug4220171.java new file mode 100644 index 00000000000..acaf05ee696 --- /dev/null +++ b/jdk/test/javax/swing/JTable/4220171/bug4220171.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4220171 + * @author Konstantin Eremin + * @summary Tests + * @library ../../regtesthelpers + * @build Util + * @run main bug4220171 + */ +import java.awt.Color; +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.*; +import javax.swing.border.LineBorder; +import sun.awt.SunToolkit; + +public class bug4220171 { + + private static JTable table; + + public static void main(String args[]) throws Exception { + + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(50); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + clickMouse(robot, 0, 0); + Util.hitKeys(robot, KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_ENTER); + toolkit.realSync(); + checkCell(0, 0); + + clickMouse(robot, 0, 1); + Util.hitKeys(robot, KeyEvent.VK_D, KeyEvent.VK_E, KeyEvent.VK_ENTER); + toolkit.realSync(); + checkCell(0, 1); + + clickMouse(robot, 1, 0); + Util.hitKeys(robot, KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_ENTER); + toolkit.realSync(); + checkCell(1, 0); + + clickMouse(robot, 1, 1); + Util.hitKeys(robot, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_ENTER); + toolkit.realSync(); + checkCell(1, 1); + } + + static void checkCell(final int row, final int column) throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + if (table.getValueAt(row, column) != null) { + throw new RuntimeException( + String.format("Cell (%d, %d) is editable", row, column)); + } + } + }); + } + + static void clickMouse(Robot robot, int row, int column) throws Exception { + Point point = getCellClickPoint(row, column); + robot.mouseMove(point.x, point.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + + private static Point getCellClickPoint(final int row, final int column) throws Exception { + final Point[] result = new Point[1]; + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + 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); + result[0] = point; + } + }); + + return result[0]; + } + + private static void createAndShowGUI() { + JFrame frame = new JFrame("Test"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(200, 200); + + table = new JTable(2, 2); + table.setEnabled(false); + + frame.getContentPane().add(table); + frame.setVisible(true); + } +} From 7bea3e0303a9675f82b6b9b8fbdcde402ddf98bf Mon Sep 17 00:00:00 2001 From: Alexander Scherbatiy Date: Tue, 21 Feb 2012 15:03:07 +0400 Subject: [PATCH 3/8] 7133571: [macosx] closed/javax/swing/JToolBar/4247996/bug4247996.java fails on MacOS Reviewed-by: alexp --- .../swing/JToolBar/4247996/bug4247996.java | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 jdk/test/javax/swing/JToolBar/4247996/bug4247996.java diff --git a/jdk/test/javax/swing/JToolBar/4247996/bug4247996.java b/jdk/test/javax/swing/JToolBar/4247996/bug4247996.java new file mode 100644 index 00000000000..e389a4b5dc4 --- /dev/null +++ b/jdk/test/javax/swing/JToolBar/4247996/bug4247996.java @@ -0,0 +1,115 @@ +/* + * 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 4247996 4260485 + * @summary Test that rollover toolbar doesn't corrupt buttons + * @author Peter Zhelezniakov + * @run main bug4247996 + */ +import java.awt.*; +import javax.swing.*; +import sun.awt.SunToolkit; + +public class bug4247996 { + + private static JButton button; + private static JToggleButton toogleButton; + + public static void main(String[] args) throws Exception { + + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(50); + + UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + Point point = getButtonCenter(); + robot.mouseMove(point.x, point.y); + toolkit.realSync(); + + checkButtonsSize(); + + } + + private static void checkButtonsSize() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + if (!button.getSize().equals(toogleButton.getSize())) { + throw new RuntimeException("Button sizes are different!"); + } + } + }); + } + + private static Point getButtonCenter() throws Exception { + final Point[] result = new Point[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + Point p = button.getLocationOnScreen(); + Dimension size = button.getSize(); + result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2); + } + }); + return result[0]; + } + + private static void createAndShowGUI() { + JFrame frame = new JFrame("Test"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(200, 200); + + JButton rButton = new JButton("Rollover"); + rButton.setRolloverEnabled(true); + JToolBar nrToolbar = new JToolBar(); + nrToolbar.add(rButton); + nrToolbar.remove(rButton); + + if (!rButton.isRolloverEnabled()) { + throw new Error("Failed (bug 4260485): " + + "toolbar overrode button's rollover property"); + } + + JToolBar rToolbar = new JToolBar(); + rToolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); + rToolbar.add(button = new JButton("Test")); + rToolbar.add(toogleButton = new JToggleButton("Test")); + + frame.getContentPane().add(rToolbar, BorderLayout.NORTH); + frame.setVisible(true); + } +} From 58de6a8294d0e4d791560bb1862559abcf7672e8 Mon Sep 17 00:00:00 2001 From: Alexander Scherbatiy Date: Tue, 21 Feb 2012 15:34:08 +0400 Subject: [PATCH 4/8] 7133581: [macosx] closed/javax/swing/JTree/4330357/bug4330357.java fails on MacOS Reviewed-by: alexp --- .../javax/swing/JTree/4330357/bug4330357.java | 197 ++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 jdk/test/javax/swing/JTree/4330357/bug4330357.java diff --git a/jdk/test/javax/swing/JTree/4330357/bug4330357.java b/jdk/test/javax/swing/JTree/4330357/bug4330357.java new file mode 100644 index 00000000000..599706be055 --- /dev/null +++ b/jdk/test/javax/swing/JTree/4330357/bug4330357.java @@ -0,0 +1,197 @@ +/* + * 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 4330357 + * @summary Tests that real editor in JTree cleans up after editing was stopped + * @library ../../regtesthelpers + * @build Util + * @author Peter Zhelezniakov + * @run main bug4330357 + */ +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.tree.*; +import sun.awt.SunToolkit; + +public class bug4330357 { + + private static JTree tree; + private static JButton button; + private static Robot robot; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + robot = new Robot(); + robot.setAutoDelay(50); + + UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + clickMouse(getTreeRowClickPoint(1)); + Util.hitKeys(robot, KeyEvent.VK_F2); + Util.hitKeys(robot, KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_C); + toolkit.realSync(); + + if (!hasComponent(JTextField.class)) { + throw new RuntimeException("Cell editor is missed for path: color"); + } + + + clickMouse(getButtonClickPoint()); + toolkit.realSync(); + + clickMouse(getTreeRowClickPoint(2)); + Util.hitKeys(robot, KeyEvent.VK_F2); + toolkit.realSync(); + + if (!hasComponent(JComboBox.class)) { + throw new RuntimeException("Cell editor is missed for path: sports"); + } + + if (hasComponent(JTextField.class)) { + throw new RuntimeException("Cell editor is wrongly shown for path: color"); + } + } + + static void clickMouse(Point point) { + robot.mouseMove(point.x, point.y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + } + + private static Point getTreeRowClickPoint(final int row) throws Exception { + final Point[] result = new Point[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + + Rectangle rect = tree.getRowBounds(row); + Point p = new Point(rect.x + rect.width / 2, rect.y + 2); + SwingUtilities.convertPointToScreen(p, tree); + result[0] = p; + } + }); + + return result[0]; + } + + private static Point getButtonClickPoint() throws Exception { + final Point[] result = new Point[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + Point p = button.getLocationOnScreen(); + Dimension size = button.getSize(); + result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2); + } + }); + return result[0]; + } + + static boolean hasComponent(final Class cls) throws Exception { + final boolean[] result = new boolean[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + result[0] = Util.findSubComponent(tree, cls.getName()) != null; + } + }); + + return result[0]; + } + + private static void createAndShowGUI() { + JFrame frame = new JFrame("Test"); + frame.setSize(200, 200); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + tree = new JTree(); + tree.setEditable(true); + + final TestEditor testEditor = new TestEditor(); + tree.setCellEditor(new DefaultTreeCellEditor(tree, + (DefaultTreeCellRenderer) tree.getCellRenderer(), + testEditor)); + + button = new JButton("stop"); + + button.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent ae) { + testEditor.stopCellEditing(); + } + }); + + frame.getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER); + frame.getContentPane().add(button, BorderLayout.SOUTH); + frame.setVisible(true); + } + + static class TestEditor extends AbstractCellEditor implements TreeCellEditor { + + private JComboBox comboBox; + private JTextField textField; + private boolean comboBoxActive; + + TestEditor() { + comboBox = new JComboBox(new String[]{"one", "two"}); + textField = new JTextField(); + } + + public Component getTreeCellEditorComponent(JTree tree, Object value, + boolean isSelected, + boolean expanded, + boolean leaf, int row) { + if (row % 2 == 0) { + comboBoxActive = true; + return comboBox; + } + comboBoxActive = false; + return textField; + } + + public Object getCellEditorValue() { + if (comboBoxActive) { + return comboBox.getSelectedItem(); + } + return textField.getText(); + } + } +} From df18cb7401b43b30643d9ac1925a7cdc82a2bedb Mon Sep 17 00:00:00 2001 From: Charles Lee Date: Tue, 21 Feb 2012 18:15:14 +0400 Subject: [PATCH 5/8] 7146572: enableInputMethod(false) does not work in the TextArea and TextField on the linux platform Peers' constructors shouldn't override user's enableInputMethod() settings Reviewed-by: anthony --- jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java | 2 -- jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java index 972446dc8b3..37b096f8470 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java @@ -105,7 +105,6 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { this.target = target; //ComponentAccessor.enableEvents(target,AWTEvent.MOUSE_WHEEL_EVENT_MASK); - target.enableInputMethods(true); firstChangeSkipped = false; String text = ((TextArea)target).getText(); @@ -113,7 +112,6 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { jtext.setWrapStyleWord(true); jtext.getDocument().addDocumentListener(jtext); XToolkit.specialPeerMap.put(jtext,this); - jtext.enableInputMethods(true); textPane = new AWTTextPane(jtext,this, target.getParent()); setBounds(x, y, width, height, SET_BOUNDS); diff --git a/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java index bb7ac17032b..8a09c90735d 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java @@ -73,8 +73,6 @@ public class XTextFieldPeer extends XComponentPeer implements TextFieldPeer { xtext = new XAWTTextField(text,this, target.getParent()); xtext.getDocument().addDocumentListener(xtext); xtext.setCursor(target.getCursor()); - target.enableInputMethods(true); - xtext.enableInputMethods(true); XToolkit.specialPeerMap.put(xtext,this); TextField txt = (TextField) target; From 942b3e2aaec4b739b57aecc9e9cfc9681eeeaec7 Mon Sep 17 00:00:00 2001 From: Pavel Porvatov Date: Wed, 22 Feb 2012 14:31:13 +0400 Subject: [PATCH 6/8] 7107099: JScrollBar does not show up even if there are enough lebgth of textstring in textField Reviewed-by: alexp --- .../share/classes/javax/swing/JViewport.java | 16 ++- .../swing/JViewport/7107099/bug7107099.java | 104 ++++++++++++++++++ 2 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 jdk/test/javax/swing/JViewport/7107099/bug7107099.java diff --git a/jdk/src/share/classes/javax/swing/JViewport.java b/jdk/src/share/classes/javax/swing/JViewport.java index c1b1e9a4f59..51975d7cd6c 100644 --- a/jdk/src/share/classes/javax/swing/JViewport.java +++ b/jdk/src/share/classes/javax/swing/JViewport.java @@ -27,9 +27,7 @@ package javax.swing; import java.awt.*; import java.awt.event.*; -import java.awt.image.VolatileImage; import java.awt.peer.ComponentPeer; -import java.applet.Applet; import java.beans.Transient; import javax.swing.plaf.ViewportUI; @@ -265,6 +263,14 @@ public class JViewport extends JComponent implements Accessible */ private boolean hasHadValidView; + /** + * When view is changed we have to synchronize scrollbar values + * with viewport (see the BasicScrollPaneUI#syncScrollPaneWithViewport method). + * This flag allows to invoke that method while ScrollPaneLayout#layoutContainer + * is running. + */ + private boolean viewChanged; + /** Creates a JViewport. */ public JViewport() { super(); @@ -830,7 +836,9 @@ public class JViewport extends JComponent implements Accessible backingStoreImage = null; } super.reshape(x, y, w, h); - if (sizeChanged) { + if (sizeChanged || viewChanged) { + viewChanged = false; + fireStateChanged(); } } @@ -967,6 +975,8 @@ public class JViewport extends JComponent implements Accessible hasHadValidView = true; } + viewChanged = true; + revalidate(); repaint(); } diff --git a/jdk/test/javax/swing/JViewport/7107099/bug7107099.java b/jdk/test/javax/swing/JViewport/7107099/bug7107099.java new file mode 100644 index 00000000000..eff27bccdae --- /dev/null +++ b/jdk/test/javax/swing/JViewport/7107099/bug7107099.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 7107099 + @summary JScrollBar does not show up even if there are enough lebgth of textstring in textField + @author Pavel Porvatov +*/ + +import sun.awt.SunToolkit; + +import javax.swing.*; +import java.awt.*; + +public class bug7107099 { + private static JFrame frame; + private static JTextArea textarea; + private static JScrollPane scrollPane; + + private static int value; + private static int min; + private static int max; + private static int extent; + + public static void main(String[] args) throws Exception { + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + textarea = new JTextArea("before###1###\nbefore###2###\nbefore###3###\nbefore###4###\nbefore###5###\n"); + + scrollPane = new JScrollPane(textarea); + scrollPane.setPreferredSize(new Dimension(100, 50)); + + frame = new JFrame(); + frame.setLayout(new BorderLayout()); + frame.setSize(200, 200); + frame.add(scrollPane, BorderLayout.SOUTH); + frame.setVisible(true); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel(); + + value = model.getValue(); + min = model.getMinimum(); + max = model.getMaximum(); + extent = model.getExtent(); + + // Do tricky manipulation for testing purpose + textarea.setText(null); + scrollPane.setViewportView(textarea); + textarea.setText("after###1###\nafter###1###\nafter###1###\nafter###1###\nafter###1###\n"); + textarea.setCaretPosition(0); + } + }); + + toolkit.realSync(); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel(); + + if (value != model.getValue() || + min != model.getMinimum() || + max != model.getMaximum() || + extent != model.getExtent()) { + throw new RuntimeException("Test bug7107099 failed"); + } + + System.out.println("Test bug7107099 passed"); + + frame.dispose(); + } + }); + } +} From d76f84108fa891c7b34f75f830183f2200cf75e3 Mon Sep 17 00:00:00 2001 From: Oleg Pekhovskiy Date: Fri, 24 Feb 2012 13:50:37 +0400 Subject: [PATCH 7/8] 7145980: Dispose method of window.java takes long Reviewed-by: anthony --- jdk/src/share/classes/java/awt/Component.java | 5 +- jdk/src/share/classes/java/awt/Window.java | 62 +++++++++++-------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/jdk/src/share/classes/java/awt/Component.java b/jdk/src/share/classes/java/awt/Component.java index 22c380137c0..63fe2a80be9 100644 --- a/jdk/src/share/classes/java/awt/Component.java +++ b/jdk/src/share/classes/java/awt/Component.java @@ -10070,11 +10070,12 @@ public abstract class Component implements ImageObserver, MenuContainer, } Window window = getContainingWindow(); if (window != null) { - if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants()) { + if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants() || window.isDisposing()) { if (mixingLog.isLoggable(PlatformLogger.FINE)) { mixingLog.fine("containing window = " + window + "; has h/w descendants = " + window.hasHeavyweightDescendants() + - "; has l/w descendants = " + window.hasLightweightDescendants()); + "; has l/w descendants = " + window.hasLightweightDescendants() + + "; disposing = " + window.isDisposing()); } return false; } diff --git a/jdk/src/share/classes/java/awt/Window.java b/jdk/src/share/classes/java/awt/Window.java index 646d9ded822..1e2ee59a09a 100644 --- a/jdk/src/share/classes/java/awt/Window.java +++ b/jdk/src/share/classes/java/awt/Window.java @@ -226,6 +226,7 @@ public class Window extends Container implements Accessible { static boolean systemSyncLWRequests = false; boolean syncLWRequests = false; transient boolean beforeFirstShow = true; + private transient boolean disposing = false; static final int OPENED = 0x01; @@ -1162,36 +1163,41 @@ public class Window extends Container implements Accessible { void doDispose() { class DisposeAction implements Runnable { public void run() { - // Check if this window is the fullscreen window for the - // device. Exit the fullscreen mode prior to disposing - // of the window if that's the case. - GraphicsDevice gd = getGraphicsConfiguration().getDevice(); - if (gd.getFullScreenWindow() == Window.this) { - gd.setFullScreenWindow(null); - } + disposing = true; + try { + // Check if this window is the fullscreen window for the + // device. Exit the fullscreen mode prior to disposing + // of the window if that's the case. + GraphicsDevice gd = getGraphicsConfiguration().getDevice(); + if (gd.getFullScreenWindow() == Window.this) { + gd.setFullScreenWindow(null); + } - Object[] ownedWindowArray; - synchronized(ownedWindowList) { - ownedWindowArray = new Object[ownedWindowList.size()]; - ownedWindowList.copyInto(ownedWindowArray); - } - for (int i = 0; i < ownedWindowArray.length; i++) { - Window child = (Window) (((WeakReference) - (ownedWindowArray[i])).get()); - if (child != null) { - child.disposeImpl(); + Object[] ownedWindowArray; + synchronized(ownedWindowList) { + ownedWindowArray = new Object[ownedWindowList.size()]; + ownedWindowList.copyInto(ownedWindowArray); } - } - hide(); - beforeFirstShow = true; - removeNotify(); - synchronized (inputContextLock) { - if (inputContext != null) { - inputContext.dispose(); - inputContext = null; + for (int i = 0; i < ownedWindowArray.length; i++) { + Window child = (Window) (((WeakReference) + (ownedWindowArray[i])).get()); + if (child != null) { + child.disposeImpl(); + } } + hide(); + beforeFirstShow = true; + removeNotify(); + synchronized (inputContextLock) { + if (inputContext != null) { + inputContext.dispose(); + inputContext = null; + } + } + clearCurrentFocusCycleRootOnHide(); + } finally { + disposing = false; } - clearCurrentFocusCycleRootOnHide(); } } DisposeAction action = new DisposeAction(); @@ -2734,6 +2740,10 @@ public class Window extends Container implements Accessible { return visible; } + boolean isDisposing() { + return disposing; + } + /** * @deprecated As of J2SE 1.4, replaced by * {@link Component#applyComponentOrientation Component.applyComponentOrientation}. From cbf5f3e4de975c0ab5f9de62302dc3006b878dcf Mon Sep 17 00:00:00 2001 From: Alexander Scherbatiy Date: Wed, 29 Feb 2012 18:47:39 +0400 Subject: [PATCH 8/8] 7133573: [macosx] closed/javax/swing/JToolTip/4846413/bug4846413.java fails on MacOS Reviewed-by: alexp --- .../swing/JToolTip/4846413/bug4846413.java | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 jdk/test/javax/swing/JToolTip/4846413/bug4846413.java diff --git a/jdk/test/javax/swing/JToolTip/4846413/bug4846413.java b/jdk/test/javax/swing/JToolTip/4846413/bug4846413.java new file mode 100644 index 00000000000..3195e919fc4 --- /dev/null +++ b/jdk/test/javax/swing/JToolTip/4846413/bug4846413.java @@ -0,0 +1,138 @@ +/* + * 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 4846413 + * @summary Checks if No tooltip modification when no KeyStroke modifier + * @library ../../regtesthelpers + * @build Util + * @author Konstantin Eremin + * @run main bug4846413 + */ +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Robot; +import java.awt.Toolkit; +import javax.swing.*; +import java.awt.event.*; +import javax.swing.plaf.metal.MetalToolTipUI; +import sun.awt.SunToolkit; + +public class bug4846413 { + + private static volatile boolean isTooltipAdded; + private static JButton button; + + public static void main(String[] args) throws Exception { + + SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Robot robot = new Robot(); + robot.setAutoDelay(50); + + UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + + public void run() { + createAndShowGUI(); + } + }); + + toolkit.realSync(); + + Point movePoint = getButtonPoint(); + robot.mouseMove(movePoint.x, movePoint.y); + toolkit.realSync(); + + long timeout = System.currentTimeMillis() + 9000; + while (!isTooltipAdded && (System.currentTimeMillis() < timeout)) { + try {Thread.sleep(500);} catch (Exception e) {} + } + + checkToolTip(); + } + + private static void checkToolTip() throws Exception { + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + JToolTip tooltip = (JToolTip) Util.findSubComponent( + JFrame.getFrames()[0], "JToolTip"); + + if (tooltip == null) { + throw new RuntimeException("Tooltip has not been found!"); + } + + MetalToolTipUI tooltipUI = (MetalToolTipUI) MetalToolTipUI.createUI(tooltip); + tooltipUI.installUI(tooltip); + + if (!"-Insert".equals(tooltipUI.getAcceleratorString())) { + throw new RuntimeException("Tooltip acceleration is not properly set!"); + } + + } + }); + } + + private static Point getButtonPoint() throws Exception { + final Point[] result = new Point[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + + @Override + public void run() { + Point p = button.getLocationOnScreen(); + Dimension size = button.getSize(); + result[0] = new Point(p.x + size.width / 2, p.y + size.height / 2); + } + }); + return result[0]; + } + + private static void createAndShowGUI() { + JFrame frame = new JFrame("Test"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(200, 200); + + button = new JButton("Press me"); + button.setToolTipText("test"); + button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( + KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0, true), "someCommand"); + button.getActionMap().put("someCommand", null); + frame.getContentPane().add(button); + + JLayeredPane layeredPane = (JLayeredPane) Util.findSubComponent( + frame, "JLayeredPane"); + layeredPane.addContainerListener(new ContainerAdapter() { + + @Override + public void componentAdded(ContainerEvent e) { + isTooltipAdded = true; + } + }); + + frame.setVisible(true); + } +}