Java Code Examples for java.awt.GraphicsDevice#getDefaultConfiguration()
The following examples show how to use
java.awt.GraphicsDevice#getDefaultConfiguration() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Skin.java From dsworkbench with Apache License 2.0 | 6 votes |
public Image getImage(int pID, double pScaling) { try { HashMap<Double, BufferedImage> imageCache = cache.get(pID); if (imageCache == null) { imageCache = new HashMap<>(); cache.put(pID, imageCache); } BufferedImage cached = imageCache.get(pScaling); if (cached == null) { Image scaled = mTextures.get(pID).getScaledInstance((int) (iFieldWidth / pScaling), (int) (iFieldHeight / pScaling), BufferedImage.SCALE_REPLICATE); GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); cached = gc.createCompatibleImage(scaled.getWidth(null), scaled.getHeight(null), Transparency.BITMASK); Graphics2D g = cached.createGraphics(); g.drawImage(scaled, 0, 0, null); g.dispose(); imageCache.put(pScaling, cached); } return cached; } catch (Exception e) { return null; } }
Example 2
Source File: MarsTerminal.java From mars-sim with GNU General Public License v3.0 | 6 votes |
static Image iconToImage(Icon icon) { if (icon instanceof ImageIcon) { return ((ImageIcon)icon).getImage(); } else { int w = icon.getIconWidth(); int h = icon.getIconHeight(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage image = gc.createCompatibleImage(w, h); Graphics2D g = image.createGraphics(); icon.paintIcon(null, g, 0, 0); g.dispose(); return image; } }
Example 3
Source File: bug8071705.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static Rectangle setLocation(JFrame frame, GraphicsDevice device) { GraphicsConfiguration conf = device.getDefaultConfiguration(); Rectangle bounds = conf.getBounds(); // put just below half screen int x = bounds.x + bounds.width/2; int y = bounds.y + bounds.height/2; frame.setLocation(x, y); return bounds; }
Example 4
Source File: D3DSurfaceData.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static D3DGraphicsConfig getGC(WComponentPeer peer) { GraphicsConfiguration gc; if (peer != null) { gc = peer.getGraphicsConfiguration(); } else { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = env.getDefaultScreenDevice(); gc = gd.getDefaultConfiguration(); } return (gc instanceof D3DGraphicsConfig) ? (D3DGraphicsConfig)gc : null; }
Example 5
Source File: Loupe.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 5 votes |
private BufferedImage createBuffer() { GraphicsEnvironment local = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = local.getDefaultScreenDevice(); GraphicsConfiguration config = device.getDefaultConfiguration(); Container parent = getParent(); return config.createCompatibleImage(parent.getWidth(), parent.getHeight(), Transparency.TRANSLUCENT); }
Example 6
Source File: X11SurfaceData.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static X11GraphicsConfig getGC(X11ComponentPeer peer) { if (peer != null) { return (X11GraphicsConfig) peer.getGraphicsConfiguration(); } else { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = env.getDefaultScreenDevice(); return (X11GraphicsConfig)gd.getDefaultConfiguration(); } }
Example 7
Source File: SunGraphicsEnvironment.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Return the bounds of a GraphicsDevice, less its screen insets. * See also java.awt.GraphicsEnvironment.getUsableBounds(); */ public static Rectangle getUsableBounds(GraphicsDevice gd) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle usableBounds = gc.getBounds(); usableBounds.x += insets.left; usableBounds.y += insets.top; usableBounds.width -= (insets.left + insets.right); usableBounds.height -= (insets.top + insets.bottom); return usableBounds; }
Example 8
Source File: D3DSurfaceData.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static D3DGraphicsConfig getGC(WComponentPeer peer) { GraphicsConfiguration gc; if (peer != null) { gc = peer.getGraphicsConfiguration(); } else { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = env.getDefaultScreenDevice(); gc = gd.getDefaultConfiguration(); } return (gc instanceof D3DGraphicsConfig) ? (D3DGraphicsConfig)gc : null; }
Example 9
Source File: D3DSurfaceData.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static D3DGraphicsConfig getGC(WComponentPeer peer) { GraphicsConfiguration gc; if (peer != null) { gc = peer.getGraphicsConfiguration(); } else { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = env.getDefaultScreenDevice(); gc = gd.getDefaultConfiguration(); } return (gc instanceof D3DGraphicsConfig) ? (D3DGraphicsConfig)gc : null; }
Example 10
Source File: CGLSurfaceData.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static CGLGraphicsConfig getGC(CPlatformView pView) { if (pView != null) { return (CGLGraphicsConfig)pView.getGraphicsConfiguration(); } else { // REMIND: this should rarely (never?) happen, but what if // default config is not CGL? GraphicsEnvironment env = GraphicsEnvironment .getLocalGraphicsEnvironment(); GraphicsDevice gd = env.getDefaultScreenDevice(); return (CGLGraphicsConfig) gd.getDefaultConfiguration(); } }
Example 11
Source File: UnmanagedDrawImagePerformance.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static VolatileImage makeVI(final int type) { final GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); final GraphicsDevice gd = ge.getDefaultScreenDevice(); final GraphicsConfiguration gc = gd.getDefaultConfiguration(); return gc.createCompatibleVolatileImage(SIZE, SIZE, type); }
Example 12
Source File: bug8071705.java From hottub with GNU General Public License v2.0 | 5 votes |
private static Rectangle setLocation(JFrame frame, GraphicsDevice device) { GraphicsConfiguration conf = device.getDefaultConfiguration(); Rectangle bounds = conf.getBounds(); // put just below half screen int x = bounds.x + bounds.width/2; int y = bounds.y + bounds.height/2; frame.setLocation(x, y); return bounds; }
Example 13
Source File: GLXSurfaceData.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static GLXGraphicsConfig getGC(X11ComponentPeer peer) { if (peer != null) { return (GLXGraphicsConfig)peer.getGraphicsConfiguration(); } else { // REMIND: this should rarely (never?) happen, but what if // default config is not GLX? GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = env.getDefaultScreenDevice(); return (GLXGraphicsConfig)gd.getDefaultConfiguration(); } }
Example 14
Source File: imageOps.java From openbd-core with GNU General Public License v3.0 | 5 votes |
public static BufferedImage rotate(BufferedImage _origImg, int angle, Color bgColor) { // Convert the degrees to radians double radians = Math.toRadians(angle); // Determine the sin and cos of the angle double sin = Math.abs(Math.sin(radians)); double cos = Math.abs(Math.cos(radians)); // Store the original width and height of the image int w = _origImg.getWidth(); int h = _origImg.getHeight(); // Determine the width and height of the rotated image int neww = (int) Math.floor(w * cos + h * sin); int newh = (int) Math.floor(h * cos + w * sin); // Create a BufferedImage to store the rotated image GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.OPAQUE); // Render the rotated image Graphics2D g = result.createGraphics(); g.setBackground(bgColor); g.clearRect(0, 0, neww, newh); g.translate((neww - w) / 2, (newh - h) / 2); g.rotate(radians, w / 2, h / 2); g.drawRenderedImage(_origImg, null); g.dispose(); // Return the rotated image return result; }
Example 15
Source File: X11SurfaceData.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static X11GraphicsConfig getGC(X11ComponentPeer peer) { if (peer != null) { return (X11GraphicsConfig) peer.getGraphicsConfiguration(); } else { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = env.getDefaultScreenDevice(); return (X11GraphicsConfig)gd.getDefaultConfiguration(); } }
Example 16
Source File: SunGraphicsEnvironment.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * Return the bounds of a GraphicsDevice, less its screen insets. * See also java.awt.GraphicsEnvironment.getUsableBounds(); */ public static Rectangle getUsableBounds(GraphicsDevice gd) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); Rectangle usableBounds = gc.getBounds(); usableBounds.x += insets.left; usableBounds.y += insets.top; usableBounds.width -= (insets.left + insets.right); usableBounds.height -= (insets.top + insets.bottom); return usableBounds; }
Example 17
Source File: ScreenInsetsTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { boolean passed = true; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gds = ge.getScreenDevices(); for (GraphicsDevice gd : gds) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); Rectangle gcBounds = gc.getBounds(); Insets gcInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc); int left = gcInsets.left; int right = gcInsets.right; int bottom = gcInsets.bottom; int top = gcInsets.top; if (left < 0 || right < 0 || bottom < 0 || top < 0) { throw new RuntimeException("Negative value: " + gcInsets); } int maxW = gcBounds.width / 3; int maxH = gcBounds.height / 3; if (left > maxW || right > maxW || bottom > maxH || top > maxH) { throw new RuntimeException("Big value: " + gcInsets); } if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { // this state is used in the test - sorry continue; } Frame f = new Frame("Test", gc); f.setUndecorated(true); f.setBounds(gcBounds.x + 100, gcBounds.y + 100, 320, 240); f.setVisible(true); Util.waitForIdle(null); f.setExtendedState(Frame.MAXIMIZED_BOTH); Util.waitForIdle(null); Rectangle fBounds = f.getBounds(); // workaround: on Windows maximized windows have negative coordinates if (fBounds.x < gcBounds.x) { fBounds.width -= (gcBounds.x - fBounds.x) * 2; // width is decreased fBounds.x = gcBounds.x; } if (fBounds.y < gcBounds.y) { fBounds.height -= (gcBounds.y - fBounds.y) * 2; // height is decreased fBounds.y = gcBounds.y; } Insets expected = new Insets(fBounds.y - gcBounds.y, fBounds.x - gcBounds.x, gcBounds.y + gcBounds.height - fBounds.y - fBounds.height, gcBounds.x + gcBounds.width - fBounds.x - fBounds.width); if (!expected.equals(gcInsets)) { passed = false; System.err.println("Wrong insets for GraphicsConfig: " + gc); System.err.println("\tExpected: " + expected); System.err.println("\tActual: " + gcInsets); } f.dispose(); } if (!passed) { throw new RuntimeException("TEST FAILED: Toolkit.getScreenInsets() returns wrong value for some screens"); } }
Example 18
Source File: RSLContextInvalidationTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); VolatileImage vi = gc.createCompatibleVolatileImage(100, 100); vi.validate(gc); VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100); vi1.validate(gc); if (!(vi instanceof DestSurfaceProvider)) { System.out.println("Test considered PASSED: no HW acceleration"); return; } DestSurfaceProvider p = (DestSurfaceProvider)vi; Surface s = p.getDestSurface(); if (!(s instanceof AccelSurface)) { System.out.println("Test considered PASSED: no HW acceleration"); return; } AccelSurface dst = (AccelSurface)s; Graphics g = vi.createGraphics(); g.drawImage(vi1, 95, 95, null); g.setColor(Color.red); g.fillRect(0, 0, 100, 100); g.setColor(Color.black); g.fillRect(0, 0, 100, 100); // after this the validated context color is black RenderQueue rq = dst.getContext().getRenderQueue(); rq.lock(); try { dst.getContext().saveState(); dst.getContext().restoreState(); } finally { rq.unlock(); } // this will cause ResetPaint (it will set color to extended EA=ff, // which is ffffffff==Color.white) g.drawImage(vi1, 95, 95, null); // now try filling with black again, but it will come up as white // because this fill rect won't validate the color properly g.setColor(Color.black); g.fillRect(0, 0, 100, 100); BufferedImage bi = vi.getSnapshot(); if (bi.getRGB(50, 50) != Color.black.getRGB()) { throw new RuntimeException("Test FAILED: found color="+ Integer.toHexString(bi.getRGB(50, 50))+" instead of "+ Integer.toHexString(Color.black.getRGB())); } System.out.println("Test PASSED."); }
Example 19
Source File: MultiScreenLocationTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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!"); }
Example 20
Source File: RSLContextInvalidationTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); VolatileImage vi = gc.createCompatibleVolatileImage(100, 100); vi.validate(gc); VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100); vi1.validate(gc); if (!(vi instanceof DestSurfaceProvider)) { System.out.println("Test considered PASSED: no HW acceleration"); return; } DestSurfaceProvider p = (DestSurfaceProvider)vi; Surface s = p.getDestSurface(); if (!(s instanceof AccelSurface)) { System.out.println("Test considered PASSED: no HW acceleration"); return; } AccelSurface dst = (AccelSurface)s; Graphics g = vi.createGraphics(); g.drawImage(vi1, 95, 95, null); g.setColor(Color.red); g.fillRect(0, 0, 100, 100); g.setColor(Color.black); g.fillRect(0, 0, 100, 100); // after this the validated context color is black RenderQueue rq = dst.getContext().getRenderQueue(); rq.lock(); try { dst.getContext().saveState(); dst.getContext().restoreState(); } finally { rq.unlock(); } // this will cause ResetPaint (it will set color to extended EA=ff, // which is ffffffff==Color.white) g.drawImage(vi1, 95, 95, null); // now try filling with black again, but it will come up as white // because this fill rect won't validate the color properly g.setColor(Color.black); g.fillRect(0, 0, 100, 100); BufferedImage bi = vi.getSnapshot(); if (bi.getRGB(50, 50) != Color.black.getRGB()) { throw new RuntimeException("Test FAILED: found color="+ Integer.toHexString(bi.getRGB(50, 50))+" instead of "+ Integer.toHexString(Color.black.getRGB())); } System.out.println("Test PASSED."); }