Example usage for java.awt GraphicsEnvironment getLocalGraphicsEnvironment

List of usage examples for java.awt GraphicsEnvironment getLocalGraphicsEnvironment

Introduction

In this page you can find the example usage for java.awt GraphicsEnvironment getLocalGraphicsEnvironment.

Prototype

public static GraphicsEnvironment getLocalGraphicsEnvironment() 

Source Link

Document

Returns the local GraphicsEnvironment .

Usage

From source file:cz.zeno.miner.ui.MinerUI.java

/**
 * Creates new form MinerUI/*from w  w  w . java  2s  . c o  m*/
 */
public MinerUI() {
    //init GUI components
    initComponents();
    Point p = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    p.translate(-this.getWidth() / 2, -this.getHeight() / 2);
    setLocation(p);

    for (String s : Utils.getAvailableSerialPorts())
        device.addItem(s);
    //output, where status text is appended, should always show newest messages.. (shift automatically its caret)
    //        DefaultCaret caret = (DefaultCaret)output.getCaret();  
    //        caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); 
}

From source file:com.mightypocket.ashot.AndroDemon.java

public AndroDemon(final Mediator mediator) {
    super(mediator.getApplication());
    this.mediator = mediator;

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    gc = gd.getDefaultConfiguration();/*from  w  w w. ja  va  2  s. c om*/
}

From source file:Utils.java

/**
 * <p>//w  ww  .j  a v  a 2 s  .c  o  m
 * Returns the <code>Point</code> at which a window should be placed to
 * center that window on the screen.
 * </p>
 * <p>
 * Some thought was taken as to whether to implement a method such as this,
 * or to simply make a method that, given a window, will center it.  It was
 * decided that it is better to not alter an object within a method.
 * </p>
 *
 * @param window The window to calculate the center point for.  This object
 *               can not be null.
 *
 * @return the <code>Point</code> at which the window should be placed to
 *         center that window on the screen.
 */

private static Rectangle getUsableDeviceBounds(Window window) {
    Window owner = window.getOwner();
    GraphicsConfiguration gc = null;

    if (owner == null) {
        gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration();
    } else {
        gc = owner.getGraphicsConfiguration();
    }

    Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
    Rectangle bounds = gc.getBounds();
    bounds.x += insets.left;
    bounds.y += insets.top;
    bounds.width -= (insets.left + insets.right);
    bounds.height -= (insets.top + insets.bottom);

    return bounds;
}

From source file:GUIUtils.java

public static Rectangle getScreenBoundsFor(Rectangle rc) {
    final GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    final List<GraphicsConfiguration> configs = new ArrayList<GraphicsConfiguration>();

    for (int i = 0; i < gds.length; i++) {
        GraphicsConfiguration gc = gds[i].getDefaultConfiguration();
        if (rc.intersects(gc.getBounds())) {
            configs.add(gc);//w w  w. j a  v a 2 s .  c  om
        }
    }

    GraphicsConfiguration selected = null;
    if (configs.size() > 0) {
        for (Iterator<GraphicsConfiguration> it = configs.iterator(); it.hasNext();) {
            GraphicsConfiguration gcc = it.next();
            if (selected == null)
                selected = gcc;
            else {
                if (gcc.getBounds().contains(rc.x + 20, rc.y + 20)) {
                    selected = gcc;
                    break;
                }
            }
        }
    } else {
        selected = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                .getDefaultConfiguration();
    }

    int x = selected.getBounds().x;
    int y = selected.getBounds().y;
    int w = selected.getBounds().width;
    int h = selected.getBounds().height;

    return new Rectangle(x, y, w, h);
}

From source file:org.apache.pdfbox.pdmodel.font.FontManager.java

/**
 * Get the standard font from the environment, usually Arial or Times New Roman. 
 *
 * @return The standard font //  w  w  w  .j av a2  s  . co  m
 * 
 */
public static java.awt.Font getStandardFont() {
    Font awtFont = getAwtFont(standardFont);
    if (awtFont == null) {
        // PDFBOX-1069
        LOG.error("Standard font '" + standardFont + "' is not part of the environment");
        LOG.error("Available fonts:");
        for (Font font : GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()) {
            LOG.error("\t" + font.getFontName());
        }
    }
    return awtFont;
}

From source file:wsattacker.sso.openid.attacker.evaluation.SeleniumBrowser.java

public static WebDriver getWebDriver() {

    if (INSTANCE == null || hasQuit(INSTANCE) || INSTANCE.getWindowHandles().isEmpty()) {
        // create chrome profile
        //ChromeOptions options = new ChromeOptions();
        //options.addExtensions(new File("adblock.crx"));

        FirefoxProfile profile = new FirefoxProfile();

        // install adblock plus
        File tmpFile = new File("adblock.xpi");
        try {/* w  w  w .  j a v  a 2 s .c  om*/
            InputStream inputStream = SeleniumBrowser.class.getResourceAsStream("/adblock_firefox.xpi");
            FileUtils.copyInputStreamToFile(inputStream, tmpFile);
            profile.addExtension(tmpFile);
        } catch (IOException ex) {
            Logger.getLogger(EvaluationGui.class.getName()).log(Level.SEVERE, null, ex);
        }

        // disable local and session storage
        // some websites (e.g. stackoverflow) use those storages in addition
        // to session cookies
        profile.setPreference("dom.storage.enabled", false);

        // start new Firefox instance
        INSTANCE = new FirefoxDriver(profile);

        // screen size
        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        int width = gd.getDisplayMode().getWidth();
        int height = gd.getDisplayMode().getHeight();

        width = width > 1440 ? 1440 : width;
        height = height > 900 ? 900 : height;

        INSTANCE.manage().window().setPosition(new Point(0, 0));
        INSTANCE.manage().window().setSize(new Dimension(width, height));

        tmpFile.delete();
    }

    return INSTANCE;
}

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 {/* w  w w  .jav a  2s . co 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:Main.java

public static GraphicsDevice getScreenByLocation(Point p) {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    final GraphicsDevice[] screens = ge.getScreenDevices();

    for (final GraphicsDevice screen : screens) {
        final Rectangle bounds = screen.getDefaultConfiguration().getBounds();

        if (bounds.contains(p)) {
            return screen;

        }/*w ww.j a  v  a  2  s .  c o m*/

    }
    return null;

}

From source file:net.team2xh.crt.gui.util.GUIToolkit.java

/**
 * Register a local font to the graphical environment.
 *
 * After registering a font, its font family can be used normally as if
 * the font was installed on the OS./*from w w w.j ava2s . co  m*/
 *
 * @param caller Caller instance for resource aquisition
 * @param path Font file path
 */
public static void registerFont(Object caller, String path) {
    try {
        URI uri = caller.getClass().getResource(path).toURI();
        File fontFile = new File(uri);
        Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        ge.registerFont(font);
    } catch (FontFormatException | IOException | URISyntaxException e) {
        System.out.println(e.getMessage());
    }
}

From source file:Main.java

/**
 * @param bounds/*www. j  av a 2  s .  com*/
 * @return
 */
public static GraphicsDevice getScreenByBounds(Rectangle bounds) {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    final GraphicsDevice[] screens = ge.getScreenDevices();
    Rectangle biggestIntersection = null;
    GraphicsDevice bestScreen = null;
    for (final GraphicsDevice screen : screens) {
        final Rectangle sb = screen.getDefaultConfiguration().getBounds();
        Rectangle intersection = sb.intersection(bounds);
        if (intersection != null) {
            if (biggestIntersection == null || intersection.width
                    * intersection.height > biggestIntersection.width * biggestIntersection.height) {
                biggestIntersection = intersection;
                bestScreen = screen;
                if (intersection.equals(bounds)) {
                    // it will not get better
                    break;
                }
            }
        }

    }
    return (biggestIntersection == null || biggestIntersection.width * biggestIntersection.height == 0) ? null
            : bestScreen;
}