/** * Create possibly volatile scratch image for fast painting. A scratch image can become * invalidated, when this happens any actions involving it are ignored, and it needs to be * recreated. Use isScratchImageValid() to check this. */ public static Image createScratchImage(int width, int height) { try { Image img = (Image) tryMethod( output_comp, "createVolatileImage", new Object[] {new Integer(width), new Integer(height)}); if (img == null) { // no such method -> create regular image return output_comp.createImage(width, height); } // if (img.validate(output_comp.getGraphicsConfiguration()) // == VolatileImage.IMAGE_INCOMPATIBLE) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); Integer valid = (Integer) tryMethod(img, "validate", new Object[] {gc}); // output_comp.getGraphicsConfiguration() }); if (valid.intValue() == 2) { // I checked, IMAGE_INCOMPATIBLE=2 // Hmm, somehow it didn't work. Create regular image. return output_comp.createImage(width, height); } return img; } catch (java.security.AccessControlException e) { // we're not allowed to do this (we're probably an applet) return output_comp.createImage(width, height); } }
/** Create empty image with given alpha mode that should be efficient on this display */ public static BufferedImage createCompatibleImage(int width, int height, int transparency) { // try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); // always use bitmask transparency BufferedImage bimage = gc.createCompatibleImage(width, height, transparency); return bimage; // } catch (HeadlessException e) { // this exception is not in 1.2 // The system does not have a screen // e.printStackTrace(); // return null; // } }
public void setwnd() { GraphicsDevice dev = getGraphicsConfiguration().getDevice(); if (prefs == null) return; try { dev.setDisplayMode(prefs); dev.setFullScreenWindow(null); setVisible(false); dispose(); setUndecorated(false); setVisible(true); } catch (Exception e) { throw (new RuntimeException(e)); } prefs = null; }
public void setfs() { GraphicsDevice dev = getGraphicsConfiguration().getDevice(); if (prefs != null) return; prefs = dev.getDisplayMode(); try { setVisible(false); dispose(); setUndecorated(true); setVisible(true); dev.setFullScreenWindow(this); dev.setDisplayMode(fsmode); pack(); } catch (Exception e) { throw (new RuntimeException(e)); } }
DisplayMode findmode(int w, int h) { GraphicsDevice dev = getGraphicsConfiguration().getDevice(); if (!dev.isFullScreenSupported()) return (null); DisplayMode b = null; for (DisplayMode m : dev.getDisplayModes()) { int d = m.getBitDepth(); if ((m.getWidth() == w) && (m.getHeight() == h) && ((d == 24) || (d == 32) || (d == DisplayMode.BIT_DEPTH_MULTI))) { if ((b == null) || (d > b.getBitDepth()) || ((d == b.getBitDepth()) && (m.getRefreshRate() > b.getRefreshRate()))) b = m; } } return (b); }
public GraphicsDevice getGraphicsDeviceAt(Point pos) { GraphicsDevice device = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice lstGDs[] = ge.getScreenDevices(); ArrayList<GraphicsDevice> lstDevices = new ArrayList<>(lstGDs.length); for (GraphicsDevice gd : lstGDs) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); Rectangle screenBounds = gc.getBounds(); if (screenBounds.contains(pos)) { lstDevices.add(gd); } } if (lstDevices.size() == 1) { device = lstDevices.get(0); } return device; }
public Rectangle getScreenViewableBounds(GraphicsDevice gd) { Rectangle bounds = new Rectangle(0, 0, 0, 0); if (gd != null) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); bounds = gc.getBounds(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); bounds.x += insets.left; bounds.y += insets.top; bounds.width -= (insets.left + insets.right); bounds.height -= (insets.top + insets.bottom); } return bounds; }
public GraphicsConfiguration getDeviceConfiguration() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); return (gd.getDefaultConfiguration()); }