use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.
the class RSLAPITest method main.
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
testGC(gc);
if (failed) {
throw new RuntimeException("Test FAILED. See err output for more");
}
System.out.println("Test PASSED.");
}
use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.
the class OpaqueImageToSurfaceBlitTest method main.
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);
vi.validate(gc);
BufferedImage bi = new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
int[] data = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
data[0] = 0x0000007f;
data[1] = 0x0000007f;
data[2] = 0xff00007f;
data[3] = 0xff00007f;
Graphics2D g = vi.createGraphics();
g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
g.drawImage(bi, 0, 0, null);
bi = vi.getSnapshot();
if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {
throw new RuntimeException("Test FAILED: color at 0x0 =" + Integer.toHexString(bi.getRGB(0, 0)) + " differs from 1x1 =" + Integer.toHexString(bi.getRGB(1, 1)));
}
System.out.println("Test PASSED.");
}
use of java.awt.GraphicsEnvironment in project sulky by huxi.
the class Windows method showWindow.
public static void showWindow(Window window, Window centerParent, boolean pack) {
final Logger logger = LoggerFactory.getLogger(Windows.class);
if (pack) {
window.pack();
}
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle maxBounds = ge.getMaximumWindowBounds();
if (logger.isDebugEnabled())
logger.debug("MaximumWindowBounds: {}", maxBounds);
Rectangle windowBounds = window.getBounds();
if (logger.isDebugEnabled())
logger.debug("Original windowBounds: {}", windowBounds);
if (windowBounds.width > maxBounds.width) {
windowBounds.width = maxBounds.width;
}
if (windowBounds.height > maxBounds.height) {
windowBounds.height = maxBounds.height;
}
if (logger.isDebugEnabled())
logger.debug("Corrected windowBounds: {}", windowBounds);
Rectangle centerBounds = maxBounds;
if (centerParent != null && centerParent.isVisible()) {
centerBounds = centerParent.getBounds();
if (logger.isDebugEnabled())
logger.debug("Retrieved parent container bounds...");
}
if (logger.isDebugEnabled())
logger.debug("centerBounds: {}", centerBounds);
windowBounds.x = centerBounds.x + (centerBounds.width - windowBounds.width) / 2;
windowBounds.y = centerBounds.y + (centerBounds.height - windowBounds.height) / 2;
if (logger.isDebugEnabled())
logger.debug("centered bounds: {}", windowBounds);
// first, correct upper left corner
if (windowBounds.x < maxBounds.x) {
windowBounds.x = maxBounds.x;
}
if (windowBounds.y < maxBounds.y) {
windowBounds.y = maxBounds.y;
}
if (logger.isDebugEnabled())
logger.debug("corrected1: {}", windowBounds);
// second, check bottom right
if (windowBounds.x + windowBounds.width > maxBounds.x + maxBounds.width) {
windowBounds.x = maxBounds.width - windowBounds.width;
}
if (windowBounds.y + windowBounds.height > maxBounds.y + maxBounds.height) {
windowBounds.y = maxBounds.height - windowBounds.height;
}
if (logger.isDebugEnabled())
logger.debug("corrected1: {}", windowBounds);
// if window/window is simply too large.
if (windowBounds.x < maxBounds.x) {
windowBounds.x = maxBounds.x;
}
if (windowBounds.y < maxBounds.y) {
windowBounds.y = maxBounds.y;
}
if (logger.isDebugEnabled())
logger.debug("changed bounds: {}", windowBounds);
window.setBounds(windowBounds);
window.setVisible(true);
}
use of java.awt.GraphicsEnvironment in project vcell by virtualcell.
the class BeanUtils method centerOnScreen.
public static void centerOnScreen(Window window) {
if (window != null) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
final Rectangle maxBounds = ge.getMaximumWindowBounds();
Dimension screenSize = maxBounds.getSize();
Dimension size = window.getSize();
if (size.height > screenSize.height)
size.height = screenSize.height;
if (size.width > screenSize.width)
size.width = screenSize.width;
window.setLocation((screenSize.width - size.width) / 2, (screenSize.height - size.height) / 2);
}
}
use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.
the class OffScreenImage method createGraphics.
public Graphics2D createGraphics() {
if (c == null) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
return env.createGraphics(this);
}
Color bg = c.getBackground();
if (bg == null) {
bg = SystemColor.window;
}
Color fg = c.getForeground();
if (fg == null) {
fg = SystemColor.windowText;
}
Font font = c.getFont();
if (font == null) {
if (defaultFont == null) {
defaultFont = new Font("Dialog", Font.PLAIN, 12);
}
font = defaultFont;
}
return new SunGraphics2D(SurfaceData.getPrimarySurfaceData(this), fg, bg, font);
}
Aggregations