Changeset 4932 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2012-02-14T21:27:53+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java
r4634 r4932 138 138 } 139 139 140 static public WindowGeometry mainWindow(String preferenceKey, String arg, boolean maximize) { 141 Dimension screenDimension = getScreenSize(null); 142 if (arg != null) { 143 final Matcher m = Pattern.compile("(\\d+)x(\\d+)(([+-])(\\d+)([+-])(\\d+))?").matcher(arg); 144 if (m.matches()) { 145 int w = Integer.valueOf(m.group(1)); 146 int h = Integer.valueOf(m.group(2)); 147 int x = 0, y = 0; 148 if (m.group(3) != null) { 149 x = Integer.valueOf(m.group(5)); 150 y = Integer.valueOf(m.group(7)); 151 if (m.group(4).equals("-")) { 152 x = screenDimension.width - x - w; 153 } 154 if (m.group(6).equals("-")) { 155 y = screenDimension.height - y - h; 156 } 157 } 158 return new WindowGeometry(new Point(x,y), new Dimension(w,h)); 159 } else { 160 System.out.println(tr("Ignoring malformed geometry: {0}", arg)); 161 } 162 } 163 WindowGeometry def; 164 if(maximize) 165 def = new WindowGeometry(new Point(0,0), screenDimension); 166 else 167 def = new WindowGeometry(new Point(0,0), new Dimension(1000, 740)); 168 return new WindowGeometry(preferenceKey, def); 169 } 170 140 171 /** 141 172 * Creates a window geometry from the values kept in the preference store under the … … 163 194 initFromPreferences(preferenceKey); 164 195 } catch(WindowGeometryException e) { 165 // System.out.println(tr("Warning: Failed to restore window geometry from key ''{0}''. Falling back to default geometry. Details: {1}", preferenceKey, e.getMessage()));166 196 initFromWindowGeometry(defaultGeometry); 167 197 } … … 201 231 202 232 /** 203 * Applies this geometry to a window 204 * 233 * Center window on screen. When preferenceKey is given, the window is centered 234 * on the screen where the corresponding window is. 235 * 205 236 * @param window the window 206 */ 207 public void apply(Window window) { 208 window.setLocation(topLeft); 209 window.setSize(extent); 210 } 211 212 /** 213 * Applies this geometry to a window. Makes sure that the window is not placed outside 214 * of the coordinate range of the current screen. 215 * 216 * @param window the window 217 */ 218 public void applySafe(Window window) { 219 Point p = new Point(topLeft); 220 if (p.x < 0 || p.x > Toolkit.getDefaultToolkit().getScreenSize().width - 10) { 221 p.x = 0; 222 } 223 if (p.y < 0 || p.y > Toolkit.getDefaultToolkit().getScreenSize().height - 10) { 224 p.y = 0; 225 } 226 window.setLocation(p); 227 window.setSize(extent); 228 } 229 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)); 243 } 244 230 245 /** 231 246 * Applies this geometry to a window. Makes sure that the window is not … … 234 249 * @param window the window 235 250 */ 236 public void applySafe MultiScreen(Window window) {251 public void applySafe(Window window) { 237 252 Point p = new Point(topLeft); 238 253 … … 265 280 } 266 281 282 /** 283 * Find the size of the screen the for given coordinates. Use first screen, 284 * when no coordinates are stored or null is passed. 285 * 286 * @param preferenceKey the key to get size and position from 287 */ 288 public static Dimension getScreenSize(String preferenceKey) { 289 /* TODO: implement this function properly */ 290 return Toolkit.getDefaultToolkit().getScreenSize(); 291 } 292 267 293 public String toString() { 268 294 return "WindowGeometry{topLeft="+topLeft+",extent="+extent+"}";
Note:
See TracChangeset
for help on using the changeset viewer.