use of java.awt.GraphicsEnvironment in project processing by processing.
the class PApplet method displayDensity.
/**
* @param display the display number to check
*/
public static int displayDensity(int display) {
if (PApplet.platform == PConstants.MACOSX) {
// This should probably be reset each time there's a display change.
// A 5-minute search didn't turn up any such event in the Java 7 API.
// Also, should we use the Toolkit associated with the editor window?
final String javaVendor = System.getProperty("java.vendor");
if (javaVendor.contains("Oracle")) {
GraphicsDevice device;
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
if (display == -1) {
device = env.getDefaultScreenDevice();
} else if (display == SPAN) {
throw new RuntimeException("displayDensity() only works with specific display numbers");
} else {
GraphicsDevice[] devices = env.getScreenDevices();
if (display > 0 && display <= devices.length) {
device = devices[display - 1];
} else {
if (devices.length == 1) {
System.err.println("Only one display is currently known, use displayDensity(1).");
} else {
System.err.format("Your displays are numbered %d through %d, " + "pass one of those numbers to displayDensity()%n", 1, devices.length);
}
throw new RuntimeException("Display " + display + " does not exist.");
}
}
try {
Field field = device.getClass().getDeclaredField("scale");
if (field != null) {
field.setAccessible(true);
Object scale = field.get(device);
if (scale instanceof Integer && ((Integer) scale).intValue() == 2) {
return 2;
}
}
} catch (Exception ignore) {
}
}
}
return 1;
}
use of java.awt.GraphicsEnvironment in project screenbird by adamhub.
the class ScreenUtil method isDualScreen.
/**
* Checks for presence of multiple screens/monitors on the current computer.
* @return True if more than one screen is detected.
*/
public static boolean isDualScreen() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screens = ge.getScreenDevices();
return screens.length > 1;
}
use of java.awt.GraphicsEnvironment in project pcgen by PCGen.
the class Main method initPrintPreviewFonts.
private static void initPrintPreviewFonts() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String fontDir = ConfigurationSettings.getOutputSheetsDir() + File.separator + "fonts" + File.separator + "NotoSans" + File.separator;
try {
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Regular.ttf")));
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Bold.ttf")));
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-Italic.ttf")));
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fontDir + "NotoSans-BoldItalic.ttf")));
} catch (IOException | FontFormatException ex) {
Logging.errorPrint("Unexpected exception loading fonts fo print p", ex);
}
}
use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.
the class MaximizedToMaximized method main.
public static void main(String[] args) throws Exception {
Frame frame = new Frame();
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
final Dimension screenSize = toolkit.getScreenSize();
final Insets screenInsets = toolkit.getScreenInsets(graphicsDevice.getDefaultConfiguration());
final Rectangle availableScreenBounds = new Rectangle(screenSize);
availableScreenBounds.x += screenInsets.left;
availableScreenBounds.y += screenInsets.top;
availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);
frame.setBounds(availableScreenBounds.x, availableScreenBounds.y, availableScreenBounds.width, availableScreenBounds.height);
frame.setVisible(true);
Rectangle frameBounds = frame.getBounds();
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
((SunToolkit) toolkit).realSync();
Rectangle maximizedFrameBounds = frame.getBounds();
if (maximizedFrameBounds.width < frameBounds.width || maximizedFrameBounds.height < frameBounds.height) {
throw new RuntimeException("Maximized frame is smaller than non maximized");
}
}
use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.
the class TextRenderingTest method main.
public static void main(final String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(width, height);
while (true) {
vi.validate(gc);
Graphics2D g2d = vi.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, width, height);
g2d.setPaint(new GradientPaint(new Point2D.Float(0, height / 2), Color.white, new Point2D.Float(width, height / 2), Color.black));
g2d.fillRect(0, 0, width, height);
String fnt = g2d.getFont().getFamily();
g2d.setFont(new Font(fnt, Font.PLAIN, 100));
// draw text with offset
g2d.drawString("IIIIIIIIII", 100, 100);
g2d.dispose();
if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
continue;
}
if (vi.contentsLost()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
continue;
}
break;
}
BufferedImage bi = vi.getSnapshot();
// the text shifted shouldn't be visible onto a painted rectangle!
// so the check: color component (blue) must decrease monotonously
int prev = Integer.MAX_VALUE;
for (int x = 0; x < width; ++x) {
int color = bi.getRGB(x, height / 2);
int b = color & 0xFF;
if (b > prev) {
throw new RuntimeException("test failed: can see the text rendered!");
}
prev = b;
}
}
Aggregations