1
2
3
4
5
6 package nl.tudelft.goal.ut2004.visualizer.timeline.map;
7
8 import java.util.ArrayList;
9 import java.util.Collections;
10 import java.util.HashSet;
11 import java.util.LinkedList;
12 import java.util.List;
13 import java.util.Set;
14 import javax.media.opengl.GL;
15
16 import nl.tudelft.goal.ut2004.visualizer.map.BlendTriangle;
17
18
19
20
21
22
23
24
25
26
27
28
29 public class GLRendererCollection<T> implements ISubGLRenderer<GLRendererCollection<T>> {
30
31 private List<ISubGLRenderer<T>> renderers = Collections.synchronizedList(new ArrayList<ISubGLRenderer<T>>());
32
33
34
35
36
37 public synchronized void addSubRenderer(ISubGLRenderer<T> subrenderer) {
38 renderers.add(subrenderer);
39 }
40
41
42
43
44
45
46 public synchronized boolean removeSubRenderer(ISubGLRenderer<T> subrenderer) {
47 return renderers.remove(subrenderer);
48 }
49
50
51
52
53
54 public synchronized List<ISubGLRenderer<T>> getSubRenderes() {
55 return Collections.unmodifiableList(new ArrayList<ISubGLRenderer<T>>(renderers));
56 }
57
58
59
60
61
62 public synchronized List<ISubGLRenderer<T>> getRenderersOf(T o) {
63 ArrayList<ISubGLRenderer<T>> result = new ArrayList<ISubGLRenderer<T>>();
64
65 for (ISubGLRenderer<T> renderer : renderers) {
66 if (renderer.getObject() == o) {
67 result.add(renderer);
68 }
69 }
70 return result;
71 }
72
73
74
75
76
77 public synchronized void removeRenderersOf(T o) {
78 List<ISubGLRenderer<T>> renderersOf = getRenderersOf(o);
79 for (ISubGLRenderer<T> renderer : renderersOf) {
80 removeSubRenderer(renderer);
81 }
82 }
83
84
85
86
87
88 public synchronized Set<T> getDrawnObjects() {
89 HashSet<T> set = new HashSet<T>();
90 for (ISubGLRenderer<T> renderer : renderers) {
91 set.add(renderer.getObject());
92 }
93 return set;
94 }
95
96 @Override
97 public synchronized void render(GL gl) {
98 ISubGLRenderer[] renderersArray = renderers.toArray(new ISubGLRenderer[0]);
99 for (ISubGLRenderer subrenderer : renderersArray) {
100 subrenderer.render(gl);
101 }
102 }
103
104 @Override
105 public GLRendererCollection<T> getObject() {
106 return this;
107 }
108
109
110
111
112
113
114 @Override
115 public synchronized void prepare(GL gl) {
116 for (ISubGLRenderer<T> renderer : renderers) {
117 renderer.prepare(gl);
118 }
119 }
120
121 @Override
122 public synchronized List<BlendTriangle> getBlendedTris() {
123 List<BlendTriangle> list = new LinkedList<BlendTriangle>();
124 ISubGLRenderer[] renderersArray = renderers.toArray(new ISubGLRenderer[0]);
125
126 for (ISubGLRenderer subrenderer : renderersArray) {
127 list.addAll(subrenderer.getBlendedTris());
128 }
129
130 return list;
131 }
132 }