提交 1f9d148e 编写于 作者: L lana

Merge

...@@ -55,7 +55,6 @@ import javax.swing.text.DefaultEditorKit; ...@@ -55,7 +55,6 @@ import javax.swing.text.DefaultEditorKit;
import java.awt.Font; import java.awt.Font;
import java.awt.Color; import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.security.AccessController; import java.security.AccessController;
...@@ -523,6 +522,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel ...@@ -523,6 +522,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
Object ScrollbarBackgroundColor = new DesktopProperty( Object ScrollbarBackgroundColor = new DesktopProperty(
"win.scrollbar.backgroundColor", "win.scrollbar.backgroundColor",
table.get("scrollbar")); table.get("scrollbar"));
Object buttonFocusColor = new FocusColorProperty();
Object TextBackground = new XPColorValue(Part.EP_EDIT, null, Prop.FILLCOLOR, Object TextBackground = new XPColorValue(Part.EP_EDIT, null, Prop.FILLCOLOR,
WindowBackgroundColor); WindowBackgroundColor);
...@@ -629,7 +629,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel ...@@ -629,7 +629,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
"Button.highlight", ControlHighlightColor, "Button.highlight", ControlHighlightColor,
"Button.disabledForeground", InactiveTextColor, "Button.disabledForeground", InactiveTextColor,
"Button.disabledShadow", ControlHighlightColor, "Button.disabledShadow", ControlHighlightColor,
"Button.focus", black, "Button.focus", buttonFocusColor,
"Button.dashedRectGapX", new XPValue(Integer.valueOf(3), Integer.valueOf(5)), "Button.dashedRectGapX", new XPValue(Integer.valueOf(3), Integer.valueOf(5)),
"Button.dashedRectGapY", new XPValue(Integer.valueOf(3), Integer.valueOf(4)), "Button.dashedRectGapY", new XPValue(Integer.valueOf(3), Integer.valueOf(4)),
"Button.dashedRectGapWidth", new XPValue(Integer.valueOf(6), Integer.valueOf(10)), "Button.dashedRectGapWidth", new XPValue(Integer.valueOf(6), Integer.valueOf(10)),
...@@ -652,7 +652,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel ...@@ -652,7 +652,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
"CheckBox.darkShadow", ControlDarkShadowColor, "CheckBox.darkShadow", ControlDarkShadowColor,
"CheckBox.light", ControlLightColor, "CheckBox.light", ControlLightColor,
"CheckBox.highlight", ControlHighlightColor, "CheckBox.highlight", ControlHighlightColor,
"CheckBox.focus", black, "CheckBox.focus", buttonFocusColor,
"CheckBox.focusInputMap", "CheckBox.focusInputMap",
new UIDefaults.LazyInputMap(new Object[] { new UIDefaults.LazyInputMap(new Object[] {
"SPACE", "pressed", "SPACE", "pressed",
...@@ -1007,7 +1007,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel ...@@ -1007,7 +1007,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
"RadioButton.darkShadow", ControlDarkShadowColor, "RadioButton.darkShadow", ControlDarkShadowColor,
"RadioButton.light", ControlLightColor, "RadioButton.light", ControlLightColor,
"RadioButton.highlight", ControlHighlightColor, "RadioButton.highlight", ControlHighlightColor,
"RadioButton.focus", black, "RadioButton.focus", buttonFocusColor,
"RadioButton.focusInputMap", "RadioButton.focusInputMap",
new UIDefaults.LazyInputMap(new Object[] { new UIDefaults.LazyInputMap(new Object[] {
"SPACE", "pressed", "SPACE", "pressed",
...@@ -2614,4 +2614,19 @@ public class WindowsLookAndFeel extends BasicLookAndFeel ...@@ -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;
}
}
} }
...@@ -89,6 +89,11 @@ public class WindowsRadioButtonUI extends BasicRadioButtonUI ...@@ -89,6 +89,11 @@ public class WindowsRadioButtonUI extends BasicRadioButtonUI
} }
} }
protected void uninstallDefaults(AbstractButton b) {
super.uninstallDefaults(b);
initialized = false;
}
protected Color getFocusColor() { protected Color getFocusColor() {
return focusColor; return focusColor;
} }
......
...@@ -10070,11 +10070,12 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -10070,11 +10070,12 @@ public abstract class Component implements ImageObserver, MenuContainer,
} }
Window window = getContainingWindow(); Window window = getContainingWindow();
if (window != null) { if (window != null) {
if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants()) { if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants() || window.isDisposing()) {
if (mixingLog.isLoggable(PlatformLogger.FINE)) { if (mixingLog.isLoggable(PlatformLogger.FINE)) {
mixingLog.fine("containing window = " + window + mixingLog.fine("containing window = " + window +
"; has h/w descendants = " + window.hasHeavyweightDescendants() + "; has h/w descendants = " + window.hasHeavyweightDescendants() +
"; has l/w descendants = " + window.hasLightweightDescendants()); "; has l/w descendants = " + window.hasLightweightDescendants() +
"; disposing = " + window.isDisposing());
} }
return false; return false;
} }
......
...@@ -226,6 +226,7 @@ public class Window extends Container implements Accessible { ...@@ -226,6 +226,7 @@ public class Window extends Container implements Accessible {
static boolean systemSyncLWRequests = false; static boolean systemSyncLWRequests = false;
boolean syncLWRequests = false; boolean syncLWRequests = false;
transient boolean beforeFirstShow = true; transient boolean beforeFirstShow = true;
private transient boolean disposing = false;
static final int OPENED = 0x01; static final int OPENED = 0x01;
...@@ -1162,36 +1163,41 @@ public class Window extends Container implements Accessible { ...@@ -1162,36 +1163,41 @@ public class Window extends Container implements Accessible {
void doDispose() { void doDispose() {
class DisposeAction implements Runnable { class DisposeAction implements Runnable {
public void run() { public void run() {
// Check if this window is the fullscreen window for the disposing = true;
// device. Exit the fullscreen mode prior to disposing try {
// of the window if that's the case. // Check if this window is the fullscreen window for the
GraphicsDevice gd = getGraphicsConfiguration().getDevice(); // device. Exit the fullscreen mode prior to disposing
if (gd.getFullScreenWindow() == Window.this) { // of the window if that's the case.
gd.setFullScreenWindow(null); GraphicsDevice gd = getGraphicsConfiguration().getDevice();
} if (gd.getFullScreenWindow() == Window.this) {
gd.setFullScreenWindow(null);
}
Object[] ownedWindowArray; Object[] ownedWindowArray;
synchronized(ownedWindowList) { synchronized(ownedWindowList) {
ownedWindowArray = new Object[ownedWindowList.size()]; ownedWindowArray = new Object[ownedWindowList.size()];
ownedWindowList.copyInto(ownedWindowArray); ownedWindowList.copyInto(ownedWindowArray);
}
for (int i = 0; i < ownedWindowArray.length; i++) {
Window child = (Window) (((WeakReference)
(ownedWindowArray[i])).get());
if (child != null) {
child.disposeImpl();
} }
} for (int i = 0; i < ownedWindowArray.length; i++) {
hide(); Window child = (Window) (((WeakReference)
beforeFirstShow = true; (ownedWindowArray[i])).get());
removeNotify(); if (child != null) {
synchronized (inputContextLock) { child.disposeImpl();
if (inputContext != null) { }
inputContext.dispose(); }
inputContext = null; hide();
beforeFirstShow = true;
removeNotify();
synchronized (inputContextLock) {
if (inputContext != null) {
inputContext.dispose();
inputContext = null;
}
} }
clearCurrentFocusCycleRootOnHide();
} finally {
disposing = false;
} }
clearCurrentFocusCycleRootOnHide();
} }
} }
DisposeAction action = new DisposeAction(); DisposeAction action = new DisposeAction();
...@@ -2734,6 +2740,10 @@ public class Window extends Container implements Accessible { ...@@ -2734,6 +2740,10 @@ public class Window extends Container implements Accessible {
return visible; return visible;
} }
boolean isDisposing() {
return disposing;
}
/** /**
* @deprecated As of J2SE 1.4, replaced by * @deprecated As of J2SE 1.4, replaced by
* {@link Component#applyComponentOrientation Component.applyComponentOrientation}. * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
......
...@@ -27,9 +27,7 @@ package javax.swing; ...@@ -27,9 +27,7 @@ package javax.swing;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.image.VolatileImage;
import java.awt.peer.ComponentPeer; import java.awt.peer.ComponentPeer;
import java.applet.Applet;
import java.beans.Transient; import java.beans.Transient;
import javax.swing.plaf.ViewportUI; import javax.swing.plaf.ViewportUI;
...@@ -265,6 +263,14 @@ public class JViewport extends JComponent implements Accessible ...@@ -265,6 +263,14 @@ public class JViewport extends JComponent implements Accessible
*/ */
private boolean hasHadValidView; 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>. */ /** Creates a <code>JViewport</code>. */
public JViewport() { public JViewport() {
super(); super();
...@@ -830,7 +836,9 @@ public class JViewport extends JComponent implements Accessible ...@@ -830,7 +836,9 @@ public class JViewport extends JComponent implements Accessible
backingStoreImage = null; backingStoreImage = null;
} }
super.reshape(x, y, w, h); super.reshape(x, y, w, h);
if (sizeChanged) { if (sizeChanged || viewChanged) {
viewChanged = false;
fireStateChanged(); fireStateChanged();
} }
} }
...@@ -967,6 +975,8 @@ public class JViewport extends JComponent implements Accessible ...@@ -967,6 +975,8 @@ public class JViewport extends JComponent implements Accessible
hasHadValidView = true; hasHadValidView = true;
} }
viewChanged = true;
revalidate(); revalidate();
repaint(); repaint();
} }
......
...@@ -105,7 +105,6 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { ...@@ -105,7 +105,6 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
this.target = target; this.target = target;
//ComponentAccessor.enableEvents(target,AWTEvent.MOUSE_WHEEL_EVENT_MASK); //ComponentAccessor.enableEvents(target,AWTEvent.MOUSE_WHEEL_EVENT_MASK);
target.enableInputMethods(true);
firstChangeSkipped = false; firstChangeSkipped = false;
String text = ((TextArea)target).getText(); String text = ((TextArea)target).getText();
...@@ -113,7 +112,6 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { ...@@ -113,7 +112,6 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
jtext.setWrapStyleWord(true); jtext.setWrapStyleWord(true);
jtext.getDocument().addDocumentListener(jtext); jtext.getDocument().addDocumentListener(jtext);
XToolkit.specialPeerMap.put(jtext,this); XToolkit.specialPeerMap.put(jtext,this);
jtext.enableInputMethods(true);
textPane = new AWTTextPane(jtext,this, target.getParent()); textPane = new AWTTextPane(jtext,this, target.getParent());
setBounds(x, y, width, height, SET_BOUNDS); setBounds(x, y, width, height, SET_BOUNDS);
......
...@@ -73,8 +73,6 @@ public class XTextFieldPeer extends XComponentPeer implements TextFieldPeer { ...@@ -73,8 +73,6 @@ public class XTextFieldPeer extends XComponentPeer implements TextFieldPeer {
xtext = new XAWTTextField(text,this, target.getParent()); xtext = new XAWTTextField(text,this, target.getParent());
xtext.getDocument().addDocumentListener(xtext); xtext.getDocument().addDocumentListener(xtext);
xtext.setCursor(target.getCursor()); xtext.setCursor(target.getCursor());
target.enableInputMethods(true);
xtext.enableInputMethods(true);
XToolkit.specialPeerMap.put(xtext,this); XToolkit.specialPeerMap.put(xtext,this);
TextField txt = (TextField) target; TextField txt = (TextField) target;
......
/*
* 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);
}
}
});
}
}
/*
* 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);
}
}
/*
* 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);
}
}
/*
* 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);
}
}
/*
* 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();
}
}
}
/*
* 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();
}
});
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册