Ticket #6953: toolbarContextMenu2.patch
File toolbarContextMenu2.patch, 5.0 KB (added by , 14 years ago) |
---|
-
src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component; 6 7 import java.awt.Font; 7 8 import java.awt.GridBagLayout; 8 9 import java.awt.ScrollPane; … … 10 11 import java.awt.event.MouseWheelListener; 11 12 import java.util.ArrayList; 12 13 import java.util.Collection; 14 import java.util.HashMap; 13 15 import java.util.Iterator; 14 16 import java.util.LinkedList; 15 17 import java.util.List; 18 import java.util.Map; 16 19 17 20 import javax.swing.BorderFactory; 18 21 import javax.swing.JComponent; … … 51 54 boolean validatePreferences(); 52 55 } 53 56 57 // all created tabs 58 private final Map<String,Component> tabs = new HashMap<String,Component>(); 54 59 private final static Collection<PreferenceSettingFactory> settingsFactory = new LinkedList<PreferenceSettingFactory>(); 55 60 private final List<PreferenceSetting> settings = new ArrayList<PreferenceSetting>(); 56 61 … … 114 119 JScrollPane sp = new JScrollPane(p); 115 120 tab = sp; 116 121 } 122 tabs.put(icon,tab); 117 123 addTab(null, ImageProvider.get("preferences", icon), tab); 118 124 setToolTipTextAt(getTabCount()-1, "<html>"+desc+"</html>"); 119 125 return p; 120 126 } 127 128 public void selectTabByName(String name) { 129 Component c = tabs.get(name); 130 if (c!=null) setSelectedComponent(c); 131 } 121 132 122 133 protected PluginPreference getPluginPreference() { 123 134 for (PreferenceSetting setting: settings) { -
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; … … 62 61 import org.openstreetmap.josm.actions.ParameterizedAction; 63 62 import org.openstreetmap.josm.actions.ParameterizedActionDecorator; 64 63 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 64 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 65 65 import org.openstreetmap.josm.tools.GBC; 66 66 import org.openstreetmap.josm.tools.ImageProvider; 67 67 … … 366 366 367 367 } 368 368 369 private static class ToolbarPopupMenu extends JPopupMenu { 370 public ToolbarPopupMenu(final ActionDefinition action) { 371 372 add(tr("Remove from toolbar",action.getDisplayName())) 373 .addActionListener(new ActionListener() { 374 public void actionPerformed(ActionEvent e) { 375 Collection<String> t = new LinkedList<String>(getToolString()); 376 ActionParser parser = new ActionParser(null); 377 // get text definition of current action 378 String res = parser.saveAction(action); 379 // remove the button from toolbar preferences 380 t.remove( res ); 381 Main.pref.putCollection("toolbar", t); 382 Main.toolbar.refreshToolbarControl(); 383 } 384 }); 385 386 add(tr("Configure toolbar")).addActionListener(new ActionListener() { 387 public void actionPerformed(ActionEvent e) { 388 final PreferenceDialog p =new PreferenceDialog(Main.parent); 389 p.selectPreferencesTabByName("toolbar"); 390 p.setVisible(true); 391 } 392 }); 393 394 } 395 } 396 369 397 /** 370 398 * Key: Registered name (property "toolbar" of action). 371 399 * Value: The action to execute. … … 920 948 Icon i = action.getDisplayIcon(); 921 949 if (i != null) 922 950 b.setIcon(i); 951 b.addMouseListener(new PopupMenuLauncher( new ToolbarPopupMenu(action))); 923 952 } 924 953 } 925 954 control.setVisible(control.getComponentCount() != 0); -
src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java
99 99 super.setVisible(visible); 100 100 } 101 101 102 void selectPreferencesTabByName(String name) { 103 tpPreferences.selectTabByName(name); 104 } 105 102 106 class CancelAction extends AbstractAction { 103 107 public CancelAction() { 104 108 putValue(NAME, tr("Cancel"));