use of java.awt.GraphicsDevice 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.GraphicsDevice 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.GraphicsDevice in project jdk8u_jdk by JetBrains.
the class CPlatformLWWindow method getGraphicsDevice.
@Override
public GraphicsDevice getGraphicsDevice() {
CGraphicsEnvironment ge = (CGraphicsEnvironment) GraphicsEnvironment.getLocalGraphicsEnvironment();
LWLightweightFramePeer peer = (LWLightweightFramePeer) getPeer();
int scale = ((LightweightFrame) peer.getTarget()).getScaleFactor();
Rectangle bounds = ((LightweightFrame) peer.getTarget()).getHostBounds();
for (GraphicsDevice d : ge.getScreenDevices()) {
if (d.getDefaultConfiguration().getBounds().intersects(bounds) && ((CGraphicsDevice) d).getScaleFactor() == scale) {
return d;
}
}
// We shouldn't be here...
return ge.getDefaultScreenDevice();
}
use of java.awt.GraphicsDevice in project vcell by virtualcell.
the class DialogUtils method findScreen.
public static int findScreen(JDialog dialog) {
GraphicsConfiguration config = dialog.getGraphicsConfiguration();
GraphicsDevice myScreen = config.getDevice();
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] allScreens = env.getScreenDevices();
int myScreenIndex = -1;
for (int i = 0; i < allScreens.length; i++) {
if (allScreens[i].equals(myScreen)) {
myScreenIndex = i;
break;
}
}
System.out.println("Dialog is on screen " + myScreenIndex);
return myScreenIndex;
}
use of java.awt.GraphicsDevice in project Lucee by lucee.
the class Image method toBufferedImage.
// This method returns a buffered image with the contents of an image
public static BufferedImage toBufferedImage(java.awt.Image image) {
if (image instanceof BufferedImage) {
return (BufferedImage) image;
}
// This code ensures that all the pixels in the image are loaded
image = new ImageIcon(image).getImage();
// Determine if the image has transparent pixels; for this method's
boolean hasAlpha = hasAlpha(image);
// Create a buffered image with a format that's compatible with the screen
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
// Determine the type of transparency of the new buffered image
int transparency = Transparency.OPAQUE;
if (hasAlpha) {
transparency = Transparency.BITMASK;
}
// Create the buffered image
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
} catch (HeadlessException e) {
// The system does not have a screen
}
if (bimage == null) {
// Create a buffered image using the default color model
int type = BufferedImage.TYPE_INT_RGB;
if (hasAlpha) {
type = BufferedImage.TYPE_INT_ARGB;
}
bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
}
// Copy image to buffered image
Graphics g = bimage.createGraphics();
// Paint the image onto the buffered image
g.drawImage(image, 0, 0, null);
g.dispose();
return bimage;
}
Aggregations