Ignore:
Timestamp:
2012-09-17T17:59:41+02:00 (12 years ago)
Author:
stoecker
Message:

allow to switch and remember display number for main window even in maximized mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java

    r5504 r5514  
    8282    /**
    8383     * Exception thrown by the WindowGeometry class if something goes wrong
    84      *
    8584     */
    8685    static public class WindowGeometryException extends Exception {
     
    10099
    101100    /**
     101     * Creates a window geometry from a position and dimension
    102102     *
    103103     * @param topLeft the top left point
     
    110110
    111111    /**
    112      *
     112     * Creates a window geometry from a rectangle
     113     *
    113114     * @param rect the position
    114115     */
     
    125126    public WindowGeometry(Window window)  {
    126127        this(window.getLocationOnScreen(), window.getSize());
     128    }
     129
     130    /**
     131     * Fixes a window geometry to shift to the correct screen.
     132     *
     133     * @param window the window
     134     */
     135    public void fixScreen(Window window)  {
     136        Rectangle oldScreen = getScreenInfo(getRectangle());
     137        Rectangle newScreen = getScreenInfo(new Rectangle(window.getLocationOnScreen(), window.getSize()));
     138        if(oldScreen.x != newScreen.x) {
     139            this.topLeft.x += newScreen.x - oldScreen.x;
     140        }
     141        if(oldScreen.y != newScreen.y) {
     142            this.topLeft.y += newScreen.y - oldScreen.y;
     143        }
    127144    }
    128145
     
    250267
    251268    /**
    252      * Replies the size spezified by the geometry
    253      *
    254      * @return the size spezified by the geometry
     269     * Replies the size specified by the geometry
     270     *
     271     * @return the size specified by the geometry
    255272     */
    256273    public Dimension getSize() {
     
    258275    }
    259276
     277    /**
     278     * Replies the size and position specified by the geometry
     279     *
     280     * @return the size and position specified by the geometry
     281     */
    260282    private Rectangle getRectangle() {
    261283        return new Rectangle(topLeft, extent);
     
    278300            GraphicsDevice gd = gs[j];
    279301            if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
    280                 virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds());
     302                virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds());
    281303            }
    282304        }
     
    303325     *
    304326     * @param preferenceKey the key to get size and position from
     327     * @return bounds of the screen
    305328     */
    306329    public static Rectangle getScreenInfo(String preferenceKey) {
     
    308331            /* default: something on screen 1 */
    309332            new WindowGeometry(new Point(0,0), new Dimension(10,10))).getRectangle();
     333        return getScreenInfo(g);
     334    }
     335
     336    /**
     337     * Find the size and position of the screen for given coordinates. Use first screen,
     338     * when no coordinates are stored or null is passed.
     339     *
     340     * @param g coordinates to check
     341     * @return bounds of the screen
     342     */
     343    private static Rectangle getScreenInfo(Rectangle g) {
    310344        GraphicsEnvironment ge = GraphicsEnvironment
    311345                .getLocalGraphicsEnvironment();
     
    351385    /**
    352386     * Find the size of the full virtual screen.
     387     * @return size of the full virtual screen
    353388     */
    354389    public static Rectangle getFullScreenInfo() {
Note: See TracChangeset for help on using the changeset viewer.