Changeset 4932 in josm for trunk/src/org
- Timestamp:
- 2012-02-14T21:27:53+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r4908 r4932 5 5 import java.awt.BorderLayout; 6 6 import java.awt.Component; 7 import java.awt.Dimension;8 7 import java.awt.GridBagConstraints; 9 8 import java.awt.GridBagLayout; 10 import java.awt.Rectangle;11 import java.awt.Toolkit;12 9 import java.awt.event.ComponentEvent; 13 10 import java.awt.event.ComponentListener; … … 90 87 import org.openstreetmap.josm.tools.Shortcut; 91 88 import org.openstreetmap.josm.tools.Utils; 89 import org.openstreetmap.josm.tools.WindowGeometry; 92 90 93 91 abstract public class Main { … … 421 419 public static final JPanel panel = new JPanel(new BorderLayout()); 422 420 423 protected static Rectangle bounds;421 protected static WindowGeometry geometry; 424 422 protected static int windowState = JFrame.NORMAL; 425 423 … … 474 472 } 475 473 476 Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); 477 String geometry = null; 478 if (args.containsKey("geometry")) { 479 geometry = args.get("geometry").iterator().next(); 480 } else { 481 geometry = Main.pref.get("gui.geometry"); 482 } 483 if (geometry.length() != 0) { 484 final Matcher m = Pattern.compile("(\\d+)x(\\d+)(([+-])(\\d+)([+-])(\\d+))?").matcher(geometry); 485 if (m.matches()) { 486 int w = Integer.valueOf(m.group(1)); 487 int h = Integer.valueOf(m.group(2)); 488 int x = 0, y = 0; 489 if (m.group(3) != null) { 490 x = Integer.valueOf(m.group(5)); 491 y = Integer.valueOf(m.group(7)); 492 if (m.group(4).equals("-")) { 493 x = screenDimension.width - x - w; 494 } 495 if (m.group(6).equals("-")) { 496 y = screenDimension.height - y - h; 497 } 498 } 499 // copied from WindowsGeometry.applySafe() 500 if (x > Toolkit.getDefaultToolkit().getScreenSize().width - 10) { 501 x = 0; 502 } 503 if (y > Toolkit.getDefaultToolkit().getScreenSize().height - 10) { 504 y = 0; 505 } 506 bounds = new Rectangle(x,y,w,h); 507 if(!Main.pref.get("gui.geometry").equals(geometry)) { 508 // remember this geometry 509 Main.pref.put("gui.geometry", geometry); 510 } 511 } else { 512 System.out.println("Ignoring malformed geometry: "+geometry); 513 } 514 } 515 if (bounds == null) { 516 bounds = !args.containsKey("no-maximize") ? new Rectangle(0,0,screenDimension.width,screenDimension.height) : new Rectangle(1000,740); 517 } 474 geometry = WindowGeometry.mainWindow("gui.geometry", 475 (args.containsKey("geometry") ? args.get("geometry").iterator().next() : null), 476 !args.containsKey("no-maximize")); 518 477 } 519 478 … … 608 567 public static boolean exitJosm(boolean exit) { 609 568 if (Main.saveUnsavedModifications()) { 610 Main.saveGuiGeometry(); 569 geometry.remember("gui.geometry"); 570 if (map != null) { 571 map.rememberToggleDialogWidth(); 572 } 573 pref.put("gui.maximized", (windowState & JFrame.MAXIMIZED_BOTH) != 0); 611 574 // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask) 612 575 if (Main.isDisplayingMapView()) { … … 714 677 } 715 678 716 static public void saveGuiGeometry() {717 // save the current window geometry and the width of the toggle dialog area718 String newGeometry = "";719 String newToggleDlgWidth = null;720 try {721 Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();722 int width = (int)bounds.getWidth();723 int height = (int)bounds.getHeight();724 int x = (int)bounds.getX();725 int y = (int)bounds.getY();726 if (width > screenDimension.width) {727 width = screenDimension.width;728 }729 if (height > screenDimension.height) {730 width = screenDimension.height;731 }732 if (x < 0) {733 x = 0;734 }735 if (y < 0) {736 y = 0;737 }738 newGeometry = width + "x" + height + "+" + x + "+" + y;739 740 if (map != null) {741 newToggleDlgWidth = Integer.toString(map.getToggleDlgWidth());742 if (newToggleDlgWidth.equals(Integer.toString(MapFrame.DEF_TOGGLE_DLG_WIDTH))) {743 newToggleDlgWidth = "";744 }745 }746 }747 catch (Exception e) {748 System.out.println("Failed to get GUI geometry: " + e);749 e.printStackTrace();750 }751 boolean maximized = (windowState & JFrame.MAXIMIZED_BOTH) != 0;752 // Main.debug("Main window: saving geometry \"" + newGeometry + "\" " + (maximized?"maximized":"normal"));753 pref.put("gui.maximized", maximized);754 pref.put("gui.geometry", newGeometry);755 if (newToggleDlgWidth != null) {756 pref.put("toggleDialogs.width", newToggleDlgWidth);757 }758 }759 679 private static class WindowPositionSizeListener extends WindowAdapter implements 760 680 ComponentListener { 761 762 681 @Override 763 682 public void windowStateChanged(WindowEvent e) { 764 683 Main.windowState = e.getNewState(); 765 // Main.debug("Main window state changed to " + Main.windowState);766 } 767 684 } 685 686 @Override 768 687 public void componentHidden(ComponentEvent e) { 769 688 } 770 689 690 @Override 771 691 public void componentMoved(ComponentEvent e) { 772 692 handleComponentEvent(e); 773 693 } 774 694 695 @Override 775 696 public void componentResized(ComponentEvent e) { 776 697 handleComponentEvent(e); 777 698 } 778 699 700 @Override 779 701 public void componentShown(ComponentEvent e) { 780 702 } … … 782 704 private void handleComponentEvent(ComponentEvent e) { 783 705 Component c = e.getComponent(); 784 if (c instanceof JFrame) { 785 if (Main.windowState == JFrame.NORMAL) { 786 Main.bounds = ((JFrame) c).getBounds(); 787 // Main.debug("Main window: new geometry " + Main.bounds); 788 } else { 789 // Main.debug("Main window state is " + Main.windowState); 790 } 791 } 792 } 793 706 if (c instanceof JFrame && c.isVisible() && Main.windowState == JFrame.NORMAL) { 707 Main.geometry = new WindowGeometry((JFrame) c); 708 } 709 } 794 710 } 795 711 public static void addListener() { -
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r4921 r4932 214 214 } 215 215 else if (mode.equals("download")) { 216 if ( Main.pref.hasKey("osm-download.bounds")) {216 if (!Main.pref.get("osm-download.bounds").isEmpty()) { 217 217 try { 218 218 v.visit(new Bounds(Main.pref.get("osm-download.bounds"), ";")); -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r4920 r4932 334 334 } 335 335 336 /* @Deprecated 336 337 synchronized public boolean hasKey(final String key) { 337 338 return properties.containsKey(key); 338 } 339 }*/ 339 340 340 341 /** … … 638 639 } 639 640 } 641 removeObsolete(); 640 642 } 641 643 … … 1727 1729 return b.toString(); 1728 1730 } 1731 1732 /** 1733 * Removes obsolete preference settings. If you throw out a once-used preference 1734 * setting, add it to the list here with an expiry date (written as comment). If you 1735 * see something with an expiry date in the past, remove it from the list. 1736 */ 1737 public void removeObsolete() { 1738 String[] obsolete = { 1739 "edit.make-parallel-way-action.snap-threshold", // 10/2011 - replaced by snap-threshold-percent. Can be removed mid 2012 1740 }; 1741 for (String key : obsolete) { 1742 boolean removed = false; 1743 if(properties.containsKey(key)) { properties.remove(key); removed = true; } 1744 if(collectionProperties.containsKey(key)) { collectionProperties.remove(key); removed = true; } 1745 if(arrayProperties.containsKey(key)) { arrayProperties.remove(key); removed = true; } 1746 if(listOfStructsProperties.containsKey(key)) { listOfStructsProperties.remove(key); removed = true; } 1747 if(removed) 1748 System.out.println(tr("Preference setting {0} has been removed since it is no longer used.", key)); 1749 } 1750 } 1729 1751 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapRendererFactory.java
r4310 r4932 115 115 private MapRendererFactory() { 116 116 registerDefaultRenderers(); 117 boolean drawWireframe = false;118 if (Main.pref.hasKey("draw.wireframe")) {119 drawWireframe = Main.pref.getBoolean("draw.wireframe",false);120 /*121 * transition 05/2011 - 'draw.wireframe' isn't supported anymore. Remove122 * it from the preferences.123 * Can be removed after ~ 01/2012124 */125 Main.pref.put("draw.wireframe", null);126 }127 if (drawWireframe){128 activate(WireframeMapRenderer.class);129 return;130 }131 132 117 String rendererClassName = Main.pref.get(PREF_KEY_RENDERER_CLASS_NAME, null); 133 118 if (rendererClassName != null) { -
trunk/src/org/openstreetmap/josm/data/preferences/AbstractProperty.java
r4282 r4932 19 19 20 20 public boolean isSet() { 21 return Main.pref.hasKey(key);21 return !Main.pref.get(key).isEmpty(); 22 22 } 23 23 -
trunk/src/org/openstreetmap/josm/data/preferences/CachedProperty.java
r4282 r4932 20 20 21 21 protected void updateValue() { 22 if ( Main.pref.hasKey(key)) {22 if (!Main.pref.get(key).isEmpty()) { 23 23 this.value = fromString(Main.pref.get(key)); 24 24 } else { -
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r4571 r4932 456 456 if(visible) { 457 457 new WindowGeometry(rememberSizePref, 458 defaultWindowGeometry).applySafe MultiScreen(this);458 defaultWindowGeometry).applySafe(this); 459 459 } else { 460 460 new WindowGeometry(this).remember(rememberSizePref); -
trunk/src/org/openstreetmap/josm/gui/MainApplet.java
r4220 r4932 50 50 setContentPane(contentPanePrivate); 51 51 setJMenuBar(menu); 52 setBounds(bounds);53 52 } 54 53 } -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r4906 r4932 65 65 mainFrame.setContentPane(contentPanePrivate); 66 66 mainFrame.setJMenuBar(menu); 67 mainFrame.setBounds(bounds);67 geometry.applySafe(mainFrame); 68 68 LinkedList<Image> l = new LinkedList<Image>(); 69 69 l.add(ImageProvider.get("logo_16x16x32").getImage()); … … 74 74 l.add(ImageProvider.get("logo_48x48x8").getImage()); 75 75 l.add(ImageProvider.get("logo").getImage()); 76 //mainFrame.setIconImage(ImageProvider.get("logo").getImage());77 76 mainFrame.setIconImages(l); 78 77 mainFrame.addWindowListener(new WindowAdapter(){ … … 247 246 monitor.indeterminateSubTask(tr("Setting defaults")); 248 247 preConstructorInit(args); 249 removeObsoletePreferences();250 248 251 249 monitor.indeterminateSubTask(tr("Creating main GUI")); … … 319 317 RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager()); 320 318 } 321 322 }323 324 /**325 * Removes obsolete preference settings. If you throw out a once-used preference326 * setting, add it to the list here with an expiry date (written as comment). If you327 * see something with an expiry date in the past, remove it from the list.328 */329 public static void removeObsoletePreferences() {330 331 String[] obsolete = {332 "edit.make-parallel-way-action.snap-threshold" // 10/2011 - replaced by snap-threshold-percent. Can be removed mid 2012333 };334 for (String key : obsolete) {335 if (Main.pref.hasKey(key)) {336 Main.pref.removeFromCollection(key, Main.pref.get(key));337 System.out.println(tr("Preference setting {0} has been removed since it is no longer used.", key));338 }339 }340 319 } 341 320 } -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r4850 r4932 479 479 480 480 /** 481 * Re turnsthe current width of the (possibly resized) toggle dialog area482 */ 483 public int getToggleDlgWidth() {484 return dialogsPanel.getWidth();481 * Remember the current width of the (possibly resized) toggle dialog area 482 */ 483 public void rememberToggleDialogWidth() { 484 Main.pref.putInteger("toggleDialogs.width", dialogsPanel.getWidth()); 485 485 } 486 486 -
trunk/src/org/openstreetmap/josm/gui/SplashScreen.java
r4681 r4932 29 29 import org.openstreetmap.josm.gui.progress.SwingRenderingProgressMonitor; 30 30 import org.openstreetmap.josm.tools.ImageProvider; 31 import org.openstreetmap.josm.tools.WindowGeometry; 31 32 32 33 /** … … 58 59 GridBagConstraints gbc = new GridBagConstraints(); 59 60 gbc.gridheight = 2; 61 gbc.insets = new Insets(0, 0, 0, 70); 60 62 innerContentPane.add(logo, gbc); 61 63 … … 92 94 pack(); 93 95 94 // Center the splash screen 95 setLocationRelativeTo(null); 96 WindowGeometry.centerOnScreen(this, "gui.geometry"); 96 97 97 98 // Add ability to hide splash screen by clicking it -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r4897 r4932 51 51 import org.openstreetmap.josm.tools.ImageProvider; 52 52 import org.openstreetmap.josm.tools.Shortcut; 53 import org.openstreetmap.josm.tools.WindowGeometry; 54 import org.openstreetmap.josm.tools.WindowGeometry.WindowGeometryException; 53 55 54 56 /** … … 507 509 }); 508 510 509 String bounds = Main.pref.get(preferencePrefix+".bounds",null); 510 if (bounds != null) { 511 String[] b = bounds.split(","); 512 setBounds(getDetachedGeometry(new Rectangle( 513 Integer.parseInt(b[0]),Integer.parseInt(b[1]),Integer.parseInt(b[2]),Integer.parseInt(b[3])))); 514 } else { 511 try { 512 new WindowGeometry(preferencePrefix+".geometry").applySafe(this); 513 } catch (WindowGeometryException e) { 515 514 ToggleDialog.this.setPreferredSize(ToggleDialog.this.getDefaultDetachedSize()); 516 515 pack(); … … 523 522 protected void rememberGeometry() { 524 523 if (detachedDialog != null) { 525 Main.pref.put(preferencePrefix+".bounds", detachedDialog.getX()+","+detachedDialog.getY()+","+detachedDialog.getWidth()+","+detachedDialog.getHeight());524 new WindowGeometry(detachedDialog).remember(preferencePrefix+".geometry"); 526 525 } 527 526 } -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r4906 r4932 328 328 boundingBoxChanged(currentBounds,null); 329 329 } 330 else if ( Main.pref.hasKey("osm-download.bounds")) {330 else if (!Main.pref.get("osm-download.bounds").isEmpty()) { 331 331 // read the bounding box from the preferences 332 332 try { -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialogManager.java
r4760 r4932 74 74 public void placeOnScreen(HistoryBrowserDialog dialog) { 75 75 WindowGeometry geometry = WindowGeometry.centerOnScreen(new Dimension(800,500)); 76 geometry.apply (dialog);76 geometry.applySafe(dialog); 77 77 Point p = dialog.getLocation(); 78 78 while(hasDialogWithCloseUpperLeftCorner(p)) { -
trunk/src/org/openstreetmap/josm/gui/io/CredentialDialog.java
r4690 r4932 75 75 public void setVisible(boolean visible) { 76 76 if (visible) { 77 WindowGeometry.centerInWindow(Main.parent, new Dimension(350,300)).apply (this);77 WindowGeometry.centerInWindow(Main.parent, new Dimension(350,300)).applySafe(this); 78 78 } 79 79 super.setVisible(visible); -
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
r4618 r4932 72 72 protected void build() { 73 73 WindowGeometry geometry = WindowGeometry.centerOnScreen(new Dimension(600,300)); 74 geometry.apply (this);74 geometry.applySafe(this); 75 75 getContentPane().setLayout(new BorderLayout()); 76 76 -
trunk/src/org/openstreetmap/josm/gui/preferences/GPXSettingsPanel.java
r4844 r4932 297 297 public void loadPreferences () { 298 298 makeAutoMarkers.setSelected(Main.pref.getBoolean("marker.makeautomarkers", true)); 299 if(layerName!=null && !Main.pref.hasKey("draw.rawgps.lines."+layerName)300 && !Main.pref.hasKey("draw.rawgps.lines.local."+layerName)){299 if(layerName!=null && Main.pref.get("draw.rawgps.lines."+layerName).isEmpty() 300 && Main.pref.get("draw.rawgps.lines.local."+layerName).isEmpty()){ 301 301 // no line preferences for layer is found 302 302 drawRawGpsLinesGlobal.setSelected(true); … … 323 323 drawRawGpsLinesActionListener.actionPerformed(null); 324 324 325 if(layerName!=null && !Main.pref.hasKey("draw.rawgps.colors."+layerName)) {325 if(layerName!=null && Main.pref.get("draw.rawgps.colors."+layerName).isEmpty()) { 326 326 colorTypeGlobal.setSelected(true); 327 327 colorDynamic.setSelected(false); -
trunk/src/org/openstreetmap/josm/io/CacheFiles.java
r4818 r4932 189 189 public void setExpire(int amount, boolean force) { 190 190 String key = "cache." + ident + "." + "expire"; 191 if( Main.pref.hasKey(key) && !force)191 if(!Main.pref.get(key).isEmpty() && !force) 192 192 return; 193 193 … … 203 203 public void setMaxSize(int amount, boolean force) { 204 204 String key = "cache." + ident + "." + "maxsize"; 205 if( Main.pref.hasKey(key) && !force)205 if(!Main.pref.get(key).isEmpty() && !force) 206 206 return; 207 207 -
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.