Ticket #3366: useful_toolbar.patch
| File useful_toolbar.patch, 7.4 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
83 83 } 84 84 for (TreePath selectedAction : actionsTree.getSelectionPaths()) { 85 85 DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedAction.getLastPathComponent(); 86 if (node.getUserObject() == null) 86 if (node.getUserObject() == null) { 87 87 selected.add(leadItem++, null); 88 else if (node.getUserObject() == null || node.getUserObject() instanceof Action)88 } else if (node.getUserObject() == null || node.getUserObject() instanceof Action) { 89 89 selected.add(leadItem++, ((Action)node.getUserObject()).getValue("toolbar")); 90 } 90 91 } 91 92 } else if (e.getActionCommand().equals(">") && selectedList.getSelectedIndex() != -1) { 92 93 while (selectedList.getSelectedIndex() != -1) { … … 159 160 160 161 private JButton createButton(String name) { 161 162 JButton b = new JButton(); 162 if (name.equals("up")) 163 if (name.equals("up")) { 163 164 b.setIcon(ImageProvider.get("dialogs", "up")); 164 else if (name.equals("down"))165 } else if (name.equals("down")) { 165 166 b.setIcon(ImageProvider.get("dialogs", "down")); 166 else167 } else { 167 168 b.setText(name); 169 } 168 170 b.addActionListener(moveAction); 169 171 b.setActionCommand(name); 170 172 return b; … … 212 214 selectedList.addListSelectionListener(new ListSelectionListener(){ 213 215 public void valueChanged(ListSelectionEvent e) { 214 216 boolean sel = selectedList.getSelectedIndex() != -1; 215 if (sel) 217 if (sel) { 216 218 actionsTree.clearSelection(); 219 } 217 220 upButton.setEnabled(sel); 218 221 downButton.setEnabled(sel); 219 222 } … … 234 237 @Override 235 238 public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) { 236 239 for (DataFlavor f : transferFlavors) { 237 if (ACTION_FLAVOR.equals(f)) {240 if (ACTION_FLAVOR.equals(f)) 238 241 return true; 239 }240 242 } 241 243 return false; 242 244 } … … 256 258 Object leadItem = dropIndex >= 0 ? selected.elementAt(dropIndex) : null; 257 259 int dataLength = draggedData.length; 258 260 259 if (leadItem != null) 261 if (leadItem != null) { 260 262 for (int i = 0; i < dataLength; i++) 261 263 if (leadItem.equals(draggedData[i])) 262 264 return false; 265 } 263 266 264 267 int dragLeadIndex = -1; 265 268 boolean localDrop = "list".equals(movingComponent); 266 269 267 270 if (localDrop) { 268 271 dragLeadIndex = selected.indexOf(draggedData[0]); 269 for (int i = 0; i < dataLength; i++) 272 for (int i = 0; i < dataLength; i++) { 270 273 selected.removeElement(draggedData[i]); 274 } 271 275 } 272 276 int[] indices = new int[dataLength]; 273 277 … … 396 400 397 401 selected.removeAllElements(); 398 402 for (String s : getToolString()) { 399 if (s.equals("|")) 403 if (s.equals("|")) { 400 404 selected.addElement(null); 401 else if (Main.toolbar.getAction(s) != null)405 } else if (Main.toolbar.getAction(s) != null) { 402 406 selected.addElement(s); 407 } 403 408 } 404 409 } 405 410 406 411 public boolean ok() { 407 412 Collection<String> t = new LinkedList<String>(); 408 413 for (int i = 0; i < selected.size(); ++i) { 409 if (selected.get(i) == null) 414 if (selected.get(i) == null) { 410 415 t.add("|"); 411 else416 } else { 412 417 t.add((String)((Main.toolbar.getAction((String)selected.get(i))).getValue("toolbar"))); 418 } 413 419 } 414 420 Main.pref.putCollection("toolbar", t); 415 421 Main.toolbar.refreshToolbarControl(); … … 450 456 public Action getAction(String s) 451 457 { 452 458 Action e = actions.get(s); 453 if(e == null) 459 if(e == null) { 454 460 e = regactions.get(s); 461 } 455 462 return e; 456 463 } 457 464 … … 460 467 loadAction(rootActionsNode, Main.main.menu); 461 468 for(Map.Entry<String, Action> a : regactions.entrySet()) 462 469 { 463 if(actions.get(a.getKey()) == null) 470 if(actions.get(a.getKey()) == null) { 464 471 rootActionsNode.add(new DefaultMutableTreeNode(a.getValue())); 472 } 465 473 } 466 474 rootActionsNode.add(new DefaultMutableTreeNode(null)); 467 475 } 468 476 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 }; 471 496 472 497 private static Collection<String> getToolString() { 473 498 return Main.pref.getCollection("toolbar", Arrays.asList(deftoolbar)); … … 491 516 loadActions(); 492 517 control.removeAll(); 493 518 for (String s : getToolString()) { 494 if (s.equals("|")) 519 if (s.equals("|")) { 495 520 control.addSeparator(); 496 else521 } else { 497 522 control.add(getAction(s)); 523 } 498 524 } 499 525 control.setVisible(control.getComponentCount() != 0); 500 526 }
