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.rmi.RemoteException;
11 import java.util.function.Supplier;
12
13 import javax.naming.NamingException;
14
15 import org.djutils.base.Identifiable;
16 import org.djutils.draw.point.OrientedPoint2d;
17 import org.opentrafficsim.base.geometry.OtsLocatable;
18 import org.opentrafficsim.base.geometry.OtsRenderable;
19 import org.opentrafficsim.draw.DrawLevel;
20 import org.opentrafficsim.draw.TextAlignment;
21 import org.opentrafficsim.draw.TextAnimation;
22 import org.opentrafficsim.draw.network.NodeAnimation.NodeData;
23
24 import nl.tudelft.simulation.naming.context.Contextualized;
25
26
27
28
29
30
31
32
33
34
35 public class NodeAnimation extends OtsRenderable<NodeData>
36 {
37
38 private static final long serialVersionUID = 20140000L;
39
40
41 private Text text;
42
43
44
45
46
47
48
49 public NodeAnimation(final NodeData node, final Contextualized contextualized) throws NamingException, RemoteException
50 {
51 super(node, contextualized);
52 this.text = new Text(node, node::getId, 0.0f, 3.0f, TextAlignment.CENTER, Color.BLACK, contextualized,
53 TextAnimation.RENDERWHEN10);
54 }
55
56
57 @Override
58 public final void paint(final Graphics2D graphics, final ImageObserver observer)
59 {
60 setRendering(graphics);
61 graphics.setColor(Color.BLACK);
62 graphics.setStroke(new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
63 graphics.draw(new Ellipse2D.Double(-0.5, -0.5, 1.0, 1.0));
64 double direction = getSource().getLocation().getDirZ();
65 if (!Double.isNaN(direction))
66 {
67 GeneralPath arrow = new GeneralPath(Path2D.WIND_EVEN_ODD, 3);
68 arrow.moveTo(0.5, -0.5);
69 arrow.lineTo(2, 0);
70 arrow.lineTo(0.5, 0.5);
71 graphics.draw(arrow);
72 }
73 resetRendering(graphics);
74 }
75
76
77 @Override
78 public void destroy(final Contextualized contextProvider)
79 {
80 super.destroy(contextProvider);
81 this.text.destroy(contextProvider);
82 }
83
84
85 @Override
86 public final String toString()
87 {
88 return "NodeAnimation [node=" + super.getSource() + "]";
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102 public class Text extends TextAnimation<NodeData, Text>
103 {
104
105 private static final long serialVersionUID = 20161211L;
106
107
108
109
110
111
112
113
114
115
116
117
118
119 @SuppressWarnings("checkstyle:parameternumber")
120 public Text(final NodeData source, final Supplier<String> text, final float dx, final float dy,
121 final TextAlignment textPlacement, final Color color, final Contextualized contextualized,
122 final ScaleDependentRendering scaleDependentRendering) throws RemoteException, NamingException
123 {
124 super(source, text, dx, dy, textPlacement, color, 2.0f, 12.0f, 50f, contextualized, scaleDependentRendering);
125 setFlip(false);
126 setRotate(false);
127 }
128
129
130 @Override
131 public final String toString()
132 {
133 return "NodeAnimation.Text []";
134 }
135 }
136
137
138
139
140
141
142
143
144
145
146 public interface NodeData extends OtsLocatable, Identifiable
147 {
148
149 @Override
150 public OrientedPoint2d getLocation();
151
152
153 @Override
154 default double getZ()
155 {
156 return DrawLevel.NODE.getZ();
157 }
158 }
159
160 }