Changeset 6838 in josm for trunk/src/org


Ignore:
Timestamp:
2014-02-11T14:27:58+01:00 (10 years ago)
Author:
akks
Message:

see #9709: button for adding preset to main toolbar
(in upper right part of preset dialog)

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

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

    r6798 r6838  
    10541054        control.setFocusTraversalKeysEnabled(!unregisterTab);
    10551055        control.setVisible(control.getComponentCount() != 0);
     1056        control.repaint();
    10561057    }
    10571058
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r6835 r6838  
    2424import javax.swing.JLabel;
    2525import javax.swing.JPanel;
     26import javax.swing.JToggleButton;
    2627import javax.swing.SwingUtilities;
    2728
     
    4243import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    4344import org.openstreetmap.josm.gui.layer.Layer;
     45import org.openstreetmap.josm.gui.preferences.ToolbarPreferences;
    4446import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;
    4547import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Link;
     
    252254            link.addToPanel(p, selected, presetInitiallyMatches);
    253255        }
    254 
     256       
     257        // "Add toolbar button"
     258        JToggleButton tb = new JToggleButton(new ToolbarButtonAction());
     259        tb.setFocusable(false);
     260        p.add(tb, GBC.std(0,0).anchor(GBC.LINE_END));
    255261        return p;
    256262    }
     
    496502        });
    497503    }
     504   
     505    /**
     506     * Action that adds or removes the button on main toolbar
     507     */
     508    public class ToolbarButtonAction extends AbstractAction {
     509        private final int toolbarIndex;
     510        public ToolbarButtonAction() {
     511            super("", ImageProvider.get("styles\\standard\\waypoint","pin"));
     512            putValue(SHORT_DESCRIPTION, tr("Add or remove toolbar button"));
     513            LinkedList<String> t = new LinkedList<String>(ToolbarPreferences.getToolString());
     514            toolbarIndex = t.indexOf(getToolbarString());
     515            putValue(SELECTED_KEY, toolbarIndex >= 0);
     516        }
     517
     518        @Override
     519        public void actionPerformed(ActionEvent ae) {
     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            }
     534    }
     535   
     536    public String getToolbarString() {
     537        ToolbarPreferences.ActionDefinition aDef
     538            = new ToolbarPreferences.ActionDefinition(this);
     539        ToolbarPreferences.ActionParser actionParser = new ToolbarPreferences.ActionParser(null);
     540        return actionParser.saveAction(aDef);
     541    }
    498542}
Note: See TracChangeset for help on using the changeset viewer.