- Timestamp:
- 2011-11-12T12:54:49+01:00 (13 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ChangesetManagerToggleAction.java
r3083 r4590 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, -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r4500 r4590 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; … … 56 60 import org.openstreetmap.josm.actions.OpenLocationAction; 57 61 import org.openstreetmap.josm.actions.OrthogonalizeAction; 58 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;59 62 import org.openstreetmap.josm.actions.PasteAction; 60 63 import org.openstreetmap.josm.actions.PasteTagsAction; … … 82 85 import org.openstreetmap.josm.actions.ZoomInAction; 83 86 import org.openstreetmap.josm.actions.ZoomOutAction; 87 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo; 84 88 import org.openstreetmap.josm.actions.audio.AudioBackAction; 85 89 import org.openstreetmap.josm.actions.audio.AudioFasterAction; … … 191 195 public final ImageryMenu imageryMenu = 192 196 (ImageryMenu)addMenu(new ImageryMenu(), marktr("Imagery"), KeyEvent.VK_I, 5, ht("/Menu/Imagery")); 197 /** the window menu is split into several groups. The first is for windows that can be opened from 198 * this menu any time, e.g. the changeset editor. The second group is for toggle dialogs and the third 199 * group is for currently open windows that cannot be toggled, e.g. relation editors. It's recommended 200 * to use WINDOW_MENU_GROUP to determine the group integer. 201 */ 202 public final JMenu windowMenu = addMenu(marktr("Windows"), KeyEvent.VK_W, 6, ht("/Menu/Windows")); 203 public static enum WINDOW_MENU_GROUP { ALWAYS, TOGGLE_DIALOG, VOLATILE } 204 193 205 public JMenu audioMenu = null; 194 public final JMenu helpMenu = addMenu(marktr("Help"), KeyEvent.VK_H, 6, ht("/Menu/Help"));195 public final int defaultMenuPos = 6;206 public final JMenu helpMenu = addMenu(marktr("Help"), KeyEvent.VK_H, 7, ht("/Menu/Help")); 207 public final int defaultMenuPos = 7; 196 208 197 209 public final JosmAction moveUpAction = new MoveAction(MoveAction.Direction.UP); … … 203 215 public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction(); 204 216 public FullscreenToggleAction fullscreenToggleAction = null; 217 218 /** this menu listener hides unnecessary JSeparators in a menu list but does not remove them. 219 * If at a later time the separators are required, they will be made visible again. Intended 220 * usage is make menus not look broken if separators are used to group the menu and some of 221 * these groups are empty. 222 */ 223 public final static MenuListener menuSeparatorHandler = new MenuListener() { 224 @Override 225 public void menuCanceled(MenuEvent arg0) {} 226 @Override 227 public void menuDeselected(MenuEvent arg0) {} 228 @Override 229 public void menuSelected(MenuEvent a) { 230 if(!(a.getSource() instanceof JMenu)) 231 return; 232 final JPopupMenu m = ((JMenu) a.getSource()).getPopupMenu(); 233 for(int i=0; i < m.getComponentCount()-1; i++) { 234 if(!(m.getComponent(i) instanceof JSeparator)) { 235 continue; 236 } 237 // hide separator if the next menu item is one as well 238 ((JSeparator) m.getComponent(i)).setVisible(!(m.getComponent(i+1) instanceof JSeparator)); 239 } 240 // hide separator at the end of the menu 241 if(m.getComponent(m.getComponentCount()-1) instanceof JSeparator) { 242 ((JSeparator) m.getComponent(m.getComponentCount()-1)).setVisible(false); 243 } 244 } 245 }; 246 247 /** 248 * Add a JosmAction to a menu. 249 * 250 * This method handles all the shortcut handling. It also makes sure that actions that are 251 * handled by the OS are not duplicated on the menu. Menu item will be added at the end of 252 * the menu. 253 * @param menu to add the action to 254 * @param the action that should get a menu item 255 */ 256 public static JMenuItem add(JMenu menu, JosmAction action) { 257 if (action.getShortcut().getAutomatic()) 258 return null; 259 JMenuItem menuitem = menu.add(action); 260 KeyStroke ks = action.getShortcut().getKeyStroke(); 261 if (ks != null) { 262 menuitem.setAccelerator(ks); 263 } 264 return menuitem; 265 } 266 205 267 /** 206 268 * Add a JosmAction to a menu. … … 208 270 * This method handles all the shortcut handling. It also makes sure that actions that are 209 271 * handled by the OS are not duplicated on the menu. 272 * @param menu to add the action to 273 * @param the action that should get a menu item 274 * @param group the item should be added to. Groups are split by a separator. 275 * 0 is the first group, -1 will add the item to the end. 210 276 */ 211 public static JMenuItem add(JMenu menu, JosmAction action) { 212 JMenuItem menuitem = null; 213 if (!action.getShortcut().getAutomatic()) { 214 menuitem = menu.add(action); 215 KeyStroke ks = action.getShortcut().getKeyStroke(); 216 if (ks != null) { 217 menuitem.setAccelerator(ks); 277 public static <E extends Enum<E>> JMenuItem add(JMenu menu, JosmAction action, Enum<E> group) { 278 if (action.getShortcut().getAutomatic()) 279 return null; 280 int i = getInsertionIndexForGroup(menu, group.ordinal()); 281 JMenuItem menuitem = (JMenuItem) menu.add(new JMenuItem(action), i); 282 KeyStroke ks = action.getShortcut().getKeyStroke(); 283 if (ks != null) { 284 menuitem.setAccelerator(ks); 285 } 286 return menuitem; 287 } 288 289 /** 290 * Add a JosmAction to a menu and automatically prints accelerator if available. 291 * Also adds a checkbox that may be toggled. 292 * @param menu to add the action to 293 * @param the action that should get a menu item 294 * @param group the item should be added to. Groups are split by a separator. Use 295 * one of the enums that are defined for some of the menus to tell in which 296 * group the item should go. 297 */ 298 public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, Enum<E> group) { 299 int i = getInsertionIndexForGroup(menu, group.ordinal()); 300 final JCheckBoxMenuItem mi = (JCheckBoxMenuItem) menu.add(new JCheckBoxMenuItem(action), i); 301 final KeyStroke ks = action.getShortcut().getKeyStroke(); 302 if (ks != null) { 303 mi.setAccelerator(ks); 304 } 305 return mi; 306 } 307 308 /** finds the correct insertion index for a given group and adds separators if necessary */ 309 private static int getInsertionIndexForGroup(JMenu menu, int group) { 310 if(group < 0) 311 return -1; 312 // look for separator that *ends* the group (or stop at end of menu) 313 int i; 314 for(i=0; i < menu.getItemCount() && group >= 0; i++) { 315 if(menu.getItem(i) == null) { 316 group--; 218 317 } 219 318 } 220 return menuitem; 319 // insert before separator that ends the group 320 if(group < 0) { 321 i--; 322 } 323 // not enough separators have been found, add them 324 while(group > 0) { 325 menu.addSeparator(); 326 group--; 327 i++; 328 } 329 return i; 221 330 } 222 331 … … 301 410 vft.setAccelerator(viewportFollowToggleAction.getShortcut().getKeyStroke()); 302 411 viewportFollowToggleAction.addButtonModel(vft.getModel()); 303 304 // -- changeset manager toggle action305 ChangesetManagerToggleAction changesetManagerToggleAction = new ChangesetManagerToggleAction();306 final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(changesetManagerToggleAction);307 viewMenu.addSeparator();308 viewMenu.add(mi);309 mi.setAccelerator(changesetManagerToggleAction.getShortcut().getKeyStroke());310 changesetManagerToggleAction.addButtonModel(mi.getModel());311 412 312 413 if(!Main.applet && Main.platform.canFullscreen()) { … … 352 453 add(toolsMenu, createMultipolygon); 353 454 455 // -- changeset manager toggle action 456 ChangesetManagerToggleAction changesetManagerToggleAction = new ChangesetManagerToggleAction(); 457 final JCheckBoxMenuItem mi = MainMenu.addWithCheckbox(windowMenu, changesetManagerToggleAction, 458 MainMenu.WINDOW_MENU_GROUP.ALWAYS); 459 changesetManagerToggleAction.addButtonModel(mi.getModel()); 460 461 354 462 if (!Main.pref.getBoolean("audio.menuinvisible", false)) { 355 463 audioMenu = addMenu(marktr("Audio"), KeyEvent.VK_U, defaultMenuPos, ht("/Menu/Audio")); … … 370 478 add(helpMenu, about); 371 479 480 481 windowMenu.addMenuListener(menuSeparatorHandler); 482 372 483 new PresetsMenuEnabler(presetsMenu).refreshEnabled(); 373 484 } -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r4585 r4590 364 364 jb.add(toolBarActions); 365 365 366 jb.addSeparator(new Dimension(0,18)); 367 toolBarToggle.setAlignmentX(0.5f); 368 jb.add(toolBarToggle); 369 otherButton.setAlignmentX(0.5f); 370 otherButton.setBorder(null); 371 otherButton.setFont(otherButton.getFont().deriveFont(Font.PLAIN)); 372 jb.add(otherButton); 366 if(Main.pref.getBoolean("sidetoolbar.togglevisible", true)) { 367 jb.addSeparator(new Dimension(0,18)); 368 toolBarToggle.setAlignmentX(0.5f); 369 jb.add(toolBarToggle); 370 otherButton.setAlignmentX(0.5f); 371 otherButton.setBorder(null); 372 otherButton.setFont(otherButton.getFont().deriveFont(Font.PLAIN)); 373 jb.add(otherButton); 374 } 373 375 374 376 if(Main.pref.getBoolean("sidetoolbar.visible", true)) -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r4512 r4590 32 32 import javax.swing.ImageIcon; 33 33 import javax.swing.JButton; 34 import javax.swing.JCheckBoxMenuItem; 34 35 import javax.swing.JComponent; 35 36 import javax.swing.JDialog; … … 42 43 import org.openstreetmap.josm.Main; 43 44 import org.openstreetmap.josm.actions.JosmAction; 45 import org.openstreetmap.josm.gui.MainMenu; 44 46 import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action; 45 47 import org.openstreetmap.josm.gui.help.HelpUtil; … … 95 97 private JPanel buttonsPanel; 96 98 99 /** holds the menu entry in the windows menu. Required to properly 100 * toggle the checkbox on show/hide 101 */ 102 protected JCheckBoxMenuItem windowMenuItem; 103 97 104 /** 98 105 * Constructor … … 140 147 141 148 RedirectInputMap.redirectToMainContentPane(this); 149 150 windowMenuItem = MainMenu.addWithCheckbox(Main.main.menu.windowMenu, 151 (JosmAction) getToggleAction(), 152 MainMenu.WINDOW_MENU_GROUP.TOGGLE_DIALOG); 142 153 } 143 154 … … 160 171 public void actionPerformed(ActionEvent e) { 161 172 toggleButtonHook(); 173 if(getValue("toolbarbutton") != null && getValue("toolbarbutton") instanceof JButton) { 174 ((JButton) getValue("toolbarbutton")).setSelected(!isShowing); 175 } 162 176 if (isShowing) { 163 177 hideDialog(); … … 195 209 // toggling the selected value in order to enforce PropertyChangeEvents 196 210 setIsShowing(true); 211 windowMenuItem.setState(true); 197 212 toggleAction.putValue("selected", false); 198 213 toggleAction.putValue("selected", true); … … 252 267 closeDetachedDialog(); 253 268 this.setVisible(false); 269 windowMenuItem.setState(false); 254 270 setIsShowing(false); 255 271 toggleAction.putValue("selected", false); … … 330 346 closeDetachedDialog(); 331 347 hideNotify(); 348 Main.main.menu.windowMenu.remove(windowMenuItem); 332 349 } 333 350 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r4563 r4590 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; … … 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; … … 68 71 import org.openstreetmap.josm.gui.DefaultNameFormatter; 69 72 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 73 import org.openstreetmap.josm.gui.MainMenu; 70 74 import org.openstreetmap.josm.gui.SideButton; 71 75 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; … … 101 105 102 106 private AutoCompletingTextField tfRole; 107 108 /** the menu item in the windows menu. Required to properly 109 * hide on dialog close. 110 */ 111 private JMenuItem windowMenuItem; 103 112 104 113 /** … … 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 … … 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 } 601 } 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); 585 619 } 586 620 -
trunk/src/org/openstreetmap/josm/gui/help/HelpBrowser.java
r4191 r4590 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; … … 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; … … 53 56 /** the unique instance */ 54 57 private static HelpBrowser instance; 58 59 /** the menu item in the windows menu. Required to properly 60 * hide on dialog close. 61 */ 62 private JMenuItem windowMenuItem; 55 63 56 64 /** … … 106 114 107 115 private HelpContentReader reader; 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 }; 108 123 109 124 /** … … 193 208 } else if (!visible && isShowing()){ 194 209 new WindowGeometry(this).remember(getClass().getName() + ".geometry"); 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); 195 217 } 196 218 super.setVisible(visible);
Note:
See TracChangeset
for help on using the changeset viewer.