Changeset 5965 in josm for trunk/src/org/openstreetmap/josm/gui/preferences
- Timestamp:
- 2013-05-17T20:45:17+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
r5954 r5965 30 30 import java.util.Map; 31 31 32 import javax.swing.AbstractAction; 32 33 import javax.swing.Action; 33 34 import javax.swing.DefaultListCellRenderer; … … 36 37 import javax.swing.ImageIcon; 37 38 import javax.swing.JButton; 39 import javax.swing.JCheckBoxMenuItem; 38 40 import javax.swing.JComponent; 39 41 import javax.swing.JLabel; … … 51 53 import javax.swing.event.ListSelectionEvent; 52 54 import javax.swing.event.ListSelectionListener; 55 import javax.swing.event.PopupMenuEvent; 56 import javax.swing.event.PopupMenuListener; 53 57 import javax.swing.event.TreeSelectionEvent; 54 58 import javax.swing.event.TreeSelectionListener; … … 66 70 import org.openstreetmap.josm.actions.ParameterizedActionDecorator; 67 71 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 68 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;69 72 import org.openstreetmap.josm.tools.GBC; 70 73 import org.openstreetmap.josm.tools.ImageProvider; … … 72 75 73 76 public class ToolbarPreferences implements PreferenceSettingFactory { 74 75 77 76 78 private static final String EMPTY_TOOLBAR_MARKER = "<!-empty-!>"; … … 228 230 skip('='); 229 231 String paramValue = readTillChar(',','}'); 230 if ("icon".equals(paramName) && paramValue.length() > 0) 232 if ("icon".equals(paramName) && paramValue.length() > 0) { 231 233 result.setIcon(paramValue); 232 else if("name".equals(paramName) && paramValue.length() > 0)234 } else if("name".equals(paramName) && paramValue.length() > 0) { 233 235 result.setName(paramValue); 236 } 234 237 skip(','); 235 238 } … … 294 297 first = false; 295 298 } 296 if(!first) 299 if(!first) { 297 300 result.append('}'); 301 } 298 302 } 299 303 … … 339 343 return null; 340 344 } 341 } else 345 } else { 342 346 rowIndex -= 2; 347 } 343 348 } 344 349 ActionParameter<Object> param = getParam(rowIndex); … … 368 373 currentAction.setIcon((String)aValue); 369 374 return; 370 } else 375 } else { 371 376 rowIndex -= 2; 377 } 372 378 } 373 379 ActionParameter<Object> param = getParam(rowIndex); … … 383 389 } 384 390 385 private static class ToolbarPopupMenu extends JPopupMenu { 386 public ToolbarPopupMenu(final ActionDefinition action) { 387 388 if(action != null) { 389 add(tr("Remove from toolbar",action.getDisplayName())) 390 .addActionListener(new ActionListener() { 391 @Override public void actionPerformed(ActionEvent e) { 391 private class ToolbarPopupMenu extends JPopupMenu { 392 ActionDefinition act; 393 394 private void setActionAndAdapt(ActionDefinition action) { 395 this.act = action; 396 doNotHide.setSelected(Main.pref.getBoolean("toolbar.always-visible", true)); 397 remove.setVisible(act!=null); 398 shortcutEdit.setVisible(act!=null); 399 } 400 401 JMenuItem remove = new JMenuItem(new AbstractAction(tr("Remove from toolbar")) { 402 @Override 403 public void actionPerformed(ActionEvent e) { 392 404 Collection<String> t = new LinkedList<String>(getToolString()); 393 405 ActionParser parser = new ActionParser(null); 394 406 // get text definition of current action 395 String res = parser.saveAction(action);407 String res = parser.saveAction(act); 396 408 // remove the button from toolbar preferences 397 409 t.remove( res ); … … 400 412 } 401 413 }); 402 }403 414 404 add(tr("Configure toolbar")).addActionListener(new ActionListener() { 405 @Override public void actionPerformed(ActionEvent e) { 415 JMenuItem configure = new JMenuItem(new AbstractAction(tr("Configure toolbar")) { 416 @Override 417 public void actionPerformed(ActionEvent e) { 406 418 final PreferenceDialog p =new PreferenceDialog(Main.parent); 407 419 p.selectPreferencesTabByName("toolbar"); … … 410 422 }); 411 423 412 add(tr("Edit shortcut")).addActionListener(new ActionListener() { 413 @Override public void actionPerformed(ActionEvent e) { 424 JMenuItem shortcutEdit = new JMenuItem(new AbstractAction(tr("Edit shortcut")) { 425 @Override 426 public void actionPerformed(ActionEvent e) { 414 427 final PreferenceDialog p =new PreferenceDialog(Main.parent); 415 p.getTabbedPane().getShortcutPreference().setDefaultFilter(action.getDisplayName());428 p.getTabbedPane().getShortcutPreference().setDefaultFilter(act.getDisplayName()); 416 429 p.selectPreferencesTabByName("shortcuts"); 417 430 p.setVisible(true); 418 // refresh toolbar to accept changes ofshortcuts without restart431 // refresh toolbar to try using changed shortcuts without restart 419 432 Main.toolbar.refreshToolbarControl(); 420 433 } 421 434 }); 422 } 423 } 435 436 JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("getSt hide toolbar and menu")) { 437 @Override 438 public void actionPerformed(ActionEvent e) { 439 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState(); 440 Main.pref.put("toolbar.always-visible", sel); 441 Main.pref.put("menu.always-visible", sel); 442 } 443 }); 444 { 445 addPopupMenuListener(new PopupMenuListener() { 446 @Override 447 public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 448 setActionAndAdapt(buttonActions.get( 449 ((JPopupMenu)e.getSource()).getInvoker() 450 )); 451 } 452 @Override 453 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} 454 455 @Override 456 public void popupMenuCanceled(PopupMenuEvent e) {} 457 }); 458 add(remove); 459 add(configure); 460 add(shortcutEdit); 461 add(doNotHide); 462 } 463 } 464 465 private ToolbarPopupMenu popupMenu = new ToolbarPopupMenu(); 424 466 425 467 /** … … 433 475 434 476 public JToolBar control = new JToolBar(); 477 private HashMap<Object, ActionDefinition> buttonActions = new HashMap<Object, ActionDefinition>(30); 435 478 436 479 @Override … … 826 869 } else { 827 870 String res = parser.saveAction(action); 828 if(res != null) 871 if(res != null) { 829 872 t.add(res); 830 873 } 874 } 831 875 } 832 876 if (t.isEmpty()) { … … 842 886 public ToolbarPreferences() { 843 887 control.setFloatable(false); 844 control. addMouseListener(new PopupMenuLauncher(new ToolbarPopupMenu(null)));888 control.setComponentPopupMenu(popupMenu); 845 889 } 846 890 … … 979 1023 public void refreshToolbarControl() { 980 1024 control.removeAll(); 1025 buttonActions.clear(); 981 1026 982 1027 for (ActionDefinition action : getDefinedActions()) { … … 985 1030 } else { 986 1031 final JButton b = addButtonAndShortcut(action); 1032 buttonActions.put(b, action); 987 1033 988 1034 Icon i = action.getDisplayIcon(); … … 1001 1047 }); 1002 1048 } 1003 b. addMouseListener(new PopupMenuLauncher( new ToolbarPopupMenu(action)));1049 b.setInheritsPopupMenu(true); 1004 1050 } 1005 1051 } … … 1014 1060 if (action.getAction() instanceof JosmAction) { 1015 1061 sc = ((JosmAction) action.getAction()).getShortcut(); 1016 if (sc.getAssignedKey() == KeyEvent.CHAR_UNDEFINED) sc = null; 1062 if (sc.getAssignedKey() == KeyEvent.CHAR_UNDEFINED) { 1063 sc = null; 1064 } 1017 1065 } 1018 1066 … … 1023 1071 1024 1072 String tt = action.getDisplayTooltip(); 1025 if (tt==null) tt=""; 1073 if (tt==null) { 1074 tt=""; 1075 } 1026 1076 1027 1077 if (sc == null || paramCode != 0) { 1028 1078 String name = (String) action.getAction().getValue("toolbar"); 1029 if (name==null) name=action.getDisplayName(); 1030 if (paramCode!=0) name = name+paramCode; 1079 if (name==null) { 1080 name=action.getDisplayName(); 1081 } 1082 if (paramCode!=0) { 1083 name = name+paramCode; 1084 } 1031 1085 String desc = action.getDisplayName() + ((paramCode==0)?"":action.parameters.toString()); 1032 1086 sc = Shortcut.registerShortcut("toolbar:"+name, tr("Toolbar: {0}", desc), … … 1044 1098 } 1045 1099 1046 if (!tt.isEmpty()) b.setToolTipText(tt); 1100 if (!tt.isEmpty()) { 1101 b.setToolTipText(tt); 1102 } 1047 1103 return b; 1048 1104 }
Note:
See TracChangeset
for help on using the changeset viewer.