Changeset 7532 in josm
- Timestamp:
- 2014-09-14T02:03:20+02:00 (10 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/defaultpresets.xml
r7511 r7532 31 31 label: simple static text label 32 32 text: the text to display 33 icon: location of icon to display (optional) 34 icon_size: maximal size of icon (optional). If no value is given, default is 16px 33 35 34 36 space: empty line -
trunk/data/tagging-preset.xsd
r7504 r7532 155 155 <attribute name="text" type="string" use="required" /> 156 156 <attribute name="text_context" type="string" /> 157 <attribute name="icon" type="string" /> 158 <attribute name="icon_size" type="integer" /> 157 159 158 160 <attribute name="name" use="prohibited" /> -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r7525 r7532 220 220 } 221 221 if (preset_name_label) { 222 TaggingPresetItems.Label.addLabel(p, get Name());222 TaggingPresetItems.Label.addLabel(p, getIcon(), getName()); 223 223 } 224 224 … … 374 374 } 375 375 376 answer = new PresetDialog(p, title, (ImageIcon) getValue(Action.SMALL_ICON),376 answer = new PresetDialog(p, title, preset_name_label ? null : (ImageIcon) getValue(Action.SMALL_ICON), 377 377 sel.isEmpty(), showNewRelation).getValue(); 378 378 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java
r7525 r7532 32 32 33 33 import javax.swing.ButtonGroup; 34 import javax.swing.Icon; 34 35 import javax.swing.ImageIcon; 35 36 import javax.swing.JButton; … … 91 92 public String display_value; 92 93 public String short_description; 94 /** The location of icon file to display */ 93 95 public String icon; 96 /** The size of displayed icon. If not set, default is size from icon file */ 94 97 public String icon_size; 95 98 /** The localized version of {@link #display_value}. */ … … 128 131 public ImageIcon getIcon() { 129 132 return icon == null ? null : loadImageIcon(icon, zipIcons, parseInteger(icon_size)); 130 }131 132 private Integer parseInteger(String str) {133 if (str == null || str.isEmpty())134 return null;135 try {136 return Integer.parseInt(str);137 } catch (Exception e) {138 //139 }140 return null;141 133 } 142 134 … … 357 349 public static class Label extends TaggingPresetTextItem { 358 350 351 /** The location of icon file to display (optional) */ 352 public String icon; 353 /** The size of displayed icon. If not set, default is 16px */ 354 public String icon_size; 355 359 356 @Override 360 357 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) { 361 358 initializeLocaleText(null); 362 addLabel(p, locale_text);359 addLabel(p, getIcon(), locale_text); 363 360 return true; 364 361 } … … 367 364 * Adds a new {@code JLabel} to the given panel. 368 365 * @param p The panel 366 * @param icon the icon (optional, can be null) 369 367 * @param label The text label 370 368 */ 371 public static void addLabel(JPanel p, String label) { 372 p.add(new JLabel(label), GBC.eol().fill(GBC.HORIZONTAL)); 369 public static void addLabel(JPanel p, Icon icon, String label) { 370 p.add(new JLabel(label, icon, JLabel.LEADING), GBC.eol().fill(GBC.HORIZONTAL)); 371 } 372 373 /** 374 * Returns the label icon, if any. 375 * @return the label icon, or {@code null} 376 */ 377 public ImageIcon getIcon() { 378 Integer size = parseInteger(icon_size); 379 return icon == null ? null : loadImageIcon(icon, TaggingPresetReader.getZipIcons(), size != null ? size : 16); 373 380 } 374 381 } … … 1507 1514 return imgProv.get(); 1508 1515 } 1516 1517 protected static Integer parseInteger(String str) { 1518 if (str == null || str.isEmpty()) 1519 return null; 1520 try { 1521 return Integer.parseInt(str); 1522 } catch (Exception e) { 1523 if (Main.isTraceEnabled()) { 1524 Main.trace(e.getMessage()); 1525 } 1526 } 1527 return null; 1528 } 1509 1529 }
Note:
See TracChangeset
for help on using the changeset viewer.