--- a/jdk/src/share/classes/com/sun/awt/AWTUtilities.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/share/classes/com/sun/awt/AWTUtilities.java Tue Jul 14 22:13:33 2009 -0700
@@ -374,7 +374,7 @@
"The window argument should not be null.");
}
- return AWTAccessor.getWindowAccessor().isOpaque(window);
+ return window.isOpaque();
}
/**
--- a/jdk/src/share/classes/java/awt/Component.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/share/classes/java/awt/Component.java Tue Jul 14 22:13:33 2009 -0700
@@ -2370,12 +2370,10 @@
* rectangular region. A non-opaque component paints only some of
* its pixels, allowing the pixels underneath it to "show through".
* A component that does not fully paint its pixels therefore
- * provides a degree of transparency. Only lightweight
- * components can be transparent.
+ * provides a degree of transparency.
* <p>
* Subclasses that guarantee to always completely paint their
- * contents should override this method and return true. All
- * of the "heavyweight" AWT components are opaque.
+ * contents should override this method and return true.
*
* @return true if this component is completely opaque
* @see #isLightweight
--- a/jdk/src/share/classes/java/awt/GraphicsDevice.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/share/classes/java/awt/GraphicsDevice.java Tue Jul 14 22:13:33 2009 -0700
@@ -281,8 +281,8 @@
if (w.getOpacity() < 1.0f) {
w.setOpacity(1.0f);
}
- Color bgColor = w.getBackground();
- if ((bgColor != null) && (bgColor.getAlpha() < 255)) {
+ if (!w.isOpaque()) {
+ Color bgColor = w.getBackground();
bgColor = new Color(bgColor.getRed(), bgColor.getGreen(),
bgColor.getBlue(), 255);
w.setBackground(bgColor);
--- a/jdk/src/share/classes/java/awt/Robot.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/share/classes/java/awt/Robot.java Tue Jul 14 22:13:33 2009 -0700
@@ -70,7 +70,7 @@
private RobotPeer peer;
private boolean isAutoWaitForIdle = false;
private int autoDelay = 0;
- private static int LEGAL_BUTTON_MASK;
+ private static int LEGAL_BUTTON_MASK = 0;
// location of robot's GC, used in mouseMove(), getPixelColor() and captureScreenImage()
private Point gdLoc;
@@ -95,23 +95,6 @@
}
init(GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice());
- int tmpMask = 0;
-
- if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
- if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
- final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
- for (int i = 0; i < buttonsNumber; i++){
- tmpMask |= InputEvent.getMaskForButton(i+1);
- }
- }
- }
- tmpMask |= InputEvent.BUTTON1_MASK|
- InputEvent.BUTTON2_MASK|
- InputEvent.BUTTON3_MASK|
- InputEvent.BUTTON1_DOWN_MASK|
- InputEvent.BUTTON2_DOWN_MASK|
- InputEvent.BUTTON3_DOWN_MASK;
- LEGAL_BUTTON_MASK = tmpMask;
}
/**
@@ -156,6 +139,28 @@
disposer = new RobotDisposer(peer);
sun.java2d.Disposer.addRecord(anchor, disposer);
}
+ initLegalButtonMask();
+ }
+
+ private static synchronized void initLegalButtonMask() {
+ if (LEGAL_BUTTON_MASK != 0) return;
+
+ int tmpMask = 0;
+ if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
+ if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
+ final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
+ for (int i = 0; i < buttonsNumber; i++){
+ tmpMask |= InputEvent.getMaskForButton(i+1);
+ }
+ }
+ }
+ tmpMask |= InputEvent.BUTTON1_MASK|
+ InputEvent.BUTTON2_MASK|
+ InputEvent.BUTTON3_MASK|
+ InputEvent.BUTTON1_DOWN_MASK|
+ InputEvent.BUTTON2_DOWN_MASK|
+ InputEvent.BUTTON3_DOWN_MASK;
+ LEGAL_BUTTON_MASK = tmpMask;
}
/* determine if the security policy allows Robot's to be created */
--- a/jdk/src/share/classes/java/awt/TrayIcon.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/share/classes/java/awt/TrayIcon.java Tue Jul 14 22:13:33 2009 -0700
@@ -143,6 +143,9 @@
*/
public TrayIcon(Image image) {
this();
+ if (image == null) {
+ throw new IllegalArgumentException("creating TrayIcon with null Image");
+ }
setImage(image);
}
--- a/jdk/src/share/classes/java/awt/Window.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/share/classes/java/awt/Window.java Tue Jul 14 22:13:33 2009 -0700
@@ -3521,6 +3521,7 @@
* @return this component's background color
*
* @see Window#setBackground
+ * @see Window#isOpaque
* @see GraphicsDevice.WindowTranslucency
*/
@Override
@@ -3583,6 +3584,7 @@
* PERPIXEL_TRANSLUCENT} translucency is not supported
*
* @see Window#getBackground
+ * @see Window#isOpaque
* @see Window#setOpacity()
* @see Window#setShape()
* @see GraphicsDevice.WindowTranslucency
@@ -3597,7 +3599,7 @@
return;
}
int oldAlpha = oldBg != null ? oldBg.getAlpha() : 255;
- int alpha = bgColor.getAlpha();
+ int alpha = bgColor != null ? bgColor.getAlpha() : 255;
if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window
GraphicsConfiguration gc = getGraphicsConfiguration();
GraphicsDevice gd = gc.getDevice();
@@ -3623,6 +3625,25 @@
}
}
+ /**
+ * Indicates if the window is currently opaque.
+ * <p>
+ * The method returns {@code false} if the background color of the window
+ * is not {@code null} and the alpha component of the color is less than
+ * 1.0f. The method returns {@code true} otherwise.
+ *
+ * @return {@code true} if the window is opaque, {@code false} otherwise
+ *
+ * @see Window#getBackground
+ * @see Window#setBackground
+ * @since 1.7
+ */
+ @Override
+ public boolean isOpaque() {
+ Color bg = getBackground();
+ return bg != null ? bg.getAlpha() == 255 : true;
+ }
+
private void updateWindow() {
synchronized (getTreeLock()) {
WindowPeer peer = (WindowPeer)getPeer();
@@ -3639,12 +3660,11 @@
*/
@Override
public void paint(Graphics g) {
- Color bgColor = getBackground();
- if ((bgColor != null) && (bgColor.getAlpha() < 255)) {
+ if (!isOpaque()) {
Graphics gg = g.create();
try {
if (gg instanceof Graphics2D) {
- gg.setColor(bgColor);
+ gg.setColor(getBackground());
((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
gg.fillRect(0, 0, getWidth(), getHeight());
}
@@ -3749,10 +3769,6 @@
public void setShape(Window window, Shape shape) {
window.setShape(shape);
}
- public boolean isOpaque(Window window) {
- Color bg = window.getBackground();
- return (bg != null) ? bg.getAlpha() == 255 : true;
- }
public void setOpaque(Window window, boolean opaque) {
Color bg = window.getBackground();
if (bg == null) {
--- a/jdk/src/share/classes/javax/swing/DefaultDesktopManager.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/share/classes/javax/swing/DefaultDesktopManager.java Tue Jul 14 22:13:33 2009 -0700
@@ -708,7 +708,7 @@
// update window if it's non-opaque
Window topLevel = SwingUtilities.getWindowAncestor(f);
Toolkit tk = Toolkit.getDefaultToolkit();
- if (!AWTAccessor.getWindowAccessor().isOpaque(topLevel) &&
+ if (!topLevel.isOpaque() &&
(tk instanceof SunToolkit) &&
((SunToolkit)tk).needUpdateWindow())
{
--- a/jdk/src/share/classes/javax/swing/RepaintManager.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/share/classes/javax/swing/RepaintManager.java Tue Jul 14 22:13:33 2009 -0700
@@ -732,7 +732,7 @@
(Window)dirty :
SwingUtilities.getWindowAncestor(dirty);
if (window != null &&
- !AWTAccessor.getWindowAccessor().isOpaque(window))
+ !window.isOpaque())
{
windows.add(window);
}
@@ -996,7 +996,7 @@
// If the window is non-opaque, it's double-buffered at peer's level
Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
- if (!AWTAccessor.getWindowAccessor().isOpaque(w)) {
+ if (!w.isOpaque()) {
Toolkit tk = Toolkit.getDefaultToolkit();
if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
return null;
@@ -1032,7 +1032,7 @@
// If the window is non-opaque, it's double-buffered at peer's level
Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
- if (!AWTAccessor.getWindowAccessor().isOpaque(w)) {
+ if (!w.isOpaque()) {
Toolkit tk = Toolkit.getDefaultToolkit();
if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
return null;
--- a/jdk/src/share/classes/sun/awt/AWTAccessor.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/share/classes/sun/awt/AWTAccessor.java Tue Jul 14 22:13:33 2009 -0700
@@ -137,11 +137,6 @@
*/
void setShape(Window window, Shape shape);
/*
- * Identify whether the given window is opaque (true)
- * or translucent (false).
- */
- boolean isOpaque(Window window);
- /*
* Set the opaque preoperty to the given window.
*/
void setOpaque(Window window, boolean isOpaque);
--- a/jdk/src/share/classes/sun/awt/SunToolkit.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/share/classes/sun/awt/SunToolkit.java Tue Jul 14 22:13:33 2009 -0700
@@ -1985,8 +1985,7 @@
*/
public static boolean isContainingTopLevelOpaque(Component c) {
Window w = getContainingWindow(c);
- return w != null && ((Window)w).getBackground() != null &&
- ((Window)w).getBackground().getAlpha() == 255;
+ return w != null && w.isOpaque();
}
/**
--- a/jdk/src/solaris/classes/sun/awt/X11/XBaseWindow.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/solaris/classes/sun/awt/X11/XBaseWindow.java Tue Jul 14 22:13:33 2009 -0700
@@ -1000,10 +1000,7 @@
int buttonState = 0;
final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
for (int i = 0; i<buttonsNumber; i++){
- // A bug in WM implementation: extra buttons doesn't have state!=0 as they should on Release message.
- if ((i != 4) && (i != 5)){
- buttonState |= (xbe.get_state() & XConstants.buttonsMask[i]);
- }
+ buttonState |= (xbe.get_state() & XConstants.buttonsMask[i]);
}
switch (xev.get_type()) {
case XConstants.ButtonPress:
--- a/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java Tue Jul 14 22:13:33 2009 -0700
@@ -194,8 +194,7 @@
// default value of a boolean field is 'false', so set isOpaque to
// true here explicitly
this.isOpaque = true;
- Color bgColor = ((Window)target).getBackground();
- setOpaque((bgColor == null) || (bgColor.getAlpha() == 255));
+ setOpaque(((Window)target).isOpaque());
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Robot/CtorTest/CtorTest.java Tue Jul 14 22:13:33 2009 -0700
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ @test
+ @bug 6855323
+ @summary Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
+ @author Dmitry Cherepanov area=awt.robot
+ @run main CtorTest
+*/
+
+/**
+ * CtorRobot.java
+ *
+ * summary: creates Robot using one parameter constructor
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+
+import sun.awt.SunToolkit;
+
+public class CtorTest
+{
+ public static void main(String []s) throws Exception
+ {
+ // one parameter constructor
+ GraphicsDevice graphicsDevice = GraphicsEnvironment.
+ getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ Robot robot = new Robot(graphicsDevice);
+ clickOnFrame(robot);
+ }
+
+ // generate mouse events
+ private static void clickOnFrame(Robot robot) {
+ Frame frame = new Frame();
+ frame.setBounds(100, 100, 100, 100);
+ frame.setVisible(true);
+
+ ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
+
+ // click in the middle of the frame
+ robot.mouseMove(150, 150);
+ robot.delay(50);
+ robot.mousePress(InputEvent.BUTTON1_MASK);
+ robot.delay(50);
+ robot.mouseRelease(InputEvent.BUTTON1_MASK);
+
+ ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/TrayIcon/CtorTest/CtorTest.java Tue Jul 14 22:13:33 2009 -0700
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ @test
+ @bug 6759726
+ @summary TrayIcon constructor throws NPE instead of documented IAE
+ @author Dmitry Cherepanov area=awt.tray
+ @run main CtorTest
+*/
+
+/**
+ * CtorTest.java
+ *
+ * summary: TrayIcon ctor throws IAE if image is null
+ */
+
+import java.awt.*;
+
+public class CtorTest
+{
+ public static void main(String []s)
+ {
+ boolean isSupported = SystemTray.isSupported();
+ if (isSupported) {
+ try {
+ TrayIcon tray = new TrayIcon(null);
+ } catch(IllegalArgumentException e) {
+ // ctor should throw IAE
+ }
+ }
+ }
+}
--- a/jdk/test/java/awt/Window/OwnedWindowsLeak/OwnedWindowsLeak.java Wed Jul 05 16:56:36 2017 +0200
+++ b/jdk/test/java/awt/Window/OwnedWindowsLeak/OwnedWindowsLeak.java Tue Jul 14 22:13:33 2009 -0700
@@ -65,6 +65,7 @@
break;
}
}
+ garbage = null;
// Third, make sure all the weak references are null
for (WeakReference<Window> ref : children)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Window/SetBackgroundNPE/SetBackgroundNPE.java Tue Jul 14 22:13:33 2009 -0700
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ @test
+ @bug 6853916
+ @summary Window.setBackground() should not throw NPE
+ @author anthony.petrov@sun.com: area=awt.toplevel
+ @run main SetBackgroundNPE
+*/
+
+import java.awt.Window;
+
+public class SetBackgroundNPE {
+ public static void main(String args[]) {
+ new Window(null).setBackground(null);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/event/MouseWheelEvent/DisabledComponent/DisabledComponent.java Tue Jul 14 22:13:33 2009 -0700
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ @test
+ @bug 6847958
+ @library ../../../regtesthelpers
+ @summary MouseWheel event is getting triggered for the disabled Textarea in jdk7 b60 pit build.
+ @author Dmitry Cherepanov: area=awt.event
+ @build Util
+ @run main DisabledComponent
+*/
+
+/**
+ * DisabledComponent.java
+ *
+ * summary: Tests that wheel events aren't coming on disabled component
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+
+import sun.awt.SunToolkit;
+
+import test.java.awt.regtesthelpers.Util;
+
+public class DisabledComponent
+{
+
+ private static volatile boolean passed = true;
+
+ public static void main(String []s) throws Exception
+ {
+ Frame frame = new Frame();
+ frame.setBounds(100,100,400,400);
+ frame.setLayout(new FlowLayout());
+
+ TextArea textArea = new TextArea("TextArea", 6, 15);
+ frame.add(textArea);
+
+ List list = new List(3);
+ list.add("1");
+ list.add("2");
+ list.add("3");
+ frame.add(list);
+
+ MouseWheelListener listener = new MouseWheelListener(){
+ @Override
+ public void mouseWheelMoved(MouseWheelEvent mwe){
+ System.err.println(mwe);
+ passed = false;
+ }
+ };
+
+
+ list.addMouseWheelListener(listener);
+ textArea.addMouseWheelListener(listener);
+
+ frame.setVisible(true);
+ ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
+
+ Robot robot = new Robot();
+
+ // point and wheel on the list
+ Util.pointOnComp(list, robot);
+ ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
+
+ robot.mouseWheel(2);
+ ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
+
+ // disable the text area
+ System.err.println(" disable text area ");
+ textArea.setEnabled(false);
+ passed = true;
+
+ // point and wheel on the text area
+ Util.pointOnComp(textArea, robot);
+ ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
+
+ robot.mouseWheel(2);
+ ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
+
+ if (!passed) {
+ throw new RuntimeException(" wrong wheel events ");
+ }
+ }
+}