1 package org.opentrafficsim.draw.road;
2
3 import java.awt.Color;
4 import java.awt.Graphics2D;
5 import java.awt.geom.Path2D;
6 import java.awt.image.ImageObserver;
7 import java.rmi.RemoteException;
8
9 import javax.naming.NamingException;
10
11 import org.opentrafficsim.base.geometry.OtsLocatable;
12 import org.opentrafficsim.base.geometry.OtsRenderable;
13 import org.opentrafficsim.draw.DrawLevel;
14 import org.opentrafficsim.draw.TextAlignment;
15 import org.opentrafficsim.draw.TextAnimation;
16 import org.opentrafficsim.draw.road.GtuGeneratorPositionAnimation.GtuGeneratorPositionData;
17
18 import nl.tudelft.simulation.naming.context.Contextualized;
19
20
21
22
23
24
25
26
27
28
29
30 public class GtuGeneratorPositionAnimation extends OtsRenderable<GtuGeneratorPositionData>
31 {
32
33
34 private static final long serialVersionUID = 20230204L;
35
36
37 private static final Path2D.Float PATH;
38
39 static
40 {
41 PATH = new Path2D.Float();
42 addChevron(PATH, 0);
43 addChevron(PATH, 1);
44 addChevron(PATH, 2);
45 }
46
47
48
49
50
51
52 private static void addChevron(final Path2D.Float path, final int number)
53 {
54 float x = number * 1.5f;
55 path.moveTo(x, -1.0);
56 path.lineTo(x + 1.0, 0.0);
57 path.lineTo(x, 1.0);
58 path.lineTo(x + 0.75, 1.0);
59 path.lineTo(x + 1.75, 0.0);
60 path.lineTo(x + 0.75, -1.0);
61 path.lineTo(x, -1.0);
62 }
63
64
65
66
67
68
69
70
71 public GtuGeneratorPositionAnimation(final GtuGeneratorPositionData source, final Contextualized contextProvider)
72 throws RemoteException, NamingException
73 {
74 super(source, contextProvider);
75 new Queue(source, contextProvider);
76 }
77
78
79 @Override
80 public void paint(final Graphics2D graphics, final ImageObserver observer)
81 {
82 graphics.setColor(Color.BLUE);
83 setRendering(graphics);
84 graphics.fill(PATH);
85 resetRendering(graphics);
86 }
87
88
89
90
91
92
93
94
95
96
97
98
99 public class Queue extends TextAnimation<GtuGeneratorPositionData, Queue>
100 {
101
102 private static final long serialVersionUID = 20230204L;
103
104
105
106
107
108
109
110
111 public Queue(final GtuGeneratorPositionData source, final Contextualized contextualized)
112 throws RemoteException, NamingException
113 {
114 super(source, () -> Integer.toString(source.getQueueCount()), 0.0f, 0.0f, TextAlignment.CENTER, Color.BLACK, 3.0f,
115 12.0f, 50f, contextualized, null, TextAnimation.RENDERWHEN10);
116 }
117 }
118
119
120
121
122
123
124
125
126
127
128 public interface GtuGeneratorPositionData extends OtsLocatable
129 {
130
131
132
133
134 int getQueueCount();
135
136
137 @Override
138 default double getZ()
139 {
140 return DrawLevel.OBJECT.getZ();
141 }
142 }
143
144 }