undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
316
test/jdk/java/awt/Window/ShapedAndTranslucentWindows/Common.java
Normal file
316
test/jdk/java/awt/Window/ShapedAndTranslucentWindows/Common.java
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
/*
|
||||
* Copyright (c) 2021, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
|
||||
/*
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
*/
|
||||
public abstract class Common {
|
||||
|
||||
ExtendedRobot robot;
|
||||
Class<? extends Frame> windowClass;
|
||||
Frame background;
|
||||
BufferedImage foreground;
|
||||
Window window;
|
||||
Container componentsContainer;
|
||||
|
||||
float opacity = 1.0f;
|
||||
static final int STATIC_STEP = 30;
|
||||
static final int STATIC_WIDTH = 25;
|
||||
static final int STATIC_BLOCKS = 30;
|
||||
static final Color BG_COLOR = Color.BLUE;
|
||||
static final Color FG_COLOR = Color.RED;
|
||||
static final int delay = 1000;
|
||||
static final SecureRandom random = new SecureRandom();
|
||||
static final int dl = 100;
|
||||
static final Class[] WINDOWS_TO_TEST = { Window.class, Frame.class, Dialog.class };
|
||||
|
||||
public Common(Class windowClass, float opacity) throws Exception{
|
||||
this.opacity = opacity;
|
||||
robot = new ExtendedRobot();
|
||||
this.windowClass = windowClass;
|
||||
EventQueue.invokeAndWait(this::initBackgroundFrame);
|
||||
EventQueue.invokeAndWait(this::initGUI);
|
||||
}
|
||||
|
||||
public Common(Class windowClass) throws Exception{
|
||||
this(windowClass, 1.0f);
|
||||
}
|
||||
|
||||
public void doTest() throws Exception {
|
||||
robot.waitForIdle(delay);
|
||||
};
|
||||
|
||||
public void dispose() {
|
||||
window.dispose();
|
||||
background.dispose();
|
||||
}
|
||||
|
||||
public abstract void applyShape();
|
||||
|
||||
public void applyDynamicShape() {
|
||||
final Area a = new Area();
|
||||
Dimension size = window.getSize();
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int y = 0; y < 3; y++) {
|
||||
a.add(new Area(new Rectangle2D.Double(
|
||||
x * size.getWidth() / 17*6, y * size.getHeight() / 17*6,
|
||||
size.getWidth() / 17*5, size.getHeight() / 17*5)));
|
||||
}
|
||||
}
|
||||
window.setShape(a);
|
||||
}
|
||||
|
||||
public void applyStaticShape() {
|
||||
final Area a = new Area();
|
||||
for (int x = 0; x < STATIC_BLOCKS; x++) {
|
||||
for (int y = 0; y < STATIC_BLOCKS; y++) {
|
||||
a.add(new Area(new Rectangle2D.Float(
|
||||
x*STATIC_STEP, y*STATIC_STEP,
|
||||
STATIC_WIDTH, STATIC_WIDTH)));
|
||||
}
|
||||
}
|
||||
window.setShape(a);
|
||||
}
|
||||
|
||||
public BufferedImage getForegroundWindow() throws Exception {
|
||||
final BufferedImage f[] = new BufferedImage[1];
|
||||
EventQueue.invokeAndWait( () -> {
|
||||
f[0] = new BufferedImage(window.getWidth(),
|
||||
window.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||
window.printAll(f[0].createGraphics());
|
||||
});
|
||||
robot.waitForIdle(delay);
|
||||
return f[0];
|
||||
}
|
||||
|
||||
public static boolean checkTranslucencyMode(GraphicsDevice.WindowTranslucency mode) {
|
||||
|
||||
if (!GraphicsEnvironment
|
||||
.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice()
|
||||
.isWindowTranslucencySupported(mode)){
|
||||
System.out.println(mode+" translucency mode isn't supported");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void applyAppDragNResizeSupport() {
|
||||
MouseAdapter m = new MouseAdapter() {
|
||||
|
||||
private Point dragOrigin = null;
|
||||
private Dimension origSize = null;
|
||||
private Point origLoc = null;
|
||||
private boolean left = false;
|
||||
private boolean top = false;
|
||||
private boolean bottom = false;
|
||||
private boolean right = false;
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
dragOrigin = e.getLocationOnScreen();
|
||||
origSize = window.getSize();
|
||||
origLoc = window.getLocationOnScreen();
|
||||
right = (origLoc.x + window.getWidth() - dragOrigin.x) < 5;
|
||||
left = !right && dragOrigin.x - origLoc.x < 5;
|
||||
bottom = (origLoc.y + window.getHeight() - dragOrigin.y) < 5;
|
||||
top = !bottom && dragOrigin.y - origLoc.y < 5;
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) { resize(e); }
|
||||
public void mouseDragged(MouseEvent e) { resize(e); }
|
||||
|
||||
void resize(MouseEvent e) {
|
||||
Point dragDelta = e.getLocationOnScreen();
|
||||
dragDelta.translate(-dragOrigin.x, -dragOrigin.y);
|
||||
Point newLoc = new Point(origLoc);
|
||||
newLoc.translate(dragDelta.x, dragDelta.y);
|
||||
Dimension newSize = new Dimension(origSize);
|
||||
if (left || right) {
|
||||
newSize.width += right ? dragDelta.x : -dragDelta.x;
|
||||
}
|
||||
if (top || bottom) {
|
||||
newSize.height += bottom ? dragDelta.y : -dragDelta.y;
|
||||
}
|
||||
if (right || (top || bottom) && !left) {
|
||||
newLoc.x = origLoc.x;
|
||||
}
|
||||
if (bottom || (left || right) && !top) {
|
||||
newLoc.y = origLoc.y;
|
||||
}
|
||||
window.setBounds(newLoc.x, newLoc.y, newSize.width, newSize.height);
|
||||
}
|
||||
};
|
||||
for (Component comp : window.getComponents()) {
|
||||
comp.addMouseListener(m);
|
||||
comp.addMouseMotionListener(m);
|
||||
}
|
||||
|
||||
window.addMouseListener(m);
|
||||
window.addMouseMotionListener(m);
|
||||
}
|
||||
|
||||
public void checkTranslucentShape() throws Exception {
|
||||
foreground = getForegroundWindow();
|
||||
Point[] points = new Point[4];
|
||||
|
||||
Dimension size = window.getSize();
|
||||
Point location = window.getLocationOnScreen();
|
||||
|
||||
points[0] = new Point(20, 20);
|
||||
points[1] = new Point(20, size.height-20);
|
||||
points[2] = new Point(size.width-20, 20);
|
||||
points[3] = new Point(size.width-20, size.height-20);
|
||||
|
||||
for (Point p : points){
|
||||
p.translate(location.x, location.y);
|
||||
Color actual = robot.getPixelColor(p.x, p.y);
|
||||
if (actual.equals(BG_COLOR)|| actual.equals(FG_COLOR))
|
||||
throw new RuntimeException("Error in point "+p+": "+actual+" equals to foreground or background color");
|
||||
else
|
||||
System.out.println("OK with foreground point "+p);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkStaticShape() throws Exception {
|
||||
Point[] points = new Point[4];
|
||||
|
||||
Dimension size = window.getSize();
|
||||
int xFactor = (int) Math.floor(size.getWidth()/STATIC_STEP)-1;
|
||||
int yFactor = (int) Math.floor(size.getHeight()/STATIC_STEP)-1;
|
||||
|
||||
// background
|
||||
points[0] = new Point((STATIC_STEP+STATIC_WIDTH)/2, (STATIC_STEP+STATIC_WIDTH)/2);
|
||||
points[1] = new Point(STATIC_STEP*xFactor+(STATIC_STEP+STATIC_WIDTH)/2, STATIC_STEP*yFactor+(STATIC_STEP+STATIC_WIDTH)/2);
|
||||
points[2] = new Point((STATIC_STEP+STATIC_WIDTH)/2, STATIC_STEP*yFactor+(STATIC_STEP+STATIC_WIDTH)/2);
|
||||
points[3] = new Point(STATIC_STEP*xFactor+(STATIC_STEP+STATIC_WIDTH)/2, (STATIC_STEP+STATIC_WIDTH)/2);
|
||||
checkShape(points, true);
|
||||
|
||||
// foreground
|
||||
if (opacity < 1.0f){
|
||||
checkTranslucentShape();
|
||||
} else {
|
||||
points[0] = new Point((STATIC_WIDTH) / 2, (STATIC_WIDTH) / 2);
|
||||
points[1] = new Point(STATIC_STEP * xFactor + (STATIC_WIDTH) / 2, STATIC_STEP * yFactor + (STATIC_WIDTH) / 2);
|
||||
points[2] = new Point((STATIC_WIDTH) / 2, STATIC_STEP * yFactor + (STATIC_WIDTH) / 2);
|
||||
points[3] = new Point(STATIC_STEP * xFactor + (STATIC_WIDTH) / 2, (STATIC_WIDTH) / 2);
|
||||
checkShape(points, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkDynamicShape() throws Exception {
|
||||
Point[] points = new Point[4];
|
||||
|
||||
Dimension size = window.getSize();
|
||||
|
||||
int blockSizeX = (int) (size.getWidth() / 17);
|
||||
int blockSizeY = (int) (size.getHeight() / 17);
|
||||
|
||||
// background
|
||||
points[0] = new Point((int) (blockSizeX * 5.5), (int) (blockSizeY * 5.5));
|
||||
points[1] = new Point((int) (size.getWidth() - blockSizeX * 5.5), (int) (size.getHeight() - blockSizeY * 5.5));
|
||||
points[2] = new Point((int) (blockSizeX * 5.5), (int) (size.getHeight() - blockSizeY * 5.5));
|
||||
points[3] = new Point((int) (size.getWidth() - blockSizeX * 5.5), (int) (blockSizeY * 5.5));
|
||||
checkShape(points, true);
|
||||
|
||||
// foreground
|
||||
if (opacity < 1.0f){
|
||||
checkTranslucentShape();
|
||||
} else {
|
||||
points[0] = new Point(3 * blockSizeX, 3 * blockSizeY);
|
||||
points[1] = new Point(14 * blockSizeX, 14 * blockSizeY);
|
||||
points[2] = new Point(3 * blockSizeX, 14 * blockSizeY);
|
||||
points[3] = new Point(14 * blockSizeX, 3 * blockSizeY);
|
||||
checkShape(points, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkShape(Point[] points, boolean areBackgroundPoints) throws Exception {
|
||||
|
||||
Point location = window.getLocationOnScreen();
|
||||
|
||||
for (Point p : points) {
|
||||
p.translate(location.x, location.y);
|
||||
if (areBackgroundPoints) {
|
||||
if (!robot.getPixelColor(p.x, p.y).equals(BG_COLOR))
|
||||
throw new RuntimeException("Background point " + p + " color " + robot.getPixelColor(p.x, p.y) +
|
||||
" does not equal to background color " + BG_COLOR);
|
||||
else
|
||||
System.out.println("OK with background point " + p);
|
||||
} else {
|
||||
if (robot.getPixelColor(p.x, p.y).equals(BG_COLOR))
|
||||
throw new RuntimeException("Foreground point " + p +
|
||||
" equals to background color " + BG_COLOR);
|
||||
else
|
||||
System.out.println("OK with foreground point " + p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void initBackgroundFrame() {
|
||||
background = new Frame();
|
||||
background.setUndecorated(true);
|
||||
background.setBackground(BG_COLOR);
|
||||
background.setSize(500, 500);
|
||||
background.setLocation(dl, dl);
|
||||
background.setVisible(true);
|
||||
}
|
||||
|
||||
public void initGUI() {
|
||||
if (windowClass.equals(Frame.class)) {
|
||||
window = new Frame();
|
||||
((Frame) window).setUndecorated(true);
|
||||
} else if (windowClass.equals(Dialog.class)) {
|
||||
window = new Dialog(background);
|
||||
((Dialog) window).setUndecorated(true);
|
||||
} else {
|
||||
window = new Window(background);
|
||||
}
|
||||
|
||||
window.setBackground(FG_COLOR);
|
||||
componentsContainer = new Panel();
|
||||
window.add(componentsContainer, BorderLayout.CENTER);
|
||||
window.setLocation(2 * dl, 2 * dl);
|
||||
window.setSize(255, 255);
|
||||
if (opacity < 1.0f)
|
||||
window.setOpacity(opacity);
|
||||
window.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
applyShape();
|
||||
}
|
||||
});
|
||||
applyShape();
|
||||
window.setVisible(true);
|
||||
applyAppDragNResizeSupport();
|
||||
window.toFront();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,240 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2016, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowFocusListener;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.HashMap;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8013450
|
||||
* @summary Check if the window events (Focus and Activation) are triggered correctly
|
||||
* when clicked on visible and clipped areas.
|
||||
*
|
||||
* Test Description: Check if PERPIXEL_TRANSPARENT Translucency type is supported
|
||||
* by the current platform. Proceed if it is supported. Apply different
|
||||
* types of shapes on a Window. Make it appear with a known background.
|
||||
* Check if mouse events which result in window-activated events are
|
||||
* triggered only within the window's shape and not outside. Repeat this
|
||||
* for Window, Dialog and Frame.
|
||||
* Expected Result: If PERPIXEL_TRANSPARENT Translucency type is supported, window should
|
||||
* gain focus and should trigger activated events only when it is clicked on the
|
||||
* visible areas. Events should be delivered to the background window if clicked
|
||||
* on the clipped areas.
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @build Common ExtendedRobot
|
||||
* @run main FocusAWTTest
|
||||
*/
|
||||
|
||||
public class FocusAWTTest extends Common {
|
||||
|
||||
ExtendedRobot robot;
|
||||
int dx;
|
||||
int dy;
|
||||
static final int x = 20;
|
||||
static final int y = 400;
|
||||
|
||||
static volatile HashMap<String, Boolean> flags = new HashMap<String, Boolean>();
|
||||
static {
|
||||
flags.put("backgroundWindowActivated", false);
|
||||
flags.put("backgroundWindowDeactivated", false);
|
||||
flags.put("backgroundWindowGotFocus", false);
|
||||
flags.put("backgroundWindowLostFocus", false);
|
||||
flags.put("foregroundWindowGotFocus", false);
|
||||
flags.put("foregroundWindowLostFocus", false);
|
||||
flags.put("foregroundWindowActivated", false);
|
||||
flags.put("foregroundWindowDeactivated", false);
|
||||
}
|
||||
|
||||
public static void main(String[] ignored) throws Exception{
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
|
||||
for (Class<Window> windowClass: WINDOWS_TO_TEST) {
|
||||
new FocusAWTTest(windowClass).doTest();
|
||||
}
|
||||
}
|
||||
|
||||
public FocusAWTTest(Class windowClass) throws Exception {
|
||||
super(windowClass);
|
||||
this.robot = new ExtendedRobot();
|
||||
robot.waitForIdle();
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
dx = background.getX() - x;
|
||||
dy = background.getY() - y;
|
||||
});
|
||||
robot.waitForIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initBackgroundFrame() {
|
||||
background = new Frame();
|
||||
background.setSize(300, 300);
|
||||
background.setLocation(x, y);
|
||||
background.setFocusable(true);
|
||||
background.setFocusableWindowState(true);
|
||||
|
||||
background.addWindowFocusListener(new WindowFocusListener() {
|
||||
public void windowGainedFocus(WindowEvent e) { flags.put("backgroundWindowGotFocus", true); }
|
||||
public void windowLostFocus(WindowEvent e) { flags.put("backgroundWindowLostFocus", true); }
|
||||
});
|
||||
|
||||
background.addWindowListener(new WindowAdapter() {
|
||||
public void windowActivated(WindowEvent e) { flags.put("backgroundWindowActivated", true); }
|
||||
public void windowDeactivated(WindowEvent e) { flags.put("backgroundWindowDeactivated", true); }
|
||||
});
|
||||
background.add(new TextArea());
|
||||
background.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGUI() {
|
||||
if (windowClass.equals(Frame.class)) {
|
||||
window = new Frame() {
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.BLUE);
|
||||
g.fillRect(0, 0, 200, 200);
|
||||
}
|
||||
};
|
||||
((Frame) window).setUndecorated(true);
|
||||
} else if (windowClass.equals(Dialog.class)) {
|
||||
window = new Dialog(background) {
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.BLUE);
|
||||
g.fillRect(0, 0, 200, 200);
|
||||
}
|
||||
};
|
||||
((Dialog) window).setUndecorated(true);
|
||||
} else {
|
||||
window = new Window(background) {
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.BLUE);
|
||||
g.fillRect(0, 0, 200, 200);
|
||||
}
|
||||
};
|
||||
window.setFocusable(true);
|
||||
window.setFocusableWindowState(true);
|
||||
}
|
||||
|
||||
window.setPreferredSize(new Dimension(200, 200));
|
||||
window.setLocation(70 + dx, 450 + dy);
|
||||
window.setLayout(new BorderLayout());
|
||||
|
||||
window.addWindowFocusListener(new WindowFocusListener() {
|
||||
public void windowGainedFocus(WindowEvent e) { flags.put("foregroundWindowGotFocus", true); }
|
||||
public void windowLostFocus(WindowEvent e) { flags.put("foregroundWindowLostFocus", true); }
|
||||
});
|
||||
|
||||
window.addWindowListener(new WindowAdapter() {
|
||||
public void windowActivated(WindowEvent e) { flags.put("foregroundWindowActivated", true); }
|
||||
public void windowDeactivated(WindowEvent e) { flags.put("foregroundWindowDeactivated", true); }
|
||||
});
|
||||
|
||||
applyShape();
|
||||
window.pack();
|
||||
window.setAlwaysOnTop(true);
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception {
|
||||
super.doTest();
|
||||
final Point wls = new Point();
|
||||
final Dimension size = new Dimension();
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
window.requestFocus();
|
||||
wls.setLocation(window.getLocationOnScreen());
|
||||
window.getSize(size);
|
||||
});
|
||||
|
||||
robot.waitForIdle();
|
||||
|
||||
check(wls.x + size.width - 5, wls.y + 5, wls.x + size.width / 3, wls.y + size.height / 3);
|
||||
check(wls.x + size.width / 2, wls.y + size.height / 2, wls.x + size.width * 2 / 3, wls.y + size.height * 2 / 3);
|
||||
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
background.dispose();
|
||||
window.dispose();
|
||||
});
|
||||
|
||||
robot.waitForIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyShape() {
|
||||
Shape shape;
|
||||
Area a = new Area(new Rectangle2D.Float(0, 0, 200, 200));
|
||||
GeneralPath gp;
|
||||
gp = new GeneralPath();
|
||||
gp.moveTo(190, 0);
|
||||
gp.lineTo(200, 0);
|
||||
gp.lineTo(200, 10);
|
||||
gp.lineTo(10, 200);
|
||||
gp.lineTo(0, 200);
|
||||
gp.lineTo(0, 190);
|
||||
gp.closePath();
|
||||
a.subtract(new Area(gp));
|
||||
shape = a;
|
||||
|
||||
window.setShape(shape);
|
||||
}
|
||||
|
||||
private void check(int xb, int yb, int xw, int yw) throws Exception {
|
||||
checkClick(xb, yb, "backgroundWindowGotFocus");
|
||||
checkClick(xw, yw, "foregroundWindowGotFocus");
|
||||
checkClick(xb, yb, "foregroundWindowLostFocus");
|
||||
checkClick(xw, yw, "backgroundWindowLostFocus");
|
||||
|
||||
if (window instanceof Dialog || window instanceof Frame) {
|
||||
checkClick(xb, yb, "backgroundWindowActivated");
|
||||
checkClick(xw, yw, "foregroundWindowActivated");
|
||||
checkClick(xb, yb, "foregroundWindowDeactivated");
|
||||
checkClick(xw, yw, "backgroundWindowDeactivated");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkClick(int x, int y, String flag) throws Exception {
|
||||
System.out.println("Trying to click point " + x + ", " + y + ", looking for " + flag + " to trigger.");
|
||||
|
||||
flags.put(flag, false);
|
||||
|
||||
robot.mouseMove(x, y);
|
||||
robot.click();
|
||||
int i = 0;
|
||||
while (i < 5000 && !flags.get(flag)) {
|
||||
robot.waitForIdle(50);
|
||||
i += 50;
|
||||
}
|
||||
|
||||
if (!flags.get(flag))
|
||||
throw new RuntimeException(flag + " is not triggered for click on point " + x + ", " + y + " for " + windowClass + "!");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,251 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2016, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.geom.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Check if a window set with shape appears in the expected shape
|
||||
*
|
||||
* Test Description: Check if PERPIXEL_TRANSPARENT Translucency type is supported
|
||||
* by the current platform. Proceed if it is supported. Apply different
|
||||
* types of shapes on a Window. Make it appear with a known background. Use
|
||||
* get pixel color to check whether it appears as expected. Repeat this for
|
||||
* Window, Dialog and Frame.
|
||||
* Expected Result: If PERPIXEL_TRANSPARENT Translucency type is supported, the
|
||||
* window should appear with the expected shape.
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @build Common ExtendedRobot
|
||||
* @run main SetShape
|
||||
*/
|
||||
|
||||
public class SetShape extends Common {
|
||||
|
||||
static int[][] pointsToCheck;
|
||||
static Shape shape;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT)) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
System.out.println("Checking shape "+i);
|
||||
Area area;
|
||||
GeneralPath path;
|
||||
switch (i) {
|
||||
case 0:
|
||||
path = new GeneralPath();
|
||||
path.moveTo(0, 40);
|
||||
path.lineTo(40, 0);
|
||||
path.lineTo(110, 0);
|
||||
path.lineTo(150, 40);
|
||||
path.lineTo(150, 110);
|
||||
path.lineTo(110, 150);
|
||||
path.lineTo(40, 150);
|
||||
path.lineTo(0, 110);
|
||||
path.closePath();
|
||||
shape = path;
|
||||
pointsToCheck = new int[][]{
|
||||
// inside shape
|
||||
{230, 240}, {286, 332}, {314, 267}, {220, 327}, {223, 246},
|
||||
{229, 274}, {335, 257}, {231, 278}, {317, 299}, {266, 236},
|
||||
// outside shape
|
||||
{340, 353}, {373, 320}, {330, 220}, {384, 300}, {349, 406},
|
||||
{213, 355}, {361, 260}, {399, 251}, {201, 374}, {199, 257}
|
||||
};
|
||||
break;
|
||||
case 1:
|
||||
area = new Area();
|
||||
area.add(new Area(new Rectangle2D.Float(50, 0, 100, 150)));
|
||||
area.add(new Area(new Rectangle2D.Float(0, 50, 200, 50)));
|
||||
area.add(new Area(new Ellipse2D.Float(0, 0, 100, 100)));
|
||||
area.add(new Area(new Ellipse2D.Float(0, 50, 100, 100)));
|
||||
area.add(new Area(new Ellipse2D.Float(100, 0, 100, 100)));
|
||||
area.add(new Area(new Ellipse2D.Float(100, 50, 100, 100)));
|
||||
shape = area;
|
||||
pointsToCheck = new int[][]{
|
||||
// inside shape
|
||||
{306, 314}, {296, 266}, {276, 335}, {380, 253}, {224, 333},
|
||||
{396, 305}, {365, 278}, {214, 331}, {289, 349}, {367, 345},
|
||||
// outside shape
|
||||
{365, 424}, {391, 391}, {346, 413}, {261, 398}, {348, 399},
|
||||
{282, 400}, {386, 215}, {399, 369}, {213, 401}, {387, 215}
|
||||
};
|
||||
break;
|
||||
case 2:
|
||||
path = new GeneralPath();
|
||||
path.moveTo(100, 0);
|
||||
double angle = -Math.PI / 2;
|
||||
double angle_step = Math.PI * 2 / 8;
|
||||
for (int c = 0; c < 8; c++, angle += angle_step) {
|
||||
path.lineTo(100 + 100 * Math.cos(angle), 100 + 100 * Math.sin(angle));
|
||||
path.lineTo(100 + 40 * Math.cos(angle + angle_step / 2), 100 + 40 * Math.sin(angle + angle_step / 2));
|
||||
}
|
||||
path.closePath();
|
||||
shape = path;
|
||||
pointsToCheck = new int[][]{
|
||||
// inside shape
|
||||
{246, 257}, {300, 314}, {255, 347}, {291, 364}, {287, 320},
|
||||
{319, 276}, {269, 345}, {325, 291}, {289, 271}, {273, 339},
|
||||
// outside shape
|
||||
{373, 267}, {269, 229}, {390, 326}, {204, 216}, {379, 408},
|
||||
{375, 330}, {296, 213}, {367, 340}, {376, 409}, {378, 308}
|
||||
};
|
||||
break;
|
||||
case 3:
|
||||
area = new Area();
|
||||
area.add(new Area(new Rectangle2D.Float(-15, 85, 230, 30)));
|
||||
area.transform(AffineTransform.getRotateInstance(-Math.PI / 4, 100, 100));
|
||||
shape = area;
|
||||
pointsToCheck = new int[][]{
|
||||
// inside shape
|
||||
{240, 366}, {254, 338}, {342, 244}, {264, 344}, {343, 240},
|
||||
{292, 303}, {225, 374}, {263, 348}, {329, 290}, {278, 327},
|
||||
// outside shape
|
||||
{353, 289}, {334, 377}, {391, 354}, {266, 358}, {280, 364},
|
||||
{232, 225}, {327, 309}, {375, 208}, {397, 292}, {204, 335}
|
||||
};
|
||||
break;
|
||||
case 4:
|
||||
area = new Area();
|
||||
area.add(new Area(new Arc2D.Float(0, -100, 400, 400, 155, 50, Arc2D.PIE)));
|
||||
area.subtract(new Area(new Ellipse2D.Float(70, 115, 20, 20)));
|
||||
area.subtract(new Area(new Ellipse2D.Float(30, 90, 18, 18)));
|
||||
area.subtract(new Area(new Ellipse2D.Float(17, 50, 30, 30)));
|
||||
area.subtract(new Area(new Ellipse2D.Float(26, 124, 26, 26)));
|
||||
area.subtract(new Area(new Ellipse2D.Float(100, 85, 25, 25)));
|
||||
area.subtract(new Area(new Ellipse2D.Float(135, 100, 14, 14)));
|
||||
shape = area;
|
||||
pointsToCheck = new int[][]{
|
||||
// inside shape
|
||||
{225, 286}, {296, 276}, {318, 269}, {211, 357}, {295, 327},
|
||||
{207, 300}, {322, 265}, {319, 262}, {259, 294}, {261, 250},
|
||||
// outside shape
|
||||
{322, 303}, {330, 367}, {302, 395}, {227, 251}, {263, 382},
|
||||
{228, 383}, {280, 366}, {294, 248}, {316, 349}, {313, 294}
|
||||
};
|
||||
break;
|
||||
case 5:
|
||||
area = new Area();
|
||||
area.add(new Area(new Rectangle2D.Float(0, 0, 90, 90)));
|
||||
area.add(new Area(new Rectangle2D.Float(100, 0, 100, 200)));
|
||||
area.add(new Area(new Ellipse2D.Float(0, 100, 100, 100)));
|
||||
shape = area;
|
||||
pointsToCheck = new int[][]{
|
||||
// inside shape
|
||||
{275, 345}, {358, 327}, {373, 374}, {273, 331}, {251, 234},
|
||||
{285, 356}, {360, 287}, {319, 343}, {232, 210}, {323, 323},
|
||||
// outside shape
|
||||
{219, 291}, {270, 302}, {296, 383}, {298, 203}, {228, 293},
|
||||
{276, 300}, {292, 294}, {293, 216}, {298, 331}, {228, 295}
|
||||
};
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
for (Class<Window> windowClass : WINDOWS_TO_TEST) {
|
||||
new SetShape(windowClass).doTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SetShape(Class windowClass) throws Exception {
|
||||
super(windowClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGUI() {
|
||||
if (windowClass.equals(Frame.class)) {
|
||||
window = new Frame();
|
||||
((Frame) window).setUndecorated(true);
|
||||
} else if (windowClass.equals(Dialog.class)) {
|
||||
window = new Dialog(background);
|
||||
((Dialog) window).setUndecorated(true);
|
||||
} else {
|
||||
window = new Window(background);
|
||||
}
|
||||
window.setBackground(FG_COLOR);
|
||||
window.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
window.setShape(shape);
|
||||
}
|
||||
});
|
||||
window.setSize(200, 200);
|
||||
window.setLocation(2*dl, 2*dl);
|
||||
window.setVisible(true);
|
||||
|
||||
System.out.println("Checking " + window.getClass().getName() + "...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception {
|
||||
robot.waitForIdle();
|
||||
|
||||
final int COUNT_TARGET = 10;
|
||||
for(int i = 0; i < COUNT_TARGET * 2; i++) {
|
||||
int x = pointsToCheck[i][0];
|
||||
int y = pointsToCheck[i][1];
|
||||
boolean inside = i < COUNT_TARGET;
|
||||
Color c = robot.getPixelColor(x, y);
|
||||
System.out.println("checking " + x + ", " + y + ", color = " + c);
|
||||
boolean matchToForeground = FG_COLOR.equals(c);
|
||||
|
||||
if (!inside && matchToForeground || inside && !matchToForeground) {
|
||||
System.err.println("Checking for transparency failed: point: " +
|
||||
x + ", " + y +
|
||||
", color = " + c + (inside ? " is not of " : " is of un") +
|
||||
"expected foreground color " + FG_COLOR);
|
||||
final Frame[] f = new Frame[1];
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
f[0] = new Frame();
|
||||
f[0].setUndecorated(true);
|
||||
f[0].setBackground(Color.YELLOW);
|
||||
f[0].setPreferredSize(new Dimension(2, 2));
|
||||
f[0].pack();
|
||||
f[0].setVisible(true);
|
||||
});
|
||||
robot.delay(1000);
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
f[0].setLocation(x, y);
|
||||
});
|
||||
robot.delay(1000);
|
||||
}
|
||||
}
|
||||
EventQueue.invokeAndWait(window::dispose);
|
||||
EventQueue.invokeAndWait(background::dispose);
|
||||
|
||||
robot.waitForIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyShape() { window.setShape(shape); }
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,217 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2016, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Check if a window set with shape clips the contents
|
||||
*
|
||||
* Test Description: Check if PERPIXEL_TRANSPARENT Translucency type is supported
|
||||
* by the current platform. Proceed if it is supported. Apply different types
|
||||
* of shapes on a Window which contains some awt components. Shape should be
|
||||
* applied in such a way that some components are partially clipped off. Check
|
||||
* if the components appear only partially and events work correctly for those
|
||||
* components - i.e. events occur only on the areas which appear and do not
|
||||
* occur on the clipped off areas. Events should be checked by clicking on the
|
||||
* visible and clipped regions. Repeat this for Window, Dialog and Frame.
|
||||
* Expected Result: If PERPIXEL_TRANSPARENT Translucency type is supported, clicking
|
||||
* on clipped region should deliver the event to the background (it should be
|
||||
* another Window behind the test window)
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @build Common ExtendedRobot
|
||||
* @run main SetShapeAndClick
|
||||
*/
|
||||
|
||||
public class SetShapeAndClick extends Common {
|
||||
|
||||
Component south, center, north;
|
||||
volatile int clicked;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
|
||||
for (Class<Window> windowClass: WINDOWS_TO_TEST)
|
||||
new SetShapeAndClick(windowClass).doTest();
|
||||
}
|
||||
|
||||
public SetShapeAndClick(Class windowClass) throws Exception {
|
||||
super(windowClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initBackgroundFrame() {
|
||||
super.initBackgroundFrame();
|
||||
background.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
clicked |= 1 << 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGUI() {
|
||||
if (windowClass.equals(Frame.class)) {
|
||||
window = new Frame();
|
||||
((Frame) window).setUndecorated(true);
|
||||
} else if (windowClass.equals(Dialog.class)) {
|
||||
window = new Dialog(background);
|
||||
((Dialog) window).setUndecorated(true);
|
||||
} else {
|
||||
window = new Window(background);
|
||||
}
|
||||
|
||||
window.setLocation(2 * dl, 2 * dl);
|
||||
window.setPreferredSize(new Dimension(200, 200));
|
||||
window.setLayout(new BorderLayout());
|
||||
|
||||
window.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
applyShape();
|
||||
}
|
||||
});
|
||||
|
||||
south = new Label("South");
|
||||
south.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
clicked |= 1 << 3;
|
||||
}
|
||||
});
|
||||
window.add(south, BorderLayout.SOUTH);
|
||||
|
||||
center = new List(5);
|
||||
center.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
clicked |= 1 << 2;
|
||||
}
|
||||
});
|
||||
window.add(center, BorderLayout.CENTER);
|
||||
|
||||
north = new TextField("North");
|
||||
north.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
clicked |= 1 << 1;
|
||||
}
|
||||
});
|
||||
window.add(north, BorderLayout.NORTH);
|
||||
|
||||
window.pack();
|
||||
window.setVisible(true);
|
||||
window.toFront();
|
||||
|
||||
System.out.println("Checking " + window.getClass().getName() + "...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception {
|
||||
|
||||
robot.waitForIdle();
|
||||
|
||||
Point wls = window.getLocationOnScreen();
|
||||
Point ls;
|
||||
int y;
|
||||
ls = north.getLocationOnScreen();
|
||||
checkClick(ls.x + north.getWidth() / 3, ls.y + north.getHeight() / 2, 1);
|
||||
|
||||
ls = center.getLocationOnScreen();
|
||||
checkClick(ls.x + center.getWidth() * 3 / 4, ls.y + center.getHeight() * 3 / 4, 2);
|
||||
|
||||
ls = south.getLocationOnScreen();
|
||||
checkClick(ls.x + south.getWidth() * 2 / 3, ls.y + south.getHeight() / 2, 3);
|
||||
|
||||
ls = center.getLocationOnScreen();
|
||||
checkClick(ls.x + center.getWidth() / 4, ls.y + center.getHeight() / 4, 2);
|
||||
|
||||
ls = north.getLocationOnScreen();
|
||||
y = ls.y + north.getHeight() / 2;
|
||||
checkClick(wls.x + 200 - (y - wls.y), y, 0);
|
||||
|
||||
EventQueue.invokeAndWait(window::toFront);
|
||||
robot.waitForIdle();
|
||||
|
||||
ls = center.getLocationOnScreen();
|
||||
y = ls.y + center.getHeight() / 2;
|
||||
checkClick(wls.x + 200 - (y - wls.y), y, 0);
|
||||
|
||||
EventQueue.invokeAndWait(window::toFront);
|
||||
robot.waitForIdle();
|
||||
|
||||
ls = south.getLocationOnScreen();
|
||||
y = ls.y + south.getHeight() / 2;
|
||||
checkClick(wls.x + 200 - (y - wls.y), y, 0);
|
||||
|
||||
EventQueue.invokeAndWait(window::dispose);
|
||||
EventQueue.invokeAndWait(background::dispose);
|
||||
|
||||
robot.waitForIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyShape() {
|
||||
Area shape = new Area(new Rectangle2D.Float(0, 0, 200, 200));
|
||||
GeneralPath gp;
|
||||
gp = new GeneralPath();
|
||||
gp.moveTo(190, 0);
|
||||
gp.lineTo(200, 0);
|
||||
gp.lineTo(200, 10);
|
||||
gp.lineTo(10, 200);
|
||||
gp.lineTo(0, 200);
|
||||
gp.lineTo(0, 190);
|
||||
gp.closePath();
|
||||
shape.subtract(new Area(gp));
|
||||
|
||||
window.setShape(shape);
|
||||
}
|
||||
|
||||
void checkClick(int x, int y, int flag) throws Exception {
|
||||
|
||||
System.out.println("Trying to click point " + x + ", " + y + ", looking for " + flag + " flag to trigger.");
|
||||
|
||||
clicked = 0;
|
||||
robot.mouseMove(x, y);
|
||||
robot.click();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
if ((clicked & (1 << flag)) == 0)
|
||||
robot.delay(50);
|
||||
else
|
||||
break;
|
||||
|
||||
if ((clicked & (1 << flag)) == 0)
|
||||
throw new RuntimeException("FAIL: Flag " + flag + " is not triggered for point " + x + ", " + y + "!");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,215 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2016, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Check if dynamically setting a shape works
|
||||
*
|
||||
* Test Description: Check if PERPIXEL_TRANSPARENT Translucency type is supported
|
||||
* by the current platform. Proceed if it is supported. Show a window which
|
||||
* contains some components and apply a shape for the Window when the window
|
||||
* is visible. Shape should be applied in such a way that some components
|
||||
* are partially clipped off. Check if the components appear only partially
|
||||
* and events work correctly for those components - ie, events occur only on
|
||||
* the areas which appear and do not occur on the clipped off areas. Events
|
||||
* should be checked by clicking on the visible and clipped regions. Repeat
|
||||
* this for Window, Dialog and Frame.
|
||||
* Expected Result: If PERPIXEL_TRANSPARENT translucency type is supported,
|
||||
* clicking on clipped region should deliver the event to the background (it
|
||||
* should be another Window behind the test window)
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @build Common ExtendedRobot
|
||||
* @run main SetShapeDynamicallyAndClick
|
||||
*/
|
||||
|
||||
public class SetShapeDynamicallyAndClick extends Common {
|
||||
|
||||
Component south, center, north;
|
||||
volatile int clicked;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
|
||||
for (Class<Window> windowClass: WINDOWS_TO_TEST)
|
||||
new SetShapeDynamicallyAndClick(windowClass).doTest();
|
||||
}
|
||||
|
||||
public SetShapeDynamicallyAndClick(Class windowClass) throws Exception {
|
||||
super(windowClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initBackgroundFrame() {
|
||||
super.initBackgroundFrame();
|
||||
background.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
clicked |= 1 << 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGUI() {
|
||||
if (windowClass.equals(Frame.class)) {
|
||||
window = new Frame();
|
||||
((Frame) window).setUndecorated(true);
|
||||
} else if (windowClass.equals(Dialog.class)) {
|
||||
window = new Dialog(background);
|
||||
((Dialog) window).setUndecorated(true);
|
||||
} else {
|
||||
window = new Window(background);
|
||||
}
|
||||
|
||||
window.setLocation(2 * dl, 2 * dl);
|
||||
window.setPreferredSize(new Dimension(200, 200));
|
||||
window.setLayout(new BorderLayout());
|
||||
|
||||
south = new Label("South");
|
||||
south.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
clicked |= 1 << 3;
|
||||
}
|
||||
});
|
||||
window.add(south, BorderLayout.SOUTH);
|
||||
|
||||
center = new List(5);
|
||||
center.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
clicked |= 1 << 2;
|
||||
}
|
||||
});
|
||||
window.add(center, BorderLayout.CENTER);
|
||||
|
||||
north = new TextField("North");
|
||||
north.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
clicked |= 1 << 1;
|
||||
}
|
||||
});
|
||||
window.add(north, BorderLayout.NORTH);
|
||||
|
||||
window.pack();
|
||||
window.setVisible(true);
|
||||
window.toFront();
|
||||
|
||||
System.out.println("Checking " + window.getClass().getName() + "...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception {
|
||||
|
||||
robot.waitForIdle();
|
||||
|
||||
Point wls = window.getLocationOnScreen();
|
||||
Point ls;
|
||||
int y;
|
||||
|
||||
EventQueue.invokeAndWait(this::applyShape);
|
||||
|
||||
robot.waitForIdle();
|
||||
|
||||
ls = north.getLocationOnScreen();
|
||||
checkClick(ls.x + north.getWidth() / 3, ls.y + north.getHeight() / 2, 1);
|
||||
|
||||
ls = center.getLocationOnScreen();
|
||||
checkClick(ls.x + center.getWidth() * 3 / 4, ls.y + center.getHeight() * 3 / 4, 2);
|
||||
|
||||
ls = south.getLocationOnScreen();
|
||||
checkClick(ls.x + south.getWidth() * 2 / 3, ls.y + south.getHeight() / 2, 3);
|
||||
|
||||
ls = center.getLocationOnScreen();
|
||||
checkClick(ls.x + center.getWidth() / 4, ls.y + center.getHeight() / 4, 2);
|
||||
|
||||
ls = north.getLocationOnScreen();
|
||||
y = ls.y + north.getHeight() / 2;
|
||||
checkClick(wls.x + 200 - (y - wls.y), y, 0);
|
||||
|
||||
EventQueue.invokeAndWait(window::toFront);
|
||||
robot.waitForIdle();
|
||||
|
||||
ls = center.getLocationOnScreen();
|
||||
y = ls.y + center.getHeight() / 2;
|
||||
checkClick(wls.x + 200 - (y - wls.y), y, 0);
|
||||
|
||||
EventQueue.invokeAndWait(window::toFront);
|
||||
robot.waitForIdle();
|
||||
|
||||
ls = south.getLocationOnScreen();
|
||||
y = ls.y + south.getHeight() / 2;
|
||||
checkClick(wls.x + 200 - (y - wls.y), y, 0);
|
||||
|
||||
EventQueue.invokeAndWait(window::dispose);
|
||||
EventQueue.invokeAndWait(background::dispose);
|
||||
|
||||
robot.waitForIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyShape() {
|
||||
Area shape = new Area(new Rectangle2D.Float(0, 0, 200, 200));
|
||||
GeneralPath gp;
|
||||
gp = new GeneralPath();
|
||||
gp.moveTo(190, 0);
|
||||
gp.lineTo(200, 0);
|
||||
gp.lineTo(200, 10);
|
||||
gp.lineTo(10, 200);
|
||||
gp.lineTo(0, 200);
|
||||
gp.lineTo(0, 190);
|
||||
gp.closePath();
|
||||
shape.subtract(new Area(gp));
|
||||
|
||||
window.setShape(shape);
|
||||
}
|
||||
|
||||
void checkClick(int x, int y, int flag) throws Exception {
|
||||
|
||||
System.out.println("Trying to click point " + x + ", " + y + ", looking for " + flag + " flag to trigger.");
|
||||
|
||||
clicked = 0;
|
||||
robot.mouseMove(x, y);
|
||||
robot.click();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
if ((clicked & (1 << flag)) == 0)
|
||||
robot.delay(50);
|
||||
else
|
||||
break;
|
||||
|
||||
if ((clicked & (1 << flag)) == 0)
|
||||
throw new RuntimeException("FAIL: Flag " + flag + " is not triggered for point " + x + ", " + y + "!");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2016, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Check if dynamically shaped window is dragged and resized
|
||||
* by mouse correctly
|
||||
*
|
||||
* Test Description: Check if specified translucency types PERPIXEL_TRANSPARENT
|
||||
* is supported on the current platform. Proceed if it is supported.
|
||||
* Create a window apply shape in componentResized listener. The shape
|
||||
* should match the window size. Drag and resize the window using AWT Robot
|
||||
* and verify that shape is correctly applied both with pixels checking and
|
||||
* clicks. Make the window appear on top of a known background. Repeat this
|
||||
* for Window, Dialog, Frame,
|
||||
* Expected Result: If PERPIXEL_TRANSPARENT translucency type is supported,
|
||||
* the window should appear with the expected shape. Clicks should come
|
||||
* to visible parts of shaped window only and to background for clipped
|
||||
* parts.
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @build Common ExtendedRobot
|
||||
* @run main Shaped
|
||||
*/
|
||||
public class Shaped extends Common{
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
|
||||
for (Class<Window> windowClass: WINDOWS_TO_TEST){
|
||||
new Shaped(windowClass).doTest();
|
||||
}
|
||||
}
|
||||
|
||||
public Shaped(Class windowClass) throws Exception{
|
||||
super(windowClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyShape(){ applyDynamicShape(); }
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception{
|
||||
super.doTest();
|
||||
|
||||
checkDynamicShape();
|
||||
|
||||
// Drag
|
||||
Point location = window.getLocationOnScreen();
|
||||
robot.dragAndDrop(location.x + dl, location.y + 5, location.x + dl + random.nextInt(dl), location.y + random.nextInt(dl));
|
||||
robot.waitForIdle(delay);
|
||||
checkDynamicShape();
|
||||
|
||||
// Resize
|
||||
location = window.getLocationOnScreen();
|
||||
robot.dragAndDrop(location.x + 4, location.y + 4, location.x + random.nextInt(2*dl)-dl, location.y + random.nextInt(2*dl)-dl);
|
||||
robot.waitForIdle(delay);
|
||||
checkDynamicShape();
|
||||
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2016, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Check if dynamically shaped window is moved and resized by
|
||||
* API correctly.
|
||||
*
|
||||
* Test Description: Check if PERPIXEL_TRANSPARENT translucency type is
|
||||
* supported on the current platform. Proceed if it is supported. Create
|
||||
* a window and apply shape in componentResized listener. The shape should
|
||||
* match the window size. Drag and resize the window using API and verify
|
||||
* that shape is correctly applied both with pixels checking and clicks.
|
||||
* Make the window appear on top of a known background. Repeat this for
|
||||
* Window, Dialog, Frame.
|
||||
* Expected Result: If PERPIXEL_TRANSPARENT translucency type is supported, the
|
||||
* window should appear with the expected shape. Clicks should come to visible
|
||||
* parts of shaped window only and to background for clipped parts.
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @run main ShapedByAPI
|
||||
*/
|
||||
public class ShapedByAPI extends Common {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
|
||||
for (Class<Window> windowClass: WINDOWS_TO_TEST){
|
||||
new ShapedByAPI(windowClass).doTest();
|
||||
}
|
||||
}
|
||||
|
||||
public ShapedByAPI(Class windowClass) throws Exception{
|
||||
super(windowClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyShape(){ applyDynamicShape(); }
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception{
|
||||
super.doTest();
|
||||
|
||||
checkDynamicShape();
|
||||
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
Point location = window.getLocationOnScreen();
|
||||
location.translate(random.nextInt(dl), random.nextInt(dl));
|
||||
window.setLocation(location);
|
||||
});
|
||||
robot.waitForIdle(delay);
|
||||
checkDynamicShape();
|
||||
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
Dimension size = window.getSize();
|
||||
window.setSize(size.width+random.nextInt(2*dl)-dl, size.height+random.nextInt(2*dl)-dl);
|
||||
});
|
||||
robot.waitForIdle(delay);
|
||||
checkDynamicShape();
|
||||
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2016, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Check if a translucent shaped window is dragged and
|
||||
* resized correctly.
|
||||
*
|
||||
* Test Description: Check if TRANSLUCENT and PERPIXEL_TRANSPARENT translucency
|
||||
* types are supported on the current platform. Proceed if it is supported.
|
||||
* Create and apply opacity of 0.3 and apply shape in componentResized
|
||||
* listener. Drag and resize the window using AWT Robot and verify that
|
||||
* shape and translucency are correctly applied both with pixels checking
|
||||
* and clicks. Make the window appear on top of a known background. Repeat
|
||||
* this for Window, Dialog, Frame.
|
||||
* Expected Result: If TRANSLUCENT and PERPIXEL_TRANSPARENT translucency types are
|
||||
* supported, the window should appear with the expected shape and translucency.
|
||||
* Clicks should come to visible parts of shaped window only and to background
|
||||
* for clipped parts.
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @build Common ExtendedRobot
|
||||
* @run main ShapedTranslucent
|
||||
*/
|
||||
public class ShapedTranslucent extends Common {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.TRANSLUCENT) &&
|
||||
checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
|
||||
for (Class<Window> windowClass: WINDOWS_TO_TEST){
|
||||
new ShapedTranslucent(windowClass).doTest();
|
||||
}
|
||||
}
|
||||
|
||||
public ShapedTranslucent(Class windowClass) throws Exception{
|
||||
super(windowClass, 0.3f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyShape(){ applyDynamicShape(); }
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception{
|
||||
super.doTest();
|
||||
|
||||
checkDynamicShape();
|
||||
|
||||
// Drag
|
||||
Point location = window.getLocationOnScreen();
|
||||
robot.dragAndDrop(location.x + dl, location.y + 5, location.x + dl + random.nextInt(dl), location.y + random.nextInt(dl));
|
||||
robot.waitForIdle(delay);
|
||||
checkDynamicShape();
|
||||
|
||||
// Resize
|
||||
location = window.getLocationOnScreen();
|
||||
robot.dragAndDrop(location.x + 4, location.y + 4, location.x + random.nextInt(2*dl)-dl, location.y + random.nextInt(2*dl)-dl);
|
||||
robot.waitForIdle(delay);
|
||||
checkDynamicShape();
|
||||
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,211 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2016, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.BitSet;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Check if a translucent shaped window trigger events correctly.
|
||||
*
|
||||
* Test Description: Check if TRANSLUCENT and PERPIXEL_TRANSPARENT traslucency
|
||||
* types are supported on the current platform. Proceed if both are
|
||||
* supported. Create a window with some components in it and a shape
|
||||
* applied. Apply the shape such that some components are partially
|
||||
* clipped. Set an opacity value less than 1. Check if the components
|
||||
* behave correctly on mouse and key events. Do this test for awt Window.
|
||||
* Expected Result: Mouse and key events must work correctly. Only that portion
|
||||
* of a component within the shape should trigger events. Key events
|
||||
* should be tested for focus events and TextField/TextArea.
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @build Common ExtendedRobot
|
||||
* @run main ShapedTranslucentWindowClick
|
||||
*/
|
||||
|
||||
public class ShapedTranslucentWindowClick extends Common {
|
||||
|
||||
Component south, center, north;
|
||||
|
||||
volatile BitSet backgroundFlags = new BitSet(11);
|
||||
volatile BitSet southFlags = new BitSet(11);
|
||||
volatile BitSet centerFlags = new BitSet(11);
|
||||
volatile BitSet northFlags = new BitSet(11);
|
||||
static BitSet reference = BitSet.valueOf(new long[] {2047}); // 111 1111 1111
|
||||
|
||||
public static void main(String[] ignored) throws Exception{
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT) &&
|
||||
checkTranslucencyMode(GraphicsDevice.WindowTranslucency.TRANSLUCENT))
|
||||
new ShapedTranslucentWindowClick(Window.class).doTest();
|
||||
}
|
||||
|
||||
public ShapedTranslucentWindowClick(Class windowClass) throws Exception {
|
||||
super(windowClass);
|
||||
addListeners(south, southFlags);
|
||||
addListeners(center, centerFlags);
|
||||
addListeners(north, northFlags);
|
||||
addListeners(background, backgroundFlags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGUI() {
|
||||
|
||||
window = new Window(background);
|
||||
south = new Button("South Button");
|
||||
center = new TextArea("Center Text Area");
|
||||
north = new TextField("North Text Field");
|
||||
|
||||
window.setLocation(250, 250);
|
||||
window.setPreferredSize(new Dimension(200, 200));
|
||||
window.setOpacity(0.7f);
|
||||
applyShape();
|
||||
window.setLayout(new BorderLayout());
|
||||
|
||||
window.add(south, BorderLayout.SOUTH);
|
||||
window.add(center, BorderLayout.CENTER);
|
||||
window.add(north, BorderLayout.NORTH);
|
||||
|
||||
window.pack();
|
||||
window.setVisible(true);
|
||||
window.toFront();
|
||||
|
||||
System.out.println("Checking " + window.getClass().getName() + "...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception {
|
||||
|
||||
robot.waitForIdle();
|
||||
robot.mouseMove(background.getLocationOnScreen().x+50, background.getLocationOnScreen().y+50);
|
||||
robot.waitForIdle();
|
||||
robot.click();
|
||||
|
||||
Point wls = window.getLocationOnScreen();
|
||||
Point ls;
|
||||
int y;
|
||||
|
||||
robot.waitForIdle();
|
||||
|
||||
ls = north.getLocationOnScreen();
|
||||
checkClickAndType(ls.x + north.getWidth() / 3, ls.y + north.getHeight() / 2, northFlags);
|
||||
|
||||
ls = center.getLocationOnScreen();
|
||||
checkClickAndType(ls.x + center.getWidth() / 4, ls.y + center.getHeight() / 4, centerFlags);
|
||||
|
||||
ls = center.getLocationOnScreen();
|
||||
checkClickAndType(ls.x + center.getWidth() * 3 / 4, ls.y + center.getHeight() * 3 / 4, centerFlags);
|
||||
|
||||
ls = south.getLocationOnScreen();
|
||||
checkClickAndType(ls.x + south.getWidth() * 2 / 3, ls.y + south.getHeight() / 2, southFlags);
|
||||
|
||||
ls = north.getLocationOnScreen();
|
||||
y = ls.y + north.getHeight() / 2;
|
||||
checkClickAndType(wls.x + 200 - (y - wls.y), y, backgroundFlags);
|
||||
|
||||
EventQueue.invokeAndWait(window::toFront);
|
||||
robot.waitForIdle();
|
||||
|
||||
ls = center.getLocationOnScreen();
|
||||
y = ls.y + center.getHeight() / 2;
|
||||
checkClickAndType(wls.x + 200 - (y - wls.y), y, backgroundFlags);
|
||||
|
||||
EventQueue.invokeAndWait(window::toFront);
|
||||
robot.waitForIdle();
|
||||
|
||||
ls = south.getLocationOnScreen();
|
||||
y = ls.y + south.getHeight() / 2;
|
||||
checkClickAndType(wls.x + 200 - (y - wls.y), y, backgroundFlags);
|
||||
|
||||
EventQueue.invokeAndWait(window::dispose);
|
||||
EventQueue.invokeAndWait(background::dispose);
|
||||
|
||||
robot.waitForIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyShape() {
|
||||
Area shape = new Area(new Rectangle2D.Float(0, 0, 200, 200));
|
||||
GeneralPath gp;
|
||||
gp = new GeneralPath();
|
||||
gp.moveTo(190, 0);
|
||||
gp.lineTo(200, 0);
|
||||
gp.lineTo(200, 10);
|
||||
gp.lineTo(10, 200);
|
||||
gp.lineTo(0, 200);
|
||||
gp.lineTo(0, 190);
|
||||
gp.closePath();
|
||||
shape.subtract(new Area(gp));
|
||||
|
||||
window.setShape(shape);
|
||||
}
|
||||
|
||||
void checkClickAndType(int x, int y, BitSet bits){
|
||||
bits.clear(0, 10);
|
||||
|
||||
robot.mouseMove(x, y);
|
||||
robot.click();
|
||||
robot.dragAndDrop(MouseInfo.getPointerInfo().getLocation(), new Point(x+5, y));
|
||||
robot.mouseWheel(1);
|
||||
robot.waitForIdle();
|
||||
|
||||
robot.type('a');
|
||||
|
||||
robot.mouseMove(350, 50);
|
||||
robot.waitForIdle();
|
||||
|
||||
//robot.delay(20*1000);
|
||||
if (!bits.equals(reference)){
|
||||
for( int i = 0; i < 11; i++)
|
||||
System.err.print(( bits.get(i) ? 1 : 0 ) + ", ");
|
||||
System.err.println();
|
||||
throw new RuntimeException("Bit mask is not fully set: "+bits);
|
||||
}
|
||||
}
|
||||
|
||||
static void addListeners(Component component, BitSet bits) {
|
||||
component.addMouseListener(new MouseListener() {
|
||||
public void mouseClicked(MouseEvent e) { bits.set(0);}
|
||||
public void mousePressed(MouseEvent e) { bits.set(1); }
|
||||
public void mouseReleased(MouseEvent e) { bits.set(2); }
|
||||
public void mouseEntered(MouseEvent e) { bits.set(3); }
|
||||
public void mouseExited(MouseEvent e) { bits.set(4); }
|
||||
});
|
||||
component.addMouseMotionListener(new MouseMotionListener() {
|
||||
public void mouseDragged(MouseEvent e) { bits.set(5); }
|
||||
public void mouseMoved(MouseEvent e) { bits.set(6); }
|
||||
});
|
||||
component.addMouseWheelListener((e) -> bits.set(7));
|
||||
component.addKeyListener(new KeyListener() {
|
||||
public void keyTyped(KeyEvent e) { bits.set(8); }
|
||||
public void keyPressed(KeyEvent e) { bits.set(9); }
|
||||
public void keyReleased(KeyEvent e) { bits.set(10); }
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2016, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Check if statically shaped window is dragged and resized correctly.
|
||||
*
|
||||
* Test Description: Check if PERPIXEL_TRANSPARENT translucency type is supported
|
||||
* on the current platform. Proceed if it is supported. Create a window
|
||||
* and apply some shape at window creation. The shape should be bigger than
|
||||
* window. Drag and resize the window using AWT Robot and verify that shape
|
||||
* is correctly applied both with pixels checking and clicks. Make the
|
||||
* window appear on top of a known background. Repeat this for Window, Dialog,
|
||||
* Frame.
|
||||
* Expected Result: If specified translucency type PERPIXEL_TRANSPARENT is supported,
|
||||
* the window should appear with the expected shape clipped to the window
|
||||
* size. Clicks should come to visible parts of shaped window only and to
|
||||
* background for clipped parts.
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @build Common ExtendedRobot
|
||||
* @run main StaticallyShaped
|
||||
*/
|
||||
|
||||
public class StaticallyShaped extends Common {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
|
||||
for (Class<Window> windowClass: WINDOWS_TO_TEST){
|
||||
new StaticallyShaped(windowClass).doTest();
|
||||
}
|
||||
}
|
||||
|
||||
public StaticallyShaped(Class windowClass) throws Exception{ super(windowClass); }
|
||||
|
||||
@Override
|
||||
public void applyShape(){ applyStaticShape(); }
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception{
|
||||
super.doTest();
|
||||
|
||||
checkStaticShape();
|
||||
|
||||
// Drag
|
||||
Point location = window.getLocationOnScreen();
|
||||
robot.dragAndDrop(location.x + dl, location.y + 5, location.x + dl + random.nextInt(dl), location.y + random.nextInt(dl));
|
||||
robot.waitForIdle(delay);
|
||||
checkStaticShape();
|
||||
|
||||
// Resize
|
||||
location = window.getLocationOnScreen();
|
||||
robot.dragAndDrop(location.x + 4, location.y + 4, location.x + random.nextInt(2*dl)-dl, location.y + random.nextInt(2*dl)-dl);
|
||||
robot.waitForIdle(delay);
|
||||
checkStaticShape();
|
||||
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2016, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Check if translucent window is dragged and resized
|
||||
* correctly.
|
||||
*
|
||||
* Test Description: Check if TRANSLUCENT translucency type is supported
|
||||
* on the current platform. Proceed if they are supported. Create
|
||||
* a window and apply opacity of 0.3. Drag and resize the window
|
||||
* using AWT Robot and verify that translucency is not affected.
|
||||
* Make the window appear on top of a known background. Repeat this
|
||||
* for Window, Dialog, Frame.
|
||||
* Expected Result: If TRANSLUCENT translucency type is supported, the
|
||||
* window should show the background. Dragging and resizing
|
||||
* shouldn't affect the translucency.
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @build Common ExtendedRobot
|
||||
* @run main Translucent
|
||||
*/
|
||||
public class Translucent extends Common {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.TRANSLUCENT))
|
||||
for (Class<Window> windowClass: WINDOWS_TO_TEST){
|
||||
new Translucent(windowClass).doTest();
|
||||
}
|
||||
}
|
||||
|
||||
public Translucent(Class windowClass) throws Exception{
|
||||
super(windowClass, 0.3f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyShape(){ }
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception{
|
||||
super.doTest();
|
||||
|
||||
checkTranslucentShape();
|
||||
|
||||
// Drag
|
||||
Point location = window.getLocationOnScreen();
|
||||
robot.dragAndDrop(location.x + dl, location.y + 5, location.x + dl + random.nextInt(dl), location.y + random.nextInt(dl));
|
||||
robot.waitForIdle(delay);
|
||||
checkTranslucentShape();
|
||||
|
||||
// Resize
|
||||
location = window.getLocationOnScreen();
|
||||
robot.dragAndDrop(location.x + 4, location.y + 4, location.x + random.nextInt(2*dl)-dl, location.y + random.nextInt(2*dl)-dl);
|
||||
robot.waitForIdle(delay);
|
||||
checkTranslucentShape();
|
||||
|
||||
dispose();
|
||||
robot.waitForIdle(delay);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,190 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2021, 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.
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Check if a Choice present in a window set with opacity less than 1.0
|
||||
* shows a translucent drop down
|
||||
*
|
||||
* Test Description: Check if TRANSLUCENT Translucency type is supported on the
|
||||
* current platform. Proceed if supported. Show a window which contains an
|
||||
* awt Choice and set with opacity less than 1.0. Another Window having a
|
||||
* canvas component drawn with an image can be used as the background for
|
||||
* the test window. Click on the ComboBox to show the drop down. Check if
|
||||
* the drop down appears translucent. Repeat this for Window, Dialog and
|
||||
* Frame.
|
||||
* Expected Result: If TRANSLUCENT Translucency type is supported, the drop down
|
||||
* should appear translucent.
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @build Common ExtendedRobot
|
||||
* @run main TranslucentChoice
|
||||
*/
|
||||
|
||||
public class TranslucentChoice extends Common {
|
||||
|
||||
Choice south;
|
||||
Component center;
|
||||
Component north;
|
||||
volatile int clicked;
|
||||
|
||||
public static void main(String[] ignored) throws Exception {
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.TRANSLUCENT))
|
||||
for (Class<Window> windowClass: WINDOWS_TO_TEST){
|
||||
new TranslucentChoice(windowClass).doTest();
|
||||
}
|
||||
}
|
||||
|
||||
public TranslucentChoice(Class windowClass) throws Exception {
|
||||
super(windowClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initBackgroundFrame() {
|
||||
super.initBackgroundFrame();
|
||||
background.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
clicked |= 1 << 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGUI() {
|
||||
if (windowClass.equals(Frame.class)) {
|
||||
window = new Frame();
|
||||
((Frame) window).setUndecorated(true);
|
||||
} else if (windowClass.equals(Dialog.class)) {
|
||||
window = new Dialog(background);
|
||||
((Dialog) window).setUndecorated(true);
|
||||
} else {
|
||||
window = new Window(background);
|
||||
}
|
||||
|
||||
window.setBackground(FG_COLOR);
|
||||
north = new Button("north");
|
||||
window.add(north, BorderLayout.NORTH);
|
||||
|
||||
center = new List(5);
|
||||
window.add(center, BorderLayout.CENTER);
|
||||
|
||||
Choice choice = new Choice();
|
||||
for(int i = 0; i < 20; i++) {
|
||||
choice.add("item " + i);
|
||||
}
|
||||
south = choice;
|
||||
|
||||
south.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
clicked |= 1 << 1;
|
||||
}
|
||||
});
|
||||
|
||||
window.add(south, BorderLayout.SOUTH);
|
||||
window.setAlwaysOnTop(true);
|
||||
window.setOpacity(0.3f);
|
||||
window.setLocation(2 * dl, 2 * dl);
|
||||
window.setSize(255, 255);
|
||||
window.pack();
|
||||
window.setVisible(true);
|
||||
|
||||
System.out.println("Checking " + window.getClass().getName() + "...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception {
|
||||
|
||||
Point ls = window.getLocationOnScreen();
|
||||
clicked = 0;
|
||||
|
||||
robot.waitForIdle();
|
||||
|
||||
checkClick(ls.x + window.getWidth() / 2, ls.y - 5, 0);
|
||||
|
||||
robot.waitForIdle(2000);
|
||||
|
||||
ls = south.getLocationOnScreen();
|
||||
|
||||
Point p1 = new Point((int) (ls.x + south.getWidth() * 0.75), ls.y + south.getHeight() * 3);
|
||||
Point p2 = new Point((int) (ls.x + south.getWidth() * 0.75), ls.y - south.getHeight() * 2);
|
||||
Color c1 = robot.getPixelColor(p1.x, p1.y);
|
||||
Color c2 = robot.getPixelColor(p2.x, p2.y);
|
||||
|
||||
checkClick(ls.x + south.getWidth() / 2, ls.y + south.getHeight() / 2, 1);
|
||||
|
||||
robot.waitForIdle(2000);
|
||||
|
||||
Color c1b = robot.getPixelColor(p1.x, p1.y);
|
||||
Color c2b = robot.getPixelColor(p2.x, p2.y);
|
||||
|
||||
if (!aproximatelyEquals(c1, c1b) && !aproximatelyEquals(south.getBackground(), c1b))
|
||||
throw new RuntimeException("Check for opaque drop down failed. Before click: " + c1 + ", after click: " + c1b + ", expected is " + south.getBackground());
|
||||
|
||||
if (!aproximatelyEquals(c2,c2b) && !aproximatelyEquals(south.getBackground(), c2b))
|
||||
throw new RuntimeException("Check for opaque drop down failed. Before click: " + c2 + ", after click: " + c2b + ", expected is " + south.getBackground());
|
||||
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
background.dispose();
|
||||
window.dispose();
|
||||
});
|
||||
|
||||
robot.waitForIdle();
|
||||
}
|
||||
|
||||
boolean aproximatelyEquals(Color c1, Color c2) {
|
||||
return ((Math.abs(c1.getRed()-c2.getRed())/256.0 +
|
||||
Math.abs(c1.getGreen()-c2.getGreen())/256.0 +
|
||||
Math.abs(c1.getBlue()-c2.getBlue())/256.0)) / 3 < 0.02;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyShape() { }
|
||||
|
||||
|
||||
void checkClick(int x, int y, int flag) throws Exception {
|
||||
|
||||
System.out.println("Trying to click point " + x + ", " + y + ", looking for " + flag + " flag to trigger.");
|
||||
|
||||
clicked = 0;
|
||||
robot.mouseMove(x, y);
|
||||
robot.click();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
if ((clicked & (1 << flag)) == 0)
|
||||
robot.delay(50);
|
||||
else
|
||||
break;
|
||||
|
||||
if ((clicked & (1 << flag)) == 0)
|
||||
throw new RuntimeException("FAIL: Flag " + flag + " is not triggered for point " + x + ", " + y + "!");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2016, 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.
|
||||
*/
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @summary Check if components present in a window set with opacity less than 1.0
|
||||
* triggers events correctly
|
||||
*
|
||||
* Test Description: Check if TRANSLUCENT Translucency type is supported on the
|
||||
* current platform. Proceed if supported. Show a window which contains some
|
||||
* components and set with opacity less than 1.0. Another Window having a
|
||||
* canvas component drawn with an image can be used as the background for the
|
||||
* test window. Click on the components present in the window and check if
|
||||
* events trigger correctly.
|
||||
* Expected Result: The components should trigger events correctly
|
||||
*
|
||||
* @author mrkam
|
||||
* @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
|
||||
* @library /lib/client
|
||||
* @build Common ExtendedRobot
|
||||
* @run main TranslucentWindowClick
|
||||
*/
|
||||
public class TranslucentWindowClick extends Common {
|
||||
|
||||
private Component south;
|
||||
private Component center;
|
||||
private Component north;
|
||||
|
||||
volatile int clicked;
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
if (checkTranslucencyMode(GraphicsDevice.WindowTranslucency.TRANSLUCENT))
|
||||
new TranslucentWindowClick(Window.class).doTest();
|
||||
}
|
||||
|
||||
public TranslucentWindowClick(Class windowClass) throws Exception {
|
||||
super(windowClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGUI() {
|
||||
if (windowClass.equals(Frame.class)) {
|
||||
window = new Frame();
|
||||
((Frame) window).setUndecorated(true);
|
||||
} else if (windowClass.equals(Dialog.class)) {
|
||||
window = new Dialog(background);
|
||||
((Dialog) window).setUndecorated(true);
|
||||
} else {
|
||||
window = new Window(background);
|
||||
}
|
||||
|
||||
window.setPreferredSize(new Dimension(200, 200));
|
||||
window.setLocation(2 * dl, 2 * dl);
|
||||
window.setLayout(new BorderLayout());
|
||||
window.setBackground(FG_COLOR);
|
||||
|
||||
south = new Button("South");
|
||||
south.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) { clicked |= 1 << 2; }
|
||||
});
|
||||
window.add(south, BorderLayout.SOUTH);
|
||||
|
||||
center = new List(5);
|
||||
center.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) { clicked |= 1 << 1; }
|
||||
});
|
||||
window.add(center, BorderLayout.CENTER);
|
||||
|
||||
north = new TextField("North");
|
||||
north.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) { clicked |= 1 << 0; }
|
||||
});
|
||||
window.add(north, BorderLayout.NORTH);
|
||||
window.setOpacity(0.2f);
|
||||
window.pack();
|
||||
window.setVisible(true);
|
||||
|
||||
System.out.println("Checking " + window.getClass().getName() + "...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doTest() throws Exception {
|
||||
Point ls;
|
||||
robot.waitForIdle();
|
||||
|
||||
ls = north.getLocationOnScreen();
|
||||
checkClick(ls.x + north.getWidth() / 3, ls.y + north.getHeight() / 2, 0);
|
||||
|
||||
ls = center.getLocationOnScreen();
|
||||
checkClick(ls.x + center.getWidth() / 4, ls.y + center.getHeight() / 4, 1);
|
||||
|
||||
ls = center.getLocationOnScreen();
|
||||
checkClick(ls.x + center.getWidth() * 3 / 4, ls.y + center.getHeight() * 3 / 4, 1);
|
||||
|
||||
ls = south.getLocationOnScreen();
|
||||
checkClick(ls.x + south.getWidth() * 2 / 3, ls.y + south.getHeight() / 2, 2);
|
||||
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
background.dispose();
|
||||
window.dispose();
|
||||
});
|
||||
|
||||
robot.waitForIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyShape() { }
|
||||
|
||||
void checkClick(int x, int y, int flag) throws Exception {
|
||||
|
||||
System.out.println("Trying to click point " + x + ", " + y + ", looking for " + flag + " flag to trigger.");
|
||||
|
||||
clicked = 0;
|
||||
robot.mouseMove(x, y);
|
||||
robot.click();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
if ((clicked & (1 << flag)) == 0)
|
||||
robot.delay(50);
|
||||
else
|
||||
break;
|
||||
|
||||
if ((clicked & (1 << flag)) == 0)
|
||||
throw new RuntimeException("FAIL: Flag " + flag + " is not triggered for point " + x + ", " + y + "!");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2017, 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
|
||||
@key headful
|
||||
@bug 6594131 8186617
|
||||
@summary Tests the Window.get/setOpacity() methods
|
||||
*/
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Robot;
|
||||
|
||||
public class WindowOpacity {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
GraphicsDevice gd =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice();
|
||||
if (!gd.isWindowTranslucencySupported(
|
||||
GraphicsDevice.WindowTranslucency.TRANSLUCENT)) {
|
||||
System.out.println(
|
||||
"Either the Toolkit or the native system does not support"
|
||||
+ " controlling the window opacity level.");
|
||||
return;
|
||||
}
|
||||
Frame f = new Frame("Opacity test");
|
||||
try {
|
||||
test(f);
|
||||
} finally {
|
||||
f.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(final Frame f) throws AWTException {
|
||||
boolean passed;
|
||||
|
||||
f.setUndecorated(true);
|
||||
float curOpacity = f.getOpacity();
|
||||
if (curOpacity < 1.0f || curOpacity > 1.0f) {
|
||||
throw new RuntimeException(
|
||||
"getOpacity() reports the initial opacity level "
|
||||
+ "other than 1.0: " + curOpacity);
|
||||
}
|
||||
|
||||
|
||||
passed = false;
|
||||
try {
|
||||
f.setOpacity(-0.5f);
|
||||
} catch (IllegalArgumentException e) {
|
||||
passed = true;
|
||||
}
|
||||
if (!passed) {
|
||||
throw new RuntimeException(
|
||||
"setOpacity() allows passing negative opacity level.");
|
||||
}
|
||||
|
||||
|
||||
passed = false;
|
||||
try {
|
||||
f.setOpacity(1.5f);
|
||||
} catch (IllegalArgumentException e) {
|
||||
passed = true;
|
||||
}
|
||||
if (!passed) {
|
||||
throw new RuntimeException(
|
||||
"setOpacity() allows passing opacity level greater than 1.0.");
|
||||
}
|
||||
|
||||
|
||||
f.setOpacity(0.5f);
|
||||
curOpacity = f.getOpacity();
|
||||
if (curOpacity < 0.5f || curOpacity > 0.5f) {
|
||||
throw new RuntimeException(
|
||||
"setOpacity() reports the opacity level that "
|
||||
+ "differs from the value set with "
|
||||
+ "setWindowOpacity: " + curOpacity);
|
||||
}
|
||||
|
||||
|
||||
f.setOpacity(0.75f);
|
||||
curOpacity = f.getOpacity();
|
||||
if (curOpacity < 0.75f || curOpacity > 0.75f) {
|
||||
throw new RuntimeException(
|
||||
"getOpacity() reports the opacity level that "
|
||||
+ "differs from the value set with "
|
||||
+ "setWindowOpacity the second time: "
|
||||
+ curOpacity);
|
||||
}
|
||||
|
||||
|
||||
f.setBounds(100, 100, 300, 200);
|
||||
f.setVisible(true);
|
||||
Robot robot = new Robot();
|
||||
robot.waitForIdle();
|
||||
|
||||
curOpacity = f.getOpacity();
|
||||
if (curOpacity < 0.75f || curOpacity > 0.75f) {
|
||||
throw new RuntimeException(
|
||||
"getOpacity() reports the opacity level that "
|
||||
+ "differs from the value set with "
|
||||
+ "setWindowOpacity before showing the frame: "
|
||||
+ curOpacity);
|
||||
}
|
||||
f.setOpacity(0.5f);
|
||||
robot.waitForIdle();
|
||||
curOpacity = f.getOpacity();
|
||||
if (curOpacity < 0.5f || curOpacity > 0.5f) {
|
||||
throw new RuntimeException(
|
||||
"getOpacity() reports the opacity level that "
|
||||
+ "differs from the value set with "
|
||||
+ "setWindowOpacity after showing the frame: "
|
||||
+ curOpacity);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue