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

The following examples show how to use java.awt.Component#getGraphicsConfiguration() . 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
Source File: AquaLnFPopupLocationFix.java    From cropplanning with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
Source File: Destinations.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: Destinations.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: ScreenResolution.java    From Pixie with 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 5
Source File: AbstractCachedPainter.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
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 6
Source File: Destinations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 7
Source File: Destinations.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: Destinations.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 9
Source File: Destinations.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 10
Source File: Destinations.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 11
Source File: Destinations.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: SunVolatileImage.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 13
Source File: SunVolatileImage.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 14
Source File: SunVolatileImage.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 15
Source File: SunVolatileImage.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 16
Source File: SunVolatileImage.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 17
Source File: SunVolatileImage.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 18
Source File: SunVolatileImage.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 19
Source File: SunVolatileImage.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public SunVolatileImage(Component comp,
                        int width, int height, Object context)
{
    this(comp, comp.getGraphicsConfiguration(),
         width, height, context, null);
}
 
Example 20
Source File: ScreenResolution.java    From Pixie with 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());
}