List of usage examples for java.awt GraphicsEnvironment getLocalGraphicsEnvironment
public static GraphicsEnvironment getLocalGraphicsEnvironment()
From source file:Main.java
/** * Returns the GraphicsConfiguration for a point. *///from w ww . j a v a 2s . c o m public static GraphicsConfiguration getGraphicsConfiguration(Component aComp, int anX, int aY) { // Get initial GC from component (if available) and point on screen GraphicsConfiguration gc = aComp != null ? aComp.getGraphicsConfiguration() : null; Point spoint = getScreenLocation(aComp, anX, aY); // Replace with alternate GraphicsConfiguration if point on another screen for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) { GraphicsConfiguration dgc = gd.getDefaultConfiguration(); if (dgc.getBounds().contains(spoint.x, spoint.y)) { gc = dgc; break; } } } // Return GraphicsConfiguration return gc; }
From source file:Main.java
/** * Gers screen rectangle/* www .j a v a 2 s. co m*/ * * @return */ private static Rectangle getScreenRect() { final Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); return screen; }
From source file:Main.java
public static GraphicsConfiguration getGraphicsConfigurationForCurrentLocation(Window window) { GraphicsConfiguration ownedConfig = window.getGraphicsConfiguration(); Point currLocation = window.getLocation(); // Shortcut for "owned" case if (ownedConfig.getBounds().contains(currLocation)) return ownedConfig; // Search for the right screen GraphicsDevice[] screens = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); for (GraphicsDevice screen : screens) for (GraphicsConfiguration config : screen.getConfigurations()) if (config.getBounds().contains(currLocation)) return config; // If none found, lets return the "owned" one return ownedConfig; }
From source file:Main.java
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }/* w w w. j av a 2 s . c o m*/ // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200, gc.getImageCapabilities()); } catch (Exception e) { // The system does not have a screen } return bimage; }
From source file:Main.java
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }//from w ww .j ava 2 s . c o m // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200); } catch (HeadlessException e) { // The system does not have a screen } return bimage; }
From source file:Main.java
private static Rectangle getScreenBounds(Window aWindow) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] devices = ge.getScreenDevices(); if (aWindow == null) return devices[0].getDefaultConfiguration().getBounds(); Rectangle bounds = aWindow.getBounds(); int centerX = (int) bounds.getCenterX(); int centerY = (int) bounds.getCenterY(); for (GraphicsDevice device : devices) { GraphicsConfiguration gc = device.getDefaultConfiguration(); Rectangle rect = gc.getBounds(); if (rect.contains(centerX, centerY)) return rect; }/* www .j a v a2s .c o m*/ return null; }
From source file:Main.java
/** * Returns current screen size of the display. In case of multi-display system it returns the * screen size for default one.//from w w w. j av a 2s . c o m * @return */ public static Dimension getEffectiveScreenSize() { GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); int width = gd.getDisplayMode().getWidth(); int height = gd.getDisplayMode().getHeight(); return new Dimension(width, height); }
From source file:SwingUtil.java
/** * Verifies if the given point is visible on the screen. * //from ww w. j a v a 2 s. com * @param location The given location on the screen. * @return True if the location is on the screen, false otherwise. */ public static boolean isLocationInScreenBounds(Point location) { // Check if the location is in the bounds of one of the graphics devices. GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices(); Rectangle graphicsConfigurationBounds = new Rectangle(); // Iterate over the graphics devices. for (int j = 0; j < graphicsDevices.length; j++) { // Get the bounds of the device. GraphicsDevice graphicsDevice = graphicsDevices[j]; graphicsConfigurationBounds.setRect(graphicsDevice.getDefaultConfiguration().getBounds()); // Is the location in this bounds? graphicsConfigurationBounds.setRect(graphicsConfigurationBounds.x, graphicsConfigurationBounds.y, graphicsConfigurationBounds.width, graphicsConfigurationBounds.height); if (graphicsConfigurationBounds.contains(location.x, location.y)) { // The location is in this screengraphics. return true; } } // We could not find a device that contains the given point. return false; }
From source file:Main.java
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }/* www. j a va 2s . com*/ // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200, gc.getImageCapabilities(), Transparency.BITMASK); } catch (Exception e) { // The system does not have a screen } return bimage; }
From source file:Main.java
/** * Updates {@link #SCREEN_SIZE_PRIMARY } and {@link #SCREEN_SIZE_TOTAL} *///from w w w . j a va2s .c o m public static void calculateScreenSizes() { Rectangle totalBounds = new Rectangle(); Rectangle primaryBounds = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int j = 0; j < gs.length; j++) { GraphicsDevice gd = gs[j]; if (gd == ge.getDefaultScreenDevice()) { primaryBounds = new Rectangle(); } GraphicsConfiguration[] gc = gd.getConfigurations(); for (int i = 0; i < gc.length; i++) { Rectangle bounds = gc[i].getBounds(); Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc[i]); bounds.x += screenInsets.left; bounds.y += screenInsets.top; bounds.height -= screenInsets.bottom; bounds.width -= screenInsets.right; totalBounds = totalBounds.union(bounds); if (primaryBounds != null) { primaryBounds = primaryBounds.union(bounds); } } if (primaryBounds != null) { SCREEN_SIZE_PRIMARY = primaryBounds; primaryBounds = null; } } SCREEN_SIZE_TOTAL = totalBounds; }