use of java.awt.GraphicsEnvironment in project gephi by gephi.
the class Java2dHelper method createCompatibleImage.
public static BufferedImage createCompatibleImage(int width, int height) {
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice screenDevice = environment.getDefaultScreenDevice();
GraphicsConfiguration configuration = screenDevice.getDefaultConfiguration();
return configuration.createCompatibleImage(width, height);
}
use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.
the class TestSGEuseAlternateFontforJALocales method main.
public static void main(String[] args) throws Exception {
System.out.println("Default Charset = " + Charset.defaultCharset().name());
System.out.println("Locale = " + Locale.getDefault());
String os = System.getProperty("os.name");
String encoding = System.getProperty("file.encoding");
/* Want to test the JA locale uses alternate font for DialogInput. */
boolean jaTest = encoding.equalsIgnoreCase("windows-31j");
if (!os.startsWith("Win") && jaTest) {
System.out.println("Skipping Windows only test");
return;
}
String className = "sun.java2d.SunGraphicsEnvironment";
String methodName = "useAlternateFontforJALocales";
Class sge = Class.forName(className);
Method uafMethod = sge.getMethod(methodName, (Class[]) null);
Object ret = uafMethod.invoke(null);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.preferLocaleFonts();
ge.preferProportionalFonts();
if (jaTest) {
Font msMincho = new Font("MS Mincho", Font.PLAIN, 12);
if (!msMincho.getFamily(Locale.ENGLISH).equals("MS Mincho")) {
System.out.println("MS Mincho not installed. Skipping test");
return;
}
Font dialogInput = new Font("DialogInput", Font.PLAIN, 12);
Font courierNew = new Font("Courier New", Font.PLAIN, 12);
Font msGothic = new Font("MS Gothic", Font.PLAIN, 12);
BufferedImage bi = new BufferedImage(1, 1, 1);
Graphics2D g2d = bi.createGraphics();
FontMetrics cnMetrics = g2d.getFontMetrics(courierNew);
FontMetrics diMetrics = g2d.getFontMetrics(dialogInput);
FontMetrics mmMetrics = g2d.getFontMetrics(msMincho);
FontMetrics mgMetrics = g2d.getFontMetrics(msGothic);
// "preferLocaleFonts for Japanese
if (cnMetrics.charWidth('A') == diMetrics.charWidth('A')) {
throw new RuntimeException("Courier New should not be used for DialogInput");
}
// not definite proof.
if (diMetrics.charWidth('A') != mmMetrics.charWidth('A')) {
throw new RuntimeException("MS Mincho should be used for DialogInput");
}
}
}
use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.
the class bug7181438 method createVolatileImage.
private static VolatileImage createVolatileImage() {
final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
return gc.createCompatibleVolatileImage(SIZE, SIZE, Transparency.TRANSLUCENT);
}
use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.
the class VolatileImageBug method main.
public static void main(String[] args) {
boolean iaeThrown = false;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
try {
VolatileImage volatileImage = gc.createCompatibleVolatileImage(0, 0);
} catch (IllegalArgumentException iae) {
iaeThrown = true;
}
if (!iaeThrown) {
throw new RuntimeException("IllegalArgumentException not thrown " + "for createCompatibleVolatileImage(0,0)");
}
}
use of java.awt.GraphicsEnvironment in project jdk8u_jdk by JetBrains.
the class HelvLtOblTest method main.
public static void main(String[] args) throws Exception {
String os = System.getProperty("os.name");
if (!os.startsWith("Mac")) {
return;
}
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] fonts = ge.getAllFonts();
for (int i = 0; i < fonts.length; i++) {
if (fonts[i].getPSName().equals("Helvetica-LightOblique")) {
helvFont = fonts[i];
break;
}
}
if (helvFont == null) {
return;
}
final HelvLtOblTest test = new HelvLtOblTest();
SwingUtilities.invokeLater(() -> {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add("Center", test);
f.pack();
f.setVisible(true);
});
test.compareImages();
}
Aggregations