Ignore:
Timestamp:
2014-02-12T15:58:32+01:00 (10 years ago)
Author:
akks
Message:

see #9709: "Add to toolbar" in preset list context menu (F3-right click)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

    r6838 r6844  
    469469     * Value: The action to execute.
    470470     */
    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"));
    475475
    476476    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);
    478478
    479479    @Override
     
    529529        private class ActionTransferable implements Transferable {
    530530
    531             private DataFlavor[] flavors = new DataFlavor[] { ACTION_FLAVOR };
     531            private final DataFlavor[] flavors = new DataFlavor[] { ACTION_FLAVOR };
    532532
    533533            private final List<ActionDefinition> actions;
     
    10561056        control.repaint();
    10571057    }
     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    }
    10581081
    10591082    private JButton addButtonAndShortcut(ActionDefinition action) {
Note: See TracChangeset for help on using the changeset viewer.