Changeset 10590 in josm
- Timestamp:
- 2016-07-22T23:20:40+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r10346 r10590 313 313 private final QuadBuckets<Node> nodes = new QuadBuckets<>(); 314 314 315 private <T extends OsmPrimitive> Collection<T> getPrimitives(Predicate<? super OsmPrimitive> predicate) { 315 /** 316 * Gets a filtered collection of primitives matching the given predicate. 317 * @param <T> The primitive type. 318 * @param predicate The predicate to match 319 * @return The list of primtives. 320 * @since 10590 321 */ 322 public <T extends OsmPrimitive> Collection<T> getPrimitives(java.util.function.Predicate<? super OsmPrimitive> predicate) { 316 323 return new SubclassFilteredCollection<>(allPrimitives, predicate); 317 324 } -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
r10446 r10590 86 86 public static final String PRESET_ICON_ERROR_MSG_PREFIX = "Could not get presets icon "; 87 87 88 /** 89 * The preset group this preset belongs to. 90 */ 88 91 public TaggingPresetMenu group; 92 93 /** 94 * The name of the tagging preset. 95 * @see #getRawName() 96 */ 89 97 public String name; 98 /** 99 * The icon name that was used for this preset. 100 */ 90 101 public String iconName; 91 102 public String name_context; 103 /** 104 * A cache for the local name. Should never be accessed directly. 105 * @see #getLocaleName() 106 */ 92 107 public String locale_name; 93 108 public boolean preset_name_label; … … 128 143 } 129 144 145 /** 146 * Gets the localized version of the name 147 * @return The name that should be displayed to the user. 148 */ 130 149 public String getLocaleName() { 131 150 if (locale_name == null) { … … 189 208 public void finished(final ImageResource result) { 190 209 if (result != null) { 191 GuiHelper.runInEDT(new Runnable() { 192 @Override 193 public void run() { 194 result.attachImageIcon(TaggingPreset.this); 195 } 196 }); 210 GuiHelper.runInEDT(() -> result.attachImageIcon(TaggingPreset.this)); 197 211 } else { 198 212 Main.warn(TaggingPreset.this + ": " + PRESET_ICON_ERROR_MSG_PREFIX + iconName); … … 386 400 members.add(rm); 387 401 } 388 SwingUtilities.invokeLater(new Runnable() { 389 @Override 390 public void run() { 391 RelationEditor.getEditor(Main.getLayerManager().getEditLayer(), r, members).setVisible(true); 392 } 393 }); 402 SwingUtilities.invokeLater(() -> RelationEditor.getEditor(Main.getLayerManager().getEditLayer(), r, members).setVisible(true)); 394 403 } 395 404 ds.setSelected(ds.getSelected()); // force update -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetHandler.java
r8863 r10590 8 8 import org.openstreetmap.josm.data.osm.Tag; 9 9 10 /** 11 * This interface needs to be implemented in order to display a tagging preset. It allows the preset dialog to query the primitives it should 12 * be displayed for and modify them. 13 */ 10 14 public interface TaggingPresetHandler { 15 /** 16 * Gets the selection the preset should be applied to. 17 * @return A collection of primitives. 18 */ 11 19 Collection<OsmPrimitive> getSelection(); 12 20 21 /** 22 * Update the given tags on the selection. 23 * @param tags The tags to update. 24 */ 13 25 void updateTags(List<Tag> tags); 14 26 } -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetListener.java
r8863 r10590 5 5 * Notification of tagging presets events. 6 6 * @since 7100 7 * @see TaggingPresets#addListener(TaggingPresetListener) 7 8 */ 9 @FunctionalInterface 8 10 public interface TaggingPresetListener { 9 11 -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReader.java
r10378 r10590 44 44 import org.openstreetmap.josm.io.UTFInputStreamReader; 45 45 import org.openstreetmap.josm.tools.Predicates; 46 import org.openstreetmap.josm.tools.Utils;47 46 import org.openstreetmap.josm.tools.XmlObjectParser; 48 47 import org.xml.sax.SAXException; … … 227 226 if (all.contains(tp)) { 228 227 lastmenuOriginal = tp; 229 tp = (TaggingPresetMenu) Utils.filter(all, Predicates.<TaggingPreset>equalTo(tp)).iterator().next();228 tp = (TaggingPresetMenu) all.stream().filter(Predicates.equalTo(tp)).findFirst().get(); 230 229 lastmenuOriginal.group = null; 231 230 } else { -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java
r9422 r10590 5 5 6 6 import java.awt.event.ActionEvent; 7 import java.awt.event.ActionListener;8 7 9 8 import org.openstreetmap.josm.Main; … … 37 36 setContent(selector, false); 38 37 DataSet.addSelectionListener(selector); 39 selector.setDblClickListener(new ActionListener() { 40 @Override 41 public void actionPerformed(ActionEvent e) { 42 buttonAction(0, null); 43 } 44 }); 38 selector.setDblClickListener(e -> buttonAction(0, null)); 45 39 } 46 40 -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java
r10453 r10590 5 5 6 6 import java.awt.event.ActionEvent; 7 import java.awt.event.ActionListener;8 7 import java.awt.event.KeyEvent; 9 8 import java.util.HashSet; … … 15 14 import org.openstreetmap.josm.gui.ExtendedDialog; 16 15 import org.openstreetmap.josm.tools.Shortcut; 17 import org.openstreetmap.josm.tools.Utils;18 16 19 17 /** … … 71 69 selector = new TaggingPresetSelector(false, false); 72 70 setContent(selector, false); 73 selector.setDblClickListener(new ActionListener() { 74 @Override 75 public void actionPerformed(ActionEvent e) { 76 buttonAction(0, null); 77 } 78 }); 71 selector.setDblClickListener(e -> buttonAction(0, null)); 79 72 } 80 73 … … 93 86 TaggingPreset preset = selector.getSelectedPresetAndUpdateClassification(); 94 87 if (preset != null) { 95 final Set<OsmPrimitive> matching = new HashSet<>(Utils.filter(Main.getLayerManager().getEditDataSet().allPrimitives(), preset)); 88 89 final Set<OsmPrimitive> matching = new HashSet<>(Main.getLayerManager().getEditDataSet().getPrimitives(preset)); 96 90 Main.getLayerManager().getEditDataSet().setSelected(matching); 97 91 } -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSelector.java
r10446 r10590 8 8 import java.awt.Dimension; 9 9 import java.awt.event.ActionEvent; 10 import java.awt.event.ItemEvent;11 import java.awt.event.ItemListener;12 10 import java.util.ArrayList; 13 11 import java.util.Collection; … … 47 45 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 48 46 import org.openstreetmap.josm.gui.widgets.SearchTextResultListPanel; 49 import org.openstreetmap.josm.tools.Predicate;50 47 import org.openstreetmap.josm.tools.Utils; 51 48 … … 189 186 ckOnlyApplicable.setText(tr("Show only applicable to selection")); 190 187 pnChecks.add(ckOnlyApplicable); 191 ckOnlyApplicable.addItemListener(new ItemListener() { 192 @Override 193 public void itemStateChanged(ItemEvent e) { 194 filterItems(); 195 } 196 }); 188 ckOnlyApplicable.addItemListener(e -> filterItems()); 197 189 } else { 198 190 ckOnlyApplicable = null; … … 203 195 ckSearchInTags.setText(tr("Search in tags")); 204 196 ckSearchInTags.setSelected(SEARCH_IN_TAGS.get()); 205 ckSearchInTags.addItemListener(new ItemListener() { 206 @Override 207 public void itemStateChanged(ItemEvent e) { 208 filterItems(); 209 } 210 }); 197 ckSearchInTags.addItemListener(e -> filterItems()); 211 198 pnChecks.add(ckSearchInTags); 212 199 } else { … … 247 234 248 235 final TaggingPreset oldPreset = getSelectedPreset(); 249 lsResultModel.setItems(Utils.transform(result, new Utils.Function<PresetClassification, TaggingPreset>() { 250 @Override 251 public TaggingPreset apply(PresetClassification x) { 252 return x.preset; 253 } 254 })); 236 lsResultModel.setItems(Utils.transform(result, x -> x.preset)); 255 237 final TaggingPreset newPreset = getSelectedPreset(); 256 238 if (!Objects.equals(oldPreset, newPreset)) { … … 299 281 if (!suitable && preset.types.contains(TaggingPresetType.RELATION) 300 282 && preset.roles != null && !preset.roles.roles.isEmpty()) { 301 final Predicate<Role> memberExpressionMatchesOnePrimitive = new Predicate<Role>() { 302 @Override 303 public boolean evaluate(Role object) { 304 return object.memberExpression != null 305 && Utils.exists(selectedPrimitives, object.memberExpression); 306 } 307 }; 308 suitable = Utils.exists(preset.roles.roles, memberExpressionMatchesOnePrimitive); 283 suitable = preset.roles.roles.stream().anyMatch( 284 object -> object.memberExpression != null && Utils.exists(selectedPrimitives, object.memberExpression)); 309 285 // keep the preset to allow the creation of new relations 310 286 } -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresets.java
r9266 r10590 15 15 import org.openstreetmap.josm.gui.MenuScroller; 16 16 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 17 import org.openstreetmap.josm.tools.Predicate; 18 import org.openstreetmap.josm.tools.Utils; 17 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 19 18 20 19 /** … … 108 107 public static Collection<TaggingPreset> getMatchingPresets(final Collection<TaggingPresetType> t, 109 108 final Map<String, String> tags, final boolean onlyShowable) { 110 return Utils.filter(getTaggingPresets(), new Predicate<TaggingPreset>() { 111 @Override 112 public boolean evaluate(TaggingPreset object) { 113 return object.matches(t, tags, onlyShowable); 114 } 115 }); 109 return SubclassFilteredCollection.filter(getTaggingPresets(), preset -> preset.matches(t, tags, onlyShowable)); 116 110 } 117 111 … … 125 119 */ 126 120 public static Collection<TaggingPreset> getMatchingPresets(final OsmPrimitive primitive) { 127 return Utils.filter(getTaggingPresets(), new Predicate<TaggingPreset>() { 128 @Override 129 public boolean evaluate(TaggingPreset object) { 130 return object.evaluate(primitive); 131 } 132 }); 121 return SubclassFilteredCollection.filter(getTaggingPresets(), preset -> preset.evaluate(primitive)); 133 122 } 134 123 -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java
r10420 r10590 21 21 import java.util.Set; 22 22 import java.util.TreeSet; 23 import java.util.stream.Collectors; 23 24 24 25 import javax.swing.ImageIcon; … … 365 366 public Collection<String> getDisplayValues() { 366 367 initListEntries(); 367 return Utils.transform(lhm.values(), new Utils.Function<PresetListEntry, String>() { 368 @Override 369 public String apply(PresetListEntry x) { 370 return x.getDisplayValue(true); 371 } 372 }); 368 return lhm.values().stream().map(x -> x.getDisplayValue(true)).collect(Collectors.toList()); 373 369 } 374 370 375 371 @Override 376 372 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) { 377 378 373 initListEntries(); 379 374 -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/KeyedItem.java
r9665 r10590 8 8 import java.util.HashMap; 9 9 import java.util.Map; 10 import java.util.NoSuchElementException; 10 11 import java.util.SortedSet; 11 12 import java.util.TreeSet; … … 92 93 } 93 94 95 /** 96 * Usage information on a 97 */ 94 98 protected static class Usage { 95 public SortedSet<String> values; // NOSONAR 99 /** 100 * A set of values that were used for this key. 101 */ 102 public final SortedSet<String> values = new TreeSet<>();; // NOSONAR 96 103 private boolean hadKeys; 97 104 private boolean hadEmpty; 98 105 106 /** 107 * Check if there is exactly one value for this key. 108 * @return <code>true</code> if there was exactly one value. 109 */ 99 110 public boolean hasUniqueValue() { 100 111 return values.size() == 1 && !hadEmpty; 101 112 } 102 113 114 /** 115 * Check if this key was not used in any primitive 116 * @return <code>true</code> if it was unused. 117 */ 103 118 public boolean unused() { 104 119 return values.isEmpty(); 105 120 } 106 121 122 /** 123 * Get the first value available. 124 * @return The first value 125 * @throws NoSuchElementException if there is no such value. 126 */ 107 127 public String getFirst() { 108 128 return values.first(); 109 129 } 110 130 131 /** 132 * Check if we encountered any primitive that had any keys 133 * @return <code>true</code> if any of the primtives had any tags. 134 */ 111 135 public boolean hadKeys() { 112 136 return hadKeys; … … 116 140 protected static Usage determineTextUsage(Collection<OsmPrimitive> sel, String key) { 117 141 Usage returnValue = new Usage(); 118 returnValue.values = new TreeSet<>();119 142 for (OsmPrimitive s : sel) { 120 143 String v = s.get(key); … … 132 155 133 156 protected static Usage determineBooleanUsage(Collection<OsmPrimitive> sel, String key) { 134 135 157 Usage returnValue = new Usage(); 136 returnValue.values = new TreeSet<>();137 158 for (OsmPrimitive s : sel) { 138 159 String booleanValue = OsmUtils.getNamedOsmBoolean(s.get(key)); -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java
r9665 r10590 6 6 import java.util.Collection; 7 7 import java.util.List; 8 import java.util.Optional; 8 9 9 10 import javax.swing.JLabel; … … 17 18 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 18 19 import org.openstreetmap.josm.tools.GBC; 19 import org.openstreetmap.josm.tools.Predicate;20 import org.openstreetmap.josm.tools.Utils;21 20 22 21 /** … … 32 31 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) { 33 32 final String presetName = preset_name; 34 final TaggingPreset t = Utils.filter(TaggingPresets.getTaggingPresets(), new Predicate<TaggingPreset>() { 35 @Override 36 public boolean evaluate(TaggingPreset object) { 37 return presetName.equals(object.name); 38 } 39 }).iterator().next(); 40 if (t == null) 33 Optional<TaggingPreset> found = TaggingPresets.getTaggingPresets().stream().filter(preset -> presetName.equals(preset.name)).findFirst(); 34 if (!found.isPresent()) 41 35 return false; 36 TaggingPreset t = found.get(); 42 37 JLabel lbl = new TaggingPresetLabel(t); 43 38 lbl.addMouseListener(new MouseAdapter() { -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Text.java
r10378 r10590 7 7 import java.awt.GridBagLayout; 8 8 import java.awt.Insets; 9 import java.awt.event.ActionEvent;10 import java.awt.event.ActionListener;11 9 import java.text.NumberFormat; 12 10 import java.text.ParseException; … … 143 141 final int buttonvalue = (NumberFormat.getIntegerInstance().parse(ai.replace("+", ""))).intValue(); 144 142 if (auto_increment_selected == buttonvalue) aibutton.setSelected(true); 145 aibutton.addActionListener(new ActionListener() { 146 @Override 147 public void actionPerformed(ActionEvent e) { 148 auto_increment_selected = buttonvalue; 149 } 150 }); 143 aibutton.addActionListener(e -> auto_increment_selected = buttonvalue); 151 144 pnl.add(aibutton, GBC.std()); 152 145 } catch (ParseException x) { … … 167 160 releasebutton.setMargin(new Insets(0, 0, 0, 0)); 168 161 releasebutton.setFocusable(false); 169 releasebutton.addActionListener(new ActionListener() { 170 @Override 171 public void actionPerformed(ActionEvent e) { 172 auto_increment_selected = 0; 173 clearbutton.setSelected(true); 174 } 162 releasebutton.addActionListener(e -> { 163 auto_increment_selected = 0; 164 clearbutton.setSelected(true); 175 165 }); 176 166 saveHorizontalSpace(releasebutton);
Note:
See TracChangeset
for help on using the changeset viewer.