1
2
3
4
5
6 package nl.tudelft.goal.ut2004.visualizer.timeline.map;
7
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashSet;
12 import java.util.List;
13 import java.util.Set;
14
15 import javax.media.opengl.GL;
16
17
18
19
20
21
22
23
24
25
26
27 public class CollectionRenderer<T> implements ISubGLRenderer<Collection<T>> {
28
29 private List<ISubGLRenderer<T>> renderers = Collections.synchronizedList(new ArrayList<ISubGLRenderer<T>>());
30
31
32
33
34
35
36
37 public synchronized void addRenderer(ISubGLRenderer<? extends T> subrenderer) {
38 renderers.add((ISubGLRenderer<T>) subrenderer);
39 }
40
41
42
43
44
45
46
47
48 public synchronized boolean removeRenderer(ISubGLRenderer<? extends T> subrenderer) {
49 return renderers.remove(subrenderer);
50 }
51
52
53
54
55
56
57
58 public synchronized void removeRenderersOf(Object o) {
59 Collection<ISubGLRenderer<T>> toRemove = new ArrayList<ISubGLRenderer<T>>();
60
61 for (ISubGLRenderer<T> renderer : renderers) {
62 if (renderer.getObject() == o) {
63 toRemove.add(renderer);
64 }
65
66 }
67
68 renderers.removeAll(toRemove);
69 }
70
71
72
73
74
75
76 public synchronized Set<T> getDrawnObjects() {
77 HashSet<T> set = new HashSet<T>();
78 for (ISubGLRenderer<T> renderer : renderers) {
79 set.add(renderer.getObject());
80 }
81 return set;
82 }
83
84 @Override
85 public synchronized void render(GL gl) {
86 for (ISubGLRenderer<T> subrenderer : renderers) {
87 subrenderer.render(gl);
88 }
89 }
90
91 @Override
92 public synchronized Collection<T> getObject() {
93 Collection<T> objects = new ArrayList<T>();
94 for (ISubGLRenderer<T> subrenderer : renderers) {
95 objects.add(subrenderer.getObject());
96 }
97
98 return objects;
99 }
100
101
102
103
104
105
106 @Override
107 public synchronized void prepare(GL gl) {
108 for (ISubGLRenderer<T> renderer : renderers) {
109 renderer.prepare(gl);
110 }
111 }
112
113 public synchronized T getObjectsByGLName(int glName) {
114
115 for (ISubGLRenderer<T> renderer : renderers) {
116 if (renderer.getGLName() == glName) {
117 return renderer.getObject();
118 }
119
120 }
121
122 return null;
123
124 }
125
126 public synchronized Collection<T> getObjectsByGLName(int[] list) {
127
128 Collection<T> results = new ArrayList<T>();
129 for (int glName : list) {
130 T result = getObjectsByGLName(glName);
131 if (result != null) {
132 results.add(result);
133 }
134 }
135
136 return results;
137
138 }
139
140 public void destroy() {
141 for(ISubGLRenderer<T> renderer : renderers){
142 renderer.destroy();
143 }
144
145 }
146
147 @Override
148 public int getGLName() {
149 return -1;
150 }
151 }