Changeset 8510 in josm for trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
- Timestamp:
- 2015-06-20T23:42:21+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
r8509 r8510 113 113 114 114 public String getDisplayTooltip() { 115 if (!name.isEmpty())115 if (!name.isEmpty()) 116 116 return name; 117 117 … … 124 124 125 125 public Icon getDisplayIcon() { 126 if (ico != null)126 if (ico != null) 127 127 return ico; 128 128 Object o = action.getValue(Action.LARGE_ICON_KEY); 129 if (o == null)129 if (o == null) 130 130 o = action.getValue(Action.SMALL_ICON); 131 131 return (Icon) o; … … 156 156 if (!(getAction() instanceof ParameterizedAction)) return false; 157 157 for (Object o: parameters.values()) { 158 if (o !=null) return true;158 if (o != null) return true; 159 159 } 160 160 return false; … … 208 208 skip('('); 209 209 210 ParameterizedAction parametrizedAction = (ParameterizedAction) action;210 ParameterizedAction parametrizedAction = (ParameterizedAction) action; 211 211 Map<String, ActionParameter<?>> actionParams = new ConcurrentHashMap<>(); 212 212 for (ActionParameter<?> param: parametrizedAction.getActionParameters()) { … … 217 217 String paramName = readTillChar('=', '='); 218 218 skip('='); 219 String paramValue = readTillChar(',', ')');219 String paramValue = readTillChar(',', ')'); 220 220 if (!paramName.isEmpty() && !paramValue.isEmpty()) { 221 221 ActionParameter<?> actionParam = actionParams.get(paramName); … … 234 234 String paramName = readTillChar('=', '='); 235 235 skip('='); 236 String paramValue = readTillChar(',', '}');236 String paramValue = readTillChar(',', '}'); 237 237 if ("icon".equals(paramName) && !paramValue.isEmpty()) { 238 238 result.setIcon(paramValue); 239 } else if ("name".equals(paramName) && !paramValue.isEmpty()) {239 } else if ("name".equals(paramName) && !paramValue.isEmpty()) { 240 240 result.setName(paramValue); 241 241 } … … 249 249 250 250 private void escape(String s) { 251 for (int i =0; i<s.length(); i++) {251 for (int i = 0; i < s.length(); i++) { 252 252 char ch = s.charAt(i); 253 253 if (ch == '\\' || ch == '(' || ch == '{' || ch == ',' || ch == ')' || ch == '}' || ch == '=') { … … 265 265 266 266 String val = (String) action.getAction().getValue("toolbar"); 267 if (val == null)267 if (val == null) 268 268 return null; 269 269 escape(val); 270 270 if (action.getAction() instanceof ParameterizedAction) { 271 271 result.append('('); 272 List<ActionParameter<?>> params = ((ParameterizedAction) action.getAction()).getActionParameters();273 for (int i =0; i<params.size(); i++) {274 ActionParameter<Object> param = (ActionParameter<Object>) params.get(i);272 List<ActionParameter<?>> params = ((ParameterizedAction) action.getAction()).getActionParameters(); 273 for (int i = 0; i < params.size(); i++) { 274 ActionParameter<Object> param = (ActionParameter<Object>) params.get(i); 275 275 escape(param.getName()); 276 276 result.append('='); … … 302 302 first = false; 303 303 } 304 if (!first) {304 if (!first) { 305 305 result.append('}'); 306 306 } … … 325 325 if (currentAction.isSeparator() || !(currentAction.getAction() instanceof ParameterizedAction)) 326 326 return adaptable; 327 ParameterizedAction pa = (ParameterizedAction) currentAction.getAction();327 ParameterizedAction pa = (ParameterizedAction) currentAction.getAction(); 328 328 return pa.getActionParameters().size() + adaptable; 329 329 } … … 331 331 @SuppressWarnings("unchecked") 332 332 private ActionParameter<Object> getParam(int index) { 333 ParameterizedAction pa = (ParameterizedAction) currentAction.getAction();333 ParameterizedAction pa = (ParameterizedAction) currentAction.getAction(); 334 334 return (ActionParameter<Object>) pa.getActionParameters().get(index); 335 335 } … … 337 337 @Override 338 338 public Object getValueAt(int rowIndex, int columnIndex) { 339 if (currentAction.getAction() instanceof AdaptableAction) {339 if (currentAction.getAction() instanceof AdaptableAction) { 340 340 if (rowIndex < 2) { 341 341 switch (columnIndex) { … … 372 372 int paramIndex = rowIndex; 373 373 374 if (currentAction.getAction() instanceof AdaptableAction) {374 if (currentAction.getAction() instanceof AdaptableAction) { 375 375 if (rowIndex == 0) { 376 376 currentAction.setName(val); … … 386 386 387 387 if (param != null && !val.isEmpty()) { 388 currentAction.getParameters().put(param.getName(), param.readFromString((String) aValue));388 currentAction.getParameters().put(param.getName(), param.readFromString((String) aValue)); 389 389 } 390 390 } … … 402 402 this.act = action; 403 403 doNotHide.setSelected(Main.pref.getBoolean("toolbar.always-visible", true)); 404 remove.setVisible(act !=null);405 shortcutEdit.setVisible(act !=null);404 remove.setVisible(act != null); 405 shortcutEdit.setVisible(act != null); 406 406 } 407 407 … … 423 423 @Override 424 424 public void actionPerformed(ActionEvent e) { 425 final PreferenceDialog p =new PreferenceDialog(Main.parent);426 427 428 429 425 final PreferenceDialog p = new PreferenceDialog(Main.parent); 426 p.selectPreferencesTabByName("toolbar"); 427 p.setVisible(true); 428 } 429 }); 430 430 431 431 private JMenuItem shortcutEdit = new JMenuItem(new AbstractAction(tr("Edit shortcut")) { 432 432 @Override 433 433 public void actionPerformed(ActionEvent e) { 434 final PreferenceDialog p =new PreferenceDialog(Main.parent);434 final PreferenceDialog p = new PreferenceDialog(Main.parent); 435 435 p.getTabbedPane().getShortcutPreference().setDefaultFilter(act.getDisplayName()); 436 437 436 p.selectPreferencesTabByName("shortcuts"); 437 p.setVisible(true); 438 438 // refresh toolbar to try using changed shortcuts without restart 439 440 441 439 Main.toolbar.refreshToolbarControl(); 440 } 441 }); 442 442 443 443 private JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide toolbar and menu")) { … … 447 447 Main.pref.put("toolbar.always-visible", sel); 448 448 Main.pref.put("menu.always-visible", sel); 449 }449 } 450 450 }); 451 451 452 { 452 453 addPopupMenuListener(new PopupMenuListener() { … … 454 455 public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 455 456 setActionAndAdapt(buttonActions.get( 456 ((JPopupMenu) e.getSource()).getInvoker()457 ((JPopupMenu) e.getSource()).getInvoker() 457 458 )); 458 459 } 460 459 461 @Override 460 462 public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} … … 496 498 protected Transferable createTransferable(JComponent c) { 497 499 List<ActionDefinition> actions = new ArrayList<>(); 498 for (ActionDefinition o: ((JList<ActionDefinition>) c).getSelectedValuesList()) {500 for (ActionDefinition o: ((JList<ActionDefinition>) c).getSelectedValuesList()) { 499 501 actions.add(o); 500 502 } … … 609 611 selected.add(leadItem++, ActionDefinition.getSeparator()); 610 612 } else if (node.getUserObject() instanceof Action) { 611 selected.add(leadItem++, new ActionDefinition((Action) node.getUserObject()));613 selected.add(leadItem++, new ActionDefinition((Action) node.getUserObject())); 612 614 } 613 615 } … … 744 746 s = tr("Separator"); 745 747 } 746 JLabel l = (JLabel) def.getListCellRendererComponent(list, s, index, isSelected, cellHasFocus);748 JLabel l = (JLabel) def.getListCellRendererComponent(list, s, index, isSelected, cellHasFocus); 747 749 l.setIcon(i); 748 750 return l; … … 750 752 }; 751 753 selectedList.setCellRenderer(renderer); 752 selectedList.addListSelectionListener(new ListSelectionListener() {754 selectedList.addListSelectionListener(new ListSelectionListener() { 753 755 @Override 754 756 public void valueChanged(ListSelectionEvent e) { … … 806 808 right.add(new JScrollPane(actionsTree), GBC.eol().fill(GBC.BOTH)); 807 809 808 final JPanel buttons = new JPanel(new GridLayout(6, 1));810 final JPanel buttons = new JPanel(new GridLayout(6, 1)); 809 811 buttons.add(upButton = createButton("up")); 810 812 buttons.add(addButton = createButton("<")); … … 814 816 815 817 final JPanel p = new JPanel(); 816 p.setLayout(new LayoutManager() {818 p.setLayout(new LayoutManager() { 817 819 @Override 818 820 public void addLayoutComponent(String name, Component comp) {} 821 819 822 @Override 820 823 public void removeLayoutComponent(Component comp) {} 824 821 825 @Override 822 826 public Dimension minimumLayoutSize(Container parent) { … … 824 828 Dimension r = right.getMinimumSize(); 825 829 Dimension b = buttons.getMinimumSize(); 826 return new Dimension(l.width+b.width+10+r.width,l.height+b.height+10+r.height); 827 } 830 return new Dimension(l.width+b.width+10+r.width, l.height+b.height+10+r.height); 831 } 832 828 833 @Override 829 834 public Dimension preferredLayoutSize(Container parent) { 830 835 Dimension l = new Dimension(200, 200); 831 836 Dimension r = new Dimension(200, 200); 832 return new Dimension(l.width+r.width+10+buttons.getPreferredSize().width,Math.max(l.height, r.height)); 833 } 837 return new Dimension(l.width+r.width+10+buttons.getPreferredSize().width, Math.max(l.height, r.height)); 838 } 839 834 840 @Override 835 841 public void layoutContainer(Container parent) { … … 837 843 Dimension b = buttons.getPreferredSize(); 838 844 int width = (d.width-10-b.width)/2; 839 left.setBounds(new Rectangle(0, 0,width,d.height));840 right.setBounds(new Rectangle(width+10+b.width, 0,width,d.height));845 left.setBounds(new Rectangle(0, 0, width, d.height)); 846 right.setBounds(new Rectangle(width+10+b.width, 0, width, d.height)); 841 847 buttons.setBounds(new Rectangle(width+5, d.height/2-b.height/2, b.width, b.height)); 842 848 } … … 873 879 } else { 874 880 String res = parser.saveAction(action); 875 if (res != null) {881 if (res != null) { 876 882 t.add(res); 877 883 } … … 905 911 for (MenuElement item : menuElement.getSubElements()) { 906 912 if (item instanceof JMenuItem) { 907 JMenuItem menuItem = (JMenuItem) item;913 JMenuItem menuItem = (JMenuItem) item; 908 914 if (menuItem.getAction() != null) { 909 915 Action action = menuItem.getAction(); 910 916 userObject = action; 911 917 Object tb = action.getValue("toolbar"); 912 if (tb == null) {918 if (tb == null) { 913 919 Main.info(tr("Toolbar action without name: {0}", 914 920 action.getClass().getName())); 915 921 continue; 916 922 } else if (!(tb instanceof String)) { 917 if (!(tb instanceof Boolean) || (Boolean)tb) {923 if (!(tb instanceof Boolean) || (Boolean) tb) { 918 924 Main.info(tr("Strange toolbar value: {0}", 919 925 action.getClass().getName())); … … 923 929 String toolbar = (String) tb; 924 930 Action r = actions.get(toolbar); 925 if (r != null && r != action && !toolbar.startsWith("imagery_")) {931 if (r != null && r != action && !toolbar.startsWith("imagery_")) { 926 932 Main.info(tr("Toolbar action {0} overwritten: {1} gets {2}", 927 933 toolbar, r.getClass().getName(), action.getClass().getName())); … … 941 947 public Action getAction(String s) { 942 948 Action e = actions.get(s); 943 if (e == null) {949 if (e == null) { 944 950 e = regactions.get(s); 945 951 } … … 990 996 } else { 991 997 ActionDefinition a = actionParser.loadAction(s); 992 if (a != null) {998 if (a != null) { 993 999 result.add(a); 994 1000 } else { … … 1031 1037 control.removeAll(); 1032 1038 buttonActions.clear(); 1033 boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) !=null;1039 boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null; 1034 1040 1035 1041 for (ActionDefinition action : getDefinedActions()) { … … 1077 1083 t.remove(definitionText); 1078 1084 } else { 1079 if (preferredIndex >=0 && preferredIndex < t.size()) {1085 if (preferredIndex >= 0 && preferredIndex < t.size()) { 1080 1086 t.add(preferredIndex, definitionText); // add to specified place 1081 1087 } else { … … 1105 1111 1106 1112 String tt = action.getDisplayTooltip(); 1107 if (tt ==null) {1108 tt ="";1113 if (tt == null) { 1114 tt = ""; 1109 1115 } 1110 1116 1111 1117 if (sc == null || paramCode != 0) { 1112 1118 String name = (String) action.getAction().getValue("toolbar"); 1113 if (name ==null) {1114 name =action.getDisplayName();1115 } 1116 if (paramCode !=0) {1119 if (name == null) { 1120 name = action.getDisplayName(); 1121 } 1122 if (paramCode != 0) { 1117 1123 name = name+paramCode; 1118 1124 } 1119 String desc = action.getDisplayName() + ((paramCode ==0)?"":action.parameters.toString());1125 String desc = action.getDisplayName() + ((paramCode == 0) ? "" : action.parameters.toString()); 1120 1126 sc = Shortcut.registerShortcut("toolbar:"+name, tr("Toolbar: {0}", desc), 1121 1127 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE); … … 1126 1132 if (sc.isAssignedUser()) { 1127 1133 if (tt.startsWith("<html>") && tt.endsWith("</html>")) { 1128 tt = tt.substring(6, tt.length()-6);1134 tt = tt.substring(6, tt.length()-6); 1129 1135 } 1130 1136 tt = Main.platform.makeTooltip(tt, sc);
Note:
See TracChangeset
for help on using the changeset viewer.