1 package org.opentrafficsim.draw.network;
2
3 import java.awt.Color;
4 import java.awt.Graphics2D;
5 import java.awt.geom.Ellipse2D;
6 import java.awt.image.ImageObserver;
7 import java.io.Serializable;
8 import java.rmi.RemoteException;
9
10 import javax.naming.NamingException;
11
12 import org.opentrafficsim.core.network.Node;
13 import org.opentrafficsim.draw.core.ClonableRenderable2DInterface;
14 import org.opentrafficsim.draw.core.TextAlignment;
15 import org.opentrafficsim.draw.core.TextAnimation;
16
17 import nl.tudelft.simulation.dsol.animation.Locatable;
18 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
19 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
20
21
22
23
24
25
26
27
28
29
30 public class NodeAnimation extends Renderable2D implements ClonableRenderable2DInterface, Serializable
31 {
32
33 private static final long serialVersionUID = 20140000L;
34
35
36 private Text text;
37
38
39
40
41
42
43
44 public NodeAnimation(final Node node, final SimulatorInterface.TimeDoubleUnit simulator)
45 throws NamingException, RemoteException
46 {
47 super(node, simulator);
48 this.text = new Text(node, node.getId(), 0.0f, 3.0f, TextAlignment.CENTER, Color.BLACK, simulator);
49 }
50
51
52 @Override
53 public final void paint(final Graphics2D graphics, final ImageObserver observer)
54 {
55 graphics.setColor(Color.BLACK);
56 graphics.draw(new Ellipse2D.Double(-1.0, -1.0, 2.0, 2.0));
57 }
58
59
60 @Override
61 public final void destroy() throws NamingException
62 {
63 super.destroy();
64 this.text.destroy();
65 }
66
67
68 @Override
69 @SuppressWarnings("checkstyle:designforextension")
70 public ClonableRenderable2DInterface clone(final Locatable newSource, final SimulatorInterface.TimeDoubleUnit newSimulator)
71 throws NamingException, RemoteException
72 {
73
74 return new NodeAnimation((Node) newSource, newSimulator);
75 }
76
77
78 @Override
79 public final String toString()
80 {
81 return "NodeAnimation [node=" + super.getSource() + "]";
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 public class Text extends TextAnimation
98 {
99
100 private static final long serialVersionUID = 20161211L;
101
102
103
104
105
106
107
108
109
110
111
112
113 public Text(final Locatable source, final String text, final float dx, final float dy,
114 final TextAlignment textPlacement, final Color color, final SimulatorInterface.TimeDoubleUnit simulator)
115 throws RemoteException, NamingException
116 {
117 super(source, text, dx, dy, textPlacement, color, simulator);
118 setFlip(false);
119 setRotate(false);
120 }
121
122
123 @Override
124 @SuppressWarnings("checkstyle:designforextension")
125 public TextAnimation clone(final Locatable newSource, final SimulatorInterface.TimeDoubleUnit newSimulator)
126 throws RemoteException, NamingException
127 {
128 return new Text(newSource, getText(), getDx(), getDy(), getTextAlignment(), getColor(), newSimulator);
129 }
130
131
132 @Override
133 public final String toString()
134 {
135 return "NodeAnimation.Text []";
136 }
137 }
138
139 }