Java Screen Full Size getOppositeFullScreenBoundsFor(Rectangle r, boolean includeReservedInsets)

Here you can find the source of getOppositeFullScreenBoundsFor(Rectangle r, boolean includeReservedInsets)

Description

get Opposite Full Screen Bounds For

License

Open Source License

Parameter

Parameter Description
r the original rectangle
includeReservedInsets if taskbar and other windowing insets should be included in the returned area

Return

iff there are multiple monitors the other monitor than the effective view of the monitor that the rectangle mostly coveres, or null if there is just one screen

Declaration

public static Rectangle getOppositeFullScreenBoundsFor(Rectangle r, boolean includeReservedInsets) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 BSI Business Systems Integration AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/* w  w w  . ja v  a  2s.  c  o  m*/
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

import java.awt.Rectangle;

import java.util.TreeMap;

public class Main {
    /**
     * @param r
     *          the original rectangle
     * @param includeReservedInsets
     *          if taskbar and other windowing insets should be included in the
     *          returned area
     * @return iff there are multiple monitors the other monitor than the
     *         effective view of the monitor that the rectangle mostly coveres, or
     *         null if there is just one screen
     */
    public static Rectangle getOppositeFullScreenBoundsFor(Rectangle r, boolean includeReservedInsets) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        TreeMap<Integer, Rectangle> prioMap = new TreeMap<Integer, Rectangle>();
        for (GraphicsDevice dev : ge.getScreenDevices()) {
            Rectangle bounds;
            if ((!includeReservedInsets) && dev == ge.getDefaultScreenDevice()) {
                bounds = ge.getMaximumWindowBounds();
            } else {
                bounds = dev.getDefaultConfiguration().getBounds();
            }
            Rectangle intersection = bounds.intersection(r);
            prioMap.put(intersection.width * intersection.height, bounds);
        }
        if (prioMap.size() <= 1) {
            return null;
        } else {
            return prioMap.get(prioMap.firstKey());
        }
    }
}

Related

  1. fitToScreen(Dimension size, GraphicsConfiguration screen)
  2. forceToScreen(Window window)
  3. fullScreen()
  4. fullScreen(Component component)
  5. fullScreen(Window window)
  6. initializeScreenArea(int priority)
  7. locateInScreenCenter(Component c)
  8. locateOnOpticalScreenCenter(Component component)
  9. setFrameToMiddleOfTheScreen(Window window)