Changeset 16690 in josm
- Timestamp:
- 2020-06-21T09:54:52+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItem.java
r16643 r16690 126 126 } 127 127 128 protected static ImageIcon loadImageIcon(String iconName, File zipIcons, Integer maxSize) { 128 /** 129 * Loads a tagging preset icon 130 * @param iconName the icon name 131 * @param zipIcons zip file where the image is located 132 * @param maxSize maximum image size (or null) 133 * @return the requested image or null if the request failed 134 */ 135 public static ImageIcon loadImageIcon(String iconName, File zipIcons, Integer maxSize) { 129 136 final Collection<String> s = Config.getPref().getList("taggingpreset.icon.sources", null); 130 137 ImageProvider imgProv = new ImageProvider(iconName).setDirs(s).setId("presets").setArchive(zipIcons).setOptional(true); -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReader.java
r16640 r16690 37 37 import org.openstreetmap.josm.gui.tagging.presets.items.Optional; 38 38 import org.openstreetmap.josm.gui.tagging.presets.items.PresetLink; 39 import org.openstreetmap.josm.gui.tagging.presets.items.PresetListEntry; 39 40 import org.openstreetmap.josm.gui.tagging.presets.items.Roles; 40 41 import org.openstreetmap.josm.gui.tagging.presets.items.Roles.Role; … … 151 152 parser.map("space", Space.class); 152 153 parser.map("key", Key.class); 153 parser.map("list_entry", ComboMultiSelect.PresetListEntry.class);154 parser.map("list_entry", PresetListEntry.class); 154 155 parser.map("item_separator", ItemSeparator.class); 155 156 parser.mapBoth("chunk", Chunk.class); … … 188 189 Roles lastrole = null; 189 190 final List<Check> checks = new LinkedList<>(); 190 final List< ComboMultiSelect.PresetListEntry> listEntries = new LinkedList<>();191 final List<PresetListEntry> listEntries = new LinkedList<>(); 191 192 final Map<String, List<Object>> byId = new HashMap<>(); 192 193 final Deque<String> lastIds = new ArrayDeque<>(); … … 299 300 all.getLast().data.add((TaggingPresetItem) o); 300 301 } 301 } else if (o instanceof ComboMultiSelect.PresetListEntry) {302 listEntries.add(( ComboMultiSelect.PresetListEntry) o);302 } else if (o instanceof PresetListEntry) { 303 listEntries.add((PresetListEntry) o); 303 304 } else if (o instanceof CheckGroup) { 304 305 CheckGroup cg = (CheckGroup) o; -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java
r16689 r16690 22 22 import java.util.stream.IntStream; 23 23 24 import javax.swing.ImageIcon;25 24 import javax.swing.JComponent; 26 25 import javax.swing.JLabel; … … 31 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 32 31 import org.openstreetmap.josm.data.osm.Tag; 33 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;34 32 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSelector; 35 33 import org.openstreetmap.josm.spi.preferences.Config; 36 import org.openstreetmap.josm.tools.AlphanumComparator;37 34 import org.openstreetmap.josm.tools.GBC; 38 35 import org.openstreetmap.josm.tools.Logging; … … 152 149 153 150 return lbl; 154 }155 }156 157 /**158 * Preset list entry.159 */160 public static class PresetListEntry implements Comparable<PresetListEntry> {161 /** Entry value */162 public String value; // NOSONAR163 /** The context used for translating {@link #value} */164 public String value_context; // NOSONAR165 /** Value displayed to the user */166 public String display_value; // NOSONAR167 /** Text to be displayed below {@code display_value}. */168 public String short_description; // NOSONAR169 /** The location of icon file to display */170 public String icon; // NOSONAR171 /** The size of displayed icon. If not set, default is size from icon file */172 public short icon_size; // NOSONAR173 /** The localized version of {@link #display_value}. */174 public String locale_display_value; // NOSONAR175 /** The localized version of {@link #short_description}. */176 public String locale_short_description; // NOSONAR177 178 /** Cached width (currently only for Combo) to speed up preset dialog initialization */179 public short preferredWidth = -1; // NOSONAR180 /** Cached height (currently only for Combo) to speed up preset dialog initialization */181 public short preferredHeight = -1; // NOSONAR182 183 /**184 * Constructs a new {@code PresetListEntry}, uninitialized.185 */186 public PresetListEntry() {187 // Public default constructor is needed188 }189 190 /**191 * Constructs a new {@code PresetListEntry}, initialized with a value.192 * @param value value193 */194 public PresetListEntry(String value) {195 this.value = value;196 }197 198 /**199 * Returns HTML formatted contents.200 * @return HTML formatted contents201 */202 public String getListDisplay() {203 if (value.equals(DIFFERENT))204 return "<b>" + Utils.escapeReservedCharactersHTML(DIFFERENT) + "</b>";205 206 String displayValue = Utils.escapeReservedCharactersHTML(getDisplayValue());207 String shortDescription = getShortDescription(true);208 209 if (displayValue.isEmpty() && (shortDescription == null || shortDescription.isEmpty()))210 return " ";211 212 final StringBuilder res = new StringBuilder("<b>").append(displayValue).append("</b>");213 if (shortDescription != null) {214 // wrap in table to restrict the text width215 res.append("<div style=\"width:300px; padding:0 0 5px 5px\">")216 .append(shortDescription)217 .append("</div>");218 }219 return res.toString();220 }221 222 /**223 * Returns the entry icon, if any.224 * @return the entry icon, or {@code null}225 */226 public ImageIcon getIcon() {227 return icon == null ? null : loadImageIcon(icon, TaggingPresetReader.getZipIcons(), (int) icon_size);228 }229 230 /**231 * Returns the value to display.232 * @return the value to display233 */234 public String getDisplayValue() {235 return Utils.firstNonNull(locale_display_value, tr(display_value), trc(value_context, value));236 }237 238 /**239 * Returns the short description to display.240 * @param translated whether the text must be translated241 * @return the short description to display242 */243 public String getShortDescription(boolean translated) {244 return translated245 ? Utils.firstNonNull(locale_short_description, tr(short_description))246 : short_description;247 }248 249 // toString is mainly used to initialize the Editor250 @Override251 public String toString() {252 if (DIFFERENT.equals(value))253 return DIFFERENT;254 String displayValue = getDisplayValue();255 return displayValue != null ? displayValue.replaceAll("<.*>", "") : ""; // remove additional markup, e.g. <br>256 }257 258 @Override259 public boolean equals(Object o) {260 if (this == o) return true;261 if (o == null || getClass() != o.getClass()) return false;262 PresetListEntry that = (PresetListEntry) o;263 return Objects.equals(value, that.value);264 }265 266 @Override267 public int hashCode() {268 return Objects.hash(value);269 }270 271 @Override272 public int compareTo(PresetListEntry o) {273 return AlphanumComparator.getInstance().compare(this.getDisplayValue(), o.getDisplayValue());274 151 } 275 152 } -
trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/items/PresetListEntryTest.java
r16689 r16690 7 7 import org.junit.Test; 8 8 import org.openstreetmap.josm.JOSMFixture; 9 import org.openstreetmap.josm.gui.tagging.presets.items.ComboMultiSelect.PresetListEntry;10 9 11 10 /** 12 * Unit tests of {@link ComboMultiSelect} class.11 * Unit tests of {@link PresetListEntry} class. 13 12 */ 14 public class ComboMultiSelectTest {13 public class PresetListEntryTest { 15 14 16 15 /**
Note:
See TracChangeset
for help on using the changeset viewer.