use of java.awt.GraphicsEnvironment 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.GraphicsEnvironment in project jdk8u_jdk by JetBrains.
the class IncorrectSourceOffset method main.
public static void main(final String[] args) throws IOException {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(511, 255);
BufferedImage bi = new BufferedImage(511, 255, BufferedImage.TYPE_INT_ARGB);
BufferedImage gold = new BufferedImage(511, 255, BufferedImage.TYPE_INT_ARGB);
fill(gold);
while (true) {
vi.validate(gc);
fill(vi);
if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
try {
Thread.sleep(100);
} catch (final InterruptedException ignored) {
}
continue;
}
Graphics2D big = bi.createGraphics();
big.drawImage(vi, 7, 11, 127, 111, 7, 11, 127, 111, null);
big.dispose();
if (vi.contentsLost()) {
try {
Thread.sleep(100);
} catch (final InterruptedException ignored) {
}
continue;
}
break;
}
for (int x = 7; x < 127; ++x) {
for (int y = 11; y < 111; ++y) {
if (gold.getRGB(x, y) != bi.getRGB(x, y)) {
ImageIO.write(gold, "png", new File("gold.png"));
ImageIO.write(bi, "png", new File("bi.png"));
throw new RuntimeException("Test failed.");
}
}
}
}
use of java.awt.GraphicsEnvironment in project karaf by apache.
the class ScreenshotDumpProvider method createDump.
/**
* {@inheritDoc}
*/
public void createDump(DumpDestination destination) throws Exception {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
// get all graphic devices attached to computer
GraphicsDevice[] gs = ge.getScreenDevices();
// create dump entry for each device
for (int i = 0; i < gs.length; i++) {
DisplayMode mode = gs[i].getDisplayMode();
Rectangle bounds = new Rectangle(0, 0, mode.getWidth(), mode.getHeight());
BufferedImage screenshot = new Robot(gs[i]).createScreenCapture(bounds);
// to attach your entry to destination you have to execute this line
OutputStream outputStream = destination.add("screenshot/display_" + i + ".png");
ImageIO.write(screenshot, "PNG", outputStream);
outputStream.close();
}
}
use of java.awt.GraphicsEnvironment in project JMRI by JMRI.
the class ReportContext method addScreenSize.
/**
* Provide screen - size information. This is based on the
* jmri.util.JmriJFrame calculation, but isn't refactored to there because
* we also want diagnostic info
*/
public void addScreenSize() {
try {
// Find screen size. This throws null-pointer exceptions on
// some Java installs, however, for unknown reasons, so be
// prepared to fall back.
JFrame dummy = new JFrame();
try {
Insets insets = dummy.getToolkit().getScreenInsets(dummy.getGraphicsConfiguration());
Dimension screen = dummy.getToolkit().getScreenSize();
addString("Screen size h:" + screen.height + ", w:" + screen.width + " Inset t:" + insets.top + ", b:" + insets.bottom + "; l:" + insets.left + ", r:" + insets.right);
} catch (NoSuchMethodError ex) {
Dimension screen = dummy.getToolkit().getScreenSize();
addString("Screen size h:" + screen.height + ", w:" + screen.width + " (No Inset method available)");
}
} catch (HeadlessException ex) {
// failed, fall back to standard method
addString("(Cannot sense screen size due to " + ex.toString() + ")");
}
try {
// Find screen resolution. Not expected to fail, but just in case....
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
addString("Screen resolution: " + dpi);
} catch (HeadlessException ex) {
addString("Screen resolution not available");
}
//Rectangle virtualBounds = new Rectangle();
try {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
addString("Environment max bounds: " + ge.getMaximumWindowBounds());
try {
GraphicsDevice[] gs = ge.getScreenDevices();
for (GraphicsDevice gd : gs) {
GraphicsConfiguration[] gc = gd.getConfigurations();
for (int i = 0; i < gc.length; i++) {
addString("bounds[" + i + "] = " + gc[i].getBounds());
// virtualBounds = virtualBounds.union(gc[i].getBounds());
}
addString("Device: " + gd.getIDstring() + " bounds = " + gd.getDefaultConfiguration().getBounds() + " " + gd.getDefaultConfiguration().toString());
}
} catch (HeadlessException ex) {
addString("Exception getting device bounds " + ex.getMessage());
}
} catch (HeadlessException ex) {
addString("Exception getting max window bounds " + ex.getMessage());
}
// various Linux window managers
try {
Insets jmriInsets = JmriInsets.getInsets();
addString("JmriInsets t:" + jmriInsets.top + ", b:" + jmriInsets.bottom + "; l:" + jmriInsets.left + ", r:" + jmriInsets.right);
} catch (Exception ex) {
addString("Exception getting JmriInsets" + ex.getMessage());
}
}
use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.
the class CustomCompositeTest method main.
public static void main(String[] args) {
paintLatch = new CountDownLatch(1);
paintError = null;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
initGUI();
}
});
try {
paintLatch.await();
} catch (InterruptedException e) {
}
;
System.out.println("Paint is done!");
if (paintError != null) {
frame.dispose();
throw new RuntimeException("Test FAILED.", paintError);
}
System.out.println("Phase 1: PASSED.");
// now resise the frame in order to cause re-paint with accelerated
// source images.
paintError = null;
paintLatch = new CountDownLatch(1);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Dimension size = frame.getSize();
size.width += 50;
size.height += 50;
frame.setSize(size);
}
});
try {
paintLatch.await();
} catch (InterruptedException e) {
}
;
if (paintError != null) {
frame.dispose();
throw new RuntimeException("Resize test FAILED.", paintError);
}
frame.dispose();
System.out.println("Phase 2: PASSED.");
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration cfg = env.getDefaultScreenDevice().getDefaultConfiguration();
// test rendering to accelerated volatile image
testVolatileImage(cfg, true);
System.out.println("Phase 3: PASSED.");
// test rendering to unaccelerated volatile image
testVolatileImage(cfg, false);
System.out.println("Phase 4: PASSED.");
}
Aggregations