/** * 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); } }
private static GraphicsDevice getScreen(JFrame window) { for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { if (gd.getDefaultConfiguration().getBounds().contains(window.getLocationOnScreen())) return gd; } System.err.println( window + " does not appear to be on any screen; fullscreening onto default screen"); return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); }
/** 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 static void toFullScreen( JFrame window, GraphicsDevice gd, boolean tryAppleFullscreen, boolean tryExclusiveFullscreen) { if (appleEawtAvailable() && tryAppleFullscreen && appleOSVersion() >= 7 && // lion and above javaVersion() >= 7) { // java 7 and above System.out.println("trying to apple fullscreen"); enableAppleFullscreen(window); doAppleFullscreen(window); } else if (appleEawtAvailable() && // Snow Leopard and below OR apple java 6 and below TODO: test this on SL tryExclusiveFullscreen && gd.isFullScreenSupported()) { if (javaVersion() >= 7) setAutoRequestFocus(window, true); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setUndecorated(true); // window.setExtendedState(JFrame.MAXIMIZED_BOTH); gd.setFullScreenWindow(window); window.toFront(); Rectangle r = gd.getDefaultConfiguration().getBounds(); window.setBounds(r); // window.pack(); } else { // Windows and Linux TODO: test this window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setUndecorated(true); window.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight()); window.setLocation(0, 0); window.setExtendedState(JFrame.MAXIMIZED_BOTH); window.toFront(); } window.pack(); window.setVisible(true); }