Ticket #8652: revised-dialogs-toggle-action.patch
File revised-dialogs-toggle-action.patch, 46.0 KB (added by , 12 years ago) |
---|
-
org/openstreetmap/josm/actions/DialogsToggleAction.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.actions; 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 7 import java.awt.event.ActionEvent; 8 import java.awt.event.KeyEvent; 9 import java.util.ArrayList; 10 import java.util.List; 11 12 import javax.swing.ButtonModel; 13 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.tools.Shortcut; 16 17 public class DialogsToggleAction extends JosmAction { 18 private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>(); 19 private boolean selected; 20 21 public DialogsToggleAction() { 22 super( 23 tr("Toggle dialogs panel"), 24 null, /* no icon */ 25 tr("Toggle dialogs panel, maximize mapview"), 26 Shortcut.registerShortcut("menu:view:dialogspanel", tr("Toggle dialogs panel"),KeyEvent.VK_TAB, Shortcut.DIRECT), 27 false /* register */ 28 ); 29 putValue("help", ht("/Action/ToggleDialogsPanel")); 30 putValue("toolbar", "dialogspanel"); 31 Main.toolbar.register(this); 32 selected = Main.pref.getBoolean("draw.dialogspanel", true); 33 notifySelectedState(); 34 } 35 36 public void addButtonModel(ButtonModel model) { 37 if (model != null && !buttonModels.contains(model)) { 38 buttonModels.add(model); 39 } 40 } 41 42 public void removeButtonModel(ButtonModel model) { 43 if (model != null && buttonModels.contains(model)) { 44 buttonModels.remove(model); 45 } 46 } 47 48 protected void notifySelectedState() { 49 for (ButtonModel model: buttonModels) { 50 if (model.isSelected() != selected) { 51 model.setSelected(selected); 52 } 53 } 54 } 55 56 protected void toggleSelectedState() { 57 selected = !selected; 58 Main.pref.put("draw.dialogspanel", selected); 59 notifySelectedState(); 60 setMode(); 61 } 62 63 public void initial() { 64 if(selected) { 65 setMode(); 66 } 67 } 68 69 protected void setMode() { 70 if (Main.isDisplayingMapView()) { 71 Main.map.setDialogsPanelVisible(selected); 72 Main.map.statusLine.setVisible(selected || Main.pref.getBoolean("statusbar.always-visible", true)); 73 Main.toolbar.control.setVisible(selected || Main.pref.getBoolean("toolbar.always-visible", true)); 74 Main.main.menu.setVisible(selected || Main.pref.getBoolean("menu.always-visible", true)); 75 // sideToolBar listens to preference changes, use it here 76 if (!Main.pref.getBoolean("sidetoolbar.always-visible", true)) { 77 Main.pref.put("sidetoolbar.visible", selected); 78 } 79 } 80 } 81 82 @Override 83 public void actionPerformed(ActionEvent e) { 84 toggleSelectedState(); 85 } 86 } -
org/openstreetmap/josm/actions/mapmode/DrawAction.java
Property changes on: org\openstreetmap\josm\actions\DialogsToggleAction.java ___________________________________________________________________ Added: svn:mime-type + text/plain
127 127 mapFrame, ImageProvider.getCursor("crosshair", null)); 128 128 129 129 snappingShortcut = Shortcut.registerShortcut("mapmode:drawanglesnapping", 130 tr("Mode: Draw Angle snapping"), KeyEvent. VK_TAB, Shortcut.DIRECT);130 tr("Mode: Draw Angle snapping"), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE); 131 131 snapChangeAction = new SnapChangeAction(); 132 132 snapCheckboxMenuItem = addMenuItem(); 133 133 snapHelper.setMenuCheckBox(snapCheckboxMenuItem); -
org/openstreetmap/josm/gui/MainMenu.java
33 33 import org.openstreetmap.josm.actions.CreateCircleAction; 34 34 import org.openstreetmap.josm.actions.CreateMultipolygonAction; 35 35 import org.openstreetmap.josm.actions.DeleteAction; 36 import org.openstreetmap.josm.actions.DialogsToggleAction; 36 37 import org.openstreetmap.josm.actions.DistributeAction; 37 38 import org.openstreetmap.josm.actions.DownloadAction; 38 39 import org.openstreetmap.josm.actions.DownloadPrimitiveAction; … … 62 63 import org.openstreetmap.josm.actions.OpenFileAction; 63 64 import org.openstreetmap.josm.actions.OpenLocationAction; 64 65 import org.openstreetmap.josm.actions.OrthogonalizeAction; 66 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo; 65 67 import org.openstreetmap.josm.actions.PasteAction; 66 68 import org.openstreetmap.josm.actions.PasteTagsAction; 69 import org.openstreetmap.josm.actions.PreferenceToggleAction; 67 70 import org.openstreetmap.josm.actions.PreferencesAction; 68 71 import org.openstreetmap.josm.actions.PurgeAction; 69 72 import org.openstreetmap.josm.actions.RedoAction; … … 90 93 import org.openstreetmap.josm.actions.WireframeToggleAction; 91 94 import org.openstreetmap.josm.actions.ZoomInAction; 92 95 import org.openstreetmap.josm.actions.ZoomOutAction; 93 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;94 import org.openstreetmap.josm.actions.PreferenceToggleAction;95 96 import org.openstreetmap.josm.actions.audio.AudioBackAction; 96 97 import org.openstreetmap.josm.actions.audio.AudioFasterAction; 97 98 import org.openstreetmap.josm.actions.audio.AudioFwdAction; … … 229 230 public final JumpToAction jumpToAct = new JumpToAction(); 230 231 231 232 public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction(); 233 public final DialogsToggleAction dialogsToggleAction = new DialogsToggleAction(); 232 234 public FullscreenToggleAction fullscreenToggleAction = null; 233 235 234 236 /** this menu listener hides unnecessary JSeparators in a menu list but does not remove them. … … 514 516 fullscreen.setAccelerator(fullscreenToggleAction.getShortcut().getKeyStroke()); 515 517 fullscreenToggleAction.addButtonModel(fullscreen.getModel()); 516 518 } 519 520 // -- dialogs panel toggle action 521 final JCheckBoxMenuItem dialogspanel = new JCheckBoxMenuItem(dialogsToggleAction); 522 dialogspanel.setAccelerator(dialogsToggleAction.getShortcut().getKeyStroke()); 523 dialogsToggleAction.addButtonModel(dialogspanel.getModel()); 524 viewMenu.add(dialogspanel); 525 517 526 viewMenu.addSeparator(); 518 527 add(viewMenu, info); 519 528 add(viewMenu, infoweb); -
org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
418 418 419 419 @Override 420 420 public void setupDialog() { 421 setResizable(false);421 //setResizable(false); 422 422 super.setupDialog(); 423 423 424 424 setRememberWindowGeometry(getClass().getName() + ".geometry", -
org/openstreetmap/josm/gui/MapView.java
22 22 import java.util.Collection; 23 23 import java.util.Collections; 24 24 import java.util.Comparator; 25 import java.util.Enumeration;26 25 import java.util.LinkedList; 27 26 import java.util.List; 28 27 import java.util.concurrent.CopyOnWriteArrayList; … … 779 778 * the user to re-select the tool after i.e. moving a layer. While testing I found 780 779 * that I switch layers and actions at the same time and it was annoying to mind the 781 780 * order. This way it works as visual clue for new users */ 782 for (Enumeration<AbstractButton> e = Main.map.toolGroup.getElements() ; e.hasMoreElements() ;) { 783 AbstractButton button = e.nextElement(); 784 MapMode mode = (MapMode)button.getAction(); 785 boolean isLayerSupported = mode.layerIsSupported(layer); 786 button.setEnabled(isLayerSupported); 787 // Also update associated shortcut (fix #6876) 788 if (isLayerSupported) { 789 Main.registerActionShortcut(mode, mode.getShortcut()); 781 for (AbstractButton b: Main.map.allMapModeButtons) { 782 MapMode mode = (MapMode)b.getAction(); 783 if (mode.layerIsSupported(layer)) { 784 Main.registerActionShortcut(mode, mode.getShortcut()); //fix #6876 785 b.setEnabled(true); 790 786 } else { 791 787 Main.unregisterShortcut(mode.getShortcut()); 788 b.setEnabled(false); 792 789 } 793 790 } 794 791 AudioPlayer.reset(); -
org/openstreetmap/josm/gui/ExtendedDialog.java
3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.AWTKeyStroke; 6 7 import java.awt.Component; 8 import java.awt.DefaultKeyboardFocusManager; 7 9 import java.awt.Dimension; 8 10 import java.awt.GridBagConstraints; 9 11 import java.awt.GridBagLayout; … … 14 16 import java.util.Arrays; 15 17 import java.util.Collections; 16 18 import java.util.List; 19 import java.util.Set; 17 20 18 21 import javax.swing.AbstractAction; 19 22 import javax.swing.Action; 23 import javax.swing.FocusManager; 20 24 import javax.swing.Icon; 21 25 import javax.swing.JButton; 22 26 import javax.swing.JCheckBox; … … 100 104 */ 101 105 private boolean placeContentInScrollPane; 102 106 107 /** 108 * TAB is de-registered as a defaultFocusTraversalKey and reused 109 * in the main application to quickly toggle dialogs. Within 110 * ExtendedDialogs however, we'll want TAB to traverse focus. 111 */ 112 private static Set<AWTKeyStroke> defaultFocusTraversalKeys = (new DefaultKeyboardFocusManager()).getDefaultFocusTraversalKeys(FocusManager.FORWARD_TRAVERSAL_KEYS); 113 103 114 // For easy access when inherited 104 115 protected Insets contentInsets = new Insets(10,5,0,5); 105 116 protected ArrayList<JButton> buttons = new ArrayList<JButton>(); … … 147 158 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 148 159 } 149 160 this.disposeOnClose = disposeOnClose; 161 setFocusTraversalKeys(FocusManager.FORWARD_TRAVERSAL_KEYS, defaultFocusTraversalKeys); 150 162 } 151 163 152 164 /** … … 508 520 * @param togglePref The preference to save the checkbox state to 509 521 */ 510 522 public ExtendedDialog toggleEnable(String togglePref) { 511 if (!modal) {523 if (!modal) 512 524 throw new IllegalArgumentException(); 513 }514 525 this.toggleable = true; 515 526 this.togglePref = togglePref; 516 527 return this; -
org/openstreetmap/josm/gui/MapStatus.java
16 16 import java.awt.SystemColor; 17 17 import java.awt.Toolkit; 18 18 import java.awt.event.AWTEventListener; 19 import java.awt.event.ActionEvent; 19 20 import java.awt.event.InputEvent; 20 21 import java.awt.event.KeyAdapter; 21 22 import java.awt.event.KeyEvent; … … 28 29 import java.util.ConcurrentModificationException; 29 30 import java.util.List; 30 31 32 import javax.swing.AbstractAction; 31 33 import javax.swing.BorderFactory; 34 import javax.swing.JCheckBoxMenuItem; 32 35 import javax.swing.JLabel; 33 36 import javax.swing.JPanel; 37 import javax.swing.JPopupMenu; 34 38 import javax.swing.JProgressBar; 35 39 import javax.swing.JScrollPane; 36 40 import javax.swing.Popup; 37 41 import javax.swing.PopupFactory; 38 42 import javax.swing.UIManager; 43 import javax.swing.event.PopupMenuEvent; 44 import javax.swing.event.PopupMenuListener; 39 45 40 46 import org.openstreetmap.josm.Main; 41 47 import org.openstreetmap.josm.data.coor.CoordinateFormat; … … 46 52 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 47 53 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor.ProgressMonitorDialog; 48 54 import org.openstreetmap.josm.gui.util.GuiHelper; 55 import org.openstreetmap.josm.gui.widgets.JosmTextField; 49 56 import org.openstreetmap.josm.tools.GBC; 50 57 import org.openstreetmap.josm.tools.ImageProvider; 51 import org.openstreetmap.josm.gui.widgets.JosmTextField;52 58 53 59 /** 54 60 * A component that manages some status information display about the map. … … 280 286 281 287 // Set the text label in the bottom status bar 282 288 // "if mouse moved only" was added to stop heap growing 283 if (!mouseNotMoved) statusBarElementUpdate(ms); 289 if (!mouseNotMoved) { 290 statusBarElementUpdate(ms); 291 } 284 292 285 293 286 294 // Popup Information … … 685 693 this.mv = mapFrame.mapView; 686 694 this.collector = new Collector(mapFrame); 687 695 696 // Context menu of status bar 697 setComponentPopupMenu(new JPopupMenu() { 698 JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide status bar")) { 699 @Override 700 public void actionPerformed(ActionEvent e) { 701 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState(); 702 Main.pref.put("statusbar.always-visible", sel); 703 } 704 }); 705 { 706 addPopupMenuListener(new PopupMenuListener() { 707 @Override 708 public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 709 doNotHide.setSelected(Main.pref.getBoolean("statusbar.always-visible", true)); 710 } 711 @Override 712 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} 713 @Override 714 public void popupMenuCanceled(PopupMenuEvent e) {} 715 }); 716 add(doNotHide); 717 } 718 }); 719 688 720 lonText.addMouseListener(Main.main.menu.jumpToAct); 689 721 latText.addMouseListener(Main.main.menu.jumpToAct); 690 722 … … 709 741 setLayout(new GridBagLayout()); 710 742 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 711 743 744 latText.setInheritsPopupMenu(true); 745 lonText.setInheritsPopupMenu(true); 746 headingText.setInheritsPopupMenu(true); 747 angleText.setInheritsPopupMenu(true); 748 distText.setInheritsPopupMenu(true); 749 nameText.setInheritsPopupMenu(true); 750 //helpText.setInheritsPopupMenu(true); 751 //progressBar.setInheritsPopupMenu(true); 752 712 753 add(latText, GBC.std()); 713 754 add(lonText, GBC.std().insets(3,0,0,0)); 714 755 add(headingText, GBC.std().insets(3,0,0,0)); -
org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
29 29 import java.util.List; 30 30 import java.util.Map; 31 31 32 import javax.swing.AbstractAction; 32 33 import javax.swing.Action; 33 34 import javax.swing.DefaultListCellRenderer; 34 35 import javax.swing.DefaultListModel; 35 36 import javax.swing.Icon; 36 37 import javax.swing.ImageIcon; 37 38 import javax.swing.JButton; 39 import javax.swing.JCheckBoxMenuItem; 38 40 import javax.swing.JComponent; 39 41 import javax.swing.JLabel; 40 42 import javax.swing.JList; … … 50 52 import javax.swing.TransferHandler; 51 53 import javax.swing.event.ListSelectionEvent; 52 54 import javax.swing.event.ListSelectionListener; 55 import javax.swing.event.PopupMenuEvent; 56 import javax.swing.event.PopupMenuListener; 53 57 import javax.swing.event.TreeSelectionEvent; 54 58 import javax.swing.event.TreeSelectionListener; 55 59 import javax.swing.table.AbstractTableModel; … … 65 69 import org.openstreetmap.josm.actions.ParameterizedAction; 66 70 import org.openstreetmap.josm.actions.ParameterizedActionDecorator; 67 71 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 68 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;69 72 import org.openstreetmap.josm.tools.GBC; 70 73 import org.openstreetmap.josm.tools.ImageProvider; 71 74 import org.openstreetmap.josm.tools.Shortcut; 72 75 73 76 public class ToolbarPreferences implements PreferenceSettingFactory { 74 77 75 76 78 private static final String EMPTY_TOOLBAR_MARKER = "<!-empty-!>"; 77 79 78 80 public static class ActionDefinition { … … 227 229 String paramName = readTillChar('=', '='); 228 230 skip('='); 229 231 String paramValue = readTillChar(',','}'); 230 if ("icon".equals(paramName) && paramValue.length() > 0) 232 if ("icon".equals(paramName) && paramValue.length() > 0) { 231 233 result.setIcon(paramValue); 232 else if("name".equals(paramName) && paramValue.length() > 0)234 } else if("name".equals(paramName) && paramValue.length() > 0) { 233 235 result.setName(paramValue); 236 } 234 237 skip(','); 235 238 } 236 239 skip('}'); … … 293 296 escape(tmp); 294 297 first = false; 295 298 } 296 if(!first) 299 if(!first) { 297 300 result.append('}'); 298 301 } 302 } 299 303 300 304 return result.toString(); 301 305 } … … 338 342 default: 339 343 return null; 340 344 } 341 } else 345 } else { 342 346 rowIndex -= 2; 343 347 } 348 } 344 349 ActionParameter<Object> param = getParam(rowIndex); 345 350 switch (columnIndex) { 346 351 case 0: … … 367 372 } else if (rowIndex == 1) { 368 373 currentAction.setIcon((String)aValue); 369 374 return; 370 } else 375 } else { 371 376 rowIndex -= 2; 372 377 } 378 } 373 379 ActionParameter<Object> param = getParam(rowIndex); 374 380 currentAction.getParameters().put(param.getName(), param.readFromString((String)aValue)); 375 381 } … … 382 388 383 389 } 384 390 385 private static class ToolbarPopupMenu extends JPopupMenu{386 public ToolbarPopupMenu(final ActionDefinition action) {391 private class ToolbarPopupMenu extends JPopupMenu { 392 ActionDefinition act; 387 393 388 if(action != null) { 389 add(tr("Remove from toolbar",action.getDisplayName())) 390 .addActionListener(new ActionListener() { 391 @Override public void actionPerformed(ActionEvent e) { 394 private void setActionAndAdapt(ActionDefinition action) { 395 this.act = action; 396 doNotHide.setSelected(Main.pref.getBoolean("toolbar.always-visible", true)); 397 remove.setVisible(act!=null); 398 shortcutEdit.setVisible(act!=null); 399 } 400 401 JMenuItem remove = new JMenuItem(new AbstractAction(tr("Remove from toolbar")) { 402 @Override 403 public void actionPerformed(ActionEvent e) { 392 404 Collection<String> t = new LinkedList<String>(getToolString()); 393 405 ActionParser parser = new ActionParser(null); 394 406 // get text definition of current action 395 String res = parser.saveAction(action);407 String res = parser.saveAction(act); 396 408 // remove the button from toolbar preferences 397 409 t.remove( res ); 398 410 Main.pref.putCollection("toolbar", t); 399 411 Main.toolbar.refreshToolbarControl(); 400 412 } 401 413 }); 402 }403 414 404 add(tr("Configure toolbar")).addActionListener(new ActionListener() { 405 @Override public void actionPerformed(ActionEvent e) { 415 JMenuItem configure = new JMenuItem(new AbstractAction(tr("Configure toolbar")) { 416 @Override 417 public void actionPerformed(ActionEvent e) { 406 418 final PreferenceDialog p =new PreferenceDialog(Main.parent); 407 419 p.selectPreferencesTabByName("toolbar"); 408 420 p.setVisible(true); 409 421 } 410 422 }); 411 423 412 add(tr("Edit shortcut")).addActionListener(new ActionListener() { 413 @Override public void actionPerformed(ActionEvent e) { 424 JMenuItem shortcutEdit = new JMenuItem(new AbstractAction(tr("Edit shortcut")) { 425 @Override 426 public void actionPerformed(ActionEvent e) { 414 427 final PreferenceDialog p =new PreferenceDialog(Main.parent); 415 p.getTabbedPane().getShortcutPreference().setDefaultFilter(action.getDisplayName());428 p.getTabbedPane().getShortcutPreference().setDefaultFilter(act.getDisplayName()); 416 429 p.selectPreferencesTabByName("shortcuts"); 417 430 p.setVisible(true); 418 // refresh toolbar to accept changes ofshortcuts without restart431 // refresh toolbar to try using changed shortcuts without restart 419 432 Main.toolbar.refreshToolbarControl(); 420 433 } 421 434 }); 435 436 JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide toolbar and menu")) { 437 @Override 438 public void actionPerformed(ActionEvent e) { 439 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState(); 440 Main.pref.put("toolbar.always-visible", sel); 441 Main.pref.put("menu.always-visible", sel); 422 442 } 443 }); 444 { 445 addPopupMenuListener(new PopupMenuListener() { 446 @Override 447 public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 448 setActionAndAdapt(buttonActions.get( 449 ((JPopupMenu)e.getSource()).getInvoker() 450 )); 423 451 } 452 @Override 453 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} 424 454 455 @Override 456 public void popupMenuCanceled(PopupMenuEvent e) {} 457 }); 458 add(remove); 459 add(configure); 460 add(shortcutEdit); 461 add(doNotHide); 462 } 463 } 464 465 private ToolbarPopupMenu popupMenu = new ToolbarPopupMenu(); 466 425 467 /** 426 468 * Key: Registered name (property "toolbar" of action). 427 469 * Value: The action to execute. … … 432 474 private DefaultMutableTreeNode rootActionsNode = new DefaultMutableTreeNode(tr("Actions")); 433 475 434 476 public JToolBar control = new JToolBar(); 477 private HashMap<Object, ActionDefinition> buttonActions = new HashMap<Object, ActionDefinition>(30); 435 478 436 479 @Override 437 480 public PreferenceSetting createPreferenceSetting() { … … 825 868 t.add("|"); 826 869 } else { 827 870 String res = parser.saveAction(action); 828 if(res != null) 871 if(res != null) { 829 872 t.add(res); 830 873 } 831 874 } 875 } 832 876 if (t.isEmpty()) { 833 877 t = Collections.singletonList(EMPTY_TOOLBAR_MARKER); 834 878 } … … 841 885 842 886 public ToolbarPreferences() { 843 887 control.setFloatable(false); 844 control. addMouseListener(new PopupMenuLauncher(new ToolbarPopupMenu(null)));888 control.setComponentPopupMenu(popupMenu); 845 889 } 846 890 847 891 private void loadAction(DefaultMutableTreeNode node, MenuElement menu) { … … 978 1022 */ 979 1023 public void refreshToolbarControl() { 980 1024 control.removeAll(); 1025 buttonActions.clear(); 981 1026 982 1027 for (ActionDefinition action : getDefinedActions()) { 983 1028 if (action.isSeparator()) { 984 1029 control.addSeparator(); 985 1030 } else { 986 1031 final JButton b = addButtonAndShortcut(action); 1032 buttonActions.put(b, action); 987 1033 988 1034 Icon i = action.getDisplayIcon(); 989 1035 if (i != null) { … … 1000 1046 } 1001 1047 }); 1002 1048 } 1003 b. addMouseListener(new PopupMenuLauncher( new ToolbarPopupMenu(action)));1049 b.setInheritsPopupMenu(true); 1004 1050 } 1005 1051 } 1006 1052 control.setVisible(control.getComponentCount() != 0); … … 1013 1059 Shortcut sc = null; 1014 1060 if (action.getAction() instanceof JosmAction) { 1015 1061 sc = ((JosmAction) action.getAction()).getShortcut(); 1016 if (sc.getAssignedKey() == KeyEvent.CHAR_UNDEFINED) sc = null; 1062 if (sc.getAssignedKey() == KeyEvent.CHAR_UNDEFINED) { 1063 sc = null; 1017 1064 } 1065 } 1018 1066 1019 1067 long paramCode = 0; 1020 1068 if (action.hasParameters()) { … … 1022 1070 } 1023 1071 1024 1072 String tt = action.getDisplayTooltip(); 1025 if (tt==null) tt=""; 1073 if (tt==null) { 1074 tt=""; 1075 } 1026 1076 1027 1077 if (sc == null || paramCode != 0) { 1028 1078 String name = (String) action.getAction().getValue("toolbar"); 1029 if (name==null) name=action.getDisplayName(); 1030 if (paramCode!=0) name = name+paramCode; 1079 if (name==null) { 1080 name=action.getDisplayName(); 1081 } 1082 if (paramCode!=0) { 1083 name = name+paramCode; 1084 } 1031 1085 String desc = action.getDisplayName() + ((paramCode==0)?"":action.parameters.toString()); 1032 1086 sc = Shortcut.registerShortcut("toolbar:"+name, tr("Toolbar: {0}", desc), 1033 1087 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE); … … 1043 1097 } 1044 1098 } 1045 1099 1046 if (!tt.isEmpty()) b.setToolTipText(tt); 1100 if (!tt.isEmpty()) { 1101 b.setToolTipText(tt); 1102 } 1047 1103 return b; 1048 1104 } 1049 1105 -
org/openstreetmap/josm/gui/MapFrame.java
9 9 import java.awt.Dimension; 10 10 import java.awt.Font; 11 11 import java.awt.GridBagLayout; 12 import java.awt.KeyboardFocusManager; 12 13 import java.awt.Rectangle; 13 14 import java.awt.event.ActionEvent; 14 15 import java.awt.event.KeyEvent; … … 17 18 import java.util.ArrayList; 18 19 import java.util.Collection; 19 20 import java.util.HashMap; 21 import java.util.HashSet; 20 22 import java.util.List; 21 23 import java.util.Map; 22 24 import java.util.concurrent.CopyOnWriteArrayList; … … 36 38 import javax.swing.KeyStroke; 37 39 import javax.swing.SwingUtilities; 38 40 import javax.swing.border.Border; 41 import javax.swing.event.PopupMenuEvent; 42 import javax.swing.event.PopupMenuListener; 39 43 import javax.swing.plaf.basic.BasicSplitPaneDivider; 40 44 import javax.swing.plaf.basic.BasicSplitPaneUI; 41 45 … … 69 73 import org.openstreetmap.josm.gui.dialogs.ValidatorDialog; 70 74 import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog; 71 75 import org.openstreetmap.josm.gui.layer.Layer; 72 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;73 76 import org.openstreetmap.josm.tools.Destroyable; 74 77 import org.openstreetmap.josm.tools.GBC; 78 import org.openstreetmap.josm.tools.Shortcut; 75 79 76 80 /** 77 81 * One Map frame with one dataset behind. This is the container gui class whose … … 86 90 */ 87 91 public MapMode mapMode; 88 92 89 private final List<MapMode> mapModes = new ArrayList<MapMode>();90 93 /** 91 94 * The view control displayed. 92 95 */ 93 96 public final MapView mapView; 97 94 98 /** 95 * The toolbar with the action icons. To add new toggle dialog actions, use addToggleDialog96 * instead of adding directly to this list. To add a new modeuse addMapMode.99 * The toolbar with the action icons. To add new toggle dialog buttons, 100 * use addToggleDialog, to add a new map mode button use addMapMode. 97 101 */ 98 private JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL); 99 private JToolBar toolBarToggle = new JToolBar(JToolBar.VERTICAL); 100 /** 101 * The status line below the map 102 */ 103 public MapStatus statusLine; 102 private JComponent sideToolBar = new JToolBar(JToolBar.VERTICAL); 103 private final ButtonGroup toolBarActionsGroup = new ButtonGroup(); 104 private final JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL); 105 private final JToolBar toolBarToggle = new JToolBar(JToolBar.VERTICAL); 104 106 107 private final List<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>(); 108 private final List<MapMode> mapModes = new ArrayList<MapMode>(); 109 private final List<IconToggleButton> allDialogButtons = new ArrayList<IconToggleButton>(); 110 public final List<IconToggleButton> allMapModeButtons = new ArrayList<IconToggleButton>(); 111 112 private final ListAllButtonsAction listAllDialogsAction = new ListAllButtonsAction(allDialogButtons); 113 private final ListAllButtonsAction listAllMapModesAction = new ListAllButtonsAction(allMapModeButtons); 114 private final JButton listAllToggleDialogsButton = new JButton(listAllDialogsAction); 115 private final JButton listAllMapModesButton = new JButton(listAllMapModesAction); 116 { 117 listAllDialogsAction.setButton(listAllToggleDialogsButton); 118 listAllMapModesAction.setButton(listAllMapModesButton); 119 } 120 105 121 // Toggle dialogs 106 122 public ConflictDialog conflictDialog; 107 123 public FilterDialog filterDialog; … … 112 128 113 129 // Map modes 114 130 public final SelectAction mapModeSelect; 131 private final Map<Layer, MapMode> lastMapMode = new HashMap<Layer, MapMode>(); 115 132 private final MapMode mapModeDraw; 116 133 private final MapMode mapModeZoom; 117 134 118 135 /** 119 * The panel list of all toggle dialog icons. To add new toggle dialog actions, use addToggleDialog 120 * instead of adding directly to this list. 136 * The status line below the map 121 137 */ 122 private List<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>(); 138 public MapStatus statusLine; 139 140 /** 141 * The split pane with the mapview (leftPanel) and toggle dialogs (dialogsPanel). 142 */ 143 private final JSplitPane splitPane; 123 144 private final JPanel leftPanel; 124 145 private final DialogsPanel dialogsPanel; 125 146 126 public final ButtonGroup toolGroup = new ButtonGroup();127 128 private List<IconToggleButton> allDialogButtons = new ArrayList<IconToggleButton>();129 private List<IconToggleButton> allMapModeButtons = new ArrayList<IconToggleButton>();130 131 private final ListAllButtonsAction listAllDialogsAction = new ListAllButtonsAction(allDialogButtons);132 private final ListAllButtonsAction listAllMapModesAction = new ListAllButtonsAction(allMapModeButtons);133 private final JButton listAllToggleDialogsButton = new JButton(listAllDialogsAction);134 private final JButton listAllMapModesButton = new JButton(listAllMapModesAction);135 {136 listAllDialogsAction.setButton(listAllToggleDialogsButton);137 listAllMapModesAction.setButton(listAllMapModesButton);138 }139 140 147 /** 141 148 * Default width of the toggle dialog area. 142 149 */ 143 150 public static final int DEF_TOGGLE_DLG_WIDTH = 330; 144 151 145 private final Map<Layer, MapMode> lastMapMode = new HashMap<Layer, MapMode>();146 147 152 /** 148 153 * Constructs a new {@code MapFrame}. 149 154 * @param contentPane The content pane used to register shortcuts in its … … 156 161 setLayout(new BorderLayout()); 157 162 158 163 mapView = new MapView(contentPane, viewportData); 159 160 164 new FileDrop(mapView); 161 165 166 splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); 167 162 168 leftPanel = new JPanel(); 163 169 leftPanel.setLayout(new GridBagLayout()); 164 165 170 leftPanel.add(mapView, GBC.std().fill()); 171 splitPane.setLeftComponent(leftPanel); 166 172 167 // toolbar168 toolBarActions.setFloatable(false);169 addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this)));170 addMapMode(new IconToggleButton(new LassoModeAction(), true));171 addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this)));172 addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this)));173 addMapMode(new IconToggleButton(new DeleteAction(this), true));174 addMapMode(new IconToggleButton(new ParallelWayAction(this), true));175 addMapMode(new IconToggleButton(new ExtrudeAction(this), true));176 addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), true));177 178 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);179 180 JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);181 173 dialogsPanel = new DialogsPanel(splitPane); 182 splitPane.setLeftComponent(leftPanel);183 174 splitPane.setRightComponent(dialogsPanel); 184 175 185 176 /** … … 211 202 212 203 dialogsPanel.setLayout(new BoxLayout(dialogsPanel, BoxLayout.Y_AXIS)); 213 204 dialogsPanel.setPreferredSize(new Dimension(Main.pref.getInteger("toggleDialogs.width",DEF_TOGGLE_DLG_WIDTH), 0)); 214 215 205 dialogsPanel.setMinimumSize(new Dimension(24, 0)); 216 206 mapView.setMinimumSize(new Dimension(10,0)); 217 207 218 toolBarToggle.setFloatable(false); 208 // toolBarActions, map mode buttons 209 addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this))); 210 addMapMode(new IconToggleButton(new LassoModeAction(), true)); 211 addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this))); 212 addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this))); 213 addMapMode(new IconToggleButton(new DeleteAction(this), true)); 214 addMapMode(new IconToggleButton(new ParallelWayAction(this), true)); 215 addMapMode(new IconToggleButton(new ExtrudeAction(this), true)); 216 addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), true)); 217 toolBarActionsGroup.setSelected(allMapModeButtons.get(0).getModel(), true); 218 toolBarActions.setFloatable(false); 219 220 // toolBarToggles, toggle dialog buttons 219 221 LayerListDialog.createInstance(this); 220 222 addToggleDialog(LayerListDialog.getInstance()); 221 223 addToggleDialog(propertiesDialog = new PropertiesDialog(this)); … … 229 231 addToggleDialog(filterDialog = new FilterDialog()); 230 232 addToggleDialog(new ChangesetDialog(this), true); 231 233 addToggleDialog(new MapPaintDialog()); 234 toolBarToggle.setFloatable(false); 232 235 233 236 // status line below the map 234 237 statusLine = new MapStatus(this); 235 238 MapView.addLayerChangeListener(this); 239 // unregister TAB key if needed 240 if (Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null) { 241 unregisterTabKey(); 236 242 } 243 } 237 244 238 245 public boolean selectSelectTool(boolean onlyIfModeless) { 239 246 if(onlyIfModeless && !Main.pref.getBoolean("modeless", false)) … … 257 264 } 258 265 259 266 /** 267 * Free tabulator key (call if someone else needs it) 268 */ 269 public final void unregisterTabKey() { 270 System.out.println("Tab key unregistered"); 271 HashSet<KeyStroke> ks = new HashSet<KeyStroke>(1); 272 ks.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK)); 273 KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); 274 kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, ks); 275 splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, ks); 276 } 277 278 /** 260 279 * Called as some kind of destructor when the last layer has been removed. 261 280 * Delegates the call to all Destroyables within this component (e.g. MapModes) 262 281 */ 282 @Override 263 283 public void destroy() { 264 284 MapView.removeLayerChangeListener(this); 265 285 dialogsPanel.destroy(); … … 309 329 public IconToggleButton addToggleDialog(final ToggleDialog dlg, boolean isExpert) { 310 330 final IconToggleButton button = new IconToggleButton(dlg.getToggleAction(), isExpert); 311 331 button.setShowHideButtonListener(dlg); 312 addHideContextMenu(button);332 button.setInheritsPopupMenu(true); 313 333 dlg.setButton(button); 314 334 toolBarToggle.add(button); 315 335 allDialogs.add(dlg); … … 324 344 325 345 326 346 public void addMapMode(IconToggleButton b) { 327 toolBarActions.add(b);328 toolGroup.add(b);329 allMapModeButtons.add(b);330 347 if (b.getAction() instanceof MapMode) { 331 348 mapModes.add((MapMode) b.getAction()); 332 349 } else 333 350 throw new IllegalArgumentException("MapMode action must be subclass of MapMode"); 334 addHideContextMenu(b); 351 allMapModeButtons.add(b); 352 toolBarActionsGroup.add(b); 353 toolBarActions.add(b); 335 354 b.applyButtonHiddenPreferences(); 355 b.setInheritsPopupMenu(true); 336 356 } 337 357 338 358 /** … … 391 411 */ 392 412 public void fillPanel(Container panel) { 393 413 panel.add(this, BorderLayout.CENTER); 394 JToolBar jb = new JToolBar(JToolBar.VERTICAL); 395 jb.setFloatable(false); 414 415 /** 416 * sideToolBar: add map modes icons 417 */ 418 if(Main.pref.getBoolean("sidetoolbar.mapmodes.visible", true)) { 396 419 toolBarActions.setAlignmentX(0.5f); 397 jb.add(toolBarActions); 420 toolBarActions.setInheritsPopupMenu(true); 421 sideToolBar.add(toolBarActions); 398 422 listAllMapModesButton.setAlignmentX(0.5f); 399 423 listAllMapModesButton.setBorder(null); 400 424 listAllMapModesButton.setFont(listAllMapModesButton.getFont().deriveFont(Font.PLAIN)); 401 jb.add(listAllMapModesButton); 425 listAllMapModesButton.setInheritsPopupMenu(true); 426 sideToolBar.add(listAllMapModesButton); 427 } 402 428 403 if(Main.pref.getBoolean("sidetoolbar.togglevisible", true)) { 404 jb.addSeparator(new Dimension(0,18)); 429 /** 430 * sideToolBar: add toggle dialogs icons 431 */ 432 if(Main.pref.getBoolean("sidetoolbar.toggledialogs.visible", true)) { 433 ((JToolBar)sideToolBar).addSeparator(new Dimension(0,18)); 405 434 toolBarToggle.setAlignmentX(0.5f); 406 jb.add(toolBarToggle); 435 toolBarToggle.setInheritsPopupMenu(true); 436 sideToolBar.add(toolBarToggle); 407 437 listAllToggleDialogsButton.setAlignmentX(0.5f); 408 438 listAllToggleDialogsButton.setBorder(null); 409 439 listAllToggleDialogsButton.setFont(listAllToggleDialogsButton.getFont().deriveFont(Font.PLAIN)); 410 jb.add(listAllToggleDialogsButton); 440 listAllToggleDialogsButton.setInheritsPopupMenu(true); 441 sideToolBar.add(listAllToggleDialogsButton); 411 442 } 412 443 413 final Component toToggle; 414 if (Main.pref.getBoolean("sidetoolbar.scrollable", true)) { 415 final ScrollViewport svp = new ScrollViewport(jb, ScrollViewport.VERTICAL_DIRECTION); 416 toToggle = svp; 417 panel.add(svp, BorderLayout.WEST); 418 jb.addMouseWheelListener(new MouseWheelListener() { 419 420 public void mouseWheelMoved(MouseWheelEvent e) { 421 svp.scroll(0, e.getUnitsToScroll() * 5); 444 /** 445 * sideToolBar: add dynamic popup menu 446 */ 447 sideToolBar.setComponentPopupMenu(new JPopupMenu() { 448 final int staticMenuEntryCount = 2; 449 JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide toolbar on TAB")) { 450 @Override 451 public void actionPerformed(ActionEvent e) { 452 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState(); 453 Main.pref.put("sidetoolbar.always-visible", sel); 422 454 } 423 455 }); 424 } else { 425 toToggle = jb; 426 panel.add(jb, BorderLayout.WEST); 456 { 457 addPopupMenuListener(new PopupMenuListener() { 458 @Override 459 public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 460 final Object src = ((JPopupMenu)e.getSource()).getInvoker(); 461 if (src instanceof IconToggleButton) { 462 insert(new Separator(), 0); 463 insert(new AbstractAction() { 464 { 465 putValue(NAME, tr("Hide this button")); 466 putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again.")); 427 467 } 428 toToggle.setVisible(Main.pref.getBoolean("sidetoolbar.visible", true)); 468 @Override 469 public void actionPerformed(ActionEvent e) { 470 ((IconToggleButton)src).setButtonHidden(true); 471 validateToolBarsVisibility(); 472 } 473 }, 0); 474 } 475 doNotHide.setSelected(Main.pref.getBoolean("sidetoolbar.always-visible", true)); 476 } 477 @Override 478 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { 479 while (getComponentCount() > staticMenuEntryCount) { 480 remove(0); 481 } 482 } 483 @Override 484 public void popupMenuCanceled(PopupMenuEvent e) {} 485 }); 429 486 430 jb.addMouseListener(new PopupMenuLauncher(new JPopupMenu() {431 432 {433 487 add(new AbstractAction(tr("Hide edit toolbar")) { 434 435 488 @Override 436 489 public void actionPerformed(ActionEvent e) { 437 490 Main.pref.put("sidetoolbar.visible", false); 438 491 } 439 492 }); 493 add(doNotHide); 440 494 } 441 })); 495 }); 496 ((JToolBar)sideToolBar).setFloatable(false); 442 497 498 /** 499 * sideToolBar: decide scroll- and visibility 500 */ 501 if(Main.pref.getBoolean("sidetoolbar.scrollable", true)) { 502 final ScrollViewport svp = new ScrollViewport(sideToolBar, ScrollViewport.VERTICAL_DIRECTION); 503 svp.addMouseWheelListener(new MouseWheelListener() { 504 @Override 505 public void mouseWheelMoved(MouseWheelEvent e) { 506 svp.scroll(0, e.getUnitsToScroll() * 5); 507 } 508 }); 509 sideToolBar = svp; 510 } 511 sideToolBar.setVisible(Main.pref.getBoolean("sidetoolbar.visible", true)); 443 512 sidetoolbarPreferencesChangedListener = new Preferences.PreferenceChangedListener() { 444 445 513 @Override 446 514 public void preferenceChanged(PreferenceChangeEvent e) { 447 515 if ("sidetoolbar.visible".equals(e.getKey())) { 448 toToggle.setVisible(Main.pref.getBoolean("sidetoolbar.visible"));516 sideToolBar.setVisible(Main.pref.getBoolean("sidetoolbar.visible")); 449 517 } 450 518 } 451 519 }; 452 520 Main.pref.addPreferenceChangeListener(sidetoolbarPreferencesChangedListener); 453 521 522 /** 523 * sideToolBar: add it to the panel 524 */ 525 panel.add(sideToolBar, BorderLayout.WEST); 526 527 /** 528 * statusLine: add to panel 529 */ 454 530 if (statusLine != null && Main.pref.getBoolean("statusline.visible", true)) { 455 531 panel.add(statusLine, BorderLayout.SOUTH); 456 532 } 457 533 } 458 534 459 private void addHideContextMenu(final IconToggleButton b) {460 //context menu461 b.addMouseListener(new PopupMenuLauncher(new JPopupMenu() {462 {463 add(new AbstractAction() {464 {465 putValue(NAME, tr("Hide this button"));466 putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again."));467 }468 @Override469 public void actionPerformed(ActionEvent e) {470 b.setButtonHidden(true);471 validateToolBarsVisibility();472 }473 });474 }475 }));476 }477 478 535 class ListAllButtonsAction extends AbstractAction { 479 536 480 537 private JButton button; … … 543 600 return dialogsPanel.getToggleDialog(type); 544 601 } 545 602 603 public void setDialogsPanelVisible(boolean visible) { 604 rememberToggleDialogWidth(); 605 dialogsPanel.setVisible(visible); 606 splitPane.setDividerLocation(visible?splitPane.getWidth()-Main.pref.getInteger("toggleDialogs.width",DEF_TOGGLE_DLG_WIDTH):0); 607 splitPane.setDividerSize(visible?5:0); 608 } 609 546 610 /** 547 611 * Remember the current width of the (possibly resized) toggle dialog area 548 612 */ 549 613 public void rememberToggleDialogWidth() { 550 Main.pref.putInteger("toggleDialogs.width", dialogsPanel.getWidth()); 614 if (dialogsPanel.isVisible()) { 615 Main.pref.putInteger("toggleDialogs.width", splitPane.getWidth()-splitPane.getDividerLocation()); 551 616 } 617 } 552 618 553 619 /* 554 * Remove panel from top of MapView by class 555 */ 620 * Remove panel from top of MapView by class */ 556 621 public void removeTopPanel(Class<?> type) { 557 622 int n = leftPanel.getComponentCount(); 558 623 for (int i=0; i<n; i++) { … … 652 717 // After all listeners notice new layer, some buttons will be disabled/enabled 653 718 // and possibly need to be hidden/shown. 654 719 SwingUtilities.invokeLater(new Runnable() { 655 public void run() {720 @Override public void run() { 656 721 validateToolBarsVisibility(); 657 722 } 658 723 });