Example usage for java.awt GraphicsConfiguration getBounds

List of usage examples for java.awt GraphicsConfiguration getBounds

Introduction

In this page you can find the example usage for java.awt GraphicsConfiguration getBounds.

Prototype

public abstract Rectangle getBounds();

Source Link

Document

Returns the bounds of the GraphicsConfiguration in the device coordinates.

Usage

From source file:net.pms.newgui.components.WindowProperties.java

/**
 * Creates a new instance using the specified parameters.
 *
 * @param window the {@link Window} whose properties to keep track of.
 * @param standardSize the standard size of {@code window}.
 * @param mimimumSize the minimum size of {@code window}.
 * @param windowConfiguration the {@link WindowPropertiesConfiguration}
 *            instance for reading and writing the window properties.
 *//*from ww w .  j a  v a  2s  .co m*/
public WindowProperties(@Nonnull Window window, @Nullable Dimension standardSize,
        @Nullable Dimension mimimumSize, @Nullable WindowPropertiesConfiguration windowConfiguration) {
    if (window == null) {
        throw new IllegalArgumentException("window cannot be null");
    }
    this.window = window;
    this.minimumSize = mimimumSize;
    if (mimimumSize != null) {
        window.setMinimumSize(mimimumSize);
    }
    this.windowConfiguration = windowConfiguration;
    if (windowConfiguration != null) {
        getConfiguration();
        GraphicsConfiguration windowGraphicsConfiguration = window.getGraphicsConfiguration();
        if (windowBounds != null && effectiveScreenBounds != null && graphicsDevice != null
                && graphicsDevice.equals(windowGraphicsConfiguration.getDevice().getIDstring())
                && screenBounds != null && screenBounds.equals(windowGraphicsConfiguration.getBounds())) {
            setWindowBounds();
        } else {
            Rectangle screen = effectiveScreenBounds != null ? effectiveScreenBounds
                    : windowGraphicsConfiguration.getBounds();
            if (standardSize != null && screen.width >= standardSize.width
                    && screen.height >= standardSize.height) {
                window.setSize(standardSize);
            } else if (mimimumSize != null && (window.getWidth() < mimimumSize.width
                    || window.getHeight() < mimimumSize.getHeight())) {
                window.setSize(mimimumSize);
            }
            window.setLocationByPlatform(true);
        }
        if (window instanceof Frame) {
            // Set maximized state
            int maximizedState = windowState & Frame.MAXIMIZED_BOTH;
            if (maximizedState != 0) {
                ((Frame) window).setExtendedState(((Frame) window).getExtendedState() | maximizedState);
            }
        }
    }
    window.addWindowListener(this);
    window.addComponentListener(this);
}

From source file:com._17od.upm.gui.MainWindow.java

/**
 * Utility function for restoreWindowBounds
 *///from  www  . jav  a 2s.co m
private GraphicsConfiguration getGraphicsConfigurationContaining(int x, int y) {
    ArrayList configs = new ArrayList();
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = env.getScreenDevices();
    for (int i = 0; i < devices.length; i++) {
        GraphicsConfiguration[] gconfigs = devices[i].getConfigurations();
        configs.addAll(Arrays.asList(gconfigs));
    }
    for (int i = 0; i < configs.size(); i++) {
        GraphicsConfiguration config = ((GraphicsConfiguration) configs.get(i));
        Rectangle bounds = config.getBounds();
        if (bounds.contains(x, y)) {
            return config;
        }
    }
    return null;
}

From source file:com.t3.client.ui.T3Frame.java

public void showFullScreen() {
    GraphicsConfiguration graphicsConfig = getGraphicsConfiguration();
    Rectangle bounds = graphicsConfig.getBounds();

    fullScreenFrame = new FullScreenFrame();
    fullScreenFrame.add(zoneRendererPanel);

    // Under mac os x this does not properly hide the menu bar so adjust top and height
    // so menu bar does not overlay screen.
    if (TabletopTool.MAC_OS_X) {
        fullScreenFrame.setBounds(bounds.x, bounds.y + 21, bounds.width, bounds.height - 21);
    } else {/*  w w w .j a va2  s  .c o m*/
        fullScreenFrame.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
    }
    fullScreenFrame.setJMenuBar(menuBar);
    // Menu bar is visible anyways on MAC so leave menu items on it
    if (!TabletopTool.MAC_OS_X)
        menuBar.setVisible(false);

    fullScreenFrame.setVisible(true);
    this.setVisible(false);
}

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

