Changeset 2610 in josm for trunk/src


Ignore:
Timestamp:
2009-12-11T22:33:14+01:00 (12 years ago)
Author:
mjulius
Message:

Fixes #4115 - bogus warning about nodes outside download area in JoinAreasAction
DataSet.getSelected*() now return collections of the proper primitive type

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r2589 r2610  
    99import java.awt.event.ActionEvent;
    1010import java.awt.event.KeyEvent;
     11import java.awt.geom.Area;
    1112import java.awt.geom.Line2D;
    1213import java.util.ArrayList;
     
    3435import org.openstreetmap.josm.command.DeleteCommand;
    3536import org.openstreetmap.josm.command.SequenceCommand;
    36 import org.openstreetmap.josm.data.Bounds;
    3737import org.openstreetmap.josm.data.UndoRedoHandler;
    3838import org.openstreetmap.josm.data.coor.EastNorth;
    3939import org.openstreetmap.josm.data.coor.LatLon;
    4040import org.openstreetmap.josm.data.osm.DataSet;
    41 import org.openstreetmap.josm.data.osm.DataSource;
    4241import org.openstreetmap.josm.data.osm.Node;
    4342import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    4746import org.openstreetmap.josm.data.osm.Way;
    4847import org.openstreetmap.josm.gui.ExtendedDialog;
    49 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5048import org.openstreetmap.josm.tools.GBC;
    5149import org.openstreetmap.josm.tools.Shortcut;
     
    109107     */
    110108    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) {
    134124            if(!way.isClosed()) {
    135125                JOptionPane.showMessageDialog(Main.parent, tr("\"{0}\" is not closed and therefore can't be joined.", way.getName()));
     
    137127            }
    138128
    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())) {
    153137                    int option = JOptionPane.showConfirmDialog(Main.parent,
    154138                            tr("The selected way(s) have nodes outside of the downloaded data region.\n"
     
    159143
    160144                    if (option != JOptionPane.YES_OPTION) return;
    161                     askedAlready = true;
    162145                    break;
    163146                }
    164147            }
    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())) {
    176151            Main.map.mapView.repaint();
    177152            DataSet ds = Main.main.getCurrentDataSet();
     
    459434        ArrayList<RelationRole> result = new ArrayList<RelationRole>();
    460435        for (Relation r : Main.main.getCurrentDataSet().getRelations()) {
    461             if (r.isDeleted())
     436            if (r.isDeleted()) {
    462437                continue;
     438            }
    463439            for (RelationMember rm : r.getMembers()) {
    464440                if (rm.getMember() != osm) {
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2578 r2610  
    293293     * Return selected nodes.
    294294     */
    295     public Collection<OsmPrimitive> getSelectedNodes() {
     295    public Collection<Node> getSelectedNodes() {
    296296        return getSelected(nodes);
    297297    }
     
    300300     * Return selected ways.
    301301     */
    302     public Collection<OsmPrimitive> getSelectedWays() {
     302    public Collection<Way> getSelectedWays() {
    303303        return getSelected(ways);
    304304    }
     
    307307     * Return selected relations.
    308308     */
    309     public Collection<OsmPrimitive> getSelectedRelations() {
     309    public Collection<Relation> getSelectedRelations() {
    310310        return getSelected(relations);
    311311    }
     
    315315     * @param list The collection from which the selected items are returned.
    316316     */
    317     private Collection<OsmPrimitive> getSelected(Collection<? extends OsmPrimitive> list) {
     317    private <T extends OsmPrimitive> Collection<T> getSelected(Collection<T> list) {
    318318        if (list == null)
    319             return new LinkedList<OsmPrimitive>();
     319            return new LinkedList<T>();
    320320        // getSelected() is called with large lists, so
    321321        // creating the return list from the selection
    322322        // 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);
    325325        return sel;
    326326    }
Note: See TracChangeset for help on using the changeset viewer.