Changeset 12108 in josm


Ignore:
Timestamp:
2017-05-11T00:18:51+02:00 (8 years ago)
Author:
michael2402
Message:

ParallelWayAction: Use a separate temporary layer, invalidate it to update view.

File:
1 edited

Legend:

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

    r12106 r12108  
    4444import org.openstreetmap.josm.gui.Notification;
    4545import org.openstreetmap.josm.gui.draw.MapViewPath;
     46import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable;
    4647import org.openstreetmap.josm.gui.layer.Layer;
    47 import org.openstreetmap.josm.gui.layer.MapViewPaintable;
    4848import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4949import org.openstreetmap.josm.gui.util.ModifierListener;
     
    9090 * @author Ole Jørgen Brønner (olejorgenb)
    9191 */
    92 public class ParallelWayAction extends MapMode implements ModifierListener, MapViewPaintable {
     92public class ParallelWayAction extends MapMode implements ModifierListener {
    9393
    9494    private static final CachingProperty<BasicStroke> HELPER_LINE_STROKE = new StrokeProperty(prefKey("stroke.hepler-line"), "1").cached();
     
    145145    private EastNorth helperLineEnd;
    146146
     147    private final ParallelWayLayer temporaryLayer = new ParallelWayLayer();
     148
    147149    /**
    148150     * Constructs a new {@code ParallelWayAction}.
     
    168170        mv.addMouseListener(this);
    169171        mv.addMouseMotionListener(this);
    170         mv.addTemporaryLayer(this);
     172        mv.addTemporaryLayer(temporaryLayer);
    171173
    172174        //// Needed to update the mouse cursor if modifiers are changed when the mouse is motionless
     
    183185        mv.removeMouseListener(this);
    184186        mv.removeMouseMotionListener(this);
    185         mv.removeTemporaryLayer(this);
     187        mv.removeTemporaryLayer(temporaryLayer);
    186188        Main.map.statusLine.setDist(-1);
    187189        Main.map.statusLine.repaint();
     
    334336        setMode(Mode.NORMAL);
    335337        resetMouseTrackingState();
    336         mv.repaint();
     338        temporaryLayer.invalidate();
    337339    }
    338340
     
    431433        Main.map.statusLine.setDist(Math.abs(snappedRealD));
    432434        Main.map.statusLine.repaint();
    433         mv.repaint();
     435        temporaryLayer.invalidate();
    434436    }
    435437
     
    450452        }
    451453        return spec.entrySet().stream().allMatch(entry -> modifiers.contains(entry.getKey()) == entry.getValue().booleanValue());
    452     }
    453 
    454     @Override
    455     public void paint(Graphics2D g, MapView mv, Bounds bbox) {
    456         if (mode == Mode.DRAGGING) {
    457             CheckParameterUtil.ensureParameterNotNull(mv, "mv");
    458 
    459             Color mainColor = MAIN_COLOR.get();
    460             // FIXME: should clip the line (gets insanely slow when zoomed in on a very long line
    461             g.setStroke(REF_LINE_STROKE.get());
    462             g.setColor(mainColor);
    463             MapViewPath line = new MapViewPath(mv);
    464             line.moveTo(referenceSegment.getFirstNode());
    465             line.lineTo(referenceSegment.getSecondNode());
    466             g.draw(line.computeClippedLine(g.getStroke()));
    467 
    468             g.setStroke(HELPER_LINE_STROKE.get());
    469             g.setColor(mainColor);
    470             line = new MapViewPath(mv);
    471             line.moveTo(helperLineStart);
    472             line.lineTo(helperLineEnd);
    473             g.draw(line.computeClippedLine(g.getStroke()));
    474         }
    475454    }
    476455
     
    633612        }
    634613    }
     614
     615    private class ParallelWayLayer extends AbstractMapViewPaintable {
     616        @Override
     617        public void paint(Graphics2D g, MapView mv, Bounds bbox) {
     618            if (mode == Mode.DRAGGING) {
     619                CheckParameterUtil.ensureParameterNotNull(mv, "mv");
     620
     621                Color mainColor = MAIN_COLOR.get();
     622                g.setStroke(REF_LINE_STROKE.get());
     623                g.setColor(mainColor);
     624                MapViewPath line = new MapViewPath(mv);
     625                line.moveTo(referenceSegment.getFirstNode());
     626                line.lineTo(referenceSegment.getSecondNode());
     627                g.draw(line.computeClippedLine(g.getStroke()));
     628
     629                g.setStroke(HELPER_LINE_STROKE.get());
     630                g.setColor(mainColor);
     631                line = new MapViewPath(mv);
     632                line.moveTo(helperLineStart);
     633                line.lineTo(helperLineEnd);
     634                g.draw(line.computeClippedLine(g.getStroke()));
     635            }
     636        }
     637    }
    635638}
Note: See TracChangeset for help on using the changeset viewer.