use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class MultiScreenInsetsTest method main.
public static void main(String[] args) throws InterruptedException {
OSInfo.OSType type = OSInfo.getOSType();
if (type != OSInfo.OSType.LINUX && type != OSInfo.OSType.SOLARIS) {
System.out.println("This test is for Solaris and Linux only..." + "skipping!");
return;
}
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multi-screen test... skipping!");
return;
}
for (int screen = 0; screen < gds.length; ++screen) {
GraphicsDevice gd = gds[screen];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle bounds = gc.getBounds();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
Frame frame = new Frame(gc);
frame.setLocation(bounds.x + (bounds.width - SIZE) / 2, bounds.y + (bounds.height - SIZE) / 2);
frame.setSize(SIZE, SIZE);
frame.setUndecorated(true);
frame.setVisible(true);
// Maximize Frame to reach the struts
frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
Thread.sleep(2000);
Rectangle frameBounds = frame.getBounds();
frame.dispose();
if (bounds.x + insets.left != frameBounds.x || bounds.y + insets.top != frameBounds.y || bounds.width - insets.right - insets.left != frameBounds.width || bounds.height - insets.bottom - insets.top != frameBounds.height) {
throw new RuntimeException("Test FAILED! Wrong screen #" + screen + " insets: " + insets);
}
}
System.out.println("Test PASSED!");
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class MultiScreenLocationTest method main.
public static void main(String[] args) throws AWTException {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multiscreen test... skipping!");
return;
}
for (int i = 0; i < gds.length; ++i) {
GraphicsDevice gd = gds[i];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle screen = gc.getBounds();
Robot robot = new Robot(gd);
// check Robot.mouseMove()
robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
Point mouse = MouseInfo.getPointerInfo().getLocation();
Point point = screen.getLocation();
point.translate(mouseOffset.x, mouseOffset.y);
if (!point.equals(mouse)) {
throw new RuntimeException(getErrorText("Robot.mouseMove", i));
}
// check Robot.getPixelColor()
Frame frame = new Frame(gc);
frame.setUndecorated(true);
frame.setSize(100, 100);
frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
frame.setBackground(color);
frame.setVisible(true);
robot.waitForIdle();
Rectangle bounds = frame.getBounds();
if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
}
// check Robot.createScreenCapture()
BufferedImage image = robot.createScreenCapture(bounds);
int rgb = color.getRGB();
if (image.getRGB(0, 0) != rgb || image.getRGB(image.getWidth() - 1, 0) != rgb || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb || image.getRGB(0, image.getHeight() - 1) != rgb) {
throw new RuntimeException(getErrorText("Robot.createScreenCapture", i));
}
frame.dispose();
}
System.out.println("Test PASSED!");
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class DeviceIdentificationTest method main.
public static void main(String[] args) {
final Frame f = new Frame("DeviceIdentificationTest");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
f.dispose();
}
});
f.addComponentListener(new ComponentAdapter() {
public void componentMoved(ComponentEvent e) {
f.setTitle("Currently on: " + f.getGraphicsConfiguration().getDevice());
}
});
Panel p = new Panel();
Button b = new Button("Print Current Devices");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
int i = 0;
System.err.println("--- Devices: ---");
for (GraphicsDevice gd : gds) {
System.err.println("Device[" + i + "]= " + gd);
System.err.println(" bounds = " + gd.getDefaultConfiguration().getBounds());
i++;
}
System.err.println("-------------------");
}
});
p.add(b);
b = new Button("Print My Device");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GraphicsConfiguration gc = f.getGraphicsConfiguration();
GraphicsDevice gd = gc.getDevice();
System.err.println("--- My Device ---");
System.err.println("Device = " + gd);
System.err.println(" bounds = " + gd.getDefaultConfiguration().getBounds());
}
});
p.add(b);
b = new Button("Create FS Frame on my Device");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GraphicsConfiguration gc = f.getGraphicsConfiguration();
final GraphicsDevice gd = gc.getDevice();
System.err.println("--- Creating FS Frame on Device ---");
System.err.println("Device = " + gd);
System.err.println(" bounds = " + gd.getDefaultConfiguration().getBounds());
final Frame fsf = new Frame("Full-screen Frame on dev" + gd, gc) {
public void paint(Graphics g) {
g.setColor(Color.green);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.red);
g.drawString("FS on device: " + gd, 200, 200);
g.drawString("Click to exit Full-screen.", 200, 250);
}
};
fsf.setUndecorated(true);
fsf.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
gd.setFullScreenWindow(null);
fsf.dispose();
}
});
gd.setFullScreenWindow(fsf);
}
});
p.add(b);
f.add("North", p);
p = new Panel();
b = new Button("Test Passed");
b.setBackground(Color.green);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Test Passed");
f.dispose();
}
});
p.add(b);
b = new Button("Test Failed");
b.setBackground(Color.red);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Test FAILED");
f.dispose();
throw new RuntimeException("Test FAILED");
}
});
p.add(b);
f.add("South", p);
f.pack();
f.setVisible(true);
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class IncorrectClipXorModeSurface2Surface method main.
public static void main(final String[] args) throws IOException {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
AffineTransform at;
for (int size : SIZES) {
at = AffineTransform.getScaleInstance(size, size);
for (Shape clip : SHAPES) {
clip = at.createTransformedShape(clip);
for (Shape to : SHAPES) {
to = at.createTransformedShape(to);
// Prepare test images
BufferedImage snapshot;
VolatileImage source = getVolatileImage(gc, size);
VolatileImage target = getVolatileImage(gc, size);
int attempt = 0;
while (true) {
if (++attempt > 10) {
throw new RuntimeException("Too many attempts: " + attempt);
}
// Prepare source images
source.validate(gc);
Graphics2D g2d = source.createGraphics();
g2d.setColor(Color.RED);
g2d.fillRect(0, 0, size, size);
g2d.dispose();
if (source.validate(gc) != VolatileImage.IMAGE_OK) {
continue;
}
// Prepare target images
target.validate(gc);
g2d = target.createGraphics();
g2d.setColor(Color.GREEN);
g2d.fillRect(0, 0, size, size);
g2d.dispose();
if (target.validate(gc) != VolatileImage.IMAGE_OK) {
continue;
}
draw(clip, to, source, target);
snapshot = target.getSnapshot();
if (source.contentsLost() || target.contentsLost()) {
continue;
}
break;
}
// Prepare gold images
BufferedImage goldS = getSourceGold(gc, size);
BufferedImage goldT = getTargetGold(gc, size);
draw(clip, to, goldS, goldT);
validate(snapshot, goldT);
source.flush();
target.flush();
}
}
}
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class StrikeDisposalCrashTest method main.
public static void main(String[] args) {
System.setProperty("sun.java2d.font.reftype", "weak");
GraphicsDevice[] gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
Frame[] frames = new Frame[gd.length];
for (int i = 0; i < frames.length; i++) {
GraphicsConfiguration gc = gd[i].getDefaultConfiguration();
Frame f = new Frame("Frame on " + gc, gc);
f.setSize(100, 100);
f.setLocation(gc.getBounds().x, gc.getBounds().y);
f.pack();
frames[i] = f;
}
Font f1 = new Font("Dialog", Font.PLAIN, 10);
Font f2 = new Font("Dialog", Font.ITALIC, 12);
for (int i = 0; i < frames.length / 2; i++) {
// making sure the glyphs are cached in the accel. cache on
// one frame, then the other
renderText(frames[i], f1);
renderText(frames[frames.length - 1 - i], f1);
// and now the other way around, with different glyphs
renderText(frames[frames.length - 1 - i], f2);
renderText(frames[i], f2);
}
// try to force strike disposal (note that we have to use
// -Dsun.java2d.font.reftype=weak to facilitate the disposal)
System.gc();
System.runFinalization();
System.gc();
System.runFinalization();
for (Frame f : frames) {
f.dispose();
}
System.err.println("Exiting. If the test crashed after this it FAILED");
}
Aggregations