Ignore:
Timestamp:
2017-05-15T14:14:40+02:00 (3 years ago)
Author:
michael2402
Message:

See #14120: Don't make gpx tracks depend on the isChanged method, use a listener based approach instead.

Location:
trunk/src/org/openstreetmap/josm/gui/layer
Files:
6 edited

Legend:

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

    r12155 r12156  
    99import java.io.File;
    1010import java.text.DateFormat;
    11 import java.util.ArrayList;
    1211import java.util.Arrays;
    1312import java.util.Collection;
     
    6059    /**
    6160     * used by {@link ChooseTrackVisibilityAction} to determine which tracks to show/hide
     61     *
     62     * Call {@link #invalidate()} after each change!
     63     *
     64     * TODO: Make it private, make it respond to track changes.
    6265     */
    6366    public boolean[] trackVisibility = new boolean[0];
    64 
    65     private final List<GpxTrack> lastTracks = new ArrayList<>(); // List of tracks at last paint
    66     private int lastUpdateCount;
    6767
    6868    private final GpxDrawHelper drawHelper;
     
    9494        super(d.getString(GpxConstants.META_NAME));
    9595        data = d;
     96        data.addWeakChangeListener(e -> this.invalidate());
    9697        drawHelper = new GpxDrawHelper(data);
    9798        SystemOfMeasurement.addSoMChangeListener(drawHelper);
     
    151152        }
    152153
    153         if (!data.tracks.isEmpty()) {
     154        if (!data.getTracks().isEmpty()) {
    154155            info.append("<table><thead align='center'><tr><td colspan='5'>")
    155156                .append(trn("{0} track", "{0} tracks", data.tracks.size(), data.tracks.size()))
     
    159160                .append("</td></tr></thead>");
    160161
    161             for (GpxTrack trk : data.tracks) {
     162            for (GpxTrack trk : data.getTracks()) {
    162163                info.append("<tr><td>");
    163164                if (trk.getAttributes().containsKey(GpxConstants.GPX_NAME)) {
     
    182183
    183184        info.append(tr("Length: {0}", SystemOfMeasurement.getSystemOfMeasurement().getDistText(data.length()))).append("<br>")
    184             .append(trn("{0} route, ", "{0} routes, ", data.routes.size(), data.routes.size()))
    185             .append(trn("{0} waypoint", "{0} waypoints", data.waypoints.size(), data.waypoints.size())).append("<br></html>");
     185            .append(trn("{0} route, ", "{0} routes, ", data.getRoutes().size(), data.getRoutes().size()))
     186            .append(trn("{0} waypoint", "{0} waypoints", data.getWaypoints().size(), data.getWaypoints().size())).append("<br></html>");
    186187
    187188        final JScrollPane sp = new JScrollPane(new HtmlPanel(info.toString()));
     
    240241        }
    241242
    242         info.append(trn("{0} track, ", "{0} tracks, ", data.tracks.size(), data.tracks.size()))
    243             .append(trn("{0} route, ", "{0} routes, ", data.routes.size(), data.routes.size()))
    244             .append(trn("{0} waypoint", "{0} waypoints", data.waypoints.size(), data.waypoints.size())).append("<br>")
     243        info.append(trn("{0} track, ", "{0} tracks, ", data.getTracks().size(), data.getTracks().size()))
     244            .append(trn("{0} route, ", "{0} routes, ", data.getRoutes().size(), data.getRoutes().size()))
     245            .append(trn("{0} waypoint", "{0} waypoints", data.getWaypoints().size(), data.getWaypoints().size())).append("<br>")
    245246            .append(tr("Length: {0}", SystemOfMeasurement.getSystemOfMeasurement().getDistText(data.length())))
    246247            .append("<br></html>");
     
    251252    public boolean isMergable(Layer other) {
    252253        return other instanceof GpxLayer;
    253     }
    254 
    255     private int sumUpdateCount() {
    256         int updateCount = 0;
    257         for (GpxTrack track: data.tracks) {
    258             updateCount += track.getUpdateCount();
    259         }
    260         return updateCount;
    261     }
    262 
    263     @Override
    264     public boolean isChanged() {
    265         if (data.tracks.equals(lastTracks))
    266             return sumUpdateCount() != lastUpdateCount;
    267         else
    268             return true;
    269254    }
    270255
     
    279264        long from = fromDate.getTime();
    280265        long to = toDate.getTime();
    281         for (GpxTrack trk : data.tracks) {
     266        for (GpxTrack trk : data.getTracks()) {
    282267            Date[] t = GpxData.getMinMaxTimeForTrack(trk);
    283268
     
    287272            i++;
    288273        }
     274        invalidate();
    289275    }
    290276
     
    299285    @Override
    300286    public void paint(Graphics2D g, MapView mv, Bounds box) {
    301         lastUpdateCount = sumUpdateCount();
    302         lastTracks.clear();
    303         lastTracks.addAll(data.tracks);
    304 
    305287        List<WayPoint> visibleSegments = listVisibleSegments(box);
    306288        if (!visibleSegments.isEmpty()) {
     
    363345     */
    364346    private void ensureTrackVisibilityLength() {
    365         final int l = data.tracks.size();
     347        final int l = data.getTracks().size();
    366348        if (l == trackVisibility.length)
    367349            return;
     
    371353            trackVisibility[i] = true;
    372354        }
     355        invalidate();
    373356    }
    374357
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r12153 r12156  
    743743            }
    744744
    745             gpxData.tracks.add(new ImmutableGpxTrack(trk, trkAttr));
     745            gpxData.addTrack(new ImmutableGpxTrack(trk, trkAttr));
    746746        });
    747747    }
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java

    r11608 r12156  
    218218            layer.trackVisibility[table.convertRowIndexToModel(i)] = s.isSelectedIndex(i);
    219219        }
    220         Main.map.mapView.preferenceChanged(null);
    221         Main.map.repaint(100);
     220        layer.invalidate();
    222221    }
    223222
     
    292291            layer.trackVisibility[table.convertRowIndexToModel(i)] = all || s.isSelectedIndex(i);
    293292        }
     293        // layer has been changed
     294        layer.invalidate();
    294295        // ...sync with layer visibility instead to avoid having two ways to hide everything
    295296        layer.setVisible(v == 1 || !s.isSelectionEmpty());
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerAction.java

    r11848 r12156  
    7474        public DataSet convert() {
    7575            final DataSet ds = new DataSet();
    76             for (GpxTrack trk : layer.data.tracks) {
     76            for (GpxTrack trk : layer.data.getTracks()) {
    7777                for (GpxTrackSegment segment : trk.getSegments()) {
    7878                    List<Node> nodes = new ArrayList<>();
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/MarkersFromNamedPointsAction.java

    r10436 r12156  
    1111import org.openstreetmap.josm.Main;
    1212import org.openstreetmap.josm.data.gpx.GpxData;
    13 import org.openstreetmap.josm.data.gpx.GpxTrack;
    14 import org.openstreetmap.josm.data.gpx.GpxTrackSegment;
    15 import org.openstreetmap.josm.data.gpx.WayPoint;
    1613import org.openstreetmap.josm.gui.layer.GpxLayer;
    1714import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
     
    3027    public void actionPerformed(ActionEvent e) {
    3128        GpxData namedTrackPoints = new GpxData();
    32         for (GpxTrack track : layer.data.tracks) {
    33             for (GpxTrackSegment seg : track.getSegments()) {
    34                 for (WayPoint point : seg.getWayPoints()) {
    35                     if (point.attr.containsKey("name") || point.attr.containsKey("desc")) {
    36                         namedTrackPoints.waypoints.add(point);
    37                     }
    38                 }
    39             }
    40         }
     29        layer.data.getTrackPoints()
     30            .filter(point -> point.attr.containsKey("name") || point.attr.containsKey("desc"))
     31            .forEach(namedTrackPoints.waypoints::add);
    4132        MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", layer.getName()), layer.getAssociatedFile(), layer);
    4233        if (!ml.data.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java

    r11746 r12156  
    317317        WayPoint w2 = null;
    318318
    319         for (GpxTrack track : trackLayer.data.tracks) {
     319        for (GpxTrack track : trackLayer.data.getTracks()) {
    320320            for (GpxTrackSegment trackseg : track.getSegments()) {
    321321                for (WayPoint w: trackseg.getWayPoints()) {
Note: See TracChangeset for help on using the changeset viewer.