1 package org.opentrafficsim.draw.network;
2
3 import java.awt.BasicStroke;
4 import java.awt.Color;
5 import java.awt.Graphics2D;
6 import java.awt.geom.Ellipse2D;
7 import java.awt.geom.GeneralPath;
8 import java.awt.geom.Path2D;
9 import java.awt.image.ImageObserver;
10 import java.io.Serializable;
11 import java.rmi.RemoteException;
12
13 import javax.naming.NamingException;
14
15 import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
16 import org.opentrafficsim.core.geometry.Bounds;
17 import org.opentrafficsim.core.geometry.DirectedPoint;
18 import org.opentrafficsim.core.network.Node;
19 import org.opentrafficsim.draw.core.TextAlignment;
20 import org.opentrafficsim.draw.core.TextAnimation;
21
22 import nl.tudelft.simulation.dsol.animation.Locatable;
23 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
24 import nl.tudelft.simulation.dsol.animation.D2.Renderable2DInterface;
25 import nl.tudelft.simulation.introspection.DelegateIntrospection;
26 import nl.tudelft.simulation.naming.context.Contextualized;
27
28
29
30
31
32
33
34
35 @SuppressWarnings("rawtypes")
36 public class NodeAnimation extends Renderable2D<NodeAnimation.ElevatedNode>
37 implements Renderable2DInterface<NodeAnimation.ElevatedNode>, Serializable
38 {
39
40 private static final long serialVersionUID = 20140000L;
41
42
43 private Text text;
44
45
46 public static final double ZOFFSET = 0.01;
47
48
49
50
51
52
53
54 public NodeAnimation(final Node node, final OtsSimulatorInterface simulator) throws NamingException, RemoteException
55 {
56 super(new ElevatedNode(node), simulator);
57 this.text = new Text(node, node.getId(), 0.0f, 3.0f, TextAlignment.CENTER, Color.BLACK, simulator,
58 TextAnimation.RENDERWHEN10);
59 }
60
61
62 @Override
63 public final void paint(final Graphics2D graphics, final ImageObserver observer)
64 {
65 graphics.setColor(Color.BLACK);
66 graphics.setStroke(new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
67 graphics.draw(new Ellipse2D.Double(-0.5, -0.5, 1.0, 1.0));
68 double direction = getSource().getLocation().getZ();
69 if (!Double.isNaN(direction))
70 {
71 GeneralPath arrow = new GeneralPath(Path2D.WIND_EVEN_ODD, 3);
72 arrow.moveTo(0.5, -0.5);
73 arrow.lineTo(2, 0);
74 arrow.lineTo(0.5, 0.5);
75 graphics.draw(arrow);
76 }
77 }
78
79
80 @Override
81 public void destroy(final Contextualized contextProvider)
82 {
83 super.destroy(contextProvider);
84 this.text.destroy(contextProvider);
85 }
86
87
88 @Override
89 public final String toString()
90 {
91 return "NodeAnimation [node=" + super.getSource() + "]";
92 }
93
94
95 public static class ElevatedNode implements Locatable, DelegateIntrospection
96 {
97
98 private final Node node;
99
100
101 private DirectedPoint location;
102
103
104 private Bounds bounds;
105
106
107
108
109 public ElevatedNode(final Node node)
110 {
111 this.node = node;
112 DirectedPoint p = node.getLocation();
113 this.location = new DirectedPoint(p.x, p.y, p.z + ZOFFSET, p.getRotX(), p.getRotY(), p.getRotZ());
114 this.bounds = node.getBounds();
115 }
116
117
118 @Override
119 public DirectedPoint getLocation()
120 {
121 return this.location;
122 }
123
124
125
126
127 public Node getNode()
128 {
129 return this.node;
130 }
131
132
133 @Override
134 public Bounds getBounds() throws RemoteException
135 {
136 return this.bounds;
137 }
138
139
140 @Override
141 public Object getParentIntrospectionObject()
142 {
143 return this.node;
144 }
145
146 }
147
148
149
150
151
152
153
154
155
156
157
158
159 public class Text extends TextAnimation
160 {
161
162 private static final long serialVersionUID = 20161211L;
163
164
165
166
167
168
169
170
171
172
173
174
175
176 @SuppressWarnings("checkstyle:parameternumber")
177 public Text(final Locatable source, final String text, final float dx, final float dy,
178 final TextAlignment textPlacement, final Color color, final OtsSimulatorInterface simulator,
179 final ScaleDependentRendering scaleDependentRendering) throws RemoteException, NamingException
180 {
181 super(source, text, dx, dy, textPlacement, color, 2.0f, 12.0f, 50f, simulator, scaleDependentRendering);
182 setFlip(false);
183 setRotate(false);
184 }
185
186
187 @Override
188 public final String toString()
189 {
190 return "NodeAnimation.Text []";
191 }
192 }
193
194 }