Changeset 6522 in josm for trunk/src


Ignore:
Timestamp:
2013-12-24T17:21:56+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9466 - dialogs larger than the screen

File:
1 edited

Legend:

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

    r6104 r6522  
    291291    public void applySafe(Window window) {
    292292        Point p = new Point(topLeft);
    293 
     293        Dimension size = new Dimension(extent);
     294
     295        Rectangle virtualBounds = getVirtualScreenBounds();
     296
     297        // Ensure window fit on screen
     298
     299        if (p.x < virtualBounds.x) {
     300            p.x = virtualBounds.x;
     301        } else if (p.x > virtualBounds.x + virtualBounds.width - size.width) {
     302            p.x = virtualBounds.x + virtualBounds.width - size.width;
     303        }
     304
     305        if (p.y < virtualBounds.y) {
     306            p.y = virtualBounds.y;
     307        } else if (p.y > virtualBounds.y + virtualBounds.height - size.height) {
     308            p.y = virtualBounds.y + virtualBounds.height - size.height;
     309        }
     310
     311        int deltax = (p.x + size.width) - (virtualBounds.x + virtualBounds.width);
     312        if (deltax > 0) {
     313            size.width -= deltax;
     314        }
     315
     316        int deltay = (p.x + size.height) - (virtualBounds.y + virtualBounds.height);
     317        if (deltay > 0) {
     318            size.height -= deltay;
     319        }
     320
     321        // Ensure window does not hide taskbar
     322
     323        Rectangle maxbounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
     324
     325        deltax = size.width - maxbounds.width;
     326        if (deltax > 0) {
     327            size.width -= deltax;
     328        }
     329
     330        deltay = size.height - maxbounds.height;
     331        if (deltay > 0) {
     332            size.height -= deltay;
     333        }
     334
     335        window.setLocation(p);
     336        window.setSize(size);
     337    }
     338
     339    /**
     340     * Computes the virtual bounds of graphics environment, as an union of all screen bounds.
     341     * @return The virtual bounds of graphics environment, as an union of all screen bounds.
     342     * @since 6522
     343     */
     344    public Rectangle getVirtualScreenBounds() {
    294345        Rectangle virtualBounds = new Rectangle();
    295         GraphicsEnvironment ge = GraphicsEnvironment
    296                 .getLocalGraphicsEnvironment();
    297         GraphicsDevice[] gs = ge.getScreenDevices();
    298         for (GraphicsDevice gd : gs) {
     346        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
     347        for (GraphicsDevice gd : ge.getScreenDevices()) {
    299348            if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
    300349                virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds());
    301350            }
    302351        }
    303 
    304         if (p.x < virtualBounds.x) {
    305             p.x = virtualBounds.x;
    306         } else if (p.x > virtualBounds.x + virtualBounds.width - extent.width) {
    307             p.x = virtualBounds.x + virtualBounds.width - extent.width;
    308         }
    309 
    310         if (p.y < virtualBounds.y) {
    311             p.y = virtualBounds.y;
    312         } else if (p.y > virtualBounds.y + virtualBounds.height - extent.height) {
    313             p.y = virtualBounds.y + virtualBounds.height - extent.height;
    314         }
    315 
    316         window.setLocation(p);
    317         window.setSize(extent);
     352        return virtualBounds;
    318353    }
    319354
     
    385420    }
    386421
     422    @Override
    387423    public String toString() {
    388424        return "WindowGeometry{topLeft="+topLeft+",extent="+extent+"}";
Note: See TracChangeset for help on using the changeset viewer.