Example usage for java.awt GraphicsDevice getClass

List of usage examples for java.awt GraphicsDevice getClass

Introduction

In this page you can find the example usage for java.awt GraphicsDevice getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.sshtools.sshterm.SshTermFullScreenWindowContainer.java

public void setContainerVisible(boolean visible) {
    if (visible && !isContainerVisible()) {
        try {/*from ww  w  .  j a va2 s. c o  m*/
            setVisible(true);
            GraphicsDevice device = panel.getGraphicsConfiguration().getDevice();
            Method m = device.getClass().getMethod("setFullScreenWindow", new Class[] { Window.class });
            m.invoke(device, new Object[] { this });
            log.debug("Full screen container made visible");
            ((SshTerminalPanel) panel).setAutoHideTools(true);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
        }
    } else if (!visible && isContainerVisible()) {
        try {
            GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
            Method m = device.getClass().getMethod("setFullScreenWindow", new Class[] { Window.class });
            m.invoke(device, new Object[] { null });
            setVisible(false);
            log.debug("Full screen container made invisible");
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
        }
    }
}

From source file:com.sshtools.sshterm.SshTermFrame.java

public void init(SshToolsApplication application, SshToolsApplicationPanel panel)
        throws SshToolsApplicationException {
    super.init(application, panel);
    GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

    log.debug("Testing if " + device.getIDstring() + " can go full screen");
    try {//from   w  ww . ja  v a2s .c  o  m
        Method m = device.getClass().getMethod("isFullScreenSupported", new Class[] {});
        if (((Boolean) m.invoke(device, new Object[] {})).booleanValue()
                || ConfigurationLoader.checkAndGetProperty("sshterm.enableFullScreen", "true").equals("true")) {
            log.info(device.getIDstring() + " can go full screen");
            addFullScreenActions();
        }
    } catch (SecurityException e) {
    } catch (NoSuchMethodException e) {
    } catch (IllegalArgumentException e) {
    } catch (IllegalAccessException e) {
    } catch (InvocationTargetException e) {
    }
}

From source file:ded.ui.DiagramController.java

/** Get and log some details related to display scaling, particularly
  * to help diagnose the graphics bugs on HiDPI/Retina displays. */
public void logDisplayScaling() {
    // Based on code from
    // http://lubosplavucha.com/java/2013/09/02/retina-support-in-java-for-awt-swing/

    try {//from   www. j a  v a  2 s  . co  m
        // Dump a bunch of possibly interesting JVM properties.
        String propertyNames[] = { "awt.toolkit", "java.awt.graphicsenv", "java.runtime.name",
                "java.runtime.version", "java.vendor", "java.version", "java.vm.name", "java.vm.vendor",
                "java.vm.version", };
        for (String name : propertyNames) {
            this.log("property " + name + ": " + System.getProperty(name));
        }

        // Try a property specific to the Apple JVM.
        this.log("apple.awt.contentScaleFactor: "
                + Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor"));

        // Try something specific to OpenJDK.  Here, we
        // reflectively query some private field.  Yuck.
        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        try {
            Field field = gd.getClass().getDeclaredField("scale");
            field.setAccessible(true);
            this.log("GraphicsEnvironment.scale: " + field.get(gd));
        } catch (NoSuchFieldException e) {
            this.log("GraphicsEnvironment does not have a 'scale' field");
        }

        // Check some details of "compatible" images.
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        BufferedImage bi = gc.createCompatibleImage(64, 64);
        ColorModel cm = bi.getColorModel();
        this.log("compatible image color model: " + cm);

        // Do the same for a specific imageType that seems to be
        // commonly used, and that I am using when saving to PNG.
        bi = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
        cm = bi.getColorModel();
        this.log("TYPE_INT_ARGB color model: " + cm);

        // And one more.
        bi = new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB);
        cm = bi.getColorModel();
        this.log("TYPE_INT_RGB color model: " + cm);
    } catch (Exception e) {
        this.log("exception during logDisplayScaling(): " + Util.getExceptionMessage(e));
        this.logNoNewline(Util.getExceptionStackTrace(e));
    }
}

From source file:com.actelion.research.table.view.JVisualization.java

/**
 * Checks HiDPI support for Java 7 and newer.
 *
 * @return factor != 1 if HiDPI feature is enabled.
 *//*from w w  w .j  av  a 2 s  .c  o  m*/
public static float getContentScaleFactor() {
    /* with Apple-Java-6 this was:
    Object sContentScaleFactorObject = Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor");
     private static final float sRetinaFactor = (sContentScaleFactorObject == null) ? 1f : ((Float)sContentScaleFactorObject).floatValue();
    */
    if (sRetinaFactor != -1f)
        return sRetinaFactor;

    sRetinaFactor = 1f;

    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice device = env.getDefaultScreenDevice();

    try {
        Field field = device.getClass().getDeclaredField("scale");
        if (field != null) {
            field.setAccessible(true);
            Object scale = field.get(device);

            if (scale instanceof Integer) {
                sRetinaFactor = (Integer) scale;
            }
        }
    } catch (Throwable e) {
    }

    return sRetinaFactor;
}