Esempio n. 1
0
  public static void main(String[] args) {
    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice displayDevice = environment.getDefaultScreenDevice();

    frame = new Frame(displayDevice.getDefaultConfiguration());
    frame.setBackground(new Color(0xCC, 0xCC, 0xCC));
    frame.setTitle("TestBug735Inv0AppletAWT");

    try {
      Class<?> c =
          Thread.currentThread()
              .getContextClassLoader()
              .loadClass(Bug735Inv0AppletAWT.class.getName());
      applet = (Bug735Inv0AppletAWT) c.newInstance();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    frame.setLayout(null);
    frame.add(applet);
    frame.pack();
    frame.setResizable(false);

    applet.init();

    Insets insets = frame.getInsets();
    int windowW = applet.width + insets.left + insets.right;
    int windowH = applet.height + insets.top + insets.bottom;
    frame.setSize(windowW, windowH);

    Rectangle screenRect = displayDevice.getDefaultConfiguration().getBounds();
    frame.setLocation(
        screenRect.x + (screenRect.width - applet.width) / 2,
        screenRect.y + (screenRect.height - applet.height) / 2);

    int usableWindowH = windowH - insets.top - insets.bottom;
    applet.setBounds(
        (windowW - applet.width) / 2,
        insets.top + (usableWindowH - applet.height) / 2,
        applet.width,
        applet.height);

    // This allows to close the frame.
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    applet.initGL();
    frame.setVisible(true);
    applet.start();
  }
    /**
     * Creates the PickMe button on a particular display.
     *
     * @param gd the GraphicsDevice (display) to use for this button
     */
    public PickMe(GraphicsDevice gd) {

      super(gd.getDefaultConfiguration());

      // super((java.awt.Frame)null, false);

      setUndecorated(true);

      mygd = gd;

      JButton jb = new JButton("Click here to use this screen");

      jb.setBackground(Color.yellow);

      jb.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {

              pickDevice(mygd);
            }
          });

      Dimension sz = jb.getPreferredSize();

      sz.width += 30;

      sz.height = 0;

      jb.setPreferredSize(sz);

      getContentPane().add(jb);

      pack();

      Rectangle bounds = gd.getDefaultConfiguration().getBounds();

      int x = bounds.width / 2 - sz.width / 2 + bounds.x;

      int y = bounds.height / 2 - sz.height / 2 + bounds.y;

      // System.out.println("Opening picker at "+x+","+y);

      setLocation(x, y);

      setVisible(true);
    }
  public void beginExecution() {
    if (cam == null) {

      int numBuffers = 2;

      env = GraphicsEnvironment.getLocalGraphicsEnvironment();
      device = env.getDefaultScreenDevice();
      // MultiBufferTest test = new MultiBufferTest(numBuffers, device);

      try {

        GraphicsConfiguration gc = device.getDefaultConfiguration();
        mainFrame = new Frame(gc);
        mainFrame.setUndecorated(true);
        mainFrame.setIgnoreRepaint(true);
        device.setFullScreenWindow(mainFrame);
        if (device.isDisplayChangeSupported()) {
          chooseBestDisplayMode(device);
        }
        mainFrame.createBufferStrategy(numBuffers);
        bufferStrategy = mainFrame.getBufferStrategy();

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Esempio n. 4
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);
   }
 }
Esempio n. 5
0
  /**
   * Applies this geometry to a window. Makes sure that the window is not placed outside of the
   * coordinate range of all available screens.
   *
   * @param window the window
   */
  public void applySafe(Window window) {
    Point p = new Point(topLeft);

    Rectangle virtualBounds = new Rectangle();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (GraphicsDevice gd : gs) {
      if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
        virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds());
      }
    }

    if (p.x < virtualBounds.x) {
      p.x = virtualBounds.x;
    } else if (p.x > virtualBounds.x + virtualBounds.width - extent.width) {
      p.x = virtualBounds.x + virtualBounds.width - extent.width;
    }

    if (p.y < virtualBounds.y) {
      p.y = virtualBounds.y;
    } else if (p.y > virtualBounds.y + virtualBounds.height - extent.height) {
      p.y = virtualBounds.y + virtualBounds.height - extent.height;
    }

    window.setLocation(p);
    window.setSize(extent);
  }
