- Timestamp:
- 2012-08-07T22:16:56+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r5316 r5404 117 117 public static PresetType forPrimitiveType(org.openstreetmap.josm.data.osm.OsmPrimitiveType type) { 118 118 switch (type) { 119 120 121 122 123 124 125 126 127 128 129 119 case NODE: 120 return NODE; 121 case WAY: 122 return WAY; 123 case CLOSEDWAY: 124 return CLOSEDWAY; 125 case RELATION: 126 case MULTIPOLYGON: 127 return RELATION; 128 default: 129 throw new IllegalArgumentException("Unexpected primitive type: " + type); 130 130 } 131 131 } … … 166 166 public static MatchType ofString(String type) { 167 167 for (MatchType i : EnumSet.allOf(MatchType.class)) { 168 if (i.getValue().equals(type)) {168 if (i.getValue().equals(type)) 169 169 return i; 170 }171 170 } 172 171 throw new IllegalArgumentException(type + " is not allowed"); … … 229 228 Boolean matches(Map<String, String> tags) { 230 229 switch (MatchType.ofString(match)) { 231 232 233 234 235 236 237 238 239 240 230 case NONE: 231 return null; 232 case KEY: 233 return tags.containsKey(key) ? true : null; 234 case KEY_REQUIRED: 235 return tags.containsKey(key); 236 case KEY_VALUE: 237 return tags.containsKey(key) && (getValues().contains(tags.get(key))); 238 default: 239 throw new IllegalStateException(); 241 240 } 242 241 } … … 306 305 private final File zipIcons = TaggingPreset.zipIcons; 307 306 307 // Cached size (currently only for Combo) to speed up preset dialog initialization 308 private int prefferedWidth = -1; 309 private int prefferedHeight = -1; 310 308 311 public String getListDisplay() { 309 312 if (value.equals(DIFFERENT)) … … 339 342 return translated 340 343 ? Utils.firstNonNull(locale_display_value, tr(display_value), trc(value_context, value)) 341 : Utils.firstNonNull(display_value, value);344 : Utils.firstNonNull(display_value, value); 342 345 } 343 346 … … 345 348 return translated 346 349 ? Utils.firstNonNull(locale_short_description, tr(short_description)) 347 : short_description;350 : short_description; 348 351 } 349 352 … … 444 447 @Override 445 448 public Collection<String> getValues() { 446 if (default_ == null || default_.isEmpty()) {449 if (default_ == null || default_.isEmpty()) 447 450 return Collections.emptyList(); 448 }449 451 return Collections.singleton(default_); 450 452 } … … 662 664 e.locale_display_value = locale_display_values != null 663 665 ? display_array[i] 664 : trc(values_context, fixPresetString(display_array[i]));665 if (short_descriptions_array != null) {666 e.locale_short_description = locale_short_descriptions != null667 ? short_descriptions_array[i]668 : tr(fixPresetString(short_descriptions_array[i]));669 }670 lhm.put(value_array[i], e);671 display_array[i] = e.getDisplayValue(true);666 : trc(values_context, fixPresetString(display_array[i])); 667 if (short_descriptions_array != null) { 668 e.locale_short_description = locale_short_descriptions != null 669 ? short_descriptions_array[i] 670 : tr(fixPresetString(short_descriptions_array[i])); 671 } 672 lhm.put(value_array[i], e); 673 display_array[i] = e.getDisplayValue(true); 672 674 } 673 675 … … 732 734 } 733 735 734 pr otected ListCellRenderer getListCellRenderer() {735 return new ListCellRenderer() { 736 737 JLabel lbl = new JLabel(); 738 JComponent dummy = new JComponent() {739 };740 741 public Component getListCellRendererComponent(742 JList list,743 Object value,744 int index,745 boolean isSelected, 746 boolean cellHasFocus) {747 if (isSelected) {748 lbl.setBackground(list.getSelectionBackground());749 lbl.set Foreground(list.getSelectionForeground());736 private static ListCellRenderer RENDERER = new ListCellRenderer() { 737 738 JLabel lbl = new JLabel(); 739 740 public Component getListCellRendererComponent( 741 JList list, 742 Object value, 743 int index, 744 boolean isSelected, 745 boolean cellHasFocus) { 746 PresetListEntry item = (PresetListEntry) value; 747 748 // Only return cached size, item is not shown 749 if (!list.isShowing() && item.prefferedWidth != -1 && item.prefferedHeight != -1) { 750 if (index == -1) { 751 lbl.setPreferredSize(new Dimension(item.prefferedWidth, 10)); 750 752 } else { 751 lbl.setBackground(list.getBackground()); 752 lbl.setForeground(list.getForeground()); 753 } 754 755 PresetListEntry item = (PresetListEntry) value; 756 lbl.setOpaque(true); 757 lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN)); 758 lbl.setText("<html>" + item.getListDisplay() + "</html>"); 759 lbl.setIcon(item.getIcon()); 760 lbl.setEnabled(list.isEnabled()); 761 // We do not want the editor to have the maximum height of all 762 // entries. Return a dummy with bogus height. 763 if (index == -1) { 764 dummy.setPreferredSize(new Dimension(lbl.getPreferredSize().width, 10)); 765 return dummy; 753 lbl.setPreferredSize(new Dimension(item.prefferedWidth, item.prefferedHeight)); 766 754 } 767 755 return lbl; 768 756 } 769 }; 757 758 lbl.setPreferredSize(null); 759 760 761 if (isSelected) { 762 lbl.setBackground(list.getSelectionBackground()); 763 lbl.setForeground(list.getSelectionForeground()); 764 } else { 765 lbl.setBackground(list.getBackground()); 766 lbl.setForeground(list.getForeground()); 767 } 768 769 lbl.setOpaque(true); 770 lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN)); 771 lbl.setText("<html>" + item.getListDisplay() + "</html>"); 772 lbl.setIcon(item.getIcon()); 773 lbl.setEnabled(list.isEnabled()); 774 775 // Cache size 776 item.prefferedWidth = lbl.getPreferredSize().width; 777 item.prefferedHeight = lbl.getPreferredSize().height; 778 779 // We do not want the editor to have the maximum height of all 780 // entries. Return a dummy with bogus height. 781 if (index == -1) { 782 lbl.setPreferredSize(new Dimension(lbl.getPreferredSize().width, 10)); 783 } 784 return lbl; 785 } 786 }; 787 788 789 protected ListCellRenderer getListCellRenderer() { 790 return RENDERER; 770 791 } 771 792 … … 949 970 */ 950 971 private static String[] splitEscaped(char delimiter, String s) { 951 if (s == null) {972 if (s == null) 952 973 return new String[0]; 953 }954 974 List<String> result = new ArrayList<String>(); 955 975 boolean backslash = false; … … 1265 1285 1266 1286 static public EnumSet<PresetType> getType(String types) throws SAXException { 1267 if (typeCache.containsKey(types)) {1287 if (typeCache.containsKey(types)) 1268 1288 return typeCache.get(types); 1269 }1270 1289 EnumSet<PresetType> result = EnumSet.noneOf(PresetType.class); 1271 1290 for (String type : Arrays.asList(types.split(","))) { … … 1366 1385 lastrole = (Roles) o; 1367 1386 } else if (o instanceof Role) { 1368 if (lastrole == null) {1387 if (lastrole == null) 1369 1388 throw new SAXException(tr("Preset role element without parent")); 1370 }1371 1389 lastrole.roles.add((Role) o); 1372 1390 } else if (o instanceof PresetListEntry) { … … 1695 1713 1696 1714 public boolean matches(Collection<PresetType> t, Map<String, String> tags, boolean onlyShowable) { 1697 if (onlyShowable && !isShowable()) {1715 if (onlyShowable && !isShowable()) 1698 1716 return false; 1699 } else if (!typeMatches(t)) {1717 else if (!typeMatches(t)) 1700 1718 return false; 1701 }1702 1719 boolean atLeastOnePositiveMatch = false; 1703 1720 for (Item item : data) { 1704 1721 Boolean m = item.matches(tags); 1705 if (m != null && !m) {1722 if (m != null && !m) 1706 1723 return false; 1707 }else if (m != null) {1724 else if (m != null) { 1708 1725 atLeastOnePositiveMatch = true; 1709 1726 }
Note:
See TracChangeset
for help on using the changeset viewer.