1 package org.opentrafficsim.core.network.animation;
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.animation.ClonableRenderable2DInterface;
13 import org.opentrafficsim.core.animation.TextAlignment;
14 import org.opentrafficsim.core.animation.TextAnimation;
15 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
16 import org.opentrafficsim.core.network.Node;
17
18 import nl.tudelft.simulation.dsol.animation.Locatable;
19 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
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 OTSSimulatorInterface simulator) throws NamingException, RemoteException
45 {
46 super(node, simulator);
47 this.text = new Text(node, node.getId(), 0.0f, 3.0f, TextAlignment.CENTER, Color.BLACK, simulator);
48 }
49
50
51 @Override
52 public final void paint(final Graphics2D graphics, final ImageObserver observer)
53 {
54 graphics.setColor(Color.BLACK);
55 graphics.draw(new Ellipse2D.Double(-1.0, -1.0, 2.0, 2.0));
56 }
57
58
59 @Override
60 public final void destroy() throws NamingException
61 {
62 super.destroy();
63 this.text.destroy();
64 }
65
66
67 @Override
68 @SuppressWarnings("checkstyle:designforextension")
69 public ClonableRenderable2DInterface clone(final Locatable newSource, final OTSSimulatorInterface newSimulator)
70 throws NamingException, RemoteException
71 {
72
73 return new NodeAnimation((Node) newSource, newSimulator);
74 }
75
76
77 @Override
78 public final String toString()
79 {
80 return "NodeAnimation [node=" + super.getSource() + "]";
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 public class Text extends TextAnimation
97 {
98
99 private static final long serialVersionUID = 20161211L;
100
101
102
103
104
105
106
107
108
109
110
111
112 public Text(final Locatable source, final String text, final float dx, final float dy,
113 final TextAlignment textPlacement, final Color color, final OTSSimulatorInterface simulator)
114 throws RemoteException, NamingException
115 {
116 super(source, text, dx, dy, textPlacement, color, simulator);
117 setFlip(false);
118 setRotate(false);
119 }
120
121
122 @Override
123 @SuppressWarnings("checkstyle:designforextension")
124 public TextAnimation clone(final Locatable newSource, final OTSSimulatorInterface newSimulator)
125 throws RemoteException, NamingException
126 {
127 return new Text(newSource, getText(), getDx(), getDy(), getTextAlignment(), getColor(), newSimulator);
128 }
129
130
131 @Override
132 public final String toString()
133 {
134 return "NodeAnimation.Text []";
135 }
136 }
137
138 }