- Timestamp:
- 2011-04-16T23:43:53+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
r3878 r4032 11 11 import org.openstreetmap.josm.gui.layer.ImageryLayer; 12 12 13 public class AddImageryLayerAction extends JosmAction {13 public class AddImageryLayerAction extends JosmAction implements AdaptableAction { 14 14 15 15 private final ImageryInfo info; -
trunk/src/org/openstreetmap/josm/actions/ParameterizedAction.java
r3720 r4032 8 8 import javax.swing.Action; 9 9 10 public interface ParameterizedAction extends A ction {10 public interface ParameterizedAction extends AdaptableAction { 11 11 12 12 List<ActionParameter<?>> getActionParameters(); -
trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
r3737 r4032 27 27 import java.util.Map; 28 28 29 import javax.swing.AbstractAction; 29 30 import javax.swing.Action; 30 31 import javax.swing.DefaultListCellRenderer; 31 32 import javax.swing.DefaultListModel; 32 33 import javax.swing.Icon; 34 import javax.swing.ImageIcon; 33 35 import javax.swing.JButton; 34 36 import javax.swing.JComponent; … … 57 59 import org.openstreetmap.josm.Main; 58 60 import org.openstreetmap.josm.actions.ActionParameter; 61 import org.openstreetmap.josm.actions.AdaptableAction; 59 62 import org.openstreetmap.josm.actions.ParameterizedAction; 60 63 import org.openstreetmap.josm.actions.ParameterizedActionDecorator; … … 70 73 public static class ActionDefinition { 71 74 private final Action action; 75 private String name = ""; 76 private String icon = ""; 72 77 private final Map<String, Object> parameters = new HashMap<String, Object>(); 73 78 … … 89 94 public Action getAction() { 90 95 return action; 96 } 97 98 public String getName() { 99 return name; 100 } 101 102 public void setName(String name) { 103 this.name = name; 104 action.putValue(AbstractAction.SHORT_DESCRIPTION, Main.platform.makeTooltip(name, null)); 105 action.putValue(AbstractAction.NAME, name); 106 } 107 108 public String getIcon() { 109 return icon; 110 } 111 112 public void setIcon(String icon) { 113 this.icon = icon; 114 ImageIcon ico = ImageProvider.getIfAvailable("", icon); 115 if(ico != null) 116 action.putValue(AbstractAction.SMALL_ICON, ico); 91 117 } 92 118 … … 135 161 this.s = actionName.toCharArray(); 136 162 137 String name = readTillChar('(', ' (');163 String name = readTillChar('(', '{'); 138 164 Action action = actions.get(name); 139 165 … … 152 178 } 153 179 154 do{180 while (index < s.length && s[index] != ')') { 155 181 String paramName = readTillChar('=', '='); 156 182 skip('='); … … 163 189 } 164 190 skip(','); 165 } while (index < s.length && s[index] != ')'); 191 } 192 skip(')'); 193 } 194 if (action instanceof AdaptableAction) { 195 skip('{'); 196 197 while (index < s.length && s[index] != '}') { 198 String paramName = readTillChar('=', '='); 199 skip('='); 200 String paramValue = readTillChar(',','}'); 201 if ("icon".equals(paramName) && paramValue.length() > 0) 202 result.setIcon(paramValue); 203 else if("name".equals(paramName) && paramValue.length() > 0) 204 result.setName(paramValue); 205 skip(','); 206 } 207 skip('}'); 166 208 } 167 209 … … 172 214 for (int i=0; i<s.length(); i++) { 173 215 char ch = s.charAt(i); 174 if (ch == '\\' || ch == '(' || ch == ' ,' || ch == ')' || ch == '=') {216 if (ch == '\\' || ch == '(' || ch == '{' || ch == ',' || ch == ')' || ch == '}' || ch == '=') { 175 217 result.append('\\'); 176 218 result.append(ch); … … 204 246 } 205 247 } 248 if (action.getAction() instanceof AdaptableAction) { 249 boolean first = true; 250 String tmp = action.getName(); 251 if(tmp.length() != 0) { 252 result.append(first ? "{" : ","); 253 result.append("name="); 254 escape(tmp); 255 first = false; 256 } 257 tmp = action.getIcon(); 258 if(tmp.length() != 0) { 259 result.append(first ? "{" : ","); 260 result.append("icon="); 261 escape(tmp); 262 first = false; 263 } 264 if(!first) 265 result.append('}'); 266 } 206 267 207 268 return result.toString(); … … 221 282 return 0; 222 283 ParameterizedAction pa = (ParameterizedAction)currentAction.getAction(); 223 return pa.getActionParameters().size(); 284 return pa.getActionParameters().size() 285 + ((currentAction.getAction() instanceof ParameterizedAction) ? 2 : 0); 224 286 } 225 287 … … 231 293 232 294 public Object getValueAt(int rowIndex, int columnIndex) { 295 if(currentAction.getAction() instanceof ParameterizedAction) 296 { 297 if (rowIndex < 2) { 298 switch (columnIndex) { 299 case 0: 300 return rowIndex == 0 ? tr("Tooltip") : tr("Icon"); 301 case 1: 302 return rowIndex == 0 ? currentAction.getName() : currentAction.getIcon(); 303 default: 304 return null; 305 } 306 } else 307 rowIndex -= 2; 308 } 233 309 ActionParameter<Object> param = getParam(rowIndex); 234 310 switch (columnIndex) { … … 249 325 @Override 250 326 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 327 if(currentAction.getAction() instanceof ParameterizedAction) 328 { 329 if (rowIndex == 0) { 330 currentAction.setName((String)aValue); 331 return; 332 } else if (rowIndex == 1) { 333 currentAction.setIcon((String)aValue); 334 return; 335 } else 336 rowIndex -= 2; 337 } 251 338 ActionParameter<Object> param = getParam(rowIndex); 252 339 currentAction.getParameters().put(param.getName(), param.readFromString((String)aValue));
Note:
See TracChangeset
for help on using the changeset viewer.