Changeset 10200 in josm
- Timestamp:
- 2016-05-13T03:11:46+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r10093 r10200 237 237 } 238 238 239 private static Map<Option, Collection<String>> buildCommandLineArgumentMap(String[] args) { 239 /** 240 * Builds the command-line argument map. 241 * @param args command-line arguments array 242 * @return command-line argument map 243 */ 244 public static Map<Option, Collection<String>> buildCommandLineArgumentMap(String[] args) { 240 245 241 246 List<LongOpt> los = new ArrayList<>(); -
trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java
r10199 r10200 211 211 TreeSet<String> props = new TreeSet<>(); 212 212 for (Entry<String, Object> entry : prop.entrySet()) { 213 StringBuilder sb = new StringBuilder(entry.getKey() +':');213 StringBuilder sb = new StringBuilder(entry.getKey()).append(':'); 214 214 Object val = entry.getValue(); 215 215 if (val instanceof float[]) { -
trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java
r10115 r10200 24 24 * This is a helper class for persisting the geometry of a JOSM window to the preference store 25 25 * and for restoring it from the preference store. 26 * 26 * @since 2008 27 27 */ 28 28 public class WindowGeometry { 29 30 /** the top left point */ 31 private Point topLeft; 32 /** the size */ 33 private Dimension extent; 34 35 /** 36 * Creates a window geometry from a position and dimension 37 * 38 * @param topLeft the top left point 39 * @param extent the extent 40 */ 41 public WindowGeometry(Point topLeft, Dimension extent) { 42 this.topLeft = topLeft; 43 this.extent = extent; 44 } 45 46 /** 47 * Creates a window geometry from a rectangle 48 * 49 * @param rect the position 50 */ 51 public WindowGeometry(Rectangle rect) { 52 this(rect.getLocation(), rect.getSize()); 53 } 54 55 /** 56 * Creates a window geometry from the position and the size of a window. 57 * 58 * @param window the window 59 */ 60 public WindowGeometry(Window window) { 61 this(window.getLocationOnScreen(), window.getSize()); 62 } 63 64 /** 65 * Creates a window geometry from the values kept in the preference store under the 66 * key <code>preferenceKey</code> 67 * 68 * @param preferenceKey the preference key 69 * @throws WindowGeometryException if no such key exist or if the preference value has 70 * an illegal format 71 */ 72 public WindowGeometry(String preferenceKey) throws WindowGeometryException { 73 initFromPreferences(preferenceKey); 74 } 75 76 /** 77 * Creates a window geometry from the values kept in the preference store under the 78 * key <code>preferenceKey</code>. Falls back to the <code>defaultGeometry</code> if 79 * something goes wrong. 80 * 81 * @param preferenceKey the preference key 82 * @param defaultGeometry the default geometry 83 * 84 */ 85 public WindowGeometry(String preferenceKey, WindowGeometry defaultGeometry) { 86 try { 87 initFromPreferences(preferenceKey); 88 } catch (WindowGeometryException e) { 89 if (Main.isDebugEnabled()) { 90 Main.debug(e.getMessage()); 91 } 92 initFromWindowGeometry(defaultGeometry); 93 } 94 } 29 95 30 96 /** … … 85 151 */ 86 152 public static class WindowGeometryException extends Exception { 87 publicWindowGeometryException(String message, Throwable cause) {153 WindowGeometryException(String message, Throwable cause) { 88 154 super(message, cause); 89 155 } 90 156 91 publicWindowGeometryException(String message) {157 WindowGeometryException(String message) { 92 158 super(message); 93 159 } 94 }95 96 /** the top left point */97 private Point topLeft;98 /** the size */99 private Dimension extent;100 101 /**102 * Creates a window geometry from a position and dimension103 *104 * @param topLeft the top left point105 * @param extent the extent106 */107 public WindowGeometry(Point topLeft, Dimension extent) {108 this.topLeft = topLeft;109 this.extent = extent;110 }111 112 /**113 * Creates a window geometry from a rectangle114 *115 * @param rect the position116 */117 public WindowGeometry(Rectangle rect) {118 this(rect.getLocation(), rect.getSize());119 }120 121 /**122 * Creates a window geometry from the position and the size of a window.123 *124 * @param window the window125 */126 public WindowGeometry(Window window) {127 this(window.getLocationOnScreen(), window.getSize());128 160 } 129 161 … … 162 194 "Cannot restore window geometry from preferences.", 163 195 preferenceKey, field, v), e); 164 } catch ( Exception e) {196 } catch (RuntimeException e) { 165 197 throw new WindowGeometryException( 166 198 tr("Failed to parse field ''{1}'' in preference with key ''{0}''. Exception was: {2}. " + … … 195 227 int w = Integer.parseInt(m.group(1)); 196 228 int h = Integer.parseInt(m.group(2)); 197 int x = screenDimension.x, y = screenDimension.y; 229 int x = screenDimension.x; 230 int y = screenDimension.y; 198 231 if (m.group(3) != null) { 199 232 x = Integer.parseInt(m.group(5)); … … 224 257 225 258 /** 226 * Creates a window geometry from the values kept in the preference store under the227 * key <code>preferenceKey</code>228 *229 * @param preferenceKey the preference key230 * @throws WindowGeometryException if no such key exist or if the preference value has231 * an illegal format232 */233 public WindowGeometry(String preferenceKey) throws WindowGeometryException {234 initFromPreferences(preferenceKey);235 }236 237 /**238 * Creates a window geometry from the values kept in the preference store under the239 * key <code>preferenceKey</code>. Falls back to the <code>defaultGeometry</code> if240 * something goes wrong.241 *242 * @param preferenceKey the preference key243 * @param defaultGeometry the default geometry244 *245 */246 public WindowGeometry(String preferenceKey, WindowGeometry defaultGeometry) {247 try {248 initFromPreferences(preferenceKey);249 } catch (WindowGeometryException e) {250 initFromWindowGeometry(defaultGeometry);251 }252 }253 254 /**255 259 * Remembers a window geometry under a specific preference key 256 260 * … … 369 373 Rectangle virtualBounds = new Rectangle(); 370 374 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 371 for (GraphicsDevice gd : ge.getScreenDevices()) { 372 if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) { 373 virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds()); 375 if (!GraphicsEnvironment.isHeadless()) { 376 for (GraphicsDevice gd : ge.getScreenDevices()) { 377 if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) { 378 virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds()); 379 } 374 380 } 375 381 } … … 424 430 */ 425 431 private static Rectangle getScreenInfo(Rectangle g) { 426 GraphicsDevice[] gs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();427 int intersect = 0;428 432 Rectangle bounds = null; 429 for (GraphicsDevice gd : gs) { 430 if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) { 431 Rectangle b = gd.getDefaultConfiguration().getBounds(); 432 if (b.height > 0 && b.width / b.height >= 3) /* multiscreen with wrong definition */ { 433 b.width /= 2; 434 Rectangle is = b.intersection(g); 435 int s = is.width * is.height; 436 if (bounds == null || intersect < s) { 437 intersect = s; 438 bounds = b; 439 } 440 b = new Rectangle(b); 441 b.x += b.width; 442 is = b.intersection(g); 443 s = is.width * is.height; 444 if (intersect < s) { 445 intersect = s; 446 bounds = b; 447 } 448 } else { 449 Rectangle is = b.intersection(g); 450 int s = is.width * is.height; 451 if (bounds == null || intersect < s) { 452 intersect = s; 453 bounds = b; 433 if (!GraphicsEnvironment.isHeadless()) { 434 int intersect = 0; 435 for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { 436 if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) { 437 Rectangle b = gd.getDefaultConfiguration().getBounds(); 438 if (b.height > 0 && b.width / b.height >= 3) /* multiscreen with wrong definition */ { 439 b.width /= 2; 440 Rectangle is = b.intersection(g); 441 int s = is.width * is.height; 442 if (bounds == null || intersect < s) { 443 intersect = s; 444 bounds = b; 445 } 446 b = new Rectangle(b); 447 b.x += b.width; 448 is = b.intersection(g); 449 s = is.width * is.height; 450 if (intersect < s) { 451 intersect = s; 452 bounds = b; 453 } 454 } else { 455 Rectangle is = b.intersection(g); 456 int s = is.width * is.height; 457 if (bounds == null || intersect < s) { 458 intersect = s; 459 bounds = b; 460 } 454 461 } 455 462 } … … 468 475 469 476 @Override 477 public int hashCode() { 478 final int prime = 31; 479 int result = 1; 480 result = prime * result + ((extent == null) ? 0 : extent.hashCode()); 481 result = prime * result + ((topLeft == null) ? 0 : topLeft.hashCode()); 482 return result; 483 } 484 485 @Override 486 public boolean equals(Object obj) { 487 if (this == obj) 488 return true; 489 if (obj == null || getClass() != obj.getClass()) 490 return false; 491 WindowGeometry other = (WindowGeometry) obj; 492 if (extent == null) { 493 if (other.extent != null) 494 return false; 495 } else if (!extent.equals(other.extent)) 496 return false; 497 if (topLeft == null) { 498 if (other.topLeft != null) 499 return false; 500 } else if (!topLeft.equals(other.topLeft)) 501 return false; 502 return true; 503 } 504 505 @Override 470 506 public String toString() { 471 507 return "WindowGeometry{topLeft="+topLeft+",extent="+extent+'}'; -
trunk/test/unit/org/openstreetmap/josm/MainTest.java
r8857 r10200 7 7 import static org.junit.Assert.assertTrue; 8 8 9 import java.awt.Dimension; 10 import java.awt.Point; 9 11 import java.util.Collection; 10 12 13 import org.junit.BeforeClass; 11 14 import org.junit.Test; 12 15 import org.openstreetmap.josm.Main.DownloadParamType; 16 import org.openstreetmap.josm.gui.MainApplication; 17 import org.openstreetmap.josm.tools.WindowGeometry; 13 18 14 19 /** … … 16 21 */ 17 22 public class MainTest { 23 24 /** 25 * Setup test. 26 */ 27 @BeforeClass 28 public static void setUp() { 29 JOSMFixture.createUnitTestFixture().init(); 30 } 18 31 19 32 /** … … 28 41 assertEquals(DownloadParamType.httpUrl, DownloadParamType.paramType("http://somewhere.com/data.osm")); 29 42 assertEquals(DownloadParamType.httpUrl, DownloadParamType.paramType("https://somewhere.com/data.osm")); 43 } 44 45 /** 46 * Unit test of {@code Main#preConstructorInit}. 47 */ 48 @Test 49 public void testPreConstructorInit() { 50 Main.preConstructorInit(MainApplication.buildCommandLineArgumentMap(new String[0])); 51 Main.preConstructorInit(MainApplication.buildCommandLineArgumentMap(new String[]{"--geometry=400x300+10+5", "--no-maximize"})); 52 assertEquals(new WindowGeometry(new Point(10, 5), new Dimension(400, 300)), Main.geometry); 30 53 } 31 54
Note:
See TracChangeset
for help on using the changeset viewer.