1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.ximtec.igesture.util.additions3d;
27
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Vector;
31 import java.util.logging.Level;
32 import java.util.logging.Logger;
33
34 import org.sigtec.ink.input.TimestampedInputEvent;
35 import org.sigtec.input.InputHandler;
36
37 public class RecordedGesture3D implements Cloneable, InputHandler {
38
39 private static final Logger LOGGER = Logger.getLogger(RecordedGesture3D.class.getName());
40
41 private List<Point3D> points;
42 private Accelerations accelerations;
43
44
45
46
47
48
49 public RecordedGesture3D() {
50 points = new Vector<Point3D>();
51 }
52
53
54
55
56
57
58
59
60 public RecordedGesture3D(List<Point3D> points) {
61 this();
62 if (points != null) {
63 this.points = points;
64 }
65 }
66
67
68
69
70
71
72
73 public void add(Point3D point) {
74 points.add(point);
75 }
76
77
78
79
80
81
82
83 public void addAll(List<Point3D> points) {
84 this.points.addAll(points);
85 }
86
87
88
89
90
91
92
93 public void remove(Point3D point) {
94 points.remove(point);
95 }
96
97
98
99
100
101
102 public Iterator<Point3D> iterator() {
103 return points.iterator();
104 }
105
106
107
108
109
110
111
112
113 public Point3D get(int index) {
114 return points.get(index);
115 }
116
117
118
119
120
121
122 public List<Point3D> getPoints() {
123 return points;
124 }
125
126
127
128
129
130
131 public int size() {
132 return points.size();
133 }
134
135
136
137
138
139
140 public Point3D getStartPoint() {
141 return (!points.isEmpty()) ? (Point3D) points.get(0) : null;
142 }
143
144
145
146
147
148
149 public Point3D getEndPoint() {
150 return (!points.isEmpty()) ? (Point3D) points.get(points.size() - 1)
151 : null;
152 }
153
154
155
156
157
158
159 public long getDuration() {
160 Point3D startPoint = getStartPoint();
161 Point3D endPoint = getEndPoint();
162
163 if ((startPoint != null) && (endPoint != null)) {
164 return endPoint.getTimeStamp() - startPoint.getTimeStamp();
165 } else {
166 return 0;
167 }
168 }
169
170
171
172
173
174
175
176
177 public boolean hasTimestamp() {
178 return getStartPoint().hasTimeStamp();
179 }
180
181 @Override
182 public synchronized void handle(Object invoker,
183 TimestampedInputEvent timestampedEvent) {
184
185
186 }
187
188
189
190
191
192
193 public Accelerations getAccelerations() {
194 return accelerations;
195 }
196
197
198
199
200
201
202
203 public void setAccelerations(Accelerations accelerations) {
204 this.accelerations = accelerations;
205 }
206
207
208
209
210
211
212
213 public void setPoints(List<Point3D> pointsList) {
214 this.points = pointsList;
215 }
216
217
218
219
220
221 @Override
222 @SuppressWarnings("unchecked")
223 public Object clone() {
224 RecordedGesture3D clone = null;
225
226 try {
227 clone = (RecordedGesture3D)super.clone();
228 List<Point3D> clonedPoints = new Vector<Point3D>();
229
230 for (Point3D point : points) {
231 clonedPoints.add((Point3D)point.clone());
232 }
233
234 clone.points = clonedPoints;
235 clone.accelerations = (Accelerations) accelerations.clone();
236 }
237 catch (CloneNotSupportedException e) {
238 LOGGER.log(Level.SEVERE, e.toString());
239 }
240
241 return clone;
242 }
243
244 }