- Timestamp:
- 2014-02-12T15:58:32+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r6744 r6844 333 333 String res = actionParser.saveAction(aDef); 334 334 335 Collection<String> t = new LinkedList<String>(ToolbarPreferences.getToolString());336 335 // add custom search button to toolbar preferences 337 if (!t.contains(res)) t.add(res); 338 Main.pref.putCollection("toolbar", t); 339 Main.toolbar.refreshToolbarControl(); 336 Main.toolbar.addCustomButton(res, -1, false); 340 337 } 341 338 return initialValues; -
trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
r6838 r6844 469 469 * Value: The action to execute. 470 470 */ 471 private Map<String, Action> actions = new HashMap<String, Action>();472 private Map<String, Action> regactions = new HashMap<String, Action>();473 474 private DefaultMutableTreeNode rootActionsNode = new DefaultMutableTreeNode(tr("Actions"));471 private final Map<String, Action> actions = new HashMap<String, Action>(); 472 private final Map<String, Action> regactions = new HashMap<String, Action>(); 473 474 private final DefaultMutableTreeNode rootActionsNode = new DefaultMutableTreeNode(tr("Actions")); 475 475 476 476 public JToolBar control = new JToolBar(); 477 private Map<Object, ActionDefinition> buttonActions = new HashMap<Object, ActionDefinition>(30);477 private final Map<Object, ActionDefinition> buttonActions = new HashMap<Object, ActionDefinition>(30); 478 478 479 479 @Override … … 529 529 private class ActionTransferable implements Transferable { 530 530 531 private DataFlavor[] flavors = new DataFlavor[] { ACTION_FLAVOR };531 private final DataFlavor[] flavors = new DataFlavor[] { ACTION_FLAVOR }; 532 532 533 533 private final List<ActionDefinition> actions; … … 1056 1056 control.repaint(); 1057 1057 } 1058 1059 /** 1060 * The method to add custom button on toolbar like search or preset buttons 1061 * @param definitionText toolbar definition text to describe the new button, 1062 * must be carefully generated by using {@link ActionParser} 1063 * @param preferredIndex place to put the new button, give -1 for the end of toolbar 1064 * @param removeIfExists if true and the button already exists, remove it 1065 */ 1066 public void addCustomButton(String definitionText, int preferredIndex, boolean removeIfExists) { 1067 LinkedList<String> t = new LinkedList<String>(getToolString()); 1068 if (t.contains(definitionText)) { 1069 if (!removeIfExists) return; // do nothing 1070 t.remove(definitionText); 1071 } else { 1072 if (preferredIndex>=0 && preferredIndex < t.size()) { 1073 t.add(preferredIndex, definitionText); // add to specified place 1074 } else { 1075 t.add(definitionText); // add to the end 1076 } 1077 } 1078 Main.pref.putCollection("toolbar", t); 1079 Main.toolbar.refreshToolbarControl(); 1080 } 1058 1081 1059 1082 private JButton addButtonAndShortcut(ActionDefinition action) { -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r6842 r6844 519 519 public void actionPerformed(ActionEvent ae) { 520 520 String res = getToolbarString(); 521 LinkedList<String> t = new LinkedList<String>(ToolbarPreferences.getToolString()); 522 if (t.contains(res)) { 523 t.remove(res); 524 } else { 525 if (toolbarIndex>=0) { 526 t.add(toolbarIndex, res); // add to the old place 527 } else { 528 t.add(res); // add to the end 529 } 530 } 531 Main.pref.putCollection("toolbar", t); 532 Main.toolbar.refreshToolbarControl(); 533 } 521 Main.toolbar.addCustomButton(res, toolbarIndex, true); 522 } 534 523 } 535 524 -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetSelector.java
r6738 r6844 5 5 import java.awt.Component; 6 6 import java.awt.Dimension; 7 import java.awt.event.ActionEvent; 7 8 import java.awt.event.ActionListener; 8 9 import java.awt.event.ItemEvent; … … 17 18 import java.util.EnumSet; 18 19 import java.util.HashSet; 20 import java.util.LinkedList; 19 21 import java.util.List; 22 import javax.swing.AbstractAction; 20 23 import javax.swing.AbstractListModel; 21 24 import javax.swing.Action; … … 27 30 import javax.swing.JList; 28 31 import javax.swing.JPanel; 32 import javax.swing.JPopupMenu; 29 33 import javax.swing.JScrollPane; 30 34 import javax.swing.event.DocumentEvent; … … 39 43 import org.openstreetmap.josm.data.osm.Way; 40 44 import org.openstreetmap.josm.data.preferences.BooleanProperty; 45 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 41 46 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference; 42 47 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Key; … … 45 50 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Roles; 46 51 import org.openstreetmap.josm.gui.widgets.JosmTextField; 52 import org.openstreetmap.josm.gui.widgets.ListPopupMenu; 53 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 47 54 import static org.openstreetmap.josm.tools.I18n.tr; 48 55 … … 70 77 private final List<PresetClassification> classifications = new ArrayList<PresetClassification>(); 71 78 private ResultListModel lsResultModel = new ResultListModel(); 72 79 private JPopupMenu popupMenu; 80 73 81 private ActionListener dblClickListener; 74 82 private ActionListener clickListener; … … 288 296 289 297 setPreferredSize(new Dimension(400, 300)); 290 291 298 filterPresets(); 299 popupMenu = new JPopupMenu(); 300 popupMenu.add(new AbstractAction(tr("Add toolbar button")) { 301 @Override 302 public void actionPerformed(ActionEvent ae) { 303 String res = getSelectedPreset().getToolbarString(); 304 Main.toolbar.addCustomButton(res, -1, false); 305 } 306 }); 307 lsResult.addMouseListener(new PopupMenuLauncher(popupMenu)); 292 308 } 293 309
Note:
See TracChangeset
for help on using the changeset viewer.