Changeset 5015 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2012-02-22T08:42:29+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java
r4965 r5015 27 27 /** 28 28 * Replies a window geometry object for a window with a specific size which is 29 * centered on screen 29 * centered on screen, where main window is 30 30 * 31 31 * @param extent the size … … 33 33 */ 34 34 static public WindowGeometry centerOnScreen(Dimension extent) { 35 return centerOnScreen(extent, "gui.geometry"); 36 } 37 38 /** 39 * Replies a window geometry object for a window with a specific size which is 40 * centered on screen where the corresponding window is. 41 * 42 * @param extent the size 43 * @param preferenceKey the key to get window size and position from, null value format 44 * for whole virtual screen 45 * @return the geometry object 46 */ 47 static public WindowGeometry centerOnScreen(Dimension extent, String preferenceKey) { 48 Rectangle size = preferenceKey != null ? getScreenInfo(preferenceKey) 49 : getFullScreenInfo(); 35 50 Point topLeft = new Point( 36 Math.max(0, (Toolkit.getDefaultToolkit().getScreenSize().width - extent.width) /2),37 Math.max(0, (Toolkit.getDefaultToolkit().getScreenSize().height - extent.height) /2)51 size.x + Math.max(0, (size.width - extent.width) /2), 52 size.y + Math.max(0, (size.height - extent.height) /2) 38 53 ); 39 54 return new WindowGeometry(topLeft, extent); … … 92 107 this.topLeft = topLeft; 93 108 this.extent = extent; 109 } 110 111 /** 112 * 113 * @param rect the position 114 */ 115 public WindowGeometry(Rectangle rect) { 116 this.topLeft = rect.getLocation(); 117 this.extent = rect.getSize(); 94 118 } 95 119 … … 139 163 140 164 static public WindowGeometry mainWindow(String preferenceKey, String arg, boolean maximize) { 141 Dimension screenDimension = getScreenSize(null);165 Rectangle screenDimension = getScreenInfo("gui.geometry"); 142 166 if (arg != null) { 143 167 final Matcher m = Pattern.compile("(\\d+)x(\\d+)(([+-])(\\d+)([+-])(\\d+))?").matcher(arg); … … 145 169 int w = Integer.valueOf(m.group(1)); 146 170 int h = Integer.valueOf(m.group(2)); 147 int x = 0, y = 0;171 int x = screenDimension.x, y = screenDimension.y; 148 172 if (m.group(3) != null) { 149 173 x = Integer.valueOf(m.group(5)); 150 174 y = Integer.valueOf(m.group(7)); 151 175 if (m.group(4).equals("-")) { 152 x = screenDimension. width - x - w;176 x = screenDimension.x + screenDimension.width - x - w; 153 177 } 154 178 if (m.group(6).equals("-")) { 155 y = screenDimension. height - y - h;179 y = screenDimension.y + screenDimension.height - y - h; 156 180 } 157 181 } … … 163 187 WindowGeometry def; 164 188 if(maximize) 165 def = new WindowGeometry( new Point(0,0),screenDimension);189 def = new WindowGeometry(screenDimension); 166 190 else 167 def = new WindowGeometry( new Point(0,0), new Dimension(1000, 740));191 def = new WindowGeometry(screenDimension.getLocation(), new Dimension(1000, 740)); 168 192 return new WindowGeometry(preferenceKey, def); 169 193 } … … 230 254 } 231 255 232 /** 233 * Center window on screen. When preferenceKey is given, the window is centered 234 * on the screen where the corresponding window is. 235 * 236 * @param window the window 237 * @param preferenceKey the key to get size and position from 238 */ 239 public static void centerOnScreen(Window window, String preferenceKey) { 240 Dimension dim = getScreenSize(preferenceKey); 241 Dimension size = window.getSize(); 242 window.setLocation(new Point((dim.width-size.width)/2,(dim.height-size.height)/2)); 256 private Rectangle getRectangle() { 257 return new Rectangle(topLeft, extent); 243 258 } 244 259 … … 281 296 282 297 /** 283 * Find the size of the screen for given coordinates. Use first screen,298 * Find the size and position of the screen for given coordinates. Use first screen, 284 299 * when no coordinates are stored or null is passed. 285 300 * 286 301 * @param preferenceKey the key to get size and position from 287 302 */ 288 public static Dimension getScreenSize(String preferenceKey) { 303 public static Rectangle getScreenInfo(String preferenceKey) { 304 Rectangle g = new WindowGeometry(preferenceKey, 305 /* default: something on screen 1 */ 306 new WindowGeometry(new Point(0,0), new Dimension(10,10))).getRectangle(); 289 307 GraphicsEnvironment ge = GraphicsEnvironment 290 308 .getLocalGraphicsEnvironment(); 291 309 GraphicsDevice[] gs = ge.getScreenDevices(); 310 int intersect = 0; 311 Rectangle bounds = null; 292 312 for (int j = 0; j < gs.length; j++) { 293 313 GraphicsDevice gd = gs[j]; 294 314 GraphicsConfiguration[] gc = gd.getConfigurations(); 295 315 for (int i = 0; i < gc.length; i++) { 296 //System.out.println("-- " + j + " " + i + " " + gc[i].getBounds()); 316 Rectangle b = gc[i].getBounds(); 317 Rectangle is = b.intersection(g); 318 int s = is.width*is.height; 319 if(bounds == null || intersect < s) { 320 intersect = s; 321 bounds = b; 322 } 297 323 } 298 324 } 299 /* TODO: implement this function properly */ 300 return Toolkit.getDefaultToolkit().getScreenSize(); 325 return bounds; 326 } 327 328 /** 329 * Find the size of the full virtual screen. 330 */ 331 public static Rectangle getFullScreenInfo() { 332 return new Rectangle(new Point(0,0), Toolkit.getDefaultToolkit().getScreenSize()); 301 333 } 302 334
Note:
See TracChangeset
for help on using the changeset viewer.