Improve 'clear' performance (only clear overlays if possible).
This commit is contained in:
parent
bd01aadeb1
commit
825108d10e
@ -104,6 +104,9 @@ public class MainWindow extends JFrame {
|
||||
private final MapViewDrawing mapViewDrawing;
|
||||
private final BasicDrawing basicDrawing;
|
||||
|
||||
private final GraphPalette basicPalette, blackAndWhitePalette;
|
||||
private GraphPalette currentPalette;
|
||||
|
||||
// Main panel.
|
||||
private final JSplitPane mainPanel;
|
||||
|
||||
@ -150,9 +153,13 @@ public class MainWindow extends JFrame {
|
||||
// Create drawing and action listeners...
|
||||
this.basicDrawing = new BasicDrawing();
|
||||
this.mapViewDrawing = new MapViewDrawing();
|
||||
|
||||
this.drawing = this.basicDrawing;
|
||||
|
||||
// Createa palettes
|
||||
this.basicPalette = new BasicGraphPalette();
|
||||
this.blackAndWhitePalette = new BlackAndWhiteGraphPalette();
|
||||
this.currentPalette = this.basicPalette;
|
||||
|
||||
wccPanel = new AlgorithmPanel(this, WeaklyConnectedComponentsAlgorithm.class,
|
||||
"Weakly-Connected Components", new String[] {}, false, false);
|
||||
wccPanel.addStartActionListener(new ActionListener() {
|
||||
@ -452,8 +459,13 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
|
||||
// 2. We draw the graph.
|
||||
drawing.clear();
|
||||
((MapViewDrawing) drawing).drawGraph(mfile);
|
||||
if (isNewGraph) {
|
||||
drawing.clear();
|
||||
((MapViewDrawing) drawing).drawGraph(mfile);
|
||||
}
|
||||
else {
|
||||
drawing.clearOverlays();
|
||||
}
|
||||
notifyRedrawRequest();
|
||||
|
||||
}
|
||||
@ -465,8 +477,14 @@ public class MainWindow extends JFrame {
|
||||
mainPanel.setDividerLocation(oldLocation);
|
||||
notifyDrawingLoaded(mapViewDrawing, basicDrawing);
|
||||
}
|
||||
drawing.clear();
|
||||
drawing.drawGraph(graph, palette);
|
||||
if (isNewGraph || palette != this.currentPalette) {
|
||||
this.currentPalette = palette;
|
||||
drawing.clear();
|
||||
drawing.drawGraph(graph, palette);
|
||||
}
|
||||
else {
|
||||
drawing.clearOverlays();
|
||||
}
|
||||
notifyRedrawRequest();
|
||||
}
|
||||
|
||||
@ -483,7 +501,7 @@ public class MainWindow extends JFrame {
|
||||
*
|
||||
*/
|
||||
private void drawGraph() {
|
||||
drawGraph(null, new BasicGraphPalette());
|
||||
drawGraph(null, this.currentPalette);
|
||||
}
|
||||
|
||||
private void loadGraph(GraphReader reader) {
|
||||
@ -662,7 +680,7 @@ public class MainWindow extends JFrame {
|
||||
launchThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
drawGraph(BasicDrawing.class);
|
||||
drawGraph(BasicDrawing.class, basicPalette);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -676,7 +694,7 @@ public class MainWindow extends JFrame {
|
||||
launchThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
drawGraph(BasicDrawing.class, new BlackAndWhiteGraphPalette());
|
||||
drawGraph(BasicDrawing.class, blackAndWhitePalette);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -30,6 +30,11 @@ public interface Drawing {
|
||||
*/
|
||||
public void clear();
|
||||
|
||||
/**
|
||||
* Remove overlays from the drawing.
|
||||
*/
|
||||
public void clearOverlays();
|
||||
|
||||
/**
|
||||
* Draw the given point with the given color.
|
||||
*
|
||||
|
@ -392,6 +392,35 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.insa.graphics.drawing.Drawing#clear()
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
if (this.graphGraphics != null) {
|
||||
this.graphGraphics.clearRect(0, 0, this.width, this.height);
|
||||
}
|
||||
synchronized (overlays) {
|
||||
this.overlays.clear();
|
||||
}
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.insa.graphics.drawing.Drawing#clearOverlays()
|
||||
*/
|
||||
@Override
|
||||
public void clearOverlays() {
|
||||
synchronized (overlays) {
|
||||
this.overlays.clear();
|
||||
}
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lon
|
||||
* @return
|
||||
@ -433,26 +462,29 @@ public class BasicDrawing extends JPanel implements Drawing {
|
||||
return new Point((float) lon, (float) lat);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
|
||||
* drawing.DrawingClickListener)
|
||||
*/
|
||||
@Override
|
||||
public void addDrawingClickListener(DrawingClickListener listener) {
|
||||
this.drawingClickListeners.add(listener);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.insa.graphics.drawing.Drawing#removeDrawingClickListener(org.insa.
|
||||
* graphics.drawing.DrawingClickListener)
|
||||
*/
|
||||
@Override
|
||||
public void removeDrawingClickListener(DrawingClickListener listener) {
|
||||
this.drawingClickListeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if (this.graphGraphics != null) {
|
||||
this.graphGraphics.clearRect(0, 0, this.width, this.height);
|
||||
}
|
||||
synchronized (overlays) {
|
||||
this.overlays.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public BasicMarkerOverlay createMarker(Point point, Color color) {
|
||||
return new BasicMarkerOverlay(point, color);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
private class MapViewMarkerOverlay extends MapViewOverlay implements MarkerOverlay {
|
||||
|
||||
public MapViewMarkerOverlay(Marker marker, Color color) {
|
||||
super(new Layer[]{ marker }, color);
|
||||
super(new Layer[] { marker }, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -156,11 +156,11 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
public MapViewPathOverlay(PolylineAutoScaling path, MarkerAutoScaling origin,
|
||||
MarkerAutoScaling destination) {
|
||||
super(new Layer[]{ path, origin, destination }, path.getColor());
|
||||
super(new Layer[] { path, origin, destination }, path.getColor());
|
||||
}
|
||||
|
||||
public MapViewPathOverlay(PolylineAutoScaling path) {
|
||||
super(new Layer[]{ path }, path.getColor());
|
||||
super(new Layer[] { path }, path.getColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -270,6 +270,11 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.mapsforge.map.awt.view.MapView#paint(java.awt.Graphics)
|
||||
*/
|
||||
@Override
|
||||
public void paint(Graphics graphics) {
|
||||
super.paint(graphics);
|
||||
@ -282,6 +287,33 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.insa.graphics.drawing.Drawing#clear()
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
getLayerManager().getLayers().clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.insa.graphics.drawing.Drawing#clearOverlays()
|
||||
*/
|
||||
@Override
|
||||
public void clearOverlays() {
|
||||
Layers layers = getLayerManager().getLayers();
|
||||
for (Layer layer: layers) {
|
||||
if (layer instanceof PolylineAutoScaling || layer instanceof MarkerAutoScaling) {
|
||||
getLayerManager().getLayers().remove(layer, false);
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
protected LatLong convertPoint(Point point) {
|
||||
return new LatLong(point.getLatitude(), point.getLongitude());
|
||||
}
|
||||
@ -319,12 +351,6 @@ public class MapViewDrawing extends MapView implements Drawing {
|
||||
this.drawingClickListeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
getLayerManager().getLayers().clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
protected MarkerAutoScaling createMarker(Point point, Color color) {
|
||||
Image image = MarkerUtils.getMarkerForColor(color);
|
||||
return new MarkerAutoScaling(convertPoint(point), image);
|
||||
|
Loading…
Reference in New Issue
Block a user