Changeset 7517 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-09-09T22:25:13+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java
r7505 r7517 72 72 73 73 private static int auto_increment_selected = 0; 74 /** Translatation of "<different>". Use in combo boxes to display en entry matching several different values. */ 74 75 public static final String DIFFERENT = tr("<different>"); 75 76 … … 86 87 public static class PresetListEntry { 87 88 public String value; 89 /** The context used for translating {@link #value} */ 88 90 public String value_context; 89 91 public String display_value; … … 91 93 public String icon; 92 94 public String icon_size; 95 /** The localized version of {@link #display_value}. */ 93 96 public String locale_display_value; 97 /** The localized version of {@link #short_description}. */ 94 98 public String locale_short_description; 95 99 private final File zipIcons = TaggingPresetReader.getZipIcons(); … … 118 122 } 119 123 124 /** 125 * Returns the entry icon, if any. 126 * @return the entry icon, or {@code null} 127 */ 120 128 public ImageIcon getIcon() { 121 129 return icon == null ? null : loadImageIcon(icon, zipIcons, parseInteger(icon_size)); … … 133 141 } 134 142 143 /** 144 * Construxts a new {@code PresetListEntry}, uninitialized. 145 */ 135 146 public PresetListEntry() { 136 147 } … … 164 175 public EnumSet<TaggingPresetType> types; 165 176 public String key; 177 /** The text to display */ 166 178 public String text; 179 /** The context used for translating {@link #text} */ 167 180 public String text_context; 181 /** The localized version of {@link #text}. */ 168 182 public String locale_text; 169 183 public SearchCompiler.Match memberExpression; … … 211 225 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 212 226 String cstring; 213 if (count > 0 && !required) {227 if (count > 0 && !required) { 214 228 cstring = "0,"+count; 215 229 } else if(count > 0) { … … 220 234 cstring = "1-..."; 221 235 } 222 if(locale_text == null) { 223 if (text != null) { 224 if(text_context != null) { 225 locale_text = trc(text_context, fixPresetString(text)); 226 } else { 227 locale_text = tr(fixPresetString(text)); 228 } 229 } 236 if (locale_text == null) { 237 locale_text = getLocaleText(text, text_context, null); 230 238 } 231 239 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 232 240 p.add(new JLabel(key), GBC.std().insets(0,0,10,0)); 233 241 p.add(new JLabel(cstring), types == null ? GBC.eol() : GBC.std().insets(0,0,10,0)); 234 if (types != null){242 if (types != null) { 235 243 JPanel pp = new JPanel(); 236 244 for(TaggingPresetType t : types) { … … 248 256 public static enum MatchType { 249 257 250 /** 251 * Neutral, i.e., do not consider this item for matching. 252 */ 258 /** Neutral, i.e., do not consider this item for matching. */ 253 259 NONE("none"), 254 /** 255 * Positive if key matches, neutral otherwise. 256 */ 260 /** Positive if key matches, neutral otherwise. */ 257 261 KEY("key"), 258 /** 259 * Positive if key matches, negative otherwise. 260 */ 262 /** Positive if key matches, negative otherwise. */ 261 263 KEY_REQUIRED("key!"), 262 /** 263 * Positive if key and value matches, negative otherwise. 264 */ 264 /** Positive if key and value matches, negative otherwise. */ 265 265 KEY_VALUE("keyvalue"); 266 266 … … 271 271 } 272 272 273 /** 274 * Replies the associated textual value. 275 * @return the associated textual value 276 */ 273 277 public String getValue() { 274 278 return value; 275 279 } 276 280 281 /** 282 * Determines the {@code MatchType} for the given textual value. 283 * @param type the textual value 284 * @return the {@code MatchType} for the given textual value 285 */ 277 286 public static MatchType ofString(String type) { 278 287 for (MatchType i : EnumSet.allOf(MatchType.class)) { … … 288 297 boolean hadKeys = false; 289 298 boolean hadEmpty = false; 299 290 300 public boolean hasUniqueValue() { 291 301 return values.size() == 1 && !hadEmpty; … … 295 305 return values.isEmpty(); 296 306 } 307 297 308 public String getFirst() { 298 309 return values.first(); … … 310 321 public abstract static class TaggingPresetTextItem extends TaggingPresetItem { 311 322 312 /** 313 * The text to display 314 */ 323 /** The text to display */ 315 324 public String text; 316 325 317 /** 318 * The context used for translating {@link #text} 319 */ 326 /** The context used for translating {@link #text} */ 320 327 public String text_context; 321 328 322 /** 323 * The localized version of {@link #text} 324 */ 329 /** The localized version of {@link #text} */ 325 330 public String locale_text; 326 331 327 332 protected final void initializeLocaleText(String defaultText) { 328 333 if (locale_text == null) { 329 if (text == null) { 330 locale_text = defaultText; 331 } else if (text_context != null) { 332 locale_text = trc(text_context, fixPresetString(text)); 333 } else { 334 locale_text = tr(fixPresetString(text)); 335 } 334 locale_text = getLocaleText(text, text_context, defaultText); 336 335 } 337 336 } … … 353 352 } 354 353 354 /** 355 * Label type. 356 */ 355 357 public static class Label extends TaggingPresetTextItem { 356 358 … … 372 374 } 373 375 376 /** 377 * Hyperlink type. 378 */ 374 379 public static class Link extends TaggingPresetTextItem { 375 380 376 /** 377 * The link to display 378 */ 381 /** The link to display. */ 379 382 public String href; 380 383 381 /** 382 * The localized version of {@link #href} 383 */ 384 /** The localized version of {@link #href}. */ 384 385 public String locale_href; 385 386 … … 474 475 } 475 476 477 /** 478 * Horizontal separator type. 479 */ 476 480 public static class Space extends TaggingPresetItem { 477 481 … … 514 518 } 515 519 520 /** 521 * Preset item associated to an OSM key. 522 */ 516 523 public abstract static class KeyedItem extends TaggingPresetItem { 517 524 518 525 public String key; 526 /** The text to display */ 519 527 public String text; 528 /** The context used for translating {@link #text} */ 520 529 public String text_context; 521 530 public String match = getDefaultMatch().getValue(); … … 548 557 } 549 558 559 /** 560 * Invisible type allowing to hardcode an OSM key/value from the preset definition. 561 */ 550 562 public static class Key extends KeyedItem { 551 563 564 /** The hardcoded value for key */ 552 565 public String value; 553 566 … … 580 593 } 581 594 595 /** 596 * Text field type. 597 */ 582 598 public static class Text extends KeyedItem { 583 599 600 /** The localized version of {@link #text}. */ 584 601 public String locale_text; 585 602 public String default_; … … 643 660 } 644 661 if (locale_text == null) { 645 if (text != null) { 646 if (text_context != null) { 647 locale_text = trc(text_context, fixPresetString(text)); 648 } else { 649 locale_text = tr(fixPresetString(text)); 650 } 651 } 662 locale_text = getLocaleText(text, text_context, null); 652 663 } 653 664 … … 806 817 } 807 818 819 /** 820 * Checkbox type. 821 */ 808 822 public static class Check extends KeyedItem { 809 823 824 /** The localized version of {@link #text}. */ 810 825 public String locale_text; 826 /** the value to set when checked (default is "yes") */ 811 827 public String value_on = OsmUtils.trueval; 828 /** the value to set when unchecked (default is "no") */ 812 829 public String value_off = OsmUtils.falseval; 830 /** whether the off value is disabled in the dialog, i.e., only unset or yes are provided */ 813 831 public boolean disable_off = false; 832 /** ticked on/off (default is "off") */ 814 833 public boolean default_ = false; // only used for tagless objects 815 834 … … 818 837 private boolean def; 819 838 820 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) { 839 @Override 840 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) { 821 841 822 842 // find out if our key is already used in the selection. … … 825 845 def = default_; 826 846 827 if(locale_text == null) { 828 if(text_context != null) { 829 locale_text = trc(text_context, fixPresetString(text)); 830 } else { 831 locale_text = tr(fixPresetString(text)); 832 } 847 if (locale_text == null) { 848 locale_text = getLocaleText(text, text_context, null); 833 849 } 834 850 … … 837 853 // default is set and filling default values feature is disabled - check if all primitives are untagged 838 854 for (OsmPrimitive s : sel) 839 if (s.hasKeys()) {855 if (s.hasKeys()) { 840 856 def = false; 841 857 } … … 873 889 } 874 890 875 @Override public void addCommands(List<Tag> changedTags) { 891 @Override 892 public void addCommands(List<Tag> changedTags) { 876 893 // if the user hasn't changed anything, don't create a command. 877 894 if (check.getState() == initialState && !def) return; … … 883 900 null)); 884 901 } 885 @Override boolean requestFocusInWindow() {return check.requestFocusInWindow();} 902 903 @Override 904 boolean requestFocusInWindow() {return check.requestFocusInWindow();} 886 905 887 906 @Override … … 908 927 } 909 928 929 /** 930 * Abstract superclass for combo box and multi-select list types. 931 */ 910 932 public abstract static class ComboMultiSelect extends KeyedItem { 911 933 934 /** The localized version of {@link #text}. */ 912 935 public String locale_text; 913 936 public String values; 914 937 public String values_from; 938 /** The context used for translating {@link #values} */ 915 939 public String values_context; 916 940 public String display_values; 941 /** The localized version of {@link #display_values}. */ 917 942 public String locale_display_values; 918 943 public String short_descriptions; 944 /** The localized version of {@link #short_descriptions}. */ 919 945 public String locale_short_descriptions; 920 946 public String default_; … … 1000 1026 } 1001 1027 if (locale_text == null) { 1002 locale_text = trc(text_context, fixPresetString(text));1028 locale_text = getLocaleText(text, text_context, null); 1003 1029 } 1004 1030 initialized = true; … … 1187 1213 } 1188 1214 1215 /** 1216 * Combobox type. 1217 */ 1189 1218 public static class Combo extends ComboMultiSelect { 1190 1219 … … 1275 1304 } 1276 1305 } 1306 1307 /** 1308 * Multi-select list type. 1309 */ 1277 1310 public static class MultiSelect extends ComboMultiSelect { 1278 1311 … … 1310 1343 } 1311 1344 p.add(sp, GBC.eol().fill(GBC.HORIZONTAL)); 1312 1313 1314 1345 } 1315 1346 … … 1393 1424 static String fixPresetString(String s) { 1394 1425 return s == null ? s : s.replaceAll("'","''"); 1426 } 1427 1428 private static String getLocaleText(String text, String text_context, String defaultText) { 1429 if (text == null) { 1430 return defaultText; 1431 } else if (text_context != null) { 1432 return trc(text_context, fixPresetString(text)); 1433 } else { 1434 return tr(fixPresetString(text)); 1435 } 1395 1436 } 1396 1437 … … 1428 1469 } 1429 1470 1430 1431 1471 static Usage determineTextUsage(Collection<OsmPrimitive> sel, String key) { 1432 1472 Usage returnValue = new Usage(); … … 1445 1485 return returnValue; 1446 1486 } 1487 1447 1488 static Usage determineBooleanUsage(Collection<OsmPrimitive> sel, String key) { 1448 1489 … … 1457 1498 return returnValue; 1458 1499 } 1500 1459 1501 protected static ImageIcon loadImageIcon(String iconName, File zipIcons, Integer maxSize) { 1460 1502 final Collection<String> s = Main.pref.getCollection("taggingpreset.icon.sources", null);
Note:
See TracChangeset
for help on using the changeset viewer.