Changeset 2610 in josm for trunk/src/org
- Timestamp:
- 2009-12-11T22:33:14+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r2589 r2610 9 9 import java.awt.event.ActionEvent; 10 10 import java.awt.event.KeyEvent; 11 import java.awt.geom.Area; 11 12 import java.awt.geom.Line2D; 12 13 import java.util.ArrayList; … … 34 35 import org.openstreetmap.josm.command.DeleteCommand; 35 36 import org.openstreetmap.josm.command.SequenceCommand; 36 import org.openstreetmap.josm.data.Bounds;37 37 import org.openstreetmap.josm.data.UndoRedoHandler; 38 38 import org.openstreetmap.josm.data.coor.EastNorth; 39 39 import org.openstreetmap.josm.data.coor.LatLon; 40 40 import org.openstreetmap.josm.data.osm.DataSet; 41 import org.openstreetmap.josm.data.osm.DataSource;42 41 import org.openstreetmap.josm.data.osm.Node; 43 42 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 47 46 import org.openstreetmap.josm.data.osm.Way; 48 47 import org.openstreetmap.josm.gui.ExtendedDialog; 49 import org.openstreetmap.josm.gui.layer.OsmDataLayer;50 48 import org.openstreetmap.josm.tools.GBC; 51 49 import org.openstreetmap.josm.tools.Shortcut; … … 109 107 */ 110 108 public void actionPerformed(ActionEvent e) { 111 Collection<OsmPrimitive> selection = Main.main.getCurrentDataSet().getSelectedWays(); 112 113 int ways = 0; 114 Way[] selWays = new Way[2]; 115 116 LinkedList<Bounds> bounds = new LinkedList<Bounds>(); 117 OsmDataLayer dataLayer = Main.map.mapView.getEditLayer(); 118 for (DataSource ds : dataLayer.data.dataSources) { 119 if (ds.bounds != null) { 120 bounds.add(ds.bounds); 121 } 122 } 123 124 boolean askedAlready = false; 125 for (OsmPrimitive prim : selection) { 126 Way way = (Way) prim; 127 128 // Too many ways 129 if(ways == 2) { 130 JOptionPane.showMessageDialog(Main.parent, tr("Only up to two areas can be joined at the moment.")); 131 return; 132 } 133 109 LinkedList<Way> ways = new LinkedList<Way>(Main.main.getCurrentDataSet().getSelectedWays()); 110 111 if (ways.isEmpty()) { 112 JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one closed way that should be joined.")); 113 return; 114 } 115 116 // Too many ways 117 if(ways.size() > 2) { 118 JOptionPane.showMessageDialog(Main.parent, tr("Only up to two areas can be joined at the moment.")); 119 return; 120 } 121 122 List<Node> allNodes = new ArrayList<Node>(); 123 for (Way way: ways) { 134 124 if(!way.isClosed()) { 135 125 JOptionPane.showMessageDialog(Main.parent, tr("\"{0}\" is not closed and therefore can't be joined.", way.getName())); … … 137 127 } 138 128 139 // This is copied from SimplifyAction and should be probably ported to tools 140 for (Node node : way.getNodes()) { 141 if(askedAlready) { 142 break; 143 } 144 boolean isInsideOneBoundingBox = false; 145 for (Bounds b : bounds) { 146 if (b.contains(node.getCoor())) { 147 isInsideOneBoundingBox = true; 148 break; 149 } 150 } 151 152 if (!isInsideOneBoundingBox) { 129 allNodes.addAll(way.getNodes()); 130 } 131 132 // TODO: Only display this warning when nodes outside dataSourceArea are deleted 133 Area dataSourceArea = Main.main.getCurrentDataSet().getDataSourceArea(); 134 if (dataSourceArea != null) { 135 for (Node node: allNodes) { 136 if (!dataSourceArea.contains(node.getCoor())) { 153 137 int option = JOptionPane.showConfirmDialog(Main.parent, 154 138 tr("The selected way(s) have nodes outside of the downloaded data region.\n" … … 159 143 160 144 if (option != JOptionPane.YES_OPTION) return; 161 askedAlready = true;162 145 break; 163 146 } 164 147 } 165 166 selWays[ways] = way; 167 ways++; 168 } 169 170 if (ways < 1) { 171 JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one closed way the should be joined.")); 172 return; 173 } 174 175 if(joinAreas(selWays[0], selWays[ways == 2 ? 1 : 0])) { 148 } 149 150 if(joinAreas(ways.getFirst(), ways.getLast())) { 176 151 Main.map.mapView.repaint(); 177 152 DataSet ds = Main.main.getCurrentDataSet(); … … 459 434 ArrayList<RelationRole> result = new ArrayList<RelationRole>(); 460 435 for (Relation r : Main.main.getCurrentDataSet().getRelations()) { 461 if (r.isDeleted()) 436 if (r.isDeleted()) { 462 437 continue; 438 } 463 439 for (RelationMember rm : r.getMembers()) { 464 440 if (rm.getMember() != osm) { -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r2578 r2610 293 293 * Return selected nodes. 294 294 */ 295 public Collection< OsmPrimitive> getSelectedNodes() {295 public Collection<Node> getSelectedNodes() { 296 296 return getSelected(nodes); 297 297 } … … 300 300 * Return selected ways. 301 301 */ 302 public Collection< OsmPrimitive> getSelectedWays() {302 public Collection<Way> getSelectedWays() { 303 303 return getSelected(ways); 304 304 } … … 307 307 * Return selected relations. 308 308 */ 309 public Collection< OsmPrimitive> getSelectedRelations() {309 public Collection<Relation> getSelectedRelations() { 310 310 return getSelected(relations); 311 311 } … … 315 315 * @param list The collection from which the selected items are returned. 316 316 */ 317 private Collection<OsmPrimitive> getSelected(Collection<? extends OsmPrimitive> list) {317 private <T extends OsmPrimitive> Collection<T> getSelected(Collection<T> list) { 318 318 if (list == null) 319 return new LinkedList< OsmPrimitive>();319 return new LinkedList<T>(); 320 320 // getSelected() is called with large lists, so 321 321 // creating the return list from the selection 322 322 // should be faster most of the time. 323 Collection< OsmPrimitive> sel = new LinkedHashSet<OsmPrimitive>(selectedPrimitives);324 sel.retainAll( list);323 Collection<T> sel = new LinkedHashSet<T>(list); 324 sel.retainAll(selectedPrimitives); 325 325 return sel; 326 326 }
Note:
See TracChangeset
for help on using the changeset viewer.