Search in sources :

Example 1 with JmriInsets

use of jmri.util.JmriInsets in project JMRI by JMRI.

the class ReportContext method addScreenSize.

/**
     * Provide screen - size information. This is based on the
     * jmri.util.JmriJFrame calculation, but isn't refactored to there because
     * we also want diagnostic info
     */
public void addScreenSize() {
    try {
        // Find screen size. This throws null-pointer exceptions on
        // some Java installs, however, for unknown reasons, so be
        // prepared to fall back.
        JFrame dummy = new JFrame();
        try {
            Insets insets = dummy.getToolkit().getScreenInsets(dummy.getGraphicsConfiguration());
            Dimension screen = dummy.getToolkit().getScreenSize();
            addString("Screen size h:" + screen.height + ", w:" + screen.width + " Inset t:" + insets.top + ", b:" + insets.bottom + "; l:" + insets.left + ", r:" + insets.right);
        } catch (NoSuchMethodError ex) {
            Dimension screen = dummy.getToolkit().getScreenSize();
            addString("Screen size h:" + screen.height + ", w:" + screen.width + " (No Inset method available)");
        }
    } catch (HeadlessException ex) {
        // failed, fall back to standard method
        addString("(Cannot sense screen size due to " + ex.toString() + ")");
    }
    try {
        // Find screen resolution. Not expected to fail, but just in case....
        int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
        addString("Screen resolution: " + dpi);
    } catch (HeadlessException ex) {
        addString("Screen resolution not available");
    }
    //Rectangle virtualBounds = new Rectangle();
    try {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        addString("Environment max bounds: " + ge.getMaximumWindowBounds());
        try {
            GraphicsDevice[] gs = ge.getScreenDevices();
            for (GraphicsDevice gd : gs) {
                GraphicsConfiguration[] gc = gd.getConfigurations();
                for (int i = 0; i < gc.length; i++) {
                    addString("bounds[" + i + "] = " + gc[i].getBounds());
                // virtualBounds = virtualBounds.union(gc[i].getBounds());
                }
                addString("Device: " + gd.getIDstring() + " bounds = " + gd.getDefaultConfiguration().getBounds() + " " + gd.getDefaultConfiguration().toString());
            }
        } catch (HeadlessException ex) {
            addString("Exception getting device bounds " + ex.getMessage());
        }
    } catch (HeadlessException ex) {
        addString("Exception getting max window bounds " + ex.getMessage());
    }
    // various Linux window managers
    try {
        Insets jmriInsets = JmriInsets.getInsets();
        addString("JmriInsets t:" + jmriInsets.top + ", b:" + jmriInsets.bottom + "; l:" + jmriInsets.left + ", r:" + jmriInsets.right);
    } catch (Exception ex) {
        addString("Exception getting JmriInsets" + ex.getMessage());
    }
}
Also used : Insets(java.awt.Insets) JmriInsets(jmri.util.JmriInsets) GraphicsDevice(java.awt.GraphicsDevice) HeadlessException(java.awt.HeadlessException) JFrame(javax.swing.JFrame) Dimension(java.awt.Dimension) GraphicsEnvironment(java.awt.GraphicsEnvironment) SocketException(java.net.SocketException) HeadlessException(java.awt.HeadlessException) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Aggregations

Dimension (java.awt.Dimension)1 GraphicsConfiguration (java.awt.GraphicsConfiguration)1 GraphicsDevice (java.awt.GraphicsDevice)1 GraphicsEnvironment (java.awt.GraphicsEnvironment)1 HeadlessException (java.awt.HeadlessException)1 Insets (java.awt.Insets)1 SocketException (java.net.SocketException)1 JFrame (javax.swing.JFrame)1 JmriInsets (jmri.util.JmriInsets)1