--- a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java Tue Feb 28 19:55:09 2012 -0800
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java Wed Feb 29 12:29:20 2012 -0800
@@ -55,7 +55,6 @@
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 @@
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 @@
"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 @@
"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 @@
"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 @@
}
}
+ 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;
+ }
+ }
+
}
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI.java Tue Feb 28 19:55:09 2012 -0800
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI.java Wed Feb 29 12:29:20 2012 -0800
@@ -89,6 +89,11 @@
}
}
+ protected void uninstallDefaults(AbstractButton b) {
+ super.uninstallDefaults(b);
+ initialized = false;
+ }
+
protected Color getFocusColor() {
return focusColor;
}
--- a/jdk/src/share/classes/java/awt/Component.java Tue Feb 28 19:55:09 2012 -0800
+++ b/jdk/src/share/classes/java/awt/Component.java Wed Feb 29 12:29:20 2012 -0800
@@ -10070,11 +10070,12 @@
}
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;
}
--- a/jdk/src/share/classes/java/awt/Window.java Tue Feb 28 19:55:09 2012 -0800
+++ b/jdk/src/share/classes/java/awt/Window.java Wed Feb 29 12:29:20 2012 -0800
@@ -226,6 +226,7 @@
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 @@
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);
- }
-
- Object[] ownedWindowArray;
- synchronized(ownedWindowList) {
- ownedWindowArray = new Object[ownedWindowList.size()];
- ownedWindowList.copyInto(ownedWindowArray);
+ 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();
+ }
+ }
+ hide();
+ beforeFirstShow = true;
+ removeNotify();
+ synchronized (inputContextLock) {
+ if (inputContext != null) {
+ inputContext.dispose();
+ inputContext = null;
+ }
+ }
+ clearCurrentFocusCycleRootOnHide();
+ } finally {
+ disposing = false;
}
- 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();
}
}
DisposeAction action = new DisposeAction();
@@ -2734,6 +2740,10 @@
return visible;
}
+ boolean isDisposing() {
+ return disposing;
+ }
+
/**
* @deprecated As of J2SE 1.4, replaced by
* {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
--- a/jdk/src/share/classes/javax/swing/JViewport.java Tue Feb 28 19:55:09 2012 -0800
+++ b/jdk/src/share/classes/javax/swing/JViewport.java Wed Feb 29 12:29:20 2012 -0800
@@ -27,9 +27,7 @@
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 @@
*/
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 <code>JViewport</code>. */
public JViewport() {
super();
@@ -830,7 +836,9 @@
backingStoreImage = null;
}
super.reshape(x, y, w, h);
- if (sizeChanged) {
+ if (sizeChanged || viewChanged) {
+ viewChanged = false;
+
fireStateChanged();
}
}
@@ -967,6 +975,8 @@
hasHadValidView = true;
}
+ viewChanged = true;
+
revalidate();
repaint();
}
--- a/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java Tue Feb 28 19:55:09 2012 -0800
+++ b/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java Wed Feb 29 12:29:20 2012 -0800
@@ -105,7 +105,6 @@
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 @@
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);
--- a/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java Tue Feb 28 19:55:09 2012 -0800
+++ b/jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java Wed Feb 29 12:29:20 2012 -0800
@@ -73,8 +73,6 @@
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;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/java/swing/plaf/windows/WindowsRadioButtonUI/7089914/bug7089914.java Wed Feb 29 12:29:20 2012 -0800
@@ -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);
+ }
+ }
+ });
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JTable/4220171/bug4220171.java Wed Feb 29 12:29:20 2012 -0800
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JToolBar/4247996/bug4247996.java Wed Feb 29 12:29:20 2012 -0800
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JToolTip/4846413/bug4846413.java Wed Feb 29 12:29:20 2012 -0800
@@ -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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JTree/4330357/bug4330357.java Wed Feb 29 12:29:20 2012 -0800
@@ -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();
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JViewport/7107099/bug7107099.java Wed Feb 29 12:29:20 2012 -0800
@@ -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();
+ }
+ });
+ }
+}