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