public void showFullScreen() {
    GraphicsConfiguration graphicsConfig = getGraphicsConfiguration();
    Rectangle bounds = graphicsConfig.getBounds();

    fullScreenFrame = new FullScreenFrame();
    fullScreenFrame.add(zoneRendererPanel);

    // Under mac os x this does not properly hide the menu bar so adjust top and height
    // so menu bar does not overlay screen.
    if (MapTool.MAC_OS_X) {
        fullScreenFrame.setBounds(bounds.x, bounds.y + 21, bounds.width, bounds.height - 21);
    } else {/*from  ww w.j a v  a2s  .  c om*/
        fullScreenFrame.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
    }
    fullScreenFrame.setJMenuBar(menuBar);
    // Menu bar is visible anyways on MAC so leave menu items on it
    if (!MapTool.MAC_OS_X)
        menuBar.setVisible(false);

    fullScreenFrame.setVisible(true);
    this.setVisible(false);
}

From source file:org.opensc.test.pkcs11.PINEntry.java

/**
 * Contructs a PINEntry instance. /*from   w  w  w.j  a  va2s  .c  o  m*/
 */
public PINEntry() {
    super();
    Frame frame = new Frame("PIN entry");

    frame.setLayout(new GridLayout(2, 2));

    frame.add(new Label("Event:"));

    this.label = new Label("NO_EVENT");
    frame.add(this.label);

    this.prompt = new Label();
    frame.add(this.prompt);

    this.listener = new PINListener(frame);

    this.textField = new TextField();
    this.textField.setEchoChar('*');
    this.textField.addKeyListener(this.listener);
    frame.add(this.textField);
    frame.addWindowListener(this.listener);

    frame.pack();
    frame.setVisible(true);

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    Rectangle r = gc.getBounds();
    Point p = new Point((r.width - frame.getWidth()) / 2, (r.height - frame.getHeight()) / 2);

    frame.setLocation(p);
}

From source file:org.pentaho.reporting.designer.core.actions.global.ScreenCaptureAction.java

public static void saveScreenShot(final int modifiers) {
    final Component component = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    final GraphicsConfiguration graphicsConfiguration = component.getGraphicsConfiguration();
    final GraphicsDevice graphicsDevice = graphicsConfiguration.getDevice();
    try {//from   w  w w. j  a  v a 2  s  . com
        final Robot robot = new Robot(graphicsDevice);
        final BufferedImage image;
        if ((modifiers & ActionEvent.SHIFT_MASK) == ActionEvent.SHIFT_MASK) {
            image = robot.createScreenCapture(graphicsConfiguration.getBounds());
        } else {
            image = robot.createScreenCapture(component.getBounds());
        }

        final String homeDirectory = ReportDesignerBoot.getInstance().getGlobalConfig()
                .getConfigProperty("user.home", ".");
        final File homeDir = new File(homeDirectory);
        final File f = generateName(homeDir);
        if (f == null) {
            return;
        }
        final FileOutputStream fout = new FileOutputStream(f);
        try {
            final PngEncoder encoder = new PngEncoder();
            encoder.setCompressionLevel(6);
            encoder.setEncodeAlpha(false);
            encoder.setImage(image);
            final byte[] bytes = encoder.pngEncode();
            fout.write(bytes);
        } finally {
            fout.close();
        }
    } catch (IOException ioe) {
        UncaughtExceptionsModel.getInstance().addException(ioe);
    } catch (AWTException e1) {
        // ignore
        UncaughtExceptionsModel.getInstance().addException(e1);
    }
}

From source file:org.squidy.nodes.MouseIO.java

