Synchronize overlays operations in BasicDrawing.
This commit is contained in:
parent
25da6079e6
commit
8bca08f795
@ -13,6 +13,7 @@ import java.awt.geom.NoninvertibleTransformException;
|
|||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -65,7 +66,9 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
|
synchronized (overlays) {
|
||||||
BasicDrawing.this.overlays.remove(this);
|
BasicDrawing.this.overlays.remove(this);
|
||||||
|
}
|
||||||
BasicDrawing.this.repaint();
|
BasicDrawing.this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +279,8 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
private Graphics2D graphGraphics = null;
|
private Graphics2D graphGraphics = null;
|
||||||
|
|
||||||
// List of image for markers
|
// List of image for markers
|
||||||
private List<BasicOverlay> overlays = new ArrayList<>();
|
private List<BasicOverlay> overlays = Collections
|
||||||
|
.synchronizedList(new ArrayList<BasicOverlay>());
|
||||||
|
|
||||||
// Mapping DrawingClickListener -> MouseEventListener
|
// Mapping DrawingClickListener -> MouseEventListener
|
||||||
private Map<DrawingClickListener, MouseListener> listenerMapping = new IdentityHashMap<>();
|
private Map<DrawingClickListener, MouseListener> listenerMapping = new IdentityHashMap<>();
|
||||||
@ -308,10 +312,12 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw markers
|
// Draw markers
|
||||||
|
synchronized (overlays) {
|
||||||
for (BasicOverlay overlay: overlays) {
|
for (BasicOverlay overlay: overlays) {
|
||||||
overlay.draw(g);
|
overlay.draw(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param lon
|
* @param lon
|
||||||
@ -381,8 +387,10 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
if (this.graphGraphics != null) {
|
if (this.graphGraphics != null) {
|
||||||
this.graphGraphics.clearRect(0, 0, this.width, this.height);
|
this.graphGraphics.clearRect(0, 0, this.width, this.height);
|
||||||
}
|
}
|
||||||
|
synchronized (overlays) {
|
||||||
this.overlays.clear();
|
this.overlays.clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public BasicMarkerOverlay createMarker(Point point, Color color) {
|
public BasicMarkerOverlay createMarker(Point point, Color color) {
|
||||||
return new BasicMarkerOverlay(point, color);
|
return new BasicMarkerOverlay(point, color);
|
||||||
@ -391,7 +399,9 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
@Override
|
@Override
|
||||||
public MarkerOverlay drawMarker(Point point, Color color) {
|
public MarkerOverlay drawMarker(Point point, Color color) {
|
||||||
BasicMarkerOverlay marker = createMarker(point, color);
|
BasicMarkerOverlay marker = createMarker(point, color);
|
||||||
|
synchronized (overlays) {
|
||||||
this.overlays.add(marker);
|
this.overlays.add(marker);
|
||||||
|
}
|
||||||
this.repaint();
|
this.repaint();
|
||||||
return marker;
|
return marker;
|
||||||
}
|
}
|
||||||
@ -399,7 +409,9 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
@Override
|
@Override
|
||||||
public PointSetOverlay createPointSetOverlay() {
|
public PointSetOverlay createPointSetOverlay() {
|
||||||
BasicPointSetOverlay ps = new BasicPointSetOverlay();
|
BasicPointSetOverlay ps = new BasicPointSetOverlay();
|
||||||
|
synchronized (overlays) {
|
||||||
this.overlays.add(ps);
|
this.overlays.add(ps);
|
||||||
|
}
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,7 +564,9 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
destination = createMarker(path.getDestination().getPoint(), color);
|
destination = createMarker(path.getDestination().getPoint(), color);
|
||||||
}
|
}
|
||||||
BasicPathOverlay overlay = new BasicPathOverlay(points, color, origin, destination);
|
BasicPathOverlay overlay = new BasicPathOverlay(points, color, origin, destination);
|
||||||
|
synchronized (overlays) {
|
||||||
this.overlays.add(overlay);
|
this.overlays.add(overlay);
|
||||||
|
}
|
||||||
this.repaint();
|
this.repaint();
|
||||||
return overlay;
|
return overlay;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user