Changeset 4571 in josm


Ignore:
Timestamp:
2011-11-03T18:35:07+01:00 (13 years ago)
Author:
Don-vip
Message:

fix #6343 - Relation windows don't remember their last position

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java

    r4246 r4571  
    456456            if(visible) {
    457457                new WindowGeometry(rememberSizePref,
    458                         defaultWindowGeometry).applySafe(this);
     458                        defaultWindowGeometry).applySafeMultiScreen(this);
    459459            } else {
    460460                new WindowGeometry(this).remember(rememberSizePref);
  • trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java

    r3083 r4571  
    66import java.awt.Component;
    77import java.awt.Dimension;
     8import java.awt.GraphicsConfiguration;
     9import java.awt.GraphicsDevice;
     10import java.awt.GraphicsEnvironment;
    811import java.awt.Point;
     12import java.awt.Rectangle;
    913import java.awt.Toolkit;
    1014import java.awt.Window;
     
    102106        String v = "";
    103107        try {
    104             Pattern p = Pattern.compile(field + "=(\\d+)",Pattern.CASE_INSENSITIVE);
     108            Pattern p = Pattern.compile(field + "=(-?\\d+)",Pattern.CASE_INSENSITIVE);
    105109            Matcher m = p.matcher(preferenceValue);
    106110            if (!m.find())
     
    214218    public void applySafe(Window window) {
    215219        Point p = new Point(topLeft);
    216         if (p.x > Toolkit.getDefaultToolkit().getScreenSize().width - 10) {
     220        if (p.x < 0 || p.x > Toolkit.getDefaultToolkit().getScreenSize().width - 10) {
    217221            p.x  = 0;
    218222        }
    219         if (p.y > Toolkit.getDefaultToolkit().getScreenSize().height - 10) {
     223        if (p.y < 0 || p.y > Toolkit.getDefaultToolkit().getScreenSize().height - 10) {
    220224            p.y = 0;
    221225        }
     
    223227        window.setSize(extent);
    224228    }
     229   
     230    /**
     231     * Applies this geometry to a window. Makes sure that the window is not
     232     * placed outside of the coordinate range of all available screens.
     233     *
     234     * @param window the window
     235     */
     236    public void applySafeMultiScreen(Window window) {
     237        Point p = new Point(topLeft);
     238
     239        Rectangle virtualBounds = new Rectangle();
     240        GraphicsEnvironment ge = GraphicsEnvironment
     241                .getLocalGraphicsEnvironment();
     242        GraphicsDevice[] gs = ge.getScreenDevices();
     243        for (int j = 0; j < gs.length; j++) {
     244            GraphicsDevice gd = gs[j];
     245            GraphicsConfiguration[] gc = gd.getConfigurations();
     246            for (int i = 0; i < gc.length; i++) {
     247                virtualBounds = virtualBounds.union(gc[i].getBounds());
     248            }
     249        }
     250
     251        if (p.x < virtualBounds.x) {
     252            p.x = virtualBounds.x;
     253        } else if (p.x > virtualBounds.x + virtualBounds.width - extent.width) {
     254            p.x = virtualBounds.x + virtualBounds.width - extent.width;
     255        }
     256
     257        if (p.y < virtualBounds.y) {
     258            p.y = virtualBounds.y;
     259        } else if (p.y > virtualBounds.y + virtualBounds.height - extent.height) {
     260            p.y = virtualBounds.y + virtualBounds.height - extent.height;
     261        }
     262
     263        window.setLocation(p);
     264        window.setSize(extent);
     265    }
    225266}
Note: See TracChangeset for help on using the changeset viewer.