Ticket #6343: patch.diff
| File patch.diff, 3.8 KB (added by , 14 years ago) |
|---|
-
core/src/org/openstreetmap/josm/gui/ExtendedDialog.java
455 455 if(rememberSizePref.length() != 0 && defaultWindowGeometry != null) { 456 456 if(visible) { 457 457 new WindowGeometry(rememberSizePref, 458 defaultWindowGeometry).applySafe (this);458 defaultWindowGeometry).applySafeMultiScreen(this); 459 459 } else { 460 460 new WindowGeometry(this).remember(rememberSizePref); 461 461 } -
core/src/org/openstreetmap/josm/tools/WindowGeometry.java
5 5 6 6 import java.awt.Component; 7 7 import java.awt.Dimension; 8 import java.awt.GraphicsConfiguration; 9 import java.awt.GraphicsDevice; 10 import java.awt.GraphicsEnvironment; 8 11 import java.awt.Point; 12 import java.awt.Rectangle; 9 13 import java.awt.Toolkit; 10 14 import java.awt.Window; 11 15 import java.util.regex.Matcher; … … 101 105 protected int parseField(String preferenceKey, String preferenceValue, String field) throws WindowGeometryException { 102 106 String v = ""; 103 107 try { 104 Pattern p = Pattern.compile(field + "=( \\d+)",Pattern.CASE_INSENSITIVE);108 Pattern p = Pattern.compile(field + "=(-?\\d+)",Pattern.CASE_INSENSITIVE); 105 109 Matcher m = p.matcher(preferenceValue); 106 110 if (!m.find()) 107 111 throw new WindowGeometryException(tr("Preference with key ''{0}'' does not include ''{1}''. Cannot restore window geometry from preferences.", preferenceKey, field)); … … 213 217 */ 214 218 public void applySafe(Window window) { 215 219 Point p = new Point(topLeft); 216 if (p.x > Toolkit.getDefaultToolkit().getScreenSize().width - 10) {217 p.x = 0;220 if (p.x < 0 || p.x > Toolkit.getDefaultToolkit().getScreenSize().width - 10) { 221 p.x = 0; 218 222 } 219 if (p.y >Toolkit.getDefaultToolkit().getScreenSize().height - 10) {223 if (p.y < 0 || p.y > Toolkit.getDefaultToolkit().getScreenSize().height - 10) { 220 224 p.y = 0; 221 225 } 222 226 window.setLocation(p); 223 227 window.setSize(extent); 224 228 } 229 230 /** 231 * Applies this geometry to a window. Makes sure that the window is not placed outside 232 * 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.getLocalGraphicsEnvironment(); 241 GraphicsDevice[] gs = ge.getScreenDevices(); 242 for (int j = 0; j < gs.length; j++) { 243 GraphicsDevice gd = gs[j]; 244 GraphicsConfiguration[] gc = gd.getConfigurations(); 245 for (int i = 0; i < gc.length; i++) { 246 virtualBounds = virtualBounds.union(gc[i].getBounds()); 247 } 248 } 249 250 if (p.x < virtualBounds.x) { 251 p.x = virtualBounds.x; 252 } else if (p.x > virtualBounds.x + virtualBounds.width - extent.width) { 253 p.x = virtualBounds.x + virtualBounds.width - extent.width; 254 } 255 256 if (p.y < virtualBounds.y) { 257 p.y = virtualBounds.y; 258 } else if (p.y > virtualBounds.y + virtualBounds.height - extent.height) { 259 p.y = virtualBounds.y + virtualBounds.height - extent.height; 260 } 261 262 window.setLocation(p); 263 window.setSize(extent); 264 } 225 265 }
