Ticket #59: wip1.patch
| File wip1.patch, 48.2 KB (added by , 15 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/ChangesetManagerToggleAction.java
33 33 "dialogs/changeset/changesetmanager", 34 34 tr("Toggle visibility of Changeset Manager window"), 35 35 Shortcut.registerShortcut( 36 "menu: view:changesetdialog",36 "menu:windows:changesetdialog", 37 37 tr("Toggle visibility of Changeset Manager window"), 38 38 KeyEvent.VK_C, 39 39 Shortcut.GROUPS_ALT2 + Shortcut.GROUP_HOTKEY -
src/org/openstreetmap/josm/plugins/PluginProxy.java
24 24 this.plugin = plugin; 25 25 } 26 26 27 /** 28 * Not required anymore since the MapFrame is initialized only once now, so 29 * plugins may assume it exists and it won't change. Will be removed after 30 * 2012-01-01. 31 */ 32 @Deprecated 27 33 @Override public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 28 34 try { 29 35 plugin.getClass().getMethod("mapFrameInitialized", MapFrame.class, MapFrame.class).invoke(plugin, oldFrame, newFrame); -
src/org/openstreetmap/josm/plugins/PluginHandler.java
26 26 import java.util.LinkedList; 27 27 import java.util.List; 28 28 import java.util.Map; 29 import java.util.Map.Entry;30 29 import java.util.Set; 31 30 import java.util.TreeSet; 31 import java.util.Map.Entry; 32 32 import java.util.concurrent.ExecutionException; 33 33 import java.util.concurrent.ExecutorService; 34 34 import java.util.concurrent.Executors; … … 49 49 import org.openstreetmap.josm.Main; 50 50 import org.openstreetmap.josm.data.Version; 51 51 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 52 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;53 52 import org.openstreetmap.josm.gui.JMultilineLabel; 54 53 import org.openstreetmap.josm.gui.MapFrame; 54 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 55 55 import org.openstreetmap.josm.gui.download.DownloadSelection; 56 56 import org.openstreetmap.josm.gui.help.HelpUtil; 57 57 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; 58 58 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 59 59 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 60 import org.openstreetmap.josm.io.remotecontrol.RemoteControl;61 60 import org.openstreetmap.josm.tools.CheckParameterUtil; 62 61 import org.openstreetmap.josm.tools.GBC; 63 62 import org.openstreetmap.josm.tools.I18n; … … 824 823 } 825 824 826 825 /** 827 * Notified loaded plugins about a new map frame 828 * 829 * @param old the old map frame 830 * @param map the new map frame 826 * Not required anymore since the MapFrame is initialized only once now, so 827 * plugins may assume it exists and it won't change. Will be removed after 828 * 2012-01-01. 831 829 */ 830 @Deprecated 832 831 public static void notifyMapFrameChanged(MapFrame old, MapFrame map) { 833 832 for (PluginProxy plugin : pluginList) { 834 833 plugin.mapFrameInitialized(old, map); -
src/org/openstreetmap/josm/plugins/Plugin.java
80 80 } 81 81 82 82 /** 83 * Called after Main.mapFrame is initalized. (After the first data is loaded).84 * You can use this callback to tweak the newFrame to your needs, as example install85 * an alternative Painter.83 * Not required anymore since the MapFrame is initialized only once now, so 84 * plugins may assume it exists and it won't change. Will be removed after 85 * 2012-01-01. 86 86 */ 87 @Deprecated 87 88 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {} 88 89 89 90 /** -
src/org/openstreetmap/josm/Main.java
1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 5 6 import java.awt.BorderLayout; … … 87 88 import org.openstreetmap.josm.tools.Utils; 88 89 89 90 abstract public class Main { 90 91 91 /** 92 92 * Replies true if JOSM currently displays a map view. False, if it doesn't, i.e. if 93 93 * it only shows the MOTD panel. … … 95 95 * @return true if JOSM currently displays a map view 96 96 */ 97 97 static public boolean isDisplayingMapView() { 98 if (map == null) return false; 99 if (map.mapView == null) return false; 98 if (map == null) 99 return false; 100 if (map.mapView == null) 101 return false; 100 102 return true; 101 103 } 104 102 105 /** 103 106 * Global parent component for all dialogs and message boxes 104 107 */ … … 124 127 public static PrimitiveDeepCopy pasteBuffer = new PrimitiveDeepCopy(); 125 128 public static Layer pasteSource; 126 129 130 protected static JPanel contentPanePrivate = new JPanel(new BorderLayout()); 131 127 132 /** 128 133 * The MapFrame. Use setMapFrame to set or clear it. 129 134 */ 130 135 public static MapFrame map; 136 131 137 /** 132 138 * True, when in applet mode 133 139 */ … … 155 161 * Print a message if logging is on. 156 162 */ 157 163 static public int log_level = 2; 164 158 165 static public void warn(String msg) { 159 166 if (log_level < 1) 160 167 return; 161 168 System.out.println(msg); 162 169 } 170 163 171 static public void info(String msg) { 164 172 if (log_level < 2) 165 173 return; 166 174 System.out.println(msg); 167 175 } 176 168 177 static public void debug(String msg) { 169 178 if (log_level < 3) 170 179 return; … … 186 195 public static boolean isOpenjdk; 187 196 188 197 /** 189 * Set or clear (if passed <code>null</code>) the map. 198 * MapFrame is now created only once and only shown/hidden. Use show/hideMapFrame instead. 199 * This function has no use any longer. Will be removed on or after 2012-01-01. FIXME 190 200 */ 201 @Deprecated 191 202 public final void setMapFrame(final MapFrame map) { 192 MapFrame old = Main.map; 193 panel.setVisible(false); 203 } 204 205 public final void showMapFrame() { 194 206 panel.removeAll(); 195 if (map != null) {196 207 map.fillPanel(panel); 197 } else { 198 old.destroy(); 199 panel.add(gettingStarted, BorderLayout.CENTER); 200 } 201 panel.setVisible(true); 208 map.setVisible(true); 202 209 redoUndoListener.commandChanged(0,0); 210 } 203 211 204 Main.map = map; 205 206 PluginHandler.notifyMapFrameChanged(old, map); 212 public final void hideMapFrame() { 213 panel.removeAll(); 214 map.setVisible(false); 215 panel.add(gettingStarted, BorderLayout.CENTER); 216 redoUndoListener.commandChanged(0, 0); 217 panel.repaint(); 207 218 } 208 219 209 220 /** … … 214 225 if (map != null) { 215 226 map.mapView.removeLayer(layer); 216 227 if (map.mapView.getAllLayers().isEmpty()) { 217 setMapFrame(null);228 hideMapFrame(); 218 229 } 219 230 } 220 231 } … … 242 253 // creating toolbar 243 254 contentPanePrivate.add(toolbar.control, BorderLayout.NORTH); 244 255 245 registerActionShortcut(menu.help, Shortcut.registerShortcut("system:help", tr("Help"), 246 KeyEvent.VK_F1,Shortcut.GROUP_DIRECT));256 registerActionShortcut(menu.help, Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1, 257 Shortcut.GROUP_DIRECT)); 247 258 248 259 TaggingPresetPreference.initialize(); 249 260 MapPaintPreference.initialize(); … … 252 263 validator = new OsmValidator(); 253 264 MapView.addLayerChangeListener(validator); 254 265 266 map = new MapFrame(contentPanePrivate); 267 map.initializeDialogsPane(); 268 255 269 toolbar.refreshToolbarControl(); 256 270 257 271 toolbar.control.updateUI(); 258 272 contentPanePrivate.updateUI(); 259 273 274 // remove call after 2012-01-01 FIXME 275 PluginHandler.notifyMapFrameChanged(null, map); 260 276 } 261 277 262 278 /** 263 279 * Add a new layer to the map. If no map exists, create one. 264 280 */ 265 281 public final void addLayer(final Layer layer) { 266 if (map == null) { 267 final MapFrame mapFrame = new MapFrame(contentPanePrivate); 268 setMapFrame(mapFrame); 269 mapFrame.selectMapMode((MapMode)mapFrame.getDefaultButtonAction()); 270 mapFrame.setVisible(true); 271 mapFrame.initializeDialogsPane(); 282 if (!map.isVisible()) { 283 Main.map.selectMapMode((MapMode) Main.map.getDefaultButtonAction()); 284 showMapFrame(); 285 272 286 // bootstrapping problem: make sure the layer list dialog is going to 273 287 // listen to change events of the very first layer 274 288 // … … 283 297 * @return true if there is an edit layer 284 298 */ 285 299 public boolean hasEditLayer() { 286 if (getEditLayer() == null) return false; 300 if (getEditLayer() == null) 301 return false; 287 302 return true; 288 303 } 289 304 … … 293 308 * @return the current edit layer. null, if no current edit layer exists 294 309 */ 295 310 public OsmDataLayer getEditLayer() { 296 if (map == null) return null; 297 if (map.mapView == null) return null; 311 if (map == null) 312 return null; 313 if (map.mapView == null) 314 return null; 298 315 return map.mapView.getEditLayer(); 299 316 } 300 317 … … 304 321 * @return the current data set. null, if no current data set exists 305 322 */ 306 323 public DataSet getCurrentDataSet() { 307 if (!hasEditLayer()) return null; 324 if (!hasEditLayer()) 325 return null; 308 326 return getEditLayer().data; 309 327 } 310 328 … … 314 332 * @return the currently active layer. null, if currently no active layer exists 315 333 */ 316 334 public Layer getActiveLayer() { 317 if (map == null) return null; 318 if (map.mapView == null) return null; 335 if (map == null) 336 return null; 337 if (map.mapView == null) 338 return null; 319 339 return map.mapView.getActiveLayer(); 320 340 } 321 341 322 protected static JPanel contentPanePrivate = new JPanel(new BorderLayout());323 324 342 /** 325 343 * @deprecated If you just need to register shortcut for action, use registerActionShortcut instead of accessing InputMap directly 326 344 */ … … 338 356 InputMap inputMap = contentPanePrivate.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); 339 357 Object existing = inputMap.get(keyStroke); 340 358 if (existing != null && !existing.equals(action)) { 341 System.out.println(String.format("Keystroke %s is already assigned to %s, will be overridden by %s", keyStroke, existing, action)); 359 System.out.println(String.format("Keystroke %s is already assigned to %s, will be overridden by %s", 360 keyStroke, existing, action)); 342 361 } 343 362 inputMap.put(keyStroke, action); 344 363 … … 358 377 contentPanePrivate.getActionMap().remove(action); 359 378 } 360 379 361 362 380 /////////////////////////////////////////////////////////////////////////// 363 381 // Implementation part 364 382 /////////////////////////////////////////////////////////////////////////// … … 375 393 } 376 394 }; 377 395 396 /* private final List<ToggleDialog> toggleDialogs = new ArrayList<ToggleDialog>(); 397 public IconToggleButton addToggleDialog(final ToggleDialog dlg) { 398 toggleDialogs.add(tg); 399 final IconToggleButton button = new IconToggleButton(dlg.getToggleAction()); 400 button.addMouseListener(new PopupMenuLauncher(new JPopupMenu() { 401 { 402 add(new AbstractAction() { 403 { 404 putValue(NAME, tr("Hide this button")); 405 putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again.")); 406 } 407 408 @Override 409 public void actionPerformed(ActionEvent e) { 410 dlg.hideButton(); 411 validateToolBarToggle(); 412 } 413 }); 414 } 415 })); 416 dlg.setButton(button); 417 if (button.isVisible()) { 418 toolBarToggle.add(button); 419 } 420 allDialogs.add(dlg); 421 if (dialogsPanel.initialized) { 422 dialogsPanel.add(dlg); 423 } 424 return button; 425 } 426 427 public List<ToggleDialog> getToggleDialogs() { 428 return toggleDialogs; 429 } 430 431 public void validateToolBarToggle() { 432 toolBarToggle.removeAll(); 433 for (ToggleDialog dlg : allDialogs) { 434 if (dlg.getButton().isVisible()) { 435 toolBarToggle.add(dlg.getButton()); 436 } 437 } 438 }*/ 439 378 440 /** 379 441 * Should be called before the main constructor to setup some parameter stuff 380 442 * @param args The parsed argument list. … … 387 449 String laf = Main.pref.get("laf", defaultlaf); 388 450 try { 389 451 UIManager.setLookAndFeel(laf); 390 } 391 catch (final java.lang.ClassNotFoundException e) { 452 } catch (final java.lang.ClassNotFoundException e) { 392 453 System.out.println("Look and Feel not found: " + laf); 393 454 Main.pref.put("laf", defaultlaf); 394 } 395 catch (final javax.swing.UnsupportedLookAndFeelException e) { 455 } catch (final javax.swing.UnsupportedLookAndFeelException e) { 396 456 System.out.println("Look and Feel not supported: " + laf); 397 457 Main.pref.put("laf", defaultlaf); 398 458 } … … 458 518 } 459 519 } 460 520 if (bounds == null) { 461 bounds = !args.containsKey("no-maximize") ? new Rectangle(0,0,screenDimension.width,screenDimension.height) : new Rectangle(1000,740); 521 bounds = !args.containsKey("no-maximize") ? new Rectangle(0, 0, screenDimension.width, 522 screenDimension.height) : new Rectangle(1000, 740); 462 523 } 463 524 } 464 525 … … 478 539 try { 479 540 f = new File(new URI(s)); 480 541 } catch (URISyntaxException e) { 481 JOptionPane.showMessageDialog( 482 Main.parent, 483 tr("Ignoring malformed file URL: \"{0}\"", s), 484 tr("Warning"), 485 JOptionPane.WARNING_MESSAGE 486 ); 542 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed file URL: \"{0}\"", s), 543 tr("Warning"), JOptionPane.WARNING_MESSAGE); 487 544 } 488 545 if (f!=null) { 489 546 fileList.add(f); … … 495 552 break; 496 553 } 497 554 } 498 if(!fileList.isEmpty()) 499 { 555 if (!fileList.isEmpty()) { 500 556 OpenFileAction.openFiles(fileList, true); 501 557 } 502 558 } … … 511 567 break; 512 568 case fileUrl: 513 569 case fileName: 514 JOptionPane.showMessageDialog( 515 Main.parent, 516 tr("Parameter \"downloadgps\" does not accept file names or file URLs"), 517 tr("Warning"), 518 JOptionPane.WARNING_MESSAGE 519 ); 570 JOptionPane.showMessageDialog(Main.parent, 571 tr("Parameter \"downloadgps\" does not accept file names or file URLs"), tr("Warning"), 572 JOptionPane.WARNING_MESSAGE); 520 573 } 521 574 } 522 575 } … … 528 581 } 529 582 530 583 public static boolean saveUnsavedModifications() { 531 if (map == null) return true; 584 if (map == null) 585 return true; 532 586 SaveLayersDialog dialog = new SaveLayersDialog(Main.parent); 533 587 List<OsmDataLayer> layersWithUnmodifiedChanges = new ArrayList<OsmDataLayer>(); 534 588 for (OsmDataLayer l: Main.map.mapView.getLayersOfType(OsmDataLayer.class)) { … … 541 595 dialog.getModel().populate(layersWithUnmodifiedChanges); 542 596 dialog.setVisible(true); 543 597 switch(dialog.getUserAction()) { 544 case CANCEL: return false; 545 case PROCEED: return true; 546 default: return false; 598 case CANCEL: 599 return false; 600 case PROCEED: 601 return true; 602 default: 603 return false; 547 604 } 548 605 } 549 606 … … 573 630 * The type of a command line parameter, to be used in switch statements. 574 631 * @see paramType 575 632 */ 576 private enum DownloadParamType { httpUrl, fileUrl, bounds, fileName } 633 private enum DownloadParamType { 634 httpUrl, fileUrl, bounds, fileName 635 } 577 636 578 637 /** 579 638 * Guess the type of a parameter string specified on the command line with --download= or --downloadgps. … … 581 640 * @return The guessed parameter type 582 641 */ 583 642 private DownloadParamType paramType(String s) { 584 if(s.startsWith("http:")) return DownloadParamType.httpUrl; 585 if(s.startsWith("file:")) return DownloadParamType.fileUrl; 643 if (s.startsWith("http:")) 644 return DownloadParamType.httpUrl; 645 if (s.startsWith("file:")) 646 return DownloadParamType.fileUrl; 586 647 final StringTokenizer st = new StringTokenizer(s, ","); 587 648 // we assume a string with exactly 3 commas is a bounds parameter 588 if (st.countTokens() == 4) return DownloadParamType.bounds; 649 if (st.countTokens() == 4) 650 return DownloadParamType.bounds; 589 651 // everything else must be a file name 590 652 return DownloadParamType.fileName; 591 653 } … … 598 660 private static void downloadFromParamHttp(final boolean rawGps, String s) { 599 661 final Bounds b = OsmUrlToBounds.parse(s); 600 662 if (b == null) { 601 JOptionPane.showMessageDialog( 602 Main.parent, 603 tr("Ignoring malformed URL: \"{0}\"", s), 604 tr("Warning"), 605 JOptionPane.WARNING_MESSAGE 606 ); 663 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed URL: \"{0}\"", s), tr("Warning"), 664 JOptionPane.WARNING_MESSAGE); 607 665 } else { 608 666 downloadFromParamBounds(rawGps, b); 609 667 } … … 617 675 private static void downloadFromParamBounds(final boolean rawGps, String s) { 618 676 final StringTokenizer st = new StringTokenizer(s, ","); 619 677 if (st.countTokens() == 4) { 620 Bounds b = new Bounds( 621 new LatLon(Double.parseDouble(st.nextToken()),Double.parseDouble(st.nextToken())), 622 new LatLon(Double.parseDouble(st.nextToken()),Double.parseDouble(st.nextToken())) 623 ); 678 Bounds b = new Bounds(new LatLon(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())), 679 new LatLon(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()))); 624 680 downloadFromParamBounds(rawGps, b); 625 681 } 626 682 } … … 647 703 platform = new PlatformHookUnixoid(); 648 704 } else if (os.toLowerCase().startsWith("windows")) { 649 705 platform = new PlatformHookWindows(); 650 } else if (os.equals("Linux") || os.equals("Solaris") || 651 os.equals("SunOS") || os.equals("AIX") || 652 os.equals("FreeBSD") || os.equals("NetBSD") || os.equals("OpenBSD")) { 706 } else if (os.equals("Linux") || os.equals("Solaris") || os.equals("SunOS") || os.equals("AIX") 707 || os.equals("FreeBSD") || os.equals("NetBSD") || os.equals("OpenBSD")) { 653 708 platform = new PlatformHookUnixoid(); 654 709 } else if (os.toLowerCase().startsWith("mac os x")) { 655 710 platform = new PlatformHookOsx(); 656 711 } else { 657 System.err.println("I don't know your operating system '"+os+"', so I'm guessing its some kind of *nix."); 712 System.err.println("I don't know your operating system '" + os 713 + "', so I'm guessing its some kind of *nix."); 658 714 platform = new PlatformHookUnixoid(); 659 715 } 660 716 } … … 689 745 newToggleDlgWidth = ""; 690 746 } 691 747 } 692 } 693 catch (Exception e) { 748 } catch (Exception e) { 694 749 System.out.println("Failed to get GUI geometry: " + e); 695 750 e.printStackTrace(); 696 751 } … … 702 757 pref.put("toggleDialogs.width", newToggleDlgWidth); 703 758 } 704 759 } 705 private static class WindowPositionSizeListener extends WindowAdapter implements 706 ComponentListener {760 761 private static class WindowPositionSizeListener extends WindowAdapter implements ComponentListener { 707 762 708 763 @Override 709 764 public void windowStateChanged(WindowEvent e) { … … 738 793 } 739 794 740 795 } 796 741 797 public static void addListener() { 742 798 parent.addComponentListener(new WindowPositionSizeListener()); 743 799 ((JFrame)parent).addWindowStateListener(new WindowPositionSizeListener()); … … 746 802 public static void checkJava6() { 747 803 String version = System.getProperty("java.version"); 748 804 if (version != null) { 749 if (version.startsWith("1.6") || version.startsWith("6") || 750 version.startsWith("1.7")|| version.startsWith("7"))805 if (version.startsWith("1.6") || version.startsWith("6") || version.startsWith("1.7") 806 || version.startsWith("7")) 751 807 return; 752 808 if (version.startsWith("1.5") || version.startsWith("5")) { 753 JLabel ho = new JLabel("<html>"+ 754 tr("<h2>JOSM requires Java version 6.</h2>"+ 755 "Detected Java version: {0}.<br>"+ 756 "You can <ul><li>update your Java (JRE) or</li>"+ 757 "<li>use an earlier (Java 5 compatible) version of JOSM.</li></ul>"+ 758 "More Info:", version)+"</html>"); 809 JLabel ho = new JLabel("<html>" 810 + tr("<h2>JOSM requires Java version 6.</h2>" + "Detected Java version: {0}.<br>" 811 + "You can <ul><li>update your Java (JRE) or</li>" 812 + "<li>use an earlier (Java 5 compatible) version of JOSM.</li></ul>" + "More Info:", 813 version) + "</html>"); 759 814 JTextArea link = new JTextArea("http://josm.openstreetmap.de/wiki/Help/SystemRequirements"); 760 815 link.setEditable(false); 761 816 link.setBackground(panel.getBackground()); … … 768 823 panel.add(link, gbc); 769 824 final String EXIT = tr("Exit JOSM"); 770 825 final String CONTINUE = tr("Continue, try anyway"); 771 int ret = JOptionPane.showOptionDialog(null, panel, tr("Error"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, new String[] {EXIT, CONTINUE}, EXIT); 826 int ret = JOptionPane.showOptionDialog(null, panel, tr("Error"), JOptionPane.YES_NO_OPTION, 827 JOptionPane.ERROR_MESSAGE, null, new String[] { EXIT, CONTINUE }, EXIT); 772 828 if (ret == 0) { 773 829 System.exit(0); 774 830 } … … 852 908 * @param listener the listener. Ignored if null. 853 909 */ 854 910 public static void addProjectionChangeListener(ProjectionChangeListener listener) { 855 if (listener == null) return; 911 if (listener == null) 912 return; 856 913 synchronized (Main.class) { 857 914 for (WeakReference<ProjectionChangeListener> wr : listeners) { 858 915 // already registered ? => abort 859 if (wr.get() == listener) return; 916 if (wr.get() == listener) 917 return; 860 918 } 861 919 } 862 920 listeners.add(new WeakReference<ProjectionChangeListener>(listener)); … … 868 926 * @param listener the listener. Ignored if null. 869 927 */ 870 928 public static void removeProjectionChangeListener(ProjectionChangeListener listener) { 871 if (listener == null) return; 929 if (listener == null) 930 return; 872 931 synchronized(Main.class){ 873 932 Iterator<WeakReference<ProjectionChangeListener>> it = listeners.iterator(); 874 933 while(it.hasNext()){ -
src/org/openstreetmap/josm/gui/MainMenu.java
11 11 import javax.swing.JMenu; 12 12 import javax.swing.JMenuBar; 13 13 import javax.swing.JMenuItem; 14 import javax.swing.JPopupMenu; 15 import javax.swing.JSeparator; 14 16 import javax.swing.KeyStroke; 17 import javax.swing.event.MenuEvent; 18 import javax.swing.event.MenuListener; 15 19 16 20 import org.openstreetmap.josm.Main; 17 21 import org.openstreetmap.josm.actions.AboutAction; … … 52 56 import org.openstreetmap.josm.actions.OpenFileAction; 53 57 import org.openstreetmap.josm.actions.OpenLocationAction; 54 58 import org.openstreetmap.josm.actions.OrthogonalizeAction; 55 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;56 59 import org.openstreetmap.josm.actions.PasteAction; 57 60 import org.openstreetmap.josm.actions.PasteTagsAction; 58 61 import org.openstreetmap.josm.actions.PreferencesAction; … … 78 81 import org.openstreetmap.josm.actions.WireframeToggleAction; 79 82 import org.openstreetmap.josm.actions.ZoomInAction; 80 83 import org.openstreetmap.josm.actions.ZoomOutAction; 84 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo; 81 85 import org.openstreetmap.josm.actions.audio.AudioBackAction; 82 86 import org.openstreetmap.josm.actions.audio.AudioFasterAction; 83 87 import org.openstreetmap.josm.actions.audio.AudioFwdAction; … … 184 188 public final JMenu presetsMenu = addMenu(marktr("Presets"), KeyEvent.VK_P, 4, ht("/Menu/Presets")); 185 189 public final ImageryMenu imageryMenu = 186 190 (ImageryMenu)addMenu(new ImageryMenu(), marktr("Imagery"), KeyEvent.VK_I, 5, ht("/Menu/Imagery")); 191 /** the window menu is split into several groups. The first is for windows that can be opened from 192 * this menu any time, e.g. the changeset editor. The second group is for toggle dialogs and the third 193 * group is for currently open windows that cannot be toggled, e.g. relation editors. It's recommended 194 * to use WINDOW_MENU_GROUP to determine the group integer. 195 */ 196 public final JMenu windowMenu = addMenu(marktr("Windows"), KeyEvent.VK_W, 6, ht("/Menu/Windows")); 197 public static enum WINDOW_MENU_GROUP { ALWAYS, TOGGLE_DIALOG, VOLATILE } 198 187 199 public JMenu audioMenu = null; 188 public final JMenu helpMenu = addMenu(marktr("Help"), KeyEvent.VK_H, 6, ht("/Menu/Help"));189 public final int defaultMenuPos = 6;200 public final JMenu helpMenu = addMenu(marktr("Help"), KeyEvent.VK_H, 7, ht("/Menu/Help")); 201 public final int defaultMenuPos = 7; 190 202 191 203 public final JosmAction moveUpAction = new MoveAction(MoveAction.Direction.UP); 192 204 public final JosmAction moveDownAction = new MoveAction(MoveAction.Direction.DOWN); … … 196 208 197 209 public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction(); 198 210 public FullscreenToggleAction fullscreenToggleAction = null; 211 212 /** this menu listener hides unnecessary JSeparators in a menu list but does not remove them. 213 * If at a later time the separators are required, they will be made visible again. Intended 214 * usage is make menus not look broken if separators are used to group the menu and some of 215 * these groups are empty. 216 */ 217 public final static MenuListener menuSeparatorHandler = new MenuListener() { 218 @Override 219 public void menuCanceled(MenuEvent arg0) {} 220 @Override 221 public void menuDeselected(MenuEvent arg0) {} 222 @Override 223 public void menuSelected(MenuEvent a) { 224 if(!(a.getSource() instanceof JMenu)) 225 return; 226 final JPopupMenu m = ((JMenu) a.getSource()).getPopupMenu(); 227 for(int i=0; i < m.getComponentCount()-1; i++) { 228 if(!(m.getComponent(i) instanceof JSeparator)) { 229 continue; 230 } 231 // hide separator if the next menu item is one as well 232 ((JSeparator) m.getComponent(i)).setVisible(!(m.getComponent(i+1) instanceof JSeparator)); 233 } 234 // hide separator at the end of the menu 235 if(m.getComponent(m.getComponentCount()-1) instanceof JSeparator) { 236 ((JSeparator) m.getComponent(m.getComponentCount()-1)).setVisible(false); 237 } 238 } 239 }; 240 199 241 /** 200 242 * Add a JosmAction to a menu. 201 243 * 202 244 * This method handles all the shortcut handling. It also makes sure that actions that are 203 * handled by the OS are not duplicated on the menu. 245 * handled by the OS are not duplicated on the menu. Menu item will be added at the end of 246 * the menu. 247 * @param menu to add the action to 248 * @param the action that should get a menu item 204 249 */ 205 250 public static JMenuItem add(JMenu menu, JosmAction action) { 206 JMenuItem menuitem = null;207 if (!action.getShortcut().getAutomatic()) {208 menuitem = menu.add(action);251 if (action.getShortcut().getAutomatic()) 252 return null; 253 JMenuItem menuitem = menu.add(action); 209 254 KeyStroke ks = action.getShortcut().getKeyStroke(); 210 255 if (ks != null) { 211 256 menuitem.setAccelerator(ks); 212 257 } 258 return menuitem; 259 } 260 261 /** 262 * Add a JosmAction to a menu. 263 * 264 * This method handles all the shortcut handling. It also makes sure that actions that are 265 * handled by the OS are not duplicated on the menu. 266 * @param menu to add the action to 267 * @param the action that should get a menu item 268 * @param group the item should be added to. Groups are split by a separator. 269 * 0 is the first group, -1 will add the item to the end. 270 */ 271 public static <E extends Enum<E>> JMenuItem add(JMenu menu, JosmAction action, Enum<E> group) { 272 if (action.getShortcut().getAutomatic()) 273 return null; 274 int i = getInsertionIndexForGroup(menu, group.ordinal()); 275 JMenuItem menuitem = (JMenuItem) menu.add(new JMenuItem(action), i); 276 KeyStroke ks = action.getShortcut().getKeyStroke(); 277 if (ks != null) { 278 menuitem.setAccelerator(ks); 213 279 } 214 280 return menuitem; 215 281 } 216 282 283 /** 284 * Add a JosmAction to a menu and automatically prints accelerator if available. 285 * Also adds a checkbox that may be toggled. 286 * @param menu to add the action to 287 * @param the action that should get a menu item 288 * @param group the item should be added to. Groups are split by a separator. Use 289 * one of the enums that are defined for some of the menus to tell in which 290 * group the item should go. 291 */ 292 public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, Enum<E> group) { 293 int i = getInsertionIndexForGroup(menu, group.ordinal()); 294 final JCheckBoxMenuItem mi = (JCheckBoxMenuItem) menu.add(new JCheckBoxMenuItem(action), i); 295 final KeyStroke ks = action.getShortcut().getKeyStroke(); 296 if (ks != null) { 297 mi.setAccelerator(ks); 298 } 299 return mi; 300 } 301 302 /** finds the correct insertion index for a given group and adds separators if necessary */ 303 private static int getInsertionIndexForGroup(JMenu menu, int group) { 304 if(group < 0) 305 return -1; 306 // look for separator that *ends* the group (or stop at end of menu) 307 int i; 308 for(i=0; i < menu.getItemCount() && group >= 0; i++) { 309 if(menu.getItem(i) == null) { 310 group--; 311 } 312 } 313 // insert before separator that ends the group 314 if(group < 0) { 315 i--; 316 } 317 // not enough separators have been found, add them 318 while(group > 0) { 319 menu.addSeparator(); 320 group--; 321 i++; 322 } 323 return i; 324 } 325 217 326 public JMenu addMenu(String name, int mnemonicKey, int position, String relativeHelpTopic) { 218 327 return addMenu(new JMenu(tr(name)), name, mnemonicKey, position, relativeHelpTopic); 219 328 } … … 294 403 vft.setAccelerator(viewportFollowToggleAction.getShortcut().getKeyStroke()); 295 404 viewportFollowToggleAction.addButtonModel(vft.getModel()); 296 405 297 // -- changeset manager toggle action298 ChangesetManagerToggleAction changesetManagerToggleAction = new ChangesetManagerToggleAction();299 final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(changesetManagerToggleAction);300 viewMenu.addSeparator();301 viewMenu.add(mi);302 mi.setAccelerator(changesetManagerToggleAction.getShortcut().getKeyStroke());303 changesetManagerToggleAction.addButtonModel(mi.getModel());304 305 406 if(!Main.applet && Main.platform.canFullscreen()) { 306 407 // -- fullscreen toggle action 307 408 fullscreenToggleAction = new FullscreenToggleAction(); … … 341 442 add(toolsMenu, joinAreas); 342 443 add(toolsMenu, createMultipolygon); 343 444 445 // -- changeset manager toggle action 446 ChangesetManagerToggleAction changesetManagerToggleAction = new ChangesetManagerToggleAction(); 447 final JCheckBoxMenuItem mi = MainMenu.addWithCheckbox(windowMenu, changesetManagerToggleAction, 448 MainMenu.WINDOW_MENU_GROUP.ALWAYS); 449 changesetManagerToggleAction.addButtonModel(mi.getModel()); 450 451 344 452 if (!Main.pref.getBoolean("audio.menuinvisible", false)) { 345 453 audioMenu = addMenu(marktr("Audio"), KeyEvent.VK_A, defaultMenuPos, ht("/Menu/Audio")); 346 454 add(audioMenu, audioPlayPause); … … 359 467 Shortcut.GROUP_DIRECT).getKeyStroke()); 360 468 add(helpMenu, about); 361 469 470 471 windowMenu.addMenuListener(menuSeparatorHandler); 472 362 473 new PresetsMenuEnabler(presetsMenu).refreshEnabled(); 363 474 } 364 475 -
src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
25 25 import javax.swing.BorderFactory; 26 26 import javax.swing.ImageIcon; 27 27 import javax.swing.JButton; 28 import javax.swing.JCheckBoxMenuItem; 28 29 import javax.swing.JComponent; 29 30 import javax.swing.JDialog; 30 31 import javax.swing.JLabel; … … 34 35 35 36 import org.openstreetmap.josm.Main; 36 37 import org.openstreetmap.josm.actions.JosmAction; 38 import org.openstreetmap.josm.gui.MainMenu; 37 39 import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action; 38 40 import org.openstreetmap.josm.gui.help.HelpUtil; 39 41 import org.openstreetmap.josm.gui.help.Helpful; … … 47 49 * 48 50 */ 49 51 public class ToggleDialog extends JPanel implements Helpful { 50 51 52 /** The action to toggle this dialog */ 52 53 protected ToggleDialogAction toggleAction; 53 54 protected String preferencePrefix; … … 85 86 protected JToggleButton button; 86 87 protected boolean buttonHidden; 87 88 89 /** holds the menu entry in the windows menu. Required to properly 90 * toggle the checkbox on show/hide 91 */ 92 protected JCheckBoxMenuItem windowMenuItem; 93 88 94 /** 89 95 * Constructor 90 96 * (see below) … … 132 138 buttonHidden = Main.pref.getBoolean(preferencePrefix+".button_hidden", false); 133 139 134 140 RedirectInputMap.redirectToMainContentPane(this); 141 142 windowMenuItem = MainMenu.addWithCheckbox(Main.main.menu.windowMenu, 143 (JosmAction) getToggleAction(), 144 MainMenu.WINDOW_MENU_GROUP.TOGGLE_DIALOG); 135 145 } 136 146 137 147 /** … … 152 162 153 163 public void actionPerformed(ActionEvent e) { 154 164 toggleButtonHook(); 165 if(getValue("toolbarbutton") != null && getValue("toolbarbutton") instanceof JButton) { 166 ((JButton) getValue("toolbarbutton")).setSelected(!isShowing); 167 } 155 168 if (isShowing) { 156 169 hideDialog(); 157 170 dialogsPanel.reconstruct(Action.ELEMENT_SHRINKS, null); … … 187 200 } 188 201 // toggling the selected value in order to enforce PropertyChangeEvents 189 202 setIsShowing(true); 203 windowMenuItem.setState(true); 190 204 toggleAction.putValue("selected", false); 191 205 toggleAction.putValue("selected", true); 192 206 } … … 244 258 public void hideDialog() { 245 259 closeDetachedDialog(); 246 260 this.setVisible(false); 261 windowMenuItem.setState(false); 247 262 setIsShowing(false); 248 263 toggleAction.putValue("selected", false); 249 264 } … … 322 337 public void destroy() { 323 338 closeDetachedDialog(); 324 339 hideNotify(); 340 Main.main.menu.windowMenu.remove(windowMenuItem); 325 341 } 326 342 327 343 /** -
src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
34 34 import javax.swing.BorderFactory; 35 35 import javax.swing.JComponent; 36 36 import javax.swing.JLabel; 37 import javax.swing.JMenu; 38 import javax.swing.JMenuItem; 37 39 import javax.swing.JOptionPane; 38 40 import javax.swing.JPanel; 39 41 import javax.swing.JScrollPane; … … 53 55 54 56 import org.openstreetmap.josm.Main; 55 57 import org.openstreetmap.josm.actions.CopyAction; 58 import org.openstreetmap.josm.actions.JosmAction; 56 59 import org.openstreetmap.josm.actions.PasteTagsAction.TagPaster; 57 60 import org.openstreetmap.josm.command.AddCommand; 58 61 import org.openstreetmap.josm.command.ChangeCommand; … … 67 70 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 68 71 import org.openstreetmap.josm.gui.DefaultNameFormatter; 69 72 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 70 import org.openstreetmap.josm.gui. HelpAwareOptionPane.ButtonSpec;73 import org.openstreetmap.josm.gui.MainMenu; 71 74 import org.openstreetmap.josm.gui.SideButton; 75 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 72 76 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler; 73 77 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; 74 78 import org.openstreetmap.josm.gui.help.HelpUtil; … … 101 105 102 106 private AutoCompletingTextField tfRole; 103 107 108 /** the menu item in the windows menu. Required to properly 109 * hide on dialog close. 110 */ 111 private JMenuItem windowMenuItem; 112 104 113 /** 105 114 * Creates a new relation editor for the given relation. The relation will be saved if the user 106 115 * selects "ok" in the editor. … … 574 583 super.setVisible(visible); 575 584 if (visible) { 576 585 RelationDialogManager.getRelationDialogManager().positionOnScreen(this); 586 if(windowMenuItem == null) { 587 addToWindowMenu(); 588 } 577 589 } else { 578 590 // make sure all registered listeners are unregistered 579 591 // 580 592 selectionTableModel.unregister(); 581 593 memberTableModel.unregister(); 582 594 memberTable.unlinkAsListener(); 595 if(windowMenuItem != null) { 596 Main.main.menu.windowMenu.remove(windowMenuItem); 597 windowMenuItem = null; 598 } 583 599 dispose(); 584 600 } 585 601 } 586 602 603 /** adds current relation editor to the windows menu (in the "volatile" group) o*/ 604 protected void addToWindowMenu() { 605 String name = getRelation() == null ? tr("New Relation") : getRelation().getLocalName(); 606 final String tt = tr("Focus Relation Editor with relation ''{0}'' in layer ''{1}''", 607 name, getLayer().getName()); 608 name = tr("Relation Editor: {0}", name == null ? getRelation().getId() : name); 609 final JMenu wm = Main.main.menu.windowMenu; 610 final JosmAction focusAction = new JosmAction(name, "dialogs/relationlist", tt, null, false, false) { 611 @Override 612 public void actionPerformed(ActionEvent e) { 613 final RelationEditor r = (RelationEditor) getValue("relationEditor"); 614 r.setVisible(true); 615 } 616 }; 617 focusAction.putValue("relationEditor", this); 618 windowMenuItem = MainMenu.add(wm, focusAction, MainMenu.WINDOW_MENU_GROUP.VOLATILE); 619 } 620 587 621 /** 588 622 * checks whether the current relation has members referring to itself. If so, 589 623 * warns the users and provides an option for removing these members. -
src/org/openstreetmap/josm/gui/help/HelpBrowser.java
24 24 import javax.swing.JComponent; 25 25 import javax.swing.JDialog; 26 26 import javax.swing.JEditorPane; 27 import javax.swing.JMenuItem; 27 28 import javax.swing.JOptionPane; 28 29 import javax.swing.JPanel; 29 30 import javax.swing.JScrollPane; … … 44 45 import javax.swing.text.html.HTML.Tag; 45 46 46 47 import org.openstreetmap.josm.Main; 48 import org.openstreetmap.josm.actions.JosmAction; 47 49 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 50 import org.openstreetmap.josm.gui.MainMenu; 48 51 import org.openstreetmap.josm.tools.ImageProvider; 49 52 import org.openstreetmap.josm.tools.OpenBrowser; 50 53 import org.openstreetmap.josm.tools.WindowGeometry; … … 53 56 /** the unique instance */ 54 57 private static HelpBrowser instance; 55 58 59 /** the menu item in the windows menu. Required to properly 60 * hide on dialog close. 61 */ 62 private JMenuItem windowMenuItem; 63 56 64 /** 57 65 * Replies the unique instance of the help browser 58 66 * … … 106 114 107 115 private HelpContentReader reader; 108 116 117 private static final JosmAction focusAction = new JosmAction(tr("JOSM Help Browser"), "help", "", null, false, false) { 118 @Override 119 public void actionPerformed(ActionEvent e) { 120 HelpBrowser.getInstance().setVisible(true); 121 } 122 }; 123 109 124 /** 110 125 * Builds the style sheet used in the internal help browser 111 126 * … … 193 208 } else if (!visible && isShowing()){ 194 209 new WindowGeometry(this).remember(getClass().getName() + ".geometry"); 195 210 } 211 if(windowMenuItem != null && !visible) { 212 Main.main.menu.windowMenu.remove(windowMenuItem); 213 windowMenuItem = null; 214 } 215 if(windowMenuItem == null && visible) { 216 windowMenuItem = MainMenu.add(Main.main.menu.windowMenu, focusAction, MainMenu.WINDOW_MENU_GROUP.VOLATILE); 217 } 196 218 super.setVisible(visible); 197 219 } 198 220 -
src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
26 26 import java.util.List; 27 27 import java.util.Map; 28 28 29 import javax.swing.AbstractAction;30 29 import javax.swing.Action; 31 30 import javax.swing.DefaultListCellRenderer; 32 31 import javax.swing.DefaultListModel; … … 214 213 String paramName = readTillChar('=', '='); 215 214 skip('='); 216 215 String paramValue = readTillChar(',','}'); 217 if ("icon".equals(paramName) && paramValue.length() > 0) 216 if ("icon".equals(paramName) && paramValue.length() > 0) { 218 217 result.setIcon(paramValue); 219 else if("name".equals(paramName) && paramValue.length() > 0)218 } else if("name".equals(paramName) && paramValue.length() > 0) { 220 219 result.setName(paramValue); 220 } 221 221 skip(','); 222 222 } 223 223 skip('}'); … … 280 280 escape(tmp); 281 281 first = false; 282 282 } 283 if(!first) 283 if(!first) { 284 284 result.append('}'); 285 285 } 286 } 286 287 287 288 return result.toString(); 288 289 } … … 322 323 default: 323 324 return null; 324 325 } 325 } else 326 } else { 326 327 rowIndex -= 2; 327 328 } 329 } 328 330 ActionParameter<Object> param = getParam(rowIndex); 329 331 switch (columnIndex) { 330 332 case 0: … … 351 353 } else if (rowIndex == 1) { 352 354 currentAction.setIcon((String)aValue); 353 355 return; 354 } else 356 } else { 355 357 rowIndex -= 2; 356 358 } 359 } 357 360 ActionParameter<Object> param = getParam(rowIndex); 358 361 currentAction.getParameters().put(param.getName(), param.readFromString((String)aValue)); 359 362 } … … 756 759 t.add("|"); 757 760 } else { 758 761 String res = parser.saveAction(action); 759 if(res != null) 762 if(res != null) { 760 763 t.add(res); 761 764 } 762 765 } 766 } 763 767 if (t.isEmpty()) { 764 768 t = Collections.singletonList(EMPTY_TOOLBAR_MARKER); 765 769 } … … 901 905 } 902 906 903 907 /** 904 * Parse the toolbar preference setting and construct the toolbarGUI control.908 * Parse the toolbar preference setting and construct the c GUI control. 905 909 * 906 910 * Call this, if anything has changed in the toolbar settings and you want to refresh 907 911 * the toolbar content (e.g. after registering actions in a plugin) … … 915 919 } else { 916 920 JButton b = control.add(action.getParametrizedAction()); 917 921 String tt = action.getDisplayTooltip(); 918 if (tt != null && !tt.isEmpty()) 922 if (tt != null && !tt.isEmpty()) { 919 923 b.setToolTipText(tt); 924 } 920 925 Icon i = action.getDisplayIcon(); 921 if (i != null) 926 if (i != null) { 922 927 b.setIcon(i); 923 928 } 924 929 } 930 } 925 931 control.setVisible(control.getComponentCount() != 0); 926 932 } 927 933 -
src/org/openstreetmap/josm/gui/MapFrame.java
115 115 private final Map<Layer, MapMode> lastMapMode = new HashMap<Layer, MapMode>(); 116 116 117 117 public MapFrame(JPanel contentPane) { 118 // don't show right now because it is initialized before there are any layers 119 setVisible(false); 120 118 121 setSize(400,400); 119 122 setLayout(new BorderLayout()); 120 123 … … 122 125 123 126 new FileDrop(mapView); 124 127 125 // show menu entry126 Main.main.menu.viewMenu.setVisible(true);127 128 128 // toolbar 129 129 toolBarActions.setFloatable(false); 130 130 addMapMode(new IconToggleButton(new SelectAction(this))); … … 311 311 boolean old = isVisible(); 312 312 super.setVisible(aFlag); 313 313 if (old != aFlag) { 314 // show or hide menu entry 315 Main.main.menu.viewMenu.setVisible(aFlag); 314 316 firePropertyChange("visible", old, aFlag); 315 317 } 316 318 }
