| 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 PhysicalEdgePainter extends ObjectPainter { |
|---|
| 17 |
|
|---|
| 18 |
public PhysicalEdgePainter(Color color, float thickness) { |
|---|
| 19 |
setColor(color); |
|---|
| 20 |
setThickness(thickness); |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
public PhysicalEdgePainter() { |
|---|
| 24 |
setColor(Color.BLACK); |
|---|
| 25 |
setThickness(1); |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
public Color getColor() { return color; } |
|---|
| 29 |
public void setColor(Color color) { this.color = color; } |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
public float getThickness() { return thickness; } |
|---|
| 33 |
public void setThickness(float thickness) { this.thickness = thickness; } |
|---|
| 34 |
|
|---|
| 35 |
public double visualDistanceTo(Object object, Point2D.Double real, BackgroundMap map, AffineTransform realToScreen) { |
|---|
| 36 |
if(!((PhysicalEdge)object).isOnMap(map)) return Double.POSITIVE_INFINITY; |
|---|
| 37 |
return ((Line2D.Double)computeLocation(object, realToScreen)).ptSegDist( |
|---|
| 38 |
realToScreen.transform(real, null)) |
|---|
| 39 |
- thickness / 2; |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
protected void setupPainting(Graphics2D g) { |
|---|
| 43 |
|
|---|
| 44 |
g.setColor(color); |
|---|
| 45 |
g.setStroke(new BasicStroke(thickness)); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
protected Object computeLocation(Object object, AffineTransform realToScreen) { |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
return new Line2D.Double( |
|---|
| 54 |
realToScreen.transform(((PhysicalNode)((PhysicalEdge)object).getNodeA()).point, null), |
|---|
| 55 |
realToScreen.transform(((PhysicalNode)((PhysicalEdge)object).getNodeB()).point, null) |
|---|
| 56 |
); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
protected boolean needToPaint(Object object, Object location, BackgroundMap map, Graphics2D g) { |
|---|
| 60 |
if(!((PhysicalEdge)object).isOnMap(map)) return false; |
|---|
| 61 |
return g.getClipBounds(new Rectangle()).intersectsLine((Line2D)location); |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
protected void paintSingleObject(Object object, Object location, Graphics2D g) { |
|---|
| 65 |
g.draw((Line2D.Double)location); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
Color color; |
|---|
| 69 |
float thickness; |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
} |
|---|