Search in sources :

Example 66 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project javatari by ppeccin.

the class DesktopScreenWindow method openFullWindow.

private void openFullWindow() {
    if (fullWindow.isVisible())
        return;
    // Try to set full screen in the monitor we are currently in
    GraphicsConfiguration graphicsConfig = SwingHelper.getGraphicsConfigurationForCurrentLocation(this);
    setVisible(false);
    fullWindow.setBounds(graphicsConfig.getBounds());
    fullWindow.setVisible(true);
    // Try to enter FullScreen Exclusive mode if desired
    if (USE_FSEM != 0) {
        try {
            graphicsConfig.getDevice().setFullScreenWindow(fullWindow);
        } catch (Exception e) {
        // Ignore. Probably FSEM is not supported
        }
    }
    fullWindow.toFront();
    fullWindow.requestFocus();
    monitor.setDisplay(fullWindow);
    fullScreen = true;
}
Also used : IOException(java.io.IOException) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 67 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project javatari by ppeccin.

the class SwingHelper method getGraphicsConfigurationForCurrentLocation.

public static GraphicsConfiguration getGraphicsConfigurationForCurrentLocation(Window window) {
    GraphicsConfiguration ownedConfig = window.getGraphicsConfiguration();
    Point currLocation = window.getLocation();
    // Shortcut for "owned" case
    if (ownedConfig.getBounds().contains(currLocation))
        return ownedConfig;
    // Search for the right screen
    GraphicsDevice[] screens = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    for (GraphicsDevice screen : screens) for (GraphicsConfiguration config : screen.getConfigurations()) if (config.getBounds().contains(currLocation))
        return config;
    // If none found, lets return the "owned" one
    return ownedConfig;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 68 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project grounded by alejolp.

the class GameCanvas method loadGraphics.

// setIgnoreRepaint(false);
public void loadGraphics() {
    BufferedImage img;
    // Load the image data.
    try {
        img = ImageIO.read(new ByteArrayInputStream(Data.TILES_DATA));
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    // Make 0xFF00FF pixels transparent.
    int w = img.getWidth(), h = img.getHeight();
    int x, y, p = 0;
    int[] data = img.getRGB(0, 0, w, h, null, 0, w);
    for (y = 0; y < h; ++y) {
        for (x = 0; x < w; ++x, ++p) {
            if ((data[p] & 0xffffff) == 0xff00ff)
                /* Pink, it's not even a question */
                data[p] = 0x0;
        }
    }
    GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    // Update image data.
    if (config != null)
        tiles = config.createCompatibleImage(w, h, Transparency.BITMASK);
    else
        tiles = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    tiles.setRGB(0, 0, w, h, data, 0, w);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 69 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project eweb4j-framework by laiweiwei.

the class FileUtil method toBufferedImage.

private 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 e661 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;
        // int type = BufferedImage.TYPE_3BYTE_BGR;//by wang
        /*
			 * 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;
}
Also used : Graphics(java.awt.Graphics) ImageIcon(javax.swing.ImageIcon) GraphicsDevice(java.awt.GraphicsDevice) HeadlessException(java.awt.HeadlessException) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 70 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project gephi by gephi.

the class RichTooltip method showTooltip.

public void showTooltip(JComponent component, Point screenLocation) {
    if (component == null || !component.isShowing()) {
        return;
    }
    Dimension size;
    Point location = new Point();
    GraphicsConfiguration gc;
    gc = component.getGraphicsConfiguration();
    Rectangle sBounds = gc.getBounds();
    Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
    // Take into account screen insets, decrease viewport
    sBounds.x += screenInsets.left;
    sBounds.y += screenInsets.top;
    sBounds.width -= (screenInsets.left + screenInsets.right);
    sBounds.height -= (screenInsets.top + screenInsets.bottom);
    hideTooltip();
    JRichTooltipPanel tip = new JRichTooltipPanel(this);
    size = tip.getPreferredSize();
    // display directly below or above it
    location.x = screenLocation.x + 10;
    location.y = screenLocation.y - 10;
    if ((location.y + size.height) > (sBounds.y + sBounds.height)) {
        location.y = screenLocation.y - size.height;
    }
    // Tweak the X location to not overflow the screen
    if (location.x < sBounds.x) {
        location.x = sBounds.x;
    } else if (location.x - sBounds.x + size.width > sBounds.width) {
        location.x = sBounds.x + Math.max(0, sBounds.width - size.width);
    }
    PopupFactory popupFactory = PopupFactory.getSharedInstance();
    tipWindow = popupFactory.getPopup(component, tip, location.x, location.y);
    tipWindow.show();
    tipShowing = true;
}
Also used : PopupFactory(javax.swing.PopupFactory) Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Aggregations

GraphicsConfiguration (java.awt.GraphicsConfiguration)134 GraphicsEnvironment (java.awt.GraphicsEnvironment)55 BufferedImage (java.awt.image.BufferedImage)46 Rectangle (java.awt.Rectangle)43 GraphicsDevice (java.awt.GraphicsDevice)38 Graphics2D (java.awt.Graphics2D)33 VolatileImage (java.awt.image.VolatileImage)31 Point (java.awt.Point)29 Dimension (java.awt.Dimension)21 Insets (java.awt.Insets)16 File (java.io.File)16 Graphics (java.awt.Graphics)13 IOException (java.io.IOException)13 Frame (java.awt.Frame)11 JFrame (javax.swing.JFrame)8 HeadlessException (java.awt.HeadlessException)7 Window (java.awt.Window)7 ImageIcon (javax.swing.ImageIcon)7 Color (java.awt.Color)6 AffineTransform (java.awt.geom.AffineTransform)6