source: osm/applications/editors/josm/plugins/utilsplugin/UtilsPlugin/DeduplicateWayAction.java@ 5075

Last change on this file since 5075 was 5075, checked in by gabriel, 18 years ago

Import the latest upstream version of utilsplugin.

File size: 1.5 KB
Line 
1package UtilsPlugin;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.util.ArrayList;
6import java.util.LinkedList;
7import java.util.List;
8import java.util.Collection;
9
10import java.awt.event.ActionEvent;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.data.osm.Node;
15import org.openstreetmap.josm.data.osm.Segment;
16import org.openstreetmap.josm.data.osm.Way;
17import org.openstreetmap.josm.gui.MapFrame;
18import org.openstreetmap.josm.command.Command;
19import org.openstreetmap.josm.command.ChangeCommand;
20import org.openstreetmap.josm.command.SequenceCommand;
21
22import javax.swing.AbstractAction;
23
24class DeduplicateWayAction extends AbstractAction {
25 public DeduplicateWayAction() {
26 super("Deduplicate Way");
27 }
28 public void actionPerformed(ActionEvent e) {
29 Collection<OsmPrimitive> sel = Main.ds.getSelected();
30 Collection<Way> ways = new ArrayList<Way>();
31 for (OsmPrimitive osm : sel)
32 if (osm instanceof Way)
33 ways.add((Way)osm);
34
35 Collection<Command> cmds = new LinkedList<Command>();
36 for ( Way w : ways )
37 {
38 List<Segment> segs = new ArrayList<Segment>();
39
40 for ( Segment s : w.segments )
41 {
42 if( !segs.contains(s) )
43 segs.add(s);
44 }
45 if( segs.size() != w.segments.size() )
46 {
47 Way newway = new Way(w);
48 newway.segments.clear();
49 newway.segments.addAll(segs);
50 cmds.add(new ChangeCommand(w,newway));
51 }
52 }
53 if( cmds.size() != 0 )
54 Main.main.editLayer().add(new SequenceCommand(tr("Deduplicate Ways"), cmds));
55 Main.map.repaint();
56 }
57}
58
Note: See TracBrowser for help on using the repository browser.