Java Code Examples for java.awt.Component#getGraphicsConfiguration()

The following examples show how to use java.awt.Component#getGraphicsConfiguration() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Get the best graphics configuration for the specified point and component.
 */
private GraphicsConfiguration graphicsConfigurationForComponent(Component component) {
    Point point = component.getLocationOnScreen();
    
    // try to find the graphics configuration for our point of interest
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gd = ge.getScreenDevices();
    for(int i = 0; i < gd.length; i++) {
        if(gd[i].getType() != GraphicsDevice.TYPE_RASTER_SCREEN) continue;
        GraphicsConfiguration defaultGraphicsConfiguration = gd[i].getDefaultConfiguration();
        if(!defaultGraphicsConfiguration.getBounds().contains(point)) continue;
        return defaultGraphicsConfiguration;
    }
    
    // we couldn't find a graphics configuration, use the component's
    return component.getGraphicsConfiguration();
}
 
Example 2
public void setDestination(TestEnvironment env) {
    Component c = env.getCanvas();
    GraphicsConfiguration gc = c.getGraphicsConfiguration();
    int w = env.getWidth();
    int h = env.getHeight();
    if (transparency == 0) {
        env.setTestImage(gc.createCompatibleImage(w, h));
    } else {
        env.setTestImage(gc.createCompatibleImage(w, h, transparency));
    }
}
 
Example 3
public void setDestination(TestEnvironment env) {
    Component c = env.getCanvas();
    GraphicsConfiguration gc = c.getGraphicsConfiguration();
    int w = env.getWidth();
    int h = env.getHeight();
    if (transparency == 0) {
        env.setTestImage(gc.createCompatibleImage(w, h));
    } else {
        env.setTestImage(gc.createCompatibleImage(w, h, transparency));
    }
}
 
Example 4
public void setDestination(TestEnvironment env) {
    Component c = env.getCanvas();
    GraphicsConfiguration gc = c.getGraphicsConfiguration();
    int w = env.getWidth();
    int h = env.getHeight();
    if (transparency == 0) {
        env.setTestImage(gc.createCompatibleImage(w, h));
    } else {
        env.setTestImage(gc.createCompatibleImage(w, h, transparency));
    }
}
 
Example 5
public void setDestination(TestEnvironment env) {
    Component c = env.getCanvas();
    GraphicsConfiguration gc = c.getGraphicsConfiguration();
    int w = env.getWidth();
    int h = env.getHeight();
    if (transparency == 0) {
        env.setTestImage(gc.createCompatibleImage(w, h));
    } else {
        env.setTestImage(gc.createCompatibleImage(w, h, transparency));
    }
}
 
Example 6
public void setDestination(TestEnvironment env) {
    Component c = env.getCanvas();
    GraphicsConfiguration gc = c.getGraphicsConfiguration();
    int w = env.getWidth();
    int h = env.getHeight();
    if (transparency == 0) {
        env.setTestImage(gc.createCompatibleImage(w, h));
    } else {
        env.setTestImage(gc.createCompatibleImage(w, h, transparency));
    }
}
 
Example 7
public void setDestination(TestEnvironment env) {
    Component c = env.getCanvas();
    GraphicsConfiguration gc = c.getGraphicsConfiguration();
    int w = env.getWidth();
    int h = env.getHeight();
    if (transparency == 0) {
        env.setTestImage(gc.createCompatibleImage(w, h));
    } else {
        env.setTestImage(gc.createCompatibleImage(w, h, transparency));
    }
}
 
Example 8
public void setDestination(final TestEnvironment env) {
    Component c = env.getCanvas();
    GraphicsConfiguration gc = c.getGraphicsConfiguration();
    int w = env.getWidth();
    int h = env.getHeight();
    if (transparency == 0) {
        env.setTestImage(gc.createCompatibleVolatileImage(w, h));
    } else {
        env.setTestImage(gc.createCompatibleVolatileImage(w, h, transparency));
    }
}
 
Example 9
public void paint(Component c, Graphics g, int x, int y, int w, int h, Object[] args) {
	if (w <= 0 || h <= 0) {
		return;
	}
	Object key = getClass();
	GraphicsConfiguration config = c.getGraphicsConfiguration();
	Cache cache = getCache(key);
	Image image = cache.getImage(key, config, w, h, args);
	int attempts = 0;
	do {
		boolean draw = false;
		if (image instanceof VolatileImage) {
			switch (((VolatileImage) image).validate(config)) {
				case VolatileImage.IMAGE_INCOMPATIBLE:
					((VolatileImage) image).flush();
					image = null;
					break;
				case VolatileImage.IMAGE_RESTORED:
					draw = true;
					break;
			}
		}
		if (image == null) {
			image = createImage(c, w, h, config);
			cache.setImage(key, config, w, h, args, image);
			draw = true;
		}
		if (draw) {
			Graphics g2 = image.getGraphics();
			paintToImage(c, g2, w, h, args);
			g2.dispose();
		}

		paintImage(c, g, x, y, w, h, image, args);
	} while (image instanceof VolatileImage && ((VolatileImage) image).contentsLost() && ++attempts < 3);
}
 
Example 10
Source Project: Pixie   File: ScreenResolution.java    License: MIT License 5 votes vote down vote up
/**
 * Constructor where the resolution is computed.
 *
 * @param comp - the frame of the gui - needed to get the resolution of the screen where the app is showed
 */
public ScreenResolution(Component comp) {
    //set the current screen resolution                
    GraphicsConfiguration graphicsCfg = comp.getGraphicsConfiguration();
    DisplayMode displayMode = graphicsCfg.getDevice().getDisplayMode();
    resolution = new Dimension(displayMode.getWidth(), displayMode.getHeight());
}
 
Example 11
public void setDestination(TestEnvironment env) {
    Component c = env.getCanvas();
    GraphicsConfiguration gc = c.getGraphicsConfiguration();
    int w = env.getWidth();
    int h = env.getHeight();
    if (transparency == 0) {
        env.setTestImage(gc.createCompatibleImage(w, h));
    } else {
        env.setTestImage(gc.createCompatibleImage(w, h, transparency));
    }
}
 
Example 12
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 13
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 14
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 15
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 16
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 17
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 18
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 19
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 20
Source Project: Pixie   File: ScreenResolution.java    License: MIT License 4 votes vote down vote up
/**
 * Saves the resolution of the screen where the component is showed.
 *
 * @param comp - the frame for which the resolution of the containing screen is needed
 */
public void setScreenResolution(Component comp) {
    GraphicsConfiguration graphicsCfg = comp.getGraphicsConfiguration();
    DisplayMode displayMode = graphicsCfg.getDevice().getDisplayMode();
    resolution = new Dimension(displayMode.getWidth(), displayMode.getHeight());
}