| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
import java.awt.*; |
|---|
| 13 |
import java.awt.geom.*; |
|---|
| 14 |
import java.util.*; |
|---|
| 15 |
|
|---|
| 16 |
public class PhysicalNodePainter extends ObjectPainter { |
|---|
| 17 |
|
|---|
| 18 |
public PhysicalNodePainter(Color color, float radius) { |
|---|
| 19 |
setColor(color); |
|---|
| 20 |
setRadius(radius); |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
public PhysicalNodePainter() { |
|---|
| 24 |
setColor(Color.BLACK); |
|---|
| 25 |
setRadius(2); |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
public Color getColor() { return color; } |
|---|
| 29 |
public void setColor(Color color) { this.color = color; } |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
public float getRadius() { return radius; } |
|---|
| 34 |
public void setRadius(float radius) { this.radius = radius; } |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
public double visualDistanceTo(Object object, Point2D.Double real, BackgroundMap map, AffineTransform realToScreen) { |
|---|
| 38 |
|
|---|
| 39 |
if(!((PhysicalNode)object).isOnMap(map)) return Double.POSITIVE_INFINITY; |
|---|
| 40 |
return realToScreen.transform(real, null).distance( |
|---|
| 41 |
((Point2D.Double)computeLocation(object, realToScreen))) |
|---|
| 42 |
- radius; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
protected void setupPainting(Graphics2D g) { |
|---|
| 46 |
g.setColor(color); |
|---|
| 47 |
g.setStroke(new BasicStroke()); |
|---|
| 48 |
cachedEllipse.width = cachedEllipse.height = 2 * radius; |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
protected Object computeLocation(Object object, AffineTransform realToScreen) { |
|---|
| 52 |
return realToScreen.transform(((PhysicalNode) object).point, null); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
protected boolean needToPaint(Object object, Object location, BackgroundMap map, Graphics2D g) { |
|---|
| 56 |
if(!((PhysicalNode)object).isOnMap(map)) return false; |
|---|
| 57 |
return true; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
protected void paintSingleObject(Object object, Object location, Graphics2D g) { |
|---|
| 61 |
Point2D.Double screenPoint = (Point2D.Double)location; |
|---|
| 62 |
cachedEllipse.x = screenPoint.getX() - radius; |
|---|
| 63 |
cachedEllipse.y = screenPoint.getY() - radius; |
|---|
| 64 |
|
|---|
| 65 |
g.fill(cachedEllipse); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
Color color; |
|---|
| 69 |
float radius; |
|---|
| 70 |
|
|---|
| 71 |
Ellipse2D.Double cachedEllipse = new Ellipse2D.Double(); |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
} |
|---|