Search in sources :

Example 16 with GraphicsEnvironment

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);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 17 with GraphicsEnvironment

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");
        }
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Method(java.lang.reflect.Method) GraphicsEnvironment(java.awt.GraphicsEnvironment) Font(java.awt.Font) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 18 with GraphicsEnvironment

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);
}
Also used : GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 19 with GraphicsEnvironment

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)");
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 20 with GraphicsEnvironment

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();
}
Also used : JFrame(javax.swing.JFrame) GraphicsEnvironment(java.awt.GraphicsEnvironment) Font(java.awt.Font)

Aggregations

GraphicsEnvironment (java.awt.GraphicsEnvironment)87 GraphicsDevice (java.awt.GraphicsDevice)44 GraphicsConfiguration (java.awt.GraphicsConfiguration)41 BufferedImage (java.awt.image.BufferedImage)22 VolatileImage (java.awt.image.VolatileImage)21 Dimension (java.awt.Dimension)16 Graphics2D (java.awt.Graphics2D)16 Point (java.awt.Point)11 Font (java.awt.Font)10 Rectangle (java.awt.Rectangle)9 Insets (java.awt.Insets)7 File (java.io.File)7 Frame (java.awt.Frame)6 Toolkit (java.awt.Toolkit)6 AffineTransform (java.awt.geom.AffineTransform)6 HeadlessException (java.awt.HeadlessException)4 Color (java.awt.Color)3 Container (java.awt.Container)3 DisplayMode (java.awt.DisplayMode)3 GradientPaint (java.awt.GradientPaint)3