Ticket #3366: useful_toolbar.patch

File useful_toolbar.patch, 7.4 KB (added by xeen, 17 years ago)

Toolbar as suggested (plus some style nits Eclipse found neccessary)

  • src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

     
    8383                    }
    8484                    for (TreePath selectedAction : actionsTree.getSelectionPaths()) {
    8585                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedAction.getLastPathComponent();
    86                         if (node.getUserObject() == null)
     86                        if (node.getUserObject() == null) {
    8787                            selected.add(leadItem++, null);
    88                         else if (node.getUserObject() == null || node.getUserObject() instanceof Action)
     88                        } else if (node.getUserObject() == null || node.getUserObject() instanceof Action) {
    8989                            selected.add(leadItem++, ((Action)node.getUserObject()).getValue("toolbar"));
     90                        }
    9091                    }
    9192                } else if (e.getActionCommand().equals(">") && selectedList.getSelectedIndex() != -1) {
    9293                    while (selectedList.getSelectedIndex() != -1) {
     
    159160
    160161        private JButton createButton(String name) {
    161162            JButton b = new JButton();
    162             if (name.equals("up"))
     163            if (name.equals("up")) {
    163164                b.setIcon(ImageProvider.get("dialogs", "up"));
    164             else if (name.equals("down"))
     165            } else if (name.equals("down")) {
    165166                b.setIcon(ImageProvider.get("dialogs", "down"));
    166             else
     167            } else {
    167168                b.setText(name);
     169            }
    168170            b.addActionListener(moveAction);
    169171            b.setActionCommand(name);
    170172            return b;
     
    212214            selectedList.addListSelectionListener(new ListSelectionListener(){
    213215                public void valueChanged(ListSelectionEvent e) {
    214216                    boolean sel = selectedList.getSelectedIndex() != -1;
    215                     if (sel)
     217                    if (sel) {
    216218                        actionsTree.clearSelection();
     219                    }
    217220                    upButton.setEnabled(sel);
    218221                    downButton.setEnabled(sel);
    219222                }
     
    234237                @Override
    235238                public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
    236239                    for (DataFlavor f : transferFlavors) {
    237                         if (ACTION_FLAVOR.equals(f)) {
     240                        if (ACTION_FLAVOR.equals(f))
    238241                            return true;
    239                         }
    240242                    }
    241243                    return false;
    242244                }
     
    256258                        Object leadItem = dropIndex >= 0 ? selected.elementAt(dropIndex) : null;
    257259                        int dataLength = draggedData.length;
    258260
    259                         if (leadItem != null)
     261                        if (leadItem != null) {
    260262                            for (int i = 0; i < dataLength; i++)
    261263                                if (leadItem.equals(draggedData[i]))
    262264                                    return false;
     265                        }
    263266
    264267                        int dragLeadIndex = -1;
    265268                        boolean localDrop = "list".equals(movingComponent);
    266269
    267270                        if (localDrop) {
    268271                            dragLeadIndex = selected.indexOf(draggedData[0]);
    269                             for (int i = 0; i < dataLength; i++)
     272                            for (int i = 0; i < dataLength; i++) {
    270273                                selected.removeElement(draggedData[i]);
     274                            }
    271275                        }
    272276                        int[] indices = new int[dataLength];
    273277
     
    396400
    397401            selected.removeAllElements();
    398402            for (String s : getToolString()) {
    399                 if (s.equals("|"))
     403                if (s.equals("|")) {
    400404                    selected.addElement(null);
    401                 else if (Main.toolbar.getAction(s) != null)
     405                } else if (Main.toolbar.getAction(s) != null) {
    402406                    selected.addElement(s);
     407                }
    403408            }
    404409        }
    405410
    406411        public boolean ok() {
    407412            Collection<String> t = new LinkedList<String>();
    408413            for (int i = 0; i < selected.size(); ++i) {
    409                 if (selected.get(i) == null)
     414                if (selected.get(i) == null) {
    410415                    t.add("|");
    411                 else
     416                } else {
    412417                    t.add((String)((Main.toolbar.getAction((String)selected.get(i))).getValue("toolbar")));
     418                }
    413419            }
    414420            Main.pref.putCollection("toolbar", t);
    415421            Main.toolbar.refreshToolbarControl();
     
    450456    public Action getAction(String s)
    451457    {
    452458        Action e = actions.get(s);
    453         if(e == null)
     459        if(e == null) {
    454460            e = regactions.get(s);
     461        }
    455462        return e;
    456463    }
    457464
     
    460467        loadAction(rootActionsNode, Main.main.menu);
    461468        for(Map.Entry<String, Action> a : regactions.entrySet())
    462469        {
    463             if(actions.get(a.getKey()) == null)
     470            if(actions.get(a.getKey()) == null) {
    464471                rootActionsNode.add(new DefaultMutableTreeNode(a.getValue()));
     472            }
    465473        }
    466474        rootActionsNode.add(new DefaultMutableTreeNode(null));
    467475    }
    468476
    469     private static final String[] deftoolbar = {"open", "save", "exportgpx", "|",
    470     "download", "upload", "|", "undo", "redo", "|", "preference"};
     477    // This is the toolbar as suggested in #3366. If you have comments or ideas,
     478    // please add them there and reopen the ticket if it's closed.
     479    // http://josm.openstreetmap.de/ticket/3366
     480    private static final String[] deftoolbar = {
     481        "open", "save", "|", "download", "upload", "|", "undo", "redo", "|",
     482        "dialogs/search", "preference", "|", "splitway", "combineway", "ortho",
     483        "wayflip", "|", "tagging_Streets/Primary", "tagging_Streets/Secondary",
     484        "tagging_Streets/Tertiary", "tagging_Streets/Residential",
     485        "tagging_Streets/Living Street", "tagging_Ways/Footway",
     486        "tagging_Ways/Steps", "tagging_Ways/Cycleway", "tagging_Ways/Track",
     487        "tagging_Railway/Rail", "|", "tagging_Railway/Level Crossing",
     488        "tagging_Waypoints/Pedestrian Crossing", "tagging_Waypoints/Turning Circle",
     489        "|", "tagging_Car/Parking", "tagging_Public Transport/Bus Stop",
     490        "tagging_Public Transport/Station", "tagging_Public Transport/Tram Stop",
     491        "|", "tagging_Amenities/Toilets", "tagging_Amenities/Telephone",
     492        "tagging_Amenities/Post Box", "tagging_Amenities/Fountain",
     493        "tagging_Amenities/Recycling", "|", "tagging_Cash/Bank",
     494        "tagging_Shops/Supermarket", "tagging_Shops/Butcher", "tagging_Shops/Baker"
     495    };
    471496
    472497    private static Collection<String> getToolString() {
    473498        return Main.pref.getCollection("toolbar", Arrays.asList(deftoolbar));
     
    491516        loadActions();
    492517        control.removeAll();
    493518        for (String s : getToolString()) {
    494             if (s.equals("|"))
     519            if (s.equals("|")) {
    495520                control.addSeparator();
    496             else
     521            } else {
    497522                control.add(getAction(s));
     523            }
    498524        }
    499525        control.setVisible(control.getComponentCount() != 0);
    500526    }