Esempio n. 6
0
  public static BufferedImage convertIconToBufferedImage(final Icon icon) {

    if (icon == null) {
      return null;
    }
    if (icon instanceof ImageIcon) {
      final Image ret = ((ImageIcon) icon).getImage();
      if (ret instanceof BufferedImage) {
        return (BufferedImage) ret;
      }
    }
    final int w = icon.getIconWidth();
    final int h = icon.getIconHeight();
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final BufferedImage image = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);

    final Graphics2D g = image.createGraphics();
    g.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    // g.setColor(Color.RED);
    // g.fillRect(0, 0, w, h);
    icon.paintIcon(null, g, 0, 0);
    g.dispose();
    return image;
  }
Esempio n. 7
0
  public static BufferedImage createEmptyImage(final int w, final int h) {

    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final BufferedImage image = gc.createCompatibleImage(w, h, Transparency.BITMASK);
    return image;
  }
Esempio n. 8
0
  /** @param args */
  public static void main(String[] args) {
    // Make instance of this class, acts as parent for frames
    Init init = new Init();

    // get the graphics environment
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    // check there are more than one devices
    // this is actually broken (has 2 devices whether or not projector is connected)
    // odd
    if (gs.length < 1) {
      System.err.println("You haven't connected the projector!");
      System.exit(1);
    }
    // get the projector and screen
    GraphicsDevice gd0 = gs[1]; // projector
    GraphicsDevice gd1 = gs[0]; // screen
    GraphicsConfiguration gc = gd0.getDefaultConfiguration();
    // set projection's graphics configuration to device 0 (projector)
    init.m_projection = new Projection(gc);
    // create the gui frame on device 1 (screen)
    init.m_gui = new GUI(init, gd1.getDefaultConfiguration());

    // set size of control box
    init.m_gui.setSize(CONTROL_WIDTH, CONTROL_HEIGHT);

    // make projection fullscreen
    gd0.setFullScreenWindow(init.m_projection);

    // close everything on any frame's closing
    init.m_gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    init.m_projection.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // show frames
    init.m_gui.setVisible(true);
    init.m_projection.setVisible(true);

    // Create chess interface
    init.m_chess = new ChessInit();

    // Make webcam
    init.m_camera = new Camera(init);
    // Start camera going
    init.m_camera.init();
  }
Esempio n. 9
0
  /**
   * Creates a device compatible BufferedImage
   *
   * @param width the width in pixels
   * @param height the height in pixels
   */
  public static BufferedImage getDeviceCompatibleImage(int width, int height) {

    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice screenDevice = graphicsEnvironment.getDefaultScreenDevice();
    GraphicsConfiguration graphicConfiguration = screenDevice.getDefaultConfiguration();
    BufferedImage image = graphicConfiguration.createCompatibleImage(width, height);

    return image;
  }
 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();
 }
  // TODO not used
  private void showNotification() {
    final WebDialog dialog = new WebDialog();
    dialog.setUndecorated(true);
    dialog.setBackground(Color.BLACK);
    dialog.setBackground(StyleConstants.transparent);

    WebNotificationPopup popup = new WebNotificationPopup(PopupStyle.dark);
    popup.setIcon(Utils.getIcon("kontalk_small.png"));
    popup.setMargin(View.MARGIN_DEFAULT);
    popup.setDisplayTime(6000);
    popup.addNotificationListener(
        new NotificationListener() {
          @Override
          public void optionSelected(NotificationOption option) {}

          @Override
          public void accepted() {}

          @Override
          public void closed() {
            dialog.dispose();
          }
        });

    // content
    WebPanel panel = new WebPanel();
    panel.setMargin(View.MARGIN_DEFAULT);
    panel.setOpaque(false);
    WebLabel title = new WebLabel("A new Message!");
    title.setFontSize(View.FONT_SIZE_BIG);
    title.setForeground(Color.WHITE);
    panel.add(title, BorderLayout.NORTH);
    String text = "this is some message, and some longer text was added";
    WebLabel message = new WebLabel(text);
    message.setForeground(Color.WHITE);
    panel.add(message, BorderLayout.CENTER);
    popup.setContent(panel);

    // popup.packPopup();
    dialog.setSize(popup.getPreferredSize());

    // set position on screen
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    Rectangle screenBounds = gc.getBounds();
    // get height of the task bar
    // doesn't work on all environments
    // Insets toolHeight = toolkit.getScreenInsets(popup.getGraphicsConfiguration());
    int toolHeight = 40;
    dialog.setLocation(
        screenBounds.width - dialog.getWidth() - 10,
        screenBounds.height - toolHeight - dialog.getHeight());

    dialog.setVisible(true);
    NotificationManager.showNotification(dialog, popup);
  }
  /**
   * Create the window, asking for which screen to use if there are multiple monitors and either
   * forcechoice is true, or the user hasn't already picked a screen.
   *
   * @param part the JComponent to display
   * @param forcechoice false if user shouldn't be asked twice which of several monitors to use.
   */
  private void init(JComponent part, boolean forcechoice) {

    if (forcechoice) {

      defaultScreen = null;
    }

    screen = null;

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    GraphicsDevice screens[] = ge.getScreenDevices();

    if (defaultScreen != null) {

      for (int i = 0; i < screens.length; i++) {

        if (screens[i] == defaultScreen) {

          screen = defaultScreen;
        }
      }
    }

    if (screens.length == 1) {

      screen = screens[0];
    }

    if (screen == null) {

      screen = pickScreen(screens);
    }

    if (dead) {

      return;
    }

    defaultScreen = screen;

    DisplayMode dm = screen.getDisplayMode();

    GraphicsConfiguration gc = screen.getDefaultConfiguration();

    jf = new JFrame(gc);

    jf.setUndecorated(true);

    jf.setBounds(gc.getBounds());

    jf.getContentPane().add(part);

    jf.setVisible(true);

    screen.setFullScreenWindow(jf);
  }
 /**
  * Retrieves transparent image of specified dimension.
  *
  * @param width Image width.
  * @param height Image height.
  * @return Transparent image of specified dimension.
  */
 public static BufferedImage getBlankImage(int width, int height) {
   if (UIUtil.isRetina()) {
     return new JBHiDPIScaledImage(width, height, BufferedImage.TYPE_INT_ARGB);
   } else {
     GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
     GraphicsDevice d = e.getDefaultScreenDevice();
     GraphicsConfiguration c = d.getDefaultConfiguration();
     return c.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
   }
 }
Esempio n. 14
0
 public static WGLGraphicsConfig getGC(WComponentPeer peer) {
   if (peer != null) {
     return (WGLGraphicsConfig) peer.getGraphicsConfiguration();
   } else {
     // REMIND: this should rarely (never?) happen, but what if
     //         default config is not WGL?
     GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
     GraphicsDevice gd = env.getDefaultScreenDevice();
     return (WGLGraphicsConfig) gd.getDefaultConfiguration();
   }
 }
Esempio n. 15
0
 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;
 }
Esempio n. 16
0
 /** Realiza la inicializacion previa del modo pantalla completa. */
 private void init() {
   env = GraphicsEnvironment.getLocalGraphicsEnvironment();
   graphicsDevice = env.getDefaultScreenDevice();
   oldDisplayMode = graphicsDevice.getDisplayMode();
   if (!graphicsDevice.isFullScreenSupported()) {
     System.out.println("Full screen mode failed");
     System.exit(1);
   } else {
     GraphicsConfiguration gc = graphicsDevice.getDefaultConfiguration();
     window = new Frame(gc);
   }
 }
Esempio n. 17
0
  // This method returns a buffered image with the contents of an image
  public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
      return (BufferedImage) image;
    }

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();

    // Determine if the image has transparent pixels;
    // for this method's
    // implementation, see Determining If an Image Has
    // Transparent Pixels
    boolean hasAlpha = hasAlpha(image);

    // Create a buffered image with a format that's compatible
    // with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
      // Determine the type of transparency of the new
      //				 buffered image
      int transparency = Transparency.OPAQUE;
      if (hasAlpha) {
        transparency = Transparency.BITMASK;
      }

      // Create the buffered image
      GraphicsDevice gs = ge.getDefaultScreenDevice();
      GraphicsConfiguration gc = gs.getDefaultConfiguration();
      bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
    } catch (HeadlessException e) {
      // The system does not have a screen
    }

    if (bimage == null) {
      // Create a buffered image using the default color model
      int type = BufferedImage.TYPE_INT_RGB;
      if (hasAlpha) {
        type = BufferedImage.TYPE_INT_ARGB;
      }
      bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    }

    // Copy image to buffered image
    Graphics g = bimage.createGraphics();

    // Paint the image onto the buffered image
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bimage;
  }
  private void setPlayerScreen() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();

    GraphicsDevice graphicsDevice =
        (screenNumber >= 0 && screenNumber < gs.length) ? gs[screenNumber] : gs[0];

    if (playerFrame != null) {
      Rectangle rectangle = graphicsDevice.getDefaultConfiguration().getBounds();

      playerFrame.setBounds(rectangle);
    }
  }
  public TransparentSurface(int width, int height) {
    // create the offscreen buffer
    GraphicsEnvironment local = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice screen = local.getDefaultScreenDevice();
    GraphicsConfiguration conf = screen.getDefaultConfiguration();
    surface = conf.createCompatibleImage(width, height, Transparency.TRANSLUCENT);

    // create the graphics interface
    graphics = (Graphics2D) surface.createGraphics();

    // clear it
    clear();
  }
Esempio n. 20
0
  public static void centerFrame(JFrame frame) {
    GraphicsDevice defaultScreen =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    Rectangle screenSize = defaultScreen.getDefaultConfiguration().getBounds();

    int midx = screenSize.width / 2;
    int midy = screenSize.height / 2;

    int posx = midx - (frame.getWidth() / 2);
    int posy = midy - (frame.getHeight() / 2);

    frame.setLocation(posx, posy);
  }
Esempio n. 21
0
  private static BufferedImage createCompatibleImage(
      final BufferedImage img, final boolean translucent) {
    final GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice d = e.getDefaultScreenDevice();
    final GraphicsConfiguration c = d.getDefaultConfiguration();
    final int t = translucent ? Transparency.TRANSLUCENT : Transparency.BITMASK;

    final BufferedImage ret = c.createCompatibleImage(img.getWidth(), img.getHeight(), t);

    final Graphics2D g = ret.createGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();
    return ret;
  }
  @Override
  public Rectangle getScreenBounds(@NotNull Project project) {
    final GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final Point onScreen = getFrame(project).getLocationOnScreen();
    final GraphicsDevice[] devices = environment.getScreenDevices();
    for (final GraphicsDevice device : devices) {
      final Rectangle bounds = device.getDefaultConfiguration().getBounds();
      if (bounds.contains(onScreen)) {
        return bounds;
      }
    }

    return null;
  }
Esempio n. 23
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;
   // }
 }
/**
 * GraphicsManager maintains graphics context information that maybe useful for many aspects of
 * graphics rendering. This means that many of the fields are computer dependent and are placed here
 * so they are only calculated once.
 */
public class GraphicsManager {

  /** get GraphicConfiguration for default screen - this should only be done once at startup * */
  private static GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

  private static GraphicsDevice gs = ge.getDefaultScreenDevice();
  public static GraphicsConfiguration gc = gs.getDefaultConfiguration();

  private static final int MAX_RECYCLED_IMAGES = 50;
  private static int numRecycledImages = 0;
  private static HashMap<Dimension, List<BufferedImage>> recycledImages =
      new HashMap<Dimension, List<BufferedImage>>();
  /**
   * Functionally equivalent to gc.createCompatibleImage(width, height, Transparency.TRANSLUCENT)
   * but allows reusing released images.
   */
  public static BufferedImage getGCCompatibleImage(int width, int height) {
    List<BufferedImage> imgList = recycledImages.get(new Dimension(width, height));
    if (imgList == null || imgList.isEmpty())
      return gc.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
    numRecycledImages--;
    BufferedImage img = imgList.remove(imgList.size() - 1);
    // Clear the image
    Graphics2D g2D = img.createGraphics();
    g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
    Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, width, height);
    g2D.fill(rect);
    return img;
  }

  /**
   * Add an image to the recycled images list (or if img = null, does nothing). Note: the passed
   * variable should be immediately set to null to avoid aliasing bugs.
   */
  public static void recycleGCCompatibleImage(BufferedImage img) {
    if (img == null) return;
    // Make sure we don't waste too much memory
    if (numRecycledImages >= MAX_RECYCLED_IMAGES) {
      recycledImages.clear();
    }
    Dimension dim = new Dimension(img.getWidth(), img.getHeight());
    List<BufferedImage> imgList = recycledImages.get(dim);
    if (imgList == null) {
      imgList = new ArrayList<BufferedImage>();
      recycledImages.put(dim, imgList);
    }
    imgList.add(img);
  }
}
 public static boolean safeRestoreWindow(final Window frame, final Rectangle bounds) {
   final GraphicsEnvironment graphicsEnvironment =
       GraphicsEnvironment.getLocalGraphicsEnvironment();
   final GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
   for (int i = 0; i < devices.length; i++) {
     final GraphicsDevice device = devices[i];
     final Rectangle rectangle = device.getDefaultConfiguration().getBounds();
     if (rectangle.contains(bounds) || rectangle.equals(bounds)) {
       DebugLog.log("Found a usable screen-configuration: Restoring frame to " + bounds);
       frame.setBounds(bounds);
       return true;
     }
   }
   return false;
 }
Esempio n. 26
0
 public 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;
   }
 }
  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;
  }
Esempio n. 28
0
 public CapabilitiesTest(GraphicsDevice dev) {
   super(dev.getDefaultConfiguration());
   addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent ev) {
           System.exit(0);
         }
       });
   initComponents(getContentPane());
   GraphicsConfiguration[] gcs = dev.getConfigurations();
   for (int i = 0; i < gcs.length; i++) {
     gcSelection.addItem(new GCWrapper(gcs[i], i));
   }
   gcSelection.addItemListener(this);
   gcChanged();
 }
  private void createPlayerFrame() {
    if (playerFrame == null) {
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice[] gs = ge.getScreenDevices();

      GraphicsDevice graphicsDevice =
          (screenNumber >= 0 && screenNumber < gs.length) ? gs[screenNumber] : gs[0];

      playerFrame = new Frame(graphicsDevice.getDefaultConfiguration());
      playerFrame.setLayout(new BorderLayout());
      playerFrame.setUndecorated(true);
      playerFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
      playerFrame.setBackground(new java.awt.Color(0, 0, 0));
      playerFrame.setVisible(true);
    }
  }
  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }

    final JWindow window = new JWindow();
    window.setOpacity(0.95f);
    window.add(new NotificationPanel());
    window.pack();

    Toolkit toolKit = Toolkit.getDefaultToolkit();
    Dimension scrSize = toolKit.getScreenSize();
    Dimension wSize = window.getSize();

    GraphicsEnvironment gfx = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice screen = gfx.getDefaultScreenDevice();
    Insets scrInsets = toolKit.getScreenInsets(screen.getDefaultConfiguration());

    window.setLocation(scrSize.width - wSize.width - 5, scrSize.height - scrInsets.bottom);

    Timer t =
        new Timer(
            1,
            e -> {
              if (!animate(window, scrSize, scrInsets)) {
                Timer source = (Timer) e.getSource();
                source.stop();
              }
            });

    window.setVisible(true);
    t.start();

    // close listener
    window.addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosed(WindowEvent e) {
            System.exit(0);
          }
        });
  }