Changeset 9594 in josm for trunk/src


Ignore:
Timestamp:
2016-01-23T22:22:49+01:00 (4 years ago)
Author:
Don-vip
Message:

add unit test for SelectByInternalPointAction

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

Legend:

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

    r8957 r9594  
    213213
    214214    /**
    215      * Replies the current dataset
     215     * Replies the current dataset.
    216216     *
    217217     * @return the current dataset. null, if no current dataset exists
    218218     */
    219     protected static DataSet getCurrentDataSet() {
     219    public static DataSet getCurrentDataSet() {
    220220        return Main.main != null ? Main.main.getCurrentDataSet() : null;
    221221    }
  • trunk/src/org/openstreetmap/josm/actions/SelectByInternalPointAction.java

    r9183 r9594  
    22package org.openstreetmap.josm.actions;
    33
    4 import java.awt.event.ActionEvent;
    54import java.util.ArrayList;
    65import java.util.Collection;
     
    2423 * @since 7144
    2524 */
    26 public class SelectByInternalPointAction extends JosmAction {
     25public final class SelectByInternalPointAction {
     26
     27    private SelectByInternalPointAction() {
     28        // Hide public constructor for utility class
     29    }
    2730
    2831    /**
     
    3538     */
    3639    public static Collection<OsmPrimitive> getSurroundingObjects(EastNorth internalPoint) {
    37         final DataSet ds = getCurrentDataSet();
     40        final DataSet ds = JosmAction.getCurrentDataSet();
    3841        if (ds == null) {
    3942            return Collections.emptySet();
     
    4245        final Map<Double, OsmPrimitive> found = new TreeMap<>();
    4346        for (Way w : ds.getWays()) {
    44             if (w.isUsable() && w.isClosed() && w.isSelectable()) {
    45                 if (Geometry.nodeInsidePolygon(n, w.getNodes())) {
    46                     found.put(Geometry.closedWayArea(w), w);
    47                 }
     47            if (w.isUsable() && w.isClosed() && w.isSelectable() && Geometry.nodeInsidePolygon(n, w.getNodes())) {
     48                found.put(Geometry.closedWayArea(w), w);
    4849            }
    4950        }
    5051        for (Relation r : ds.getRelations()) {
    51             if (r.isUsable() && r.isMultipolygon() && r.isSelectable()) {
    52                 if (Geometry.isNodeInsideMultiPolygon(n, r, null)) {
    53                     for (RelationMember m : r.getMembers()) {
    54                         if (m.isWay() && m.getWay().isClosed()) {
    55                             found.values().remove(m.getWay());
    56                         }
     52            if (r.isUsable() && r.isMultipolygon() && r.isSelectable() && Geometry.isNodeInsideMultiPolygon(n, r, null)) {
     53                for (RelationMember m : r.getMembers()) {
     54                    if (m.isWay() && m.getWay().isClosed()) {
     55                        found.values().remove(m.getWay());
    5756                    }
    58                     // estimate multipolygon size by its bounding box area
    59                     BBox bBox = r.getBBox();
    60                     EastNorth en1 = Main.map.mapView.getProjection().latlon2eastNorth(bBox.getTopLeft());
    61                     EastNorth en2 = Main.map.mapView.getProjection().latlon2eastNorth(bBox.getBottomRight());
    62                     double s = Math.abs((en1.east() - en2.east()) * (en1.north() - en2.north()));
    63                     if (s == 0) s = 1e8;
    64                     found.put(s, r);
    6557                }
     58                // estimate multipolygon size by its bounding box area
     59                BBox bBox = r.getBBox();
     60                EastNorth en1 = Main.map.mapView.getProjection().latlon2eastNorth(bBox.getTopLeft());
     61                EastNorth en2 = Main.map.mapView.getProjection().latlon2eastNorth(bBox.getBottomRight());
     62                double s = Math.abs((en1.east() - en2.east()) * (en1.north() - en2.north()));
     63                found.put(s <= 0 ? 1e8 : s, r);
    6664            }
    6765        }
     
    8987    public static void performSelection(EastNorth internalPoint, boolean doAdd, boolean doRemove) {
    9088        final Collection<OsmPrimitive> surroundingObjects = getSurroundingObjects(internalPoint);
     89        final DataSet ds = JosmAction.getCurrentDataSet();
    9190        if (surroundingObjects.isEmpty()) {
    9291            return;
    9392        } else if (doRemove) {
    94             final Collection<OsmPrimitive> newSelection = new ArrayList<>(getCurrentDataSet().getSelected());
     93            final Collection<OsmPrimitive> newSelection = new ArrayList<>(ds.getSelected());
    9594            newSelection.removeAll(surroundingObjects);
    96             getCurrentDataSet().setSelected(newSelection);
     95            ds.setSelected(newSelection);
    9796        } else if (doAdd) {
    98             final Collection<OsmPrimitive> newSelection = new ArrayList<>(getCurrentDataSet().getSelected());
     97            final Collection<OsmPrimitive> newSelection = new ArrayList<>(ds.getSelected());
    9998            newSelection.add(surroundingObjects.iterator().next());
    100             getCurrentDataSet().setSelected(newSelection);
     99            ds.setSelected(newSelection);
    101100        } else {
    102             getCurrentDataSet().setSelected(surroundingObjects.iterator().next());
     101            ds.setSelected(surroundingObjects.iterator().next());
    103102        }
    104103    }
    105 
    106     @Override
    107     public void actionPerformed(ActionEvent e) {
    108         throw new UnsupportedOperationException();
    109     }
    110104}
Note: See TracChangeset for help on using the changeset viewer.