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();
 }
Exemple #2
0
 /**
  * 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);
   }
 }
Exemple #3
0
 public static BufferedImage tileImage(BufferedImage im, int width, int height) {
   GraphicsConfiguration gc =
       GraphicsEnvironment.getLocalGraphicsEnvironment()
           .getDefaultScreenDevice()
           .getDefaultConfiguration();
   int transparency = Transparency.OPAQUE; // Transparency.BITMASK;
   BufferedImage compatible = gc.createCompatibleImage(width, height, transparency);
   Graphics2D g = (Graphics2D) compatible.getGraphics();
   g.setPaint(new TexturePaint(im, new Rectangle(0, 0, im.getWidth(), im.getHeight())));
   g.fillRect(0, 0, width, height);
   return compatible;
 }
Exemple #4
0
 /** 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;
   // }
 }