Ignore:
Timestamp:
2009-07-19T19:04:49+02:00 (17 years ago)
Author:
Gubaer
Message:

removed dependencies to Main.ds, removed Main.ds
removed AddVisitor, NameVisitor, DeleteVisitor - unnecessary double dispatching for these simple cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r1797 r1814  
    2727import org.openstreetmap.josm.data.osm.WaySegment;
    2828import org.openstreetmap.josm.data.projection.Projection;
    29 import org.openstreetmap.josm.data.projection.Mercator;
    3029
    3130/**
     
    5554    }
    5655
    57     protected DataSet getData()
    58     {
    59         return Main.ds;
     56    protected DataSet getCurrentDataSet() {
     57        return Main.main.getCurrentDataSet();
    6058    }
    6159
     
    102100    public ProjectionBounds getProjectionBounds() {
    103101        return new ProjectionBounds(
    104         new EastNorth(
    105                 center.east() - getWidth()/2.0*scale,
    106                 center.north() - getHeight()/2.0*scale),
    107         new EastNorth(
    108                 center.east() + getWidth()/2.0*scale,
    109                 center.north() + getHeight()/2.0*scale));
     102                new EastNorth(
     103                        center.east() - getWidth()/2.0*scale,
     104                        center.north() - getHeight()/2.0*scale),
     105                        new EastNorth(
     106                                center.east() + getWidth()/2.0*scale,
     107                                center.north() + getHeight()/2.0*scale));
    110108    };
    111109
    112110    public Bounds getRealBounds() {
    113111        return new Bounds(
    114         getProjection().eastNorth2latlon(new EastNorth(
    115                 center.east() - getWidth()/2.0*scale,
    116                 center.north() - getHeight()/2.0*scale)),
    117         getProjection().eastNorth2latlon(new EastNorth(
    118                 center.east() + getWidth()/2.0*scale,
    119                 center.north() + getHeight()/2.0*scale)));
     112                getProjection().eastNorth2latlon(new EastNorth(
     113                        center.east() - getWidth()/2.0*scale,
     114                        center.north() - getHeight()/2.0*scale)),
     115                        getProjection().eastNorth2latlon(new EastNorth(
     116                                center.east() + getWidth()/2.0*scale,
     117                                center.north() + getHeight()/2.0*scale)));
    120118    };
    121119
     
    163161     */
    164162    private void zoomTo(EastNorth newCenter, double newScale) {
    165 /* TODO: check that newCenter is really inside visible world and that scale is correct, don't allow zooming out to much */
     163        /* TODO: check that newCenter is really inside visible world and that scale is correct, don't allow zooming out to much */
    166164        boolean rep = false;
    167165        if (!newCenter.equals(center)) {
     
    177175            firePropertyChange("scale", oldScale, newScale);
    178176        }
    179         if(rep)
     177        if(rep) {
    180178            repaint();
     179        }
    181180    }
    182181
     
    186185
    187186    public void zoomTo(LatLon newCenter) {
    188         if (newCenter instanceof CachedLatLon)
     187        if(newCenter instanceof CachedLatLon) {
    189188            zoomTo(((CachedLatLon)newCenter).getEastNorth(), scale);
    190         else
     189        } else {
    191190            zoomTo(getProjection().latlon2eastNorth(newCenter), scale);
     191        }
    192192    }
    193193
     
    197197        // You will get the formula by simplifying this expression: newCenter = oldCenter + mouseCoordinatesInNewZoom - mouseCoordinatesInOldZoom
    198198        zoomTo(new EastNorth(
    199         center.east() - (x - getWidth()/2.0) * (newScale - scale),
    200         center.north() + (y - getHeight()/2.0) * (newScale - scale)),
    201         newScale);
     199                center.east() - (x - getWidth()/2.0) * (newScale - scale),
     200                center.north() + (y - getHeight()/2.0) * (newScale - scale)),
     201                newScale);
    202202    }
    203203
     
    213213        // -20 to leave some border
    214214        int w = getWidth()-20;
    215         if (w < 20)
     215        if (w < 20) {
    216216            w = 20;
     217        }
    217218        int h = getHeight()-20;
    218         if (h < 20)
     219        if (h < 20) {
    219220            h = 20;
     221        }
    220222
    221223        double scaleX = (box.max.east()-box.min.east())/w;
     
    228230    public void zoomTo(Bounds box) {
    229231        zoomTo(new ProjectionBounds(getProjection().latlon2eastNorth(box.min),
    230         getProjection().latlon2eastNorth(box.max)));
     232                getProjection().latlon2eastNorth(box.max)));
    231233    }
    232234
     
    238240        double minDistanceSq = snapDistance;
    239241        Node minPrimitive = null;
    240         for (Node n : getData().nodes) {
    241             if (n.deleted || n.incomplete)
     242        for (Node n : getCurrentDataSet().nodes) {
     243            if (n.deleted || n.incomplete) {
    242244                continue;
     245            }
    243246            Point sp = getPoint(n);
    244247            double dist = p.distanceSq(sp);
     
    249252            // when multiple nodes on one point, prefer new or selected nodes
    250253            else if(dist == minDistanceSq && minPrimitive != null
    251             && ((n.id == 0 && n.selected)
    252             || (!minPrimitive.selected && (n.selected || n.id == 0))))
     254                    && ((n.id == 0 && n.selected)
     255                            || (!minPrimitive.selected && (n.selected || n.id == 0)))) {
    253256                minPrimitive = n;
     257            }
    254258        }
    255259        return minPrimitive;
     
    264268    public final List<WaySegment> getNearestWaySegments(Point p) {
    265269        TreeMap<Double, List<WaySegment>> nearest = new TreeMap<Double, List<WaySegment>>();
    266         for (Way w : getData().ways) {
    267             if (w.deleted || w.incomplete) continue;
     270        for (Way w : getCurrentDataSet().ways) {
     271            if (w.deleted || w.incomplete) {
     272                continue;
     273            }
    268274            Node lastN = null;
    269275            int i = -2;
    270276            for (Node n : w.nodes) {
    271277                i++;
    272                 if (n.deleted || n.incomplete) continue;
     278                if (n.deleted || n.incomplete) {
     279                    continue;
     280                }
    273281                if (lastN == null) {
    274282                    lastN = n;
     
    283291                double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared
    284292                if (perDist < snapDistance && a < c+snapDistance && b < c+snapDistance) {
    285                     if(w.selected) // prefer selected ways a little bit
     293                    if(w.selected) {
    286294                        perDist -= 0.00001;
     295                    }
    287296                    List<WaySegment> l;
    288297                    if (nearest.containsKey(perDist)) {
     
    315324    public final WaySegment getNearestWaySegment(Point p, Collection<WaySegment> ignore) {
    316325        List<WaySegment> nearest = getNearestWaySegments(p);
    317         if (ignore != null) nearest.removeAll(ignore);
     326        if (ignore != null) {
     327            nearest.removeAll(ignore);
     328        }
    318329        return nearest.isEmpty() ? null : nearest.get(0);
    319330    }
     
    376387    public Collection<OsmPrimitive> getAllNearest(Point p) {
    377388        Collection<OsmPrimitive> nearest = new HashSet<OsmPrimitive>();
    378             for (Way w : getData().ways) {
    379             if (w.deleted || w.incomplete) continue;
     389        for (Way w : getCurrentDataSet().ways) {
     390            if (w.deleted || w.incomplete) {
     391                continue;
     392            }
    380393            Node lastN = null;
    381394            for (Node n : w.nodes) {
    382                 if (n.deleted || n.incomplete) continue;
     395                if (n.deleted || n.incomplete) {
     396                    continue;
     397                }
    383398                if (lastN == null) {
    384399                    lastN = n;
     
    393408                if (perDist < snapDistance && a < c+snapDistance && b < c+snapDistance) {
    394409                    nearest.add(w);
    395                         break;
    396                     }
     410                    break;
     411                }
    397412                lastN = n;
    398                 }
    399             }
    400         for (Node n : getData().nodes) {
     413            }
     414        }
     415        for (Node n : getCurrentDataSet().nodes) {
    401416            if (!n.deleted && !n.incomplete
    402417                    && getPoint(n).distanceSq(p) < snapDistance) {
     
    417432    public Collection<Node> getNearestNodes(Point p) {
    418433        Collection<Node> nearest = new HashSet<Node>();
    419         for (Node n : getData().nodes) {
     434        for (Node n : getCurrentDataSet().nodes) {
    420435            if (!n.deleted && !n.incomplete
    421436                    && getPoint(n).distanceSq(p) < snapDistance) {
     
    436451    public final Collection<Node> getNearestNodes(Point p, Collection<Node> ignore) {
    437452        Collection<Node> nearest = getNearestNodes(p);
    438                 if (nearest == null) return null;
    439         if (ignore != null) nearest.removeAll(ignore);
     453        if (nearest == null) return null;
     454        if (ignore != null) {
     455            nearest.removeAll(ignore);
     456        }
    440457        return nearest.isEmpty() ? null : nearest;
    441458    }
Note: See TracChangeset for help on using the changeset viewer.