@Override
public void onStart() {

    // Search minimum/maximum of x/y.
    GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    screenBounds = new Rectangle[devices.length];
    for (int i = 0; i < devices.length; i++) {
        GraphicsDevice device = devices[i];
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        Rectangle bounds = gc.getBounds();
        screenBounds[i] = bounds;/*from  ww w  . j  a v a 2 s.  c  om*/

        double x, y;
        x = bounds.getX();
        minX = Math.min(minX, x);
        x += bounds.getWidth();
        maxX = Math.max(maxX, x);
        y = bounds.getY();
        minY = Math.min(minY, y);
        y += bounds.getHeight();
        maxY = Math.max(maxY, y);
    }

    width = Math.abs(minX) + Math.abs(maxX);
    height = Math.abs(minY) + Math.abs(maxY);

    try {
        robot = new Robot();
        robot.setAutoDelay(0);
    } catch (AWTException e) {
        if (LOG.isErrorEnabled())
            LOG.error("Could not initialize Robot.");
        publishFailure(e);
    }

    if (openInputWindow) {
        inputWindow = InputWindow.getInstance();
        inputWindow.registerMouseListener(this);
    }

    if (directInput && isWindows) {
        if (cdim == null) {
            createDirectInputMouse();
            if (cdim != null) {
                if (cdim.Init(0) != 0) {
                    cdim = null;
                    publishFailure(new SquidyException("Could not initialize DirectInput mouse."));
                }
            }
        }
        if (cdim != null) {
            if (cdim.StartCapture() != 0)
                publishFailure(new SquidyException("Could not start DirectInput mouse."));
            else
                new Thread(new Runnable() {
                    public void run() {
                        while (processing) {
                            cdim.WaitForBufferedData();
                            if (processing)
                                processDirectInputMouseBufferedData();
                        }
                    }
                }, getId() + "_DIM").start();
        }
    }
}

From source file:org.zanata.util.TestEventForScreenshotListener.java

private Rectangle getScreenRectangle() {
    // http://stackoverflow.com/a/13380999/14379
    Rectangle2D result = new Rectangle2D.Double();
    GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment();
    for (GraphicsDevice gd : localGE.getScreenDevices()) {
        for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) {
            Rectangle2D.union(result, graphicsConfiguration.getBounds(), result);
        }/*from  ww w  .j  a  v  a2  s . c om*/
    }
    return new Rectangle((int) result.getWidth(), (int) result.getHeight());
}

From source file:util.ui.UiUtilities.java

/**
 * Centers a window to its parent frame and shows it.
 * <p>//from   w  w  w . j av  a  2 s .c  o  m
 * If the window has no parent frame it will be centered to the screen.
 *
 * @param win
 *          The window to center and show.
 */
public static void centerAndShow(Window win) {
    Dimension wD = win.getSize();
    Dimension frameD;
    Point framePos;
    Frame frame = JOptionPane.getFrameForComponent(win);

    // Should this window be centered to its parent frame?
    boolean centerToParentFrame = (frame != null) && (frame != win) && frame.isShowing();

    // Center to parent frame or to screen
    if (centerToParentFrame) {
        frameD = frame.getSize();
        framePos = frame.getLocation();
    } else {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        // dual head, use first screen
        if (ge.getScreenDevices().length > 1) {
            try {
                GraphicsDevice gd = ge.getDefaultScreenDevice();
                GraphicsConfiguration config = gd.getConfigurations()[0];
                frameD = config.getBounds().getSize();
                framePos = config.getBounds().getLocation();
            } catch (RuntimeException e) {
                frameD = Toolkit.getDefaultToolkit().getScreenSize();
                framePos = new Point(0, 0);
            }
        }
        // single screen only
        else {
            frameD = Toolkit.getDefaultToolkit().getScreenSize();
            framePos = new Point(0, 0);
        }
    }

    Point wPos = new Point(framePos.x + (frameD.width - wD.width) / 2,
            framePos.y + (frameD.height - wD.height) / 2);
    wPos.x = Math.max(0, wPos.x); // Make x > 0
    wPos.y = Math.max(0, wPos.y); // Make y > 0
    win.setLocation(wPos);
    win.setVisible(true);
}