source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java@ 7206

Last change on this file since 7206 was 7171, checked in by simon04, 10 years ago

fix #9682 #10048 - Presets: disable no value for some checkboxes in the preset dialog

This avoid that unneeded keys are created/suggested by JOSM, such as building=no

File size: 55.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trc;
6
7import java.awt.Component;
8import java.awt.Dimension;
9import java.awt.Font;
10import java.awt.GridBagLayout;
11import java.awt.GridLayout;
12import java.awt.event.ActionEvent;
13import java.awt.event.ActionListener;
14import java.awt.event.MouseAdapter;
15import java.awt.event.MouseEvent;
16import java.io.File;
17import java.lang.reflect.Method;
18import java.lang.reflect.Modifier;
19import java.text.NumberFormat;
20import java.text.ParseException;
21import java.util.ArrayList;
22import java.util.Arrays;
23import java.util.Collection;
24import java.util.Collections;
25import java.util.EnumSet;
26import java.util.HashMap;
27import java.util.LinkedHashMap;
28import java.util.LinkedList;
29import java.util.List;
30import java.util.Map;
31import java.util.TreeSet;
32
33import javax.swing.ButtonGroup;
34import javax.swing.ImageIcon;
35import javax.swing.JButton;
36import javax.swing.JComponent;
37import javax.swing.JLabel;
38import javax.swing.JList;
39import javax.swing.JPanel;
40import javax.swing.JScrollPane;
41import javax.swing.JSeparator;
42import javax.swing.JToggleButton;
43import javax.swing.ListCellRenderer;
44import javax.swing.ListModel;
45
46import org.openstreetmap.josm.Main;
47import org.openstreetmap.josm.actions.search.SearchCompiler;
48import org.openstreetmap.josm.data.osm.OsmPrimitive;
49import org.openstreetmap.josm.data.osm.OsmUtils;
50import org.openstreetmap.josm.data.osm.Tag;
51import org.openstreetmap.josm.data.preferences.BooleanProperty;
52import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
53import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPriority;
54import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
55import org.openstreetmap.josm.gui.widgets.JosmComboBox;
56import org.openstreetmap.josm.gui.widgets.JosmTextField;
57import org.openstreetmap.josm.gui.widgets.QuadStateCheckBox;
58import org.openstreetmap.josm.gui.widgets.UrlLabel;
59import org.openstreetmap.josm.tools.GBC;
60import org.openstreetmap.josm.tools.ImageProvider;
61import org.openstreetmap.josm.tools.Predicate;
62import org.openstreetmap.josm.tools.Utils;
63import org.xml.sax.SAXException;
64
65/**
66 * Class that contains all subtypes of TaggingPresetItem, static supplementary data, types and methods
67 * @since 6068
68 */
69public final class TaggingPresetItems {
70 private TaggingPresetItems() {
71 }
72
73 private static int auto_increment_selected = 0;
74 public static final String DIFFERENT = tr("<different>");
75
76 private static final BooleanProperty PROP_FILL_DEFAULT = new BooleanProperty("taggingpreset.fill-default-for-tagged-primitives", false);
77
78 // cache the parsing of types using a LRU cache (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html)
79 private static final Map<String,EnumSet<TaggingPresetType>> TYPE_CACHE = new LinkedHashMap<>(16, 1.1f, true);
80
81 /**
82 * Last value of each key used in presets, used for prefilling corresponding fields
83 */
84 private static final Map<String,String> LAST_VALUES = new HashMap<>();
85
86 public static class PresetListEntry {
87 public String value;
88 public String value_context;
89 public String display_value;
90 public String short_description;
91 public String icon;
92 public String icon_size;
93 public String locale_display_value;
94 public String locale_short_description;
95 private final File zipIcons = TaggingPresetReader.getZipIcons();
96
97 // Cached size (currently only for Combo) to speed up preset dialog initialization
98 private int prefferedWidth = -1;
99 private int prefferedHeight = -1;
100
101 public String getListDisplay() {
102 if (value.equals(DIFFERENT))
103 return "<b>"+DIFFERENT.replaceAll("<", "&lt;").replaceAll(">", "&gt;")+"</b>";
104
105 if (value.isEmpty())
106 return "&nbsp;";
107
108 final StringBuilder res = new StringBuilder("<b>");
109 res.append(getDisplayValue(true));
110 res.append("</b>");
111 if (getShortDescription(true) != null) {
112 // wrap in table to restrict the text width
113 res.append("<div style=\"width:300px; padding:0 0 5px 5px\">");
114 res.append(getShortDescription(true));
115 res.append("</div>");
116 }
117 return res.toString();
118 }
119
120 public ImageIcon getIcon() {
121 return icon == null ? null : loadImageIcon(icon, zipIcons, parseInteger(icon_size));
122 }
123
124 private Integer parseInteger(String str) {
125 if (str == null || str.isEmpty())
126 return null;
127 try {
128 return Integer.parseInt(str);
129 } catch (Exception e) {
130 //
131 }
132 return null;
133 }
134
135 public PresetListEntry() {
136 }
137
138 public PresetListEntry(String value) {
139 this.value = value;
140 }
141
142 public String getDisplayValue(boolean translated) {
143 return translated
144 ? Utils.firstNonNull(locale_display_value, tr(display_value), trc(value_context, value))
145 : Utils.firstNonNull(display_value, value);
146 }
147
148 public String getShortDescription(boolean translated) {
149 return translated
150 ? Utils.firstNonNull(locale_short_description, tr(short_description))
151 : short_description;
152 }
153
154 // toString is mainly used to initialize the Editor
155 @Override
156 public String toString() {
157 if (value.equals(DIFFERENT))
158 return DIFFERENT;
159 return getDisplayValue(true).replaceAll("<.*>", ""); // remove additional markup, e.g. <br>
160 }
161 }
162
163 public static class Role {
164 public EnumSet<TaggingPresetType> types;
165 public String key;
166 public String text;
167 public String text_context;
168 public String locale_text;
169 public SearchCompiler.Match memberExpression;
170
171 public boolean required = false;
172 public long count = 0;
173
174 public void setType(String types) throws SAXException {
175 this.types = getType(types);
176 }
177
178 public void setRequisite(String str) throws SAXException {
179 if("required".equals(str)) {
180 required = true;
181 } else if(!"optional".equals(str))
182 throw new SAXException(tr("Unknown requisite: {0}", str));
183 }
184
185 public void setMember_expression(String member_expression) throws SAXException {
186 try {
187 this.memberExpression = SearchCompiler.compile(member_expression, true, true);
188 } catch (SearchCompiler.ParseError ex) {
189 throw new SAXException(tr("Illegal member expression: {0}", ex.getMessage()), ex);
190 }
191 }
192
193 /* return either argument, the highest possible value or the lowest
194 allowed value */
195 public long getValidCount(long c)
196 {
197 if(count > 0 && !required)
198 return c != 0 ? count : 0;
199 else if(count > 0)
200 return count;
201 else if(!required)
202 return c != 0 ? c : 0;
203 else
204 return c != 0 ? c : 1;
205 }
206 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
207 String cstring;
208 if(count > 0 && !required) {
209 cstring = "0,"+count;
210 } else if(count > 0) {
211 cstring = String.valueOf(count);
212 } else if(!required) {
213 cstring = "0-...";
214 } else {
215 cstring = "1-...";
216 }
217 if(locale_text == null) {
218 if (text != null) {
219 if(text_context != null) {
220 locale_text = trc(text_context, fixPresetString(text));
221 } else {
222 locale_text = tr(fixPresetString(text));
223 }
224 }
225 }
226 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0));
227 p.add(new JLabel(key), GBC.std().insets(0,0,10,0));
228 p.add(new JLabel(cstring), types == null ? GBC.eol() : GBC.std().insets(0,0,10,0));
229 if(types != null){
230 JPanel pp = new JPanel();
231 for(TaggingPresetType t : types) {
232 pp.add(new JLabel(ImageProvider.get(t.getIconName())));
233 }
234 p.add(pp, GBC.eol());
235 }
236 return true;
237 }
238 }
239
240 /**
241 * Enum denoting how a match (see {@link TaggingPresetItem#matches}) is performed.
242 */
243 public static enum MatchType {
244
245 /**
246 * Neutral, i.e., do not consider this item for matching.
247 */
248 NONE("none"),
249 /**
250 * Positive if key matches, neutral otherwise.
251 */
252 KEY("key"),
253 /**
254 * Positive if key matches, negative otherwise.
255 */
256 KEY_REQUIRED("key!"),
257 /**
258 * Positive if key and value matches, negative otherwise.
259 */
260 KEY_VALUE("keyvalue");
261
262 private final String value;
263
264 private MatchType(String value) {
265 this.value = value;
266 }
267
268 public String getValue() {
269 return value;
270 }
271
272 public static MatchType ofString(String type) {
273 for (MatchType i : EnumSet.allOf(MatchType.class)) {
274 if (i.getValue().equals(type))
275 return i;
276 }
277 throw new IllegalArgumentException(type + " is not allowed");
278 }
279 }
280
281 public static class Usage {
282 TreeSet<String> values;
283 boolean hadKeys = false;
284 boolean hadEmpty = false;
285 public boolean hasUniqueValue() {
286 return values.size() == 1 && !hadEmpty;
287 }
288
289 public boolean unused() {
290 return values.isEmpty();
291 }
292 public String getFirst() {
293 return values.first();
294 }
295
296 public boolean hadKeys() {
297 return hadKeys;
298 }
299 }
300
301 /**
302 * A tagging preset item displaying a localizable text.
303 * @since 6190
304 */
305 public abstract static class TaggingPresetTextItem extends TaggingPresetItem {
306
307 /**
308 * The text to display
309 */
310 public String text;
311
312 /**
313 * The context used for translating {@link #text}
314 */
315 public String text_context;
316
317 /**
318 * The localized version of {@link #text}
319 */
320 public String locale_text;
321
322 protected final void initializeLocaleText(String defaultText) {
323 if (locale_text == null) {
324 if (text == null) {
325 locale_text = defaultText;
326 } else if (text_context != null) {
327 locale_text = trc(text_context, fixPresetString(text));
328 } else {
329 locale_text = tr(fixPresetString(text));
330 }
331 }
332 }
333
334 @Override
335 void addCommands(List<Tag> changedTags) {
336 }
337
338 protected String fieldsToString() {
339 return (text != null ? "text=" + text + ", " : "")
340 + (text_context != null ? "text_context=" + text_context + ", " : "")
341 + (locale_text != null ? "locale_text=" + locale_text : "");
342 }
343
344 @Override
345 public String toString() {
346 return getClass().getSimpleName() + " [" + fieldsToString() + "]";
347 }
348 }
349
350 public static class Label extends TaggingPresetTextItem {
351
352 @Override
353 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
354 initializeLocaleText(null);
355 addLabel(p, locale_text);
356 return false;
357 }
358
359 public static void addLabel(JPanel p, String label) {
360 p.add(new JLabel(label), GBC.eol());
361 }
362 }
363
364 public static class Link extends TaggingPresetTextItem {
365
366 /**
367 * The link to display
368 */
369 public String href;
370
371 /**
372 * The localized version of {@link #href}
373 */
374 public String locale_href;
375
376 @Override
377 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
378 initializeLocaleText(tr("More information about this feature"));
379 String url = locale_href;
380 if (url == null) {
381 url = href;
382 }
383 if (url != null) {
384 p.add(new UrlLabel(url, locale_text, 2), GBC.eol().insets(0, 10, 0, 0));
385 }
386 return false;
387 }
388
389 @Override
390 protected String fieldsToString() {
391 return super.fieldsToString()
392 + (href != null ? "href=" + href + ", " : "")
393 + (locale_href != null ? "locale_href=" + locale_href + ", " : "");
394 }
395 }
396
397 public static class PresetLink extends TaggingPresetItem {
398
399 public String preset_name = "";
400
401 @Override
402 boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
403 final String presetName = preset_name;
404 final TaggingPreset t = Utils.filter(TaggingPresets.getTaggingPresets(), new Predicate<TaggingPreset>() {
405 @Override
406 public boolean evaluate(TaggingPreset object) {
407 return presetName.equals(object.name);
408 }
409 }).iterator().next();
410 if (t == null) return false;
411 JLabel lbl = new PresetLabel(t);
412 lbl.addMouseListener(new MouseAdapter() {
413 @Override
414 public void mouseClicked(MouseEvent arg0) {
415 t.actionPerformed(null);
416 }
417 });
418 p.add(lbl, GBC.eol().fill(GBC.HORIZONTAL));
419 return false;
420 }
421
422 @Override
423 void addCommands(List<Tag> changedTags) {
424 }
425 }
426
427 public static class Roles extends TaggingPresetItem {
428
429 public final List<Role> roles = new LinkedList<>();
430
431 @Override
432 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
433 p.add(new JLabel(" "), GBC.eol()); // space
434 if (!roles.isEmpty()) {
435 JPanel proles = new JPanel(new GridBagLayout());
436 proles.add(new JLabel(tr("Available roles")), GBC.std().insets(0, 0, 10, 0));
437 proles.add(new JLabel(tr("role")), GBC.std().insets(0, 0, 10, 0));
438 proles.add(new JLabel(tr("count")), GBC.std().insets(0, 0, 10, 0));
439 proles.add(new JLabel(tr("elements")), GBC.eol());
440 for (Role i : roles) {
441 i.addToPanel(proles, sel);
442 }
443 p.add(proles, GBC.eol());
444 }
445 return false;
446 }
447
448 @Override
449 public void addCommands(List<Tag> changedTags) {
450 }
451 }
452
453 public static class Optional extends TaggingPresetTextItem {
454
455 // TODO: Draw a box around optional stuff
456 @Override
457 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
458 initializeLocaleText(tr("Optional Attributes:"));
459 p.add(new JLabel(" "), GBC.eol()); // space
460 p.add(new JLabel(locale_text), GBC.eol());
461 p.add(new JLabel(" "), GBC.eol()); // space
462 return false;
463 }
464 }
465
466 public static class Space extends TaggingPresetItem {
467
468 @Override
469 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
470 p.add(new JLabel(" "), GBC.eol()); // space
471 return false;
472 }
473
474 @Override
475 public void addCommands(List<Tag> changedTags) {
476 }
477
478 @Override
479 public String toString() {
480 return "Space";
481 }
482 }
483
484 /**
485 * Class used to represent a {@link JSeparator} inside tagging preset window.
486 * @since 6198
487 */
488 public static class ItemSeparator extends TaggingPresetItem {
489
490 @Override
491 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
492 p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0, 5, 0, 5));
493 return false;
494 }
495
496 @Override
497 public void addCommands(List<Tag> changedTags) {
498 }
499
500 @Override
501 public String toString() {
502 return "ItemSeparator";
503 }
504 }
505
506 public abstract static class KeyedItem extends TaggingPresetItem {
507
508 public String key;
509 public String text;
510 public String text_context;
511 public String match = getDefaultMatch().getValue();
512
513 public abstract MatchType getDefaultMatch();
514 public abstract Collection<String> getValues();
515
516 @Override
517 Boolean matches(Map<String, String> tags) {
518 switch (MatchType.ofString(match)) {
519 case NONE:
520 return null;
521 case KEY:
522 return tags.containsKey(key) ? true : null;
523 case KEY_REQUIRED:
524 return tags.containsKey(key);
525 case KEY_VALUE:
526 return tags.containsKey(key) && (getValues().contains(tags.get(key)));
527 default:
528 throw new IllegalStateException();
529 }
530 }
531
532 @Override
533 public String toString() {
534 return "KeyedItem [key=" + key + ", text=" + text
535 + ", text_context=" + text_context + ", match=" + match
536 + "]";
537 }
538 }
539
540 public static class Key extends KeyedItem {
541
542 public String value;
543
544 @Override
545 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
546 return false;
547 }
548
549 @Override
550 public void addCommands(List<Tag> changedTags) {
551 changedTags.add(new Tag(key, value));
552 }
553
554 @Override
555 public MatchType getDefaultMatch() {
556 return MatchType.KEY_VALUE;
557 }
558
559 @Override
560 public Collection<String> getValues() {
561 return Collections.singleton(value);
562 }
563
564 @Override
565 public String toString() {
566 return "Key [key=" + key + ", value=" + value + ", text=" + text
567 + ", text_context=" + text_context + ", match=" + match
568 + "]";
569 }
570 }
571
572 public static class Text extends KeyedItem {
573
574 public String locale_text;
575 public String default_;
576 public String originalValue;
577 public String use_last_as_default = "false";
578 public String auto_increment;
579 public String length;
580 public String alternative_autocomplete_keys;
581
582 private JComponent value;
583
584 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
585
586 // find out if our key is already used in the selection.
587 Usage usage = determineTextUsage(sel, key);
588 AutoCompletingTextField textField = new AutoCompletingTextField();
589 if (alternative_autocomplete_keys != null) {
590 initAutoCompletionField(textField, (key + "," + alternative_autocomplete_keys).split(","));
591 } else {
592 initAutoCompletionField(textField, key);
593 }
594 if (length != null && !length.isEmpty()) {
595 textField.setMaxChars(Integer.valueOf(length));
596 }
597 if (usage.unused()){
598 if (auto_increment_selected != 0 && auto_increment != null) {
599 try {
600 textField.setText(Integer.toString(Integer.parseInt(LAST_VALUES.get(key)) + auto_increment_selected));
601 } catch (NumberFormatException ex) {
602 // Ignore - cannot auto-increment if last was non-numeric
603 }
604 }
605 else if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) {
606 // selected osm primitives are untagged or filling default values feature is enabled
607 if (!"false".equals(use_last_as_default) && LAST_VALUES.containsKey(key) && !presetInitiallyMatches) {
608 textField.setText(LAST_VALUES.get(key));
609 } else {
610 textField.setText(default_);
611 }
612 } else {
613 // selected osm primitives are tagged and filling default values feature is disabled
614 textField.setText("");
615 }
616 value = textField;
617 originalValue = null;
618 } else if (usage.hasUniqueValue()) {
619 // all objects use the same value
620 textField.setText(usage.getFirst());
621 value = textField;
622 originalValue = usage.getFirst();
623 } else {
624 // the objects have different values
625 JosmComboBox<String> comboBox = new JosmComboBox<>(usage.values.toArray(new String[0]));
626 comboBox.setEditable(true);
627 comboBox.setEditor(textField);
628 comboBox.getEditor().setItem(DIFFERENT);
629 value=comboBox;
630 originalValue = DIFFERENT;
631 }
632 if (locale_text == null) {
633 if (text != null) {
634 if (text_context != null) {
635 locale_text = trc(text_context, fixPresetString(text));
636 } else {
637 locale_text = tr(fixPresetString(text));
638 }
639 }
640 }
641
642 // if there's an auto_increment setting, then wrap the text field
643 // into a panel, appending a number of buttons.
644 // auto_increment has a format like -2,-1,1,2
645 // the text box being the first component in the panel is relied
646 // on in a rather ugly fashion further down.
647 if (auto_increment != null) {
648 ButtonGroup bg = new ButtonGroup();
649 JPanel pnl = new JPanel(new GridBagLayout());
650 pnl.add(value, GBC.std().fill(GBC.HORIZONTAL));
651
652 // first, one button for each auto_increment value
653 for (final String ai : auto_increment.split(",")) {
654 JToggleButton aibutton = new JToggleButton(ai);
655 aibutton.setToolTipText(tr("Select auto-increment of {0} for this field", ai));
656 aibutton.setMargin(new java.awt.Insets(0,0,0,0));
657 aibutton.setFocusable(false);
658 bg.add(aibutton);
659 try {
660 // TODO there must be a better way to parse a number like "+3" than this.
661 final int buttonvalue = (NumberFormat.getIntegerInstance().parse(ai.replace("+", ""))).intValue();
662 if (auto_increment_selected == buttonvalue) aibutton.setSelected(true);
663 aibutton.addActionListener(new ActionListener() {
664 @Override
665 public void actionPerformed(ActionEvent e) {
666 auto_increment_selected = buttonvalue;
667 }
668 });
669 pnl.add(aibutton, GBC.std());
670 } catch (ParseException x) {
671 Main.error("Cannot parse auto-increment value of '" + ai + "' into an integer");
672 }
673 }
674
675 // an invisible toggle button for "release" of the button group
676 final JToggleButton clearbutton = new JToggleButton("X");
677 clearbutton.setVisible(false);
678 clearbutton.setFocusable(false);
679 bg.add(clearbutton);
680 // and its visible counterpart. - this mechanism allows us to
681 // have *no* button selected after the X is clicked, instead
682 // of the X remaining selected
683 JButton releasebutton = new JButton("X");
684 releasebutton.setToolTipText(tr("Cancel auto-increment for this field"));
685 releasebutton.setMargin(new java.awt.Insets(0,0,0,0));
686 releasebutton.setFocusable(false);
687 releasebutton.addActionListener(new ActionListener() {
688 @Override
689 public void actionPerformed(ActionEvent e) {
690 auto_increment_selected = 0;
691 clearbutton.setSelected(true);
692 }
693 });
694 pnl.add(releasebutton, GBC.eol());
695 value = pnl;
696 }
697 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0));
698 p.add(value, GBC.eol().fill(GBC.HORIZONTAL));
699 return true;
700 }
701
702 private static String getValue(Component comp) {
703 if (comp instanceof JosmComboBox) {
704 return ((JosmComboBox<?>) comp).getEditor().getItem().toString();
705 } else if (comp instanceof JosmTextField) {
706 return ((JosmTextField) comp).getText();
707 } else if (comp instanceof JPanel) {
708 return getValue(((JPanel)comp).getComponent(0));
709 } else {
710 return null;
711 }
712 }
713
714 @Override
715 public void addCommands(List<Tag> changedTags) {
716
717 // return if unchanged
718 String v = getValue(value);
719 if (v == null) {
720 Main.error("No 'last value' support for component " + value);
721 return;
722 }
723
724 v = Tag.removeWhiteSpaces(v);
725
726 if (!"false".equals(use_last_as_default) || auto_increment != null) {
727 LAST_VALUES.put(key, v);
728 }
729 if (v.equals(originalValue) || (originalValue == null && v.length() == 0))
730 return;
731
732 changedTags.add(new Tag(key, v));
733 }
734
735 @Override
736 boolean requestFocusInWindow() {
737 return value.requestFocusInWindow();
738 }
739
740 @Override
741 public MatchType getDefaultMatch() {
742 return MatchType.NONE;
743 }
744
745 @Override
746 public Collection<String> getValues() {
747 if (default_ == null || default_.isEmpty())
748 return Collections.emptyList();
749 return Collections.singleton(default_);
750 }
751 }
752
753 /**
754 * A group of {@link Check}s.
755 * @since 6114
756 */
757 public static class CheckGroup extends TaggingPresetItem {
758
759 /**
760 * Number of columns (positive integer)
761 */
762 public String columns;
763
764 /**
765 * List of checkboxes
766 */
767 public final List<Check> checks = new LinkedList<>();
768
769 @Override
770 boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
771 Integer cols = Integer.valueOf(columns);
772 int rows = (int) Math.ceil(checks.size()/cols.doubleValue());
773 JPanel panel = new JPanel(new GridLayout(rows, cols));
774
775 for (Check check : checks) {
776 check.addToPanel(panel, sel, presetInitiallyMatches);
777 }
778
779 p.add(panel, GBC.eol());
780 return false;
781 }
782
783 @Override
784 void addCommands(List<Tag> changedTags) {
785 for (Check check : checks) {
786 check.addCommands(changedTags);
787 }
788 }
789
790 @Override
791 public String toString() {
792 return "CheckGroup [columns=" + columns + "]";
793 }
794 }
795
796 public static class Check extends KeyedItem {
797
798 public String locale_text;
799 public String value_on = OsmUtils.trueval;
800 public String value_off = OsmUtils.falseval;
801 public boolean disable_off = false;
802 public boolean default_ = false; // only used for tagless objects
803
804 private QuadStateCheckBox check;
805 private QuadStateCheckBox.State initialState;
806 private boolean def;
807
808 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
809
810 // find out if our key is already used in the selection.
811 final Usage usage = determineBooleanUsage(sel, key);
812 final String oneValue = usage.values.isEmpty() ? null : usage.values.last();
813 def = default_;
814
815 if(locale_text == null) {
816 if(text_context != null) {
817 locale_text = trc(text_context, fixPresetString(text));
818 } else {
819 locale_text = tr(fixPresetString(text));
820 }
821 }
822
823 if (usage.values.size() < 2 && (oneValue == null || value_on.equals(oneValue) || value_off.equals(oneValue))) {
824 if (def && !PROP_FILL_DEFAULT.get()) {
825 // default is set and filling default values feature is disabled - check if all primitives are untagged
826 for (OsmPrimitive s : sel)
827 if(s.hasKeys()) {
828 def = false;
829 }
830 }
831
832 // all selected objects share the same value which is either true or false or unset,
833 // we can display a standard check box.
834 initialState = value_on.equals(oneValue)
835 ? QuadStateCheckBox.State.SELECTED
836 : value_off.equals(oneValue)
837 ? QuadStateCheckBox.State.NOT_SELECTED
838 : def
839 ? QuadStateCheckBox.State.SELECTED
840 : QuadStateCheckBox.State.UNSET;
841 } else {
842 def = false;
843 // the objects have different values, or one or more objects have something
844 // else than true/false. we display a quad-state check box
845 // in "partial" state.
846 initialState = QuadStateCheckBox.State.PARTIAL;
847 }
848
849 final List<QuadStateCheckBox.State> allowedStates = new ArrayList<>(4);
850 if (QuadStateCheckBox.State.PARTIAL.equals(initialState))
851 allowedStates.add(QuadStateCheckBox.State.PARTIAL);
852 allowedStates.add(QuadStateCheckBox.State.SELECTED);
853 if (!disable_off || value_off.equals(oneValue))
854 allowedStates.add(QuadStateCheckBox.State.NOT_SELECTED);
855 allowedStates.add(QuadStateCheckBox.State.UNSET);
856 check = new QuadStateCheckBox(locale_text, initialState,
857 allowedStates.toArray(new QuadStateCheckBox.State[allowedStates.size()]));
858
859 p.add(check, GBC.eol().fill(GBC.HORIZONTAL));
860 return true;
861 }
862
863 @Override public void addCommands(List<Tag> changedTags) {
864 // if the user hasn't changed anything, don't create a command.
865 if (check.getState() == initialState && !def) return;
866
867 // otherwise change things according to the selected value.
868 changedTags.add(new Tag(key,
869 check.getState() == QuadStateCheckBox.State.SELECTED ? value_on :
870 check.getState() == QuadStateCheckBox.State.NOT_SELECTED ? value_off :
871 null));
872 }
873 @Override boolean requestFocusInWindow() {return check.requestFocusInWindow();}
874
875 @Override
876 public MatchType getDefaultMatch() {
877 return MatchType.NONE;
878 }
879
880 @Override
881 public Collection<String> getValues() {
882 return disable_off ? Arrays.asList(value_on) : Arrays.asList(value_on, value_off);
883 }
884
885 @Override
886 public String toString() {
887 return "Check ["
888 + (locale_text != null ? "locale_text=" + locale_text + ", " : "")
889 + (value_on != null ? "value_on=" + value_on + ", " : "")
890 + (value_off != null ? "value_off=" + value_off + ", " : "")
891 + "default_=" + default_ + ", "
892 + (check != null ? "check=" + check + ", " : "")
893 + (initialState != null ? "initialState=" + initialState
894 + ", " : "") + "def=" + def + "]";
895 }
896 }
897
898 public abstract static class ComboMultiSelect extends KeyedItem {
899
900 public String locale_text;
901 public String values;
902 public String values_from;
903 public String values_context;
904 public String display_values;
905 public String locale_display_values;
906 public String short_descriptions;
907 public String locale_short_descriptions;
908 public String default_;
909 public String delimiter = ";";
910 public String use_last_as_default = "false";
911 /** whether to use values for search via {@link TaggingPresetSelector} */
912 public String values_searchable = "false";
913
914 protected JComponent component;
915 protected final Map<String, PresetListEntry> lhm = new LinkedHashMap<>();
916 private boolean initialized = false;
917 protected Usage usage;
918 protected Object originalValue;
919
920 protected abstract Object getSelectedItem();
921 protected abstract void addToPanelAnchor(JPanel p, String def, boolean presetInitiallyMatches);
922
923 protected char getDelChar() {
924 return delimiter.isEmpty() ? ';' : delimiter.charAt(0);
925 }
926
927 @Override
928 public Collection<String> getValues() {
929 initListEntries();
930 return lhm.keySet();
931 }
932
933 public Collection<String> getDisplayValues() {
934 initListEntries();
935 return Utils.transform(lhm.values(), new Utils.Function<PresetListEntry, String>() {
936 @Override
937 public String apply(PresetListEntry x) {
938 return x.getDisplayValue(true);
939 }
940 });
941 }
942
943 @Override
944 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
945
946 initListEntries();
947
948 // find out if our key is already used in the selection.
949 usage = determineTextUsage(sel, key);
950 if (!usage.hasUniqueValue() && !usage.unused()) {
951 lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT));
952 }
953
954 p.add(new JLabel(tr("{0}:", locale_text)), GBC.std().insets(0, 0, 10, 0));
955 addToPanelAnchor(p, default_, presetInitiallyMatches);
956
957 return true;
958
959 }
960
961 private void initListEntries() {
962 if (initialized) {
963 lhm.remove(DIFFERENT); // possibly added in #addToPanel
964 return;
965 } else if (lhm.isEmpty()) {
966 initListEntriesFromAttributes();
967 } else {
968 if (values != null) {
969 Main.warn(tr("Warning in tagging preset \"{0}-{1}\": "
970 + "Ignoring ''{2}'' attribute as ''{3}'' elements are given.",
971 key, text, "values", "list_entry"));
972 }
973 if (display_values != null || locale_display_values != null) {
974 Main.warn(tr("Warning in tagging preset \"{0}-{1}\": "
975 + "Ignoring ''{2}'' attribute as ''{3}'' elements are given.",
976 key, text, "display_values", "list_entry"));
977 }
978 if (short_descriptions != null || locale_short_descriptions != null) {
979 Main.warn(tr("Warning in tagging preset \"{0}-{1}\": "
980 + "Ignoring ''{2}'' attribute as ''{3}'' elements are given.",
981 key, text, "short_descriptions", "list_entry"));
982 }
983 for (PresetListEntry e : lhm.values()) {
984 if (e.value_context == null) {
985 e.value_context = values_context;
986 }
987 }
988 }
989 if (locale_text == null) {
990 locale_text = trc(text_context, fixPresetString(text));
991 }
992 initialized = true;
993 }
994
995 private String[] initListEntriesFromAttributes() {
996 char delChar = getDelChar();
997
998 String[] value_array = null;
999
1000 if (values_from != null) {
1001 String[] class_method = values_from.split("#");
1002 if (class_method != null && class_method.length == 2) {
1003 try {
1004 Method method = Class.forName(class_method[0]).getMethod(class_method[1]);
1005 // Check method is public static String[] methodName()
1006 int mod = method.getModifiers();
1007 if (Modifier.isPublic(mod) && Modifier.isStatic(mod)
1008 && method.getReturnType().equals(String[].class) && method.getParameterTypes().length == 0) {
1009 value_array = (String[]) method.invoke(null);
1010 } else {
1011 Main.error(tr("Broken tagging preset \"{0}-{1}\" - Java method given in ''values_from'' is not \"{2}\"", key, text,
1012 "public static String[] methodName()"));
1013 }
1014 } catch (Exception e) {
1015 Main.error(tr("Broken tagging preset \"{0}-{1}\" - Java method given in ''values_from'' threw {2} ({3})", key, text,
1016 e.getClass().getName(), e.getMessage()));
1017 }
1018 }
1019 }
1020
1021 if (value_array == null) {
1022 value_array = splitEscaped(delChar, values);
1023 }
1024
1025 final String displ = Utils.firstNonNull(locale_display_values, display_values);
1026 String[] display_array = displ == null ? value_array : splitEscaped(delChar, displ);
1027
1028 final String descr = Utils.firstNonNull(locale_short_descriptions, short_descriptions);
1029 String[] short_descriptions_array = descr == null ? null : splitEscaped(delChar, descr);
1030
1031 if (display_array.length != value_array.length) {
1032 Main.error(tr("Broken tagging preset \"{0}-{1}\" - number of items in ''display_values'' must be the same as in ''values''", key, text));
1033 display_array = value_array;
1034 }
1035
1036 if (short_descriptions_array != null && short_descriptions_array.length != value_array.length) {
1037 Main.error(tr("Broken tagging preset \"{0}-{1}\" - number of items in ''short_descriptions'' must be the same as in ''values''", key, text));
1038 short_descriptions_array = null;
1039 }
1040
1041 for (int i = 0; i < value_array.length; i++) {
1042 final PresetListEntry e = new PresetListEntry(value_array[i]);
1043 e.locale_display_value = locale_display_values != null
1044 ? display_array[i]
1045 : trc(values_context, fixPresetString(display_array[i]));
1046 if (short_descriptions_array != null) {
1047 e.locale_short_description = locale_short_descriptions != null
1048 ? short_descriptions_array[i]
1049 : tr(fixPresetString(short_descriptions_array[i]));
1050 }
1051 lhm.put(value_array[i], e);
1052 display_array[i] = e.getDisplayValue(true);
1053 }
1054
1055 return display_array;
1056 }
1057
1058 protected String getDisplayIfNull() {
1059 return null;
1060 }
1061
1062 @Override
1063 public void addCommands(List<Tag> changedTags) {
1064 Object obj = getSelectedItem();
1065 String display = (obj == null) ? null : obj.toString();
1066 String value = null;
1067 if (display == null) {
1068 display = getDisplayIfNull();
1069 }
1070
1071 if (display != null) {
1072 for (String val : lhm.keySet()) {
1073 String k = lhm.get(val).toString();
1074 if (k != null && k.equals(display)) {
1075 value = val;
1076 break;
1077 }
1078 }
1079 if (value == null) {
1080 value = display;
1081 }
1082 } else {
1083 value = "";
1084 }
1085 value = Tag.removeWhiteSpaces(value);
1086
1087 // no change if same as before
1088 if (originalValue == null) {
1089 if (value.length() == 0)
1090 return;
1091 } else if (value.equals(originalValue.toString()))
1092 return;
1093
1094 if (!"false".equals(use_last_as_default)) {
1095 LAST_VALUES.put(key, value);
1096 }
1097 changedTags.add(new Tag(key, value));
1098 }
1099
1100 public void addListEntry(PresetListEntry e) {
1101 lhm.put(e.value, e);
1102 }
1103
1104 public void addListEntries(Collection<PresetListEntry> e) {
1105 for (PresetListEntry i : e) {
1106 addListEntry(i);
1107 }
1108 }
1109
1110 @Override
1111 boolean requestFocusInWindow() {
1112 return component.requestFocusInWindow();
1113 }
1114
1115 private static final ListCellRenderer<PresetListEntry> RENDERER = new ListCellRenderer<PresetListEntry>() {
1116
1117 JLabel lbl = new JLabel();
1118
1119 @Override
1120 public Component getListCellRendererComponent(
1121 JList<? extends PresetListEntry> list,
1122 PresetListEntry item,
1123 int index,
1124 boolean isSelected,
1125 boolean cellHasFocus) {
1126
1127 // Only return cached size, item is not shown
1128 if (!list.isShowing() && item.prefferedWidth != -1 && item.prefferedHeight != -1) {
1129 if (index == -1) {
1130 lbl.setPreferredSize(new Dimension(item.prefferedWidth, 10));
1131 } else {
1132 lbl.setPreferredSize(new Dimension(item.prefferedWidth, item.prefferedHeight));
1133 }
1134 return lbl;
1135 }
1136
1137 lbl.setPreferredSize(null);
1138
1139
1140 if (isSelected) {
1141 lbl.setBackground(list.getSelectionBackground());
1142 lbl.setForeground(list.getSelectionForeground());
1143 } else {
1144 lbl.setBackground(list.getBackground());
1145 lbl.setForeground(list.getForeground());
1146 }
1147
1148 lbl.setOpaque(true);
1149 lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN));
1150 lbl.setText("<html>" + item.getListDisplay() + "</html>");
1151 lbl.setIcon(item.getIcon());
1152 lbl.setEnabled(list.isEnabled());
1153
1154 // Cache size
1155 item.prefferedWidth = lbl.getPreferredSize().width;
1156 item.prefferedHeight = lbl.getPreferredSize().height;
1157
1158 // We do not want the editor to have the maximum height of all
1159 // entries. Return a dummy with bogus height.
1160 if (index == -1) {
1161 lbl.setPreferredSize(new Dimension(lbl.getPreferredSize().width, 10));
1162 }
1163 return lbl;
1164 }
1165 };
1166
1167 protected ListCellRenderer<PresetListEntry> getListCellRenderer() {
1168 return RENDERER;
1169 }
1170
1171 @Override
1172 public MatchType getDefaultMatch() {
1173 return MatchType.NONE;
1174 }
1175 }
1176
1177 public static class Combo extends ComboMultiSelect {
1178
1179 public boolean editable = true;
1180 protected JosmComboBox<PresetListEntry> combo;
1181 public String length;
1182
1183 /**
1184 * Constructs a new {@code Combo}.
1185 */
1186 public Combo() {
1187 delimiter = ",";
1188 }
1189
1190 @Override
1191 protected void addToPanelAnchor(JPanel p, String def, boolean presetInitiallyMatches) {
1192 if (!usage.unused()) {
1193 for (String s : usage.values) {
1194 if (!lhm.containsKey(s)) {
1195 lhm.put(s, new PresetListEntry(s));
1196 }
1197 }
1198 }
1199 if (def != null && !lhm.containsKey(def)) {
1200 lhm.put(def, new PresetListEntry(def));
1201 }
1202 lhm.put("", new PresetListEntry(""));
1203
1204 combo = new JosmComboBox<>(lhm.values().toArray(new PresetListEntry[0]));
1205 component = combo;
1206 combo.setRenderer(getListCellRenderer());
1207 combo.setEditable(editable);
1208 combo.reinitialize(lhm.values());
1209 AutoCompletingTextField tf = new AutoCompletingTextField();
1210 initAutoCompletionField(tf, key);
1211 if (length != null && !length.isEmpty()) {
1212 tf.setMaxChars(Integer.valueOf(length));
1213 }
1214 AutoCompletionList acList = tf.getAutoCompletionList();
1215 if (acList != null) {
1216 acList.add(getDisplayValues(), AutoCompletionItemPriority.IS_IN_STANDARD);
1217 }
1218 combo.setEditor(tf);
1219
1220 if (usage.hasUniqueValue()) {
1221 // all items have the same value (and there were no unset items)
1222 originalValue = lhm.get(usage.getFirst());
1223 combo.setSelectedItem(originalValue);
1224 } else if (def != null && usage.unused()) {
1225 // default is set and all items were unset
1226 if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) {
1227 // selected osm primitives are untagged or filling default feature is enabled
1228 combo.setSelectedItem(lhm.get(def).getDisplayValue(true));
1229 } else {
1230 // selected osm primitives are tagged and filling default feature is disabled
1231 combo.setSelectedItem("");
1232 }
1233 originalValue = lhm.get(DIFFERENT);
1234 } else if (usage.unused()) {
1235 // all items were unset (and so is default)
1236 originalValue = lhm.get("");
1237 if ("force".equals(use_last_as_default) && LAST_VALUES.containsKey(key) && !presetInitiallyMatches) {
1238 combo.setSelectedItem(lhm.get(LAST_VALUES.get(key)));
1239 } else {
1240 combo.setSelectedItem(originalValue);
1241 }
1242 } else {
1243 originalValue = lhm.get(DIFFERENT);
1244 combo.setSelectedItem(originalValue);
1245 }
1246 p.add(combo, GBC.eol().fill(GBC.HORIZONTAL));
1247
1248 }
1249
1250 @Override
1251 protected Object getSelectedItem() {
1252 return combo.getSelectedItem();
1253
1254 }
1255
1256 @Override
1257 protected String getDisplayIfNull() {
1258 if (combo.isEditable())
1259 return combo.getEditor().getItem().toString();
1260 else
1261 return null;
1262 }
1263 }
1264 public static class MultiSelect extends ComboMultiSelect {
1265
1266 public long rows = -1;
1267 protected ConcatenatingJList list;
1268
1269 @Override
1270 protected void addToPanelAnchor(JPanel p, String def, boolean presetInitiallyMatches) {
1271 list = new ConcatenatingJList(delimiter, lhm.values().toArray(new PresetListEntry[0]));
1272 component = list;
1273 ListCellRenderer<PresetListEntry> renderer = getListCellRenderer();
1274 list.setCellRenderer(renderer);
1275
1276 if (usage.hasUniqueValue() && !usage.unused()) {
1277 originalValue = usage.getFirst();
1278 list.setSelectedItem(originalValue);
1279 } else if (def != null && !usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) {
1280 originalValue = DIFFERENT;
1281 list.setSelectedItem(def);
1282 } else if (usage.unused()) {
1283 originalValue = null;
1284 list.setSelectedItem(originalValue);
1285 } else {
1286 originalValue = DIFFERENT;
1287 list.setSelectedItem(originalValue);
1288 }
1289
1290 JScrollPane sp = new JScrollPane(list);
1291 // if a number of rows has been specified in the preset,
1292 // modify preferred height of scroll pane to match that row count.
1293 if (rows != -1) {
1294 double height = renderer.getListCellRendererComponent(list,
1295 new PresetListEntry("x"), 0, false, false).getPreferredSize().getHeight() * rows;
1296 sp.setPreferredSize(new Dimension((int) sp.getPreferredSize().getWidth(), (int) height));
1297 }
1298 p.add(sp, GBC.eol().fill(GBC.HORIZONTAL));
1299
1300
1301 }
1302
1303 @Override
1304 protected Object getSelectedItem() {
1305 return list.getSelectedItem();
1306 }
1307
1308 @Override
1309 public void addCommands(List<Tag> changedTags) {
1310 // Do not create any commands if list has been disabled because of an unknown value (fix #8605)
1311 if (list.isEnabled()) {
1312 super.addCommands(changedTags);
1313 }
1314 }
1315 }
1316
1317 /**
1318 * Class that allows list values to be assigned and retrieved as a comma-delimited
1319 * string (extracted from TaggingPreset)
1320 */
1321 private static class ConcatenatingJList extends JList<PresetListEntry> {
1322 private String delimiter;
1323 public ConcatenatingJList(String del, PresetListEntry[] o) {
1324 super(o);
1325 delimiter = del;
1326 }
1327
1328 public void setSelectedItem(Object o) {
1329 if (o == null) {
1330 clearSelection();
1331 } else {
1332 String s = o.toString();
1333 TreeSet<String> parts = new TreeSet<>(Arrays.asList(s.split(delimiter)));
1334 ListModel<PresetListEntry> lm = getModel();
1335 int[] intParts = new int[lm.getSize()];
1336 int j = 0;
1337 for (int i = 0; i < lm.getSize(); i++) {
1338 if (parts.contains((lm.getElementAt(i).value))) {
1339 intParts[j++]=i;
1340 }
1341 }
1342 setSelectedIndices(Arrays.copyOf(intParts, j));
1343 // check if we have actually managed to represent the full
1344 // value with our presets. if not, cop out; we will not offer
1345 // a selection list that threatens to ruin the value.
1346 setEnabled(Utils.join(delimiter, parts).equals(getSelectedItem()));
1347 }
1348 }
1349
1350 public String getSelectedItem() {
1351 ListModel<PresetListEntry> lm = getModel();
1352 int[] si = getSelectedIndices();
1353 StringBuilder builder = new StringBuilder();
1354 for (int i=0; i<si.length; i++) {
1355 if (i>0) {
1356 builder.append(delimiter);
1357 }
1358 builder.append(lm.getElementAt(si[i]).value);
1359 }
1360 return builder.toString();
1361 }
1362 }
1363
1364 public static EnumSet<TaggingPresetType> getType(String types) throws SAXException {
1365 if (TYPE_CACHE.containsKey(types))
1366 return TYPE_CACHE.get(types);
1367 EnumSet<TaggingPresetType> result = EnumSet.noneOf(TaggingPresetType.class);
1368 for (String type : Arrays.asList(types.split(","))) {
1369 try {
1370 TaggingPresetType presetType = TaggingPresetType.fromString(type);
1371 result.add(presetType);
1372 } catch (IllegalArgumentException e) {
1373 throw new SAXException(tr("Unknown type: {0}", type), e);
1374 }
1375 }
1376 TYPE_CACHE.put(types, result);
1377 return result;
1378 }
1379
1380 static String fixPresetString(String s) {
1381 return s == null ? s : s.replaceAll("'","''");
1382 }
1383
1384 /**
1385 * allow escaped comma in comma separated list:
1386 * "A\, B\, C,one\, two" --&gt; ["A, B, C", "one, two"]
1387 * @param delimiter the delimiter, e.g. a comma. separates the entries and
1388 * must be escaped within one entry
1389 * @param s the string
1390 */
1391 private static String[] splitEscaped(char delimiter, String s) {
1392 if (s == null)
1393 return new String[0];
1394 List<String> result = new ArrayList<>();
1395 boolean backslash = false;
1396 StringBuilder item = new StringBuilder();
1397 for (int i=0; i<s.length(); i++) {
1398 char ch = s.charAt(i);
1399 if (backslash) {
1400 item.append(ch);
1401 backslash = false;
1402 } else if (ch == '\\') {
1403 backslash = true;
1404 } else if (ch == delimiter) {
1405 result.add(item.toString());
1406 item.setLength(0);
1407 } else {
1408 item.append(ch);
1409 }
1410 }
1411 if (item.length() > 0) {
1412 result.add(item.toString());
1413 }
1414 return result.toArray(new String[result.size()]);
1415 }
1416
1417
1418 static Usage determineTextUsage(Collection<OsmPrimitive> sel, String key) {
1419 Usage returnValue = new Usage();
1420 returnValue.values = new TreeSet<>();
1421 for (OsmPrimitive s : sel) {
1422 String v = s.get(key);
1423 if (v != null) {
1424 returnValue.values.add(v);
1425 } else {
1426 returnValue.hadEmpty = true;
1427 }
1428 if(s.hasKeys()) {
1429 returnValue.hadKeys = true;
1430 }
1431 }
1432 return returnValue;
1433 }
1434 static Usage determineBooleanUsage(Collection<OsmPrimitive> sel, String key) {
1435
1436 Usage returnValue = new Usage();
1437 returnValue.values = new TreeSet<>();
1438 for (OsmPrimitive s : sel) {
1439 String booleanValue = OsmUtils.getNamedOsmBoolean(s.get(key));
1440 if (booleanValue != null) {
1441 returnValue.values.add(booleanValue);
1442 }
1443 }
1444 return returnValue;
1445 }
1446 protected static ImageIcon loadImageIcon(String iconName, File zipIcons, Integer maxSize) {
1447 final Collection<String> s = Main.pref.getCollection("taggingpreset.icon.sources", null);
1448 ImageProvider imgProv = new ImageProvider(iconName).setDirs(s).setId("presets").setArchive(zipIcons).setOptional(true);
1449 if (maxSize != null) {
1450 imgProv.setMaxSize(maxSize);
1451 }
1452 return imgProv.get();
1453 }
1454}
Note: See TracBrowser for help on using the repository browser.