Changeset 3504 in josm
- Timestamp:
- 2010-09-01T10:48:28+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r3445 r3504 57 57 } 58 58 59 protected boolean confirmChangeDirectionOfWays() {59 protected static boolean confirmChangeDirectionOfWays() { 60 60 ExtendedDialog ed = new ExtendedDialog(Main.parent, 61 61 tr("Change directions?"), … … 68 68 } 69 69 70 protected void warnCombiningImpossible() {70 protected static void warnCombiningImpossible() { 71 71 String msg = tr("Could not combine ways " 72 72 + "(They could not be merged into a single string of nodes)"); … … 80 80 } 81 81 82 protected Way getTargetWay(Collection<Way> combinedWays) {82 protected static Way getTargetWay(Collection<Way> combinedWays) { 83 83 // init with an arbitrary way 84 84 Way targetWay = combinedWays.iterator().next(); … … 100 100 * @return the set of referring relations 101 101 */ 102 p rotectedSet<Relation> getParentRelations(Collection<Way> ways) {102 public static Set<Relation> getParentRelations(Collection<Way> ways) { 103 103 HashSet<Relation> ret = new HashSet<Relation>(); 104 104 for (Way w: ways) { … … 108 108 } 109 109 110 public Way combineWays(Collection<Way> ways) { 110 @Deprecated 111 public static Way combineWays(Collection<Way> ways) { 112 Pair<Way, Command> combineResult; 113 try { 114 combineResult = combineWaysWorker(ways); 115 } catch (UserCancelException ex) { 116 return null; 117 } 118 return combineResult.a; 119 } 120 121 /** 122 * @param ways 123 * @return null if ways cannot be combined. Otherwise returns the combined 124 * ways and the commands to combine 125 * @throws UserCancelException 126 */ 127 public static Pair<Way, Command> combineWaysWorker(Collection<Way> ways) throws UserCancelException { 111 128 112 129 // prepare and clean the list of ways to combine … … 170 187 Way wnew = new Way(w); 171 188 reversedTagWays.add(wnew); 172 try { 173 changePropertyCommands = reverseWayTagCorrector.execute(w, wnew); 174 } 175 catch(UserCancelException ex) { 176 return null; 177 } 189 changePropertyCommands = reverseWayTagCorrector.execute(w, wnew); 178 190 } 179 191 if ((changePropertyCommands != null) && !changePropertyCommands.isEmpty()) { … … 214 226 dialog.setVisible(true); 215 227 if (dialog.isCancelled()) 216 return null;228 throw new UserCancelException(); 217 229 } 218 230 … … 225 237 cmds.add(new DeleteCommand(deletedWays)); 226 238 final SequenceCommand sequenceCommand = new SequenceCommand(tr("Combine {0} ways", ways.size()), cmds); 227 Main.main.undoRedo.add(sequenceCommand); 228 229 return targetWay; 239 240 return new Pair<Way, Command>(targetWay, sequenceCommand); 230 241 } 231 242 … … 245 256 } 246 257 // combine and update gui 247 final Way selectedWay = combineWays(selectedWays); 258 Pair<Way, Command> combineResult; 259 try { 260 combineResult = combineWaysWorker(selectedWays); 261 } catch (UserCancelException ex) { 262 return; 263 } 264 265 if (combineResult == null) 266 return; 267 final Way selectedWay = combineResult.a; 268 Main.main.undoRedo.add(combineResult.b); 248 269 if(selectedWay != null) 249 270 { -
trunk/src/org/openstreetmap/josm/actions/JosmAction.java
r3444 r3504 179 179 * Override in subclasses to update the enabled state of the action if the 180 180 * collection of selected primitives changes. This method is called with the 181 * new selection. Avoid calling getCurrentDataSet().getSelected() because this 182 * loops over the complete data set. 183 * 184 * @param selection the collection of selected primitives 181 * new selection. 182 * 183 * @param selection the collection of selected primitives; may be empty, but not null 185 184 * 186 185 * @see #updateEnabledState() -
trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java
r2633 r3504 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.KeyEvent; 9 import java.util.ArrayList; 9 10 import java.util.Collection; 10 11 import java.util.Collections; … … 24 25 import org.openstreetmap.josm.data.osm.Way; 25 26 import org.openstreetmap.josm.tools.Shortcut; 27 import org.openstreetmap.josm.tools.Utils; 26 28 27 29 public final class ReverseWayAction extends JosmAction { 30 31 public static class ReverseWayResult { 32 private Way newWay; 33 private Collection<Command> tagCorrectionCommands; 34 private Command reverseCommand; 35 36 public ReverseWayResult(Way newWay, Collection<Command> tagCorrectionCommands, Command reverseCommand) { 37 this.newWay = newWay; 38 this.tagCorrectionCommands = tagCorrectionCommands; 39 this.reverseCommand = reverseCommand; 40 } 41 42 public Way getNewWay() { 43 return newWay; 44 } 45 46 public Collection<Command> getCommands() { 47 List<Command> c = new ArrayList<Command>(); 48 c.addAll(tagCorrectionCommands); 49 c.add(reverseCommand); 50 return c; 51 } 52 53 public Command getAsSequenceCommand() { 54 return new SequenceCommand(tr("Reverse way"), getCommands()); 55 } 56 57 public Command getReverseCommand() { 58 return reverseCommand; 59 } 60 61 public Collection<Command> getTagCorrectionCommands() { 62 return tagCorrectionCommands; 63 } 64 } 28 65 29 66 public ReverseWayAction() { 30 67 super(tr("Reverse Ways"), "wayflip", tr("Reverse the direction of all selected ways."), 31 68 Shortcut.registerShortcut("tools:reverse", tr("Tool: {0}", tr("Reverse Ways")), KeyEvent.VK_R, Shortcut.GROUP_EDIT), true); 32 putValue("help", ht("/Action/ReverseWay "));69 putValue("help", ht("/Action/ReverseWays")); 33 70 } 34 71 … … 51 88 52 89 boolean propertiesUpdated = false; 53 ReverseWayTagCorrector reverseWayTagCorrector = new ReverseWayTagCorrector();54 90 Collection<Command> c = new LinkedList<Command>(); 55 91 for (Way w : sel) { 56 Way wnew = new Way(w); 57 List<Node> nodesCopy = wnew.getNodes(); 58 Collections.reverse(nodesCopy); 59 wnew.setNodes(nodesCopy); 60 if (Main.pref.getBoolean("tag-correction.reverse-way", true)) { 61 try 62 { 63 final Collection<Command> changePropertyCommands = reverseWayTagCorrector.execute(w, wnew); 64 propertiesUpdated = propertiesUpdated 65 || (changePropertyCommands != null && !changePropertyCommands.isEmpty()); 66 c.addAll(changePropertyCommands); 67 } 68 catch(UserCancelException ex) 69 { 70 return; 71 } 92 ReverseWayResult revResult; 93 try { 94 revResult = reverseWay(w); 95 } catch (UserCancelException ex) { 96 return; 72 97 } 73 c.add(new ChangeCommand(w, wnew)); 98 c.addAll(revResult.getCommands()); 99 propertiesUpdated |= !revResult.getTagCorrectionCommands().isEmpty(); 74 100 } 75 101 Main.main.undoRedo.add(new SequenceCommand(tr("Reverse ways"), c)); … … 78 104 } 79 105 Main.map.repaint(); 106 } 107 108 /** 109 * @param w the way 110 * @return the reverse command and the tag correction commands 111 */ 112 public static ReverseWayResult reverseWay(Way w) throws UserCancelException { 113 Way wnew = new Way(w); 114 List<Node> nodesCopy = wnew.getNodes(); 115 Collections.reverse(nodesCopy); 116 wnew.setNodes(nodesCopy); 117 118 Collection<Command> corrCmds = Collections.<Command>emptyList(); 119 if (Main.pref.getBoolean("tag-correction.reverse-way", true)) { 120 corrCmds = (new ReverseWayTagCorrector()).execute(w, wnew); 121 } 122 return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w, wnew)); 80 123 } 81 124 … … 102 145 @Override 103 146 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 104 if (selection == null) { 105 setEnabled(false); 106 return; 107 } 108 int n = 0; 109 for (OsmPrimitive primitive : selection) { 110 if (primitive instanceof Way) { 111 n++; 112 } 113 } 114 setEnabled(n > 0); 147 setEnabled(Utils.exists(selection, OsmPrimitive.wayPredicate)); 115 148 } 116 149 } -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r3503 r3504 346 346 /** 347 347 * Replies an unmodifiable collection of primitives currently selected 348 * in this dataset 348 * in this dataset. May be empty, but not null. 349 349 * 350 350 * @return unmodifiable collection of primitives -
trunk/src/org/openstreetmap/josm/data/osm/Storage.java
r3503 r3504 132 132 * modify, but the read-only iteration will happen on a copy 133 133 * of the unmodified Storage. 134 * This is similar to CopyOnWriteArrayList. 134 135 */ 135 136 public Storage(Hash<? super T, ? super T> ha, int capacity, boolean safeIterator) {
Note:
See TracChangeset
for help on using the changeset viewer.