-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrabberObject.java
220 lines (197 loc) · 6.86 KB
/
GrabberObject.java
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/**************************************************************************************
* bias_tree
* Copyright (c) 2014-2017 National University of Colombia, https://github.com/remixlab
* @author Jean Pierre Charalambos, http://otrolado.info/
*
* All rights reserved. Library that eases the creation of interactive
* scenes, released under the terms of the GNU Public License v3.0
* which is available at http://www.gnu.org/licenses/gpl.html
**************************************************************************************/
package remixlab.bias;
import remixlab.bias.event.*;
/**
* {@link Grabber} object which eases third-party implementation of the
* {@link Grabber} interface.
* <p>
* Based on the concrete event type, this model object splits the
* {@link #checkIfGrabsInput(BogusEvent)} and the {@link #performInteraction(BogusEvent)}
* methods into more specific versions of them, e.g.,
* {@link #checkIfGrabsInput(ClickEvent)}, {@link #checkIfGrabsInput(DOF3Event)},
* {@link #performInteraction(DOF6Event)} , {@link #performInteraction(KeyboardEvent)} and
* so on. Thus allowing implementations of this abstract GrabberObject to override only
* those method signatures that might be of their interest.
*/
public abstract class GrabberObject implements Grabber {
/**
* Empty constructor.
*/
public GrabberObject() {
}
/**
* Constructs and adds this grabber to the agent pool.
*
* @see Agent#grabbers()
*/
public GrabberObject(Agent agent) {
agent.addGrabber(this);
}
/**
* Constructs and adds this grabber to all agents belonging to the input handler.
*
* @see InputHandler#agents()
*/
public GrabberObject(InputHandler inputHandler) {
inputHandler.addGrabber(this);
}
/**
* Check if this object is the {@link Agent#inputGrabber()} . Returns
* {@code true} if this object grabs the agent and {@code false} otherwise.
*/
public boolean grabsInput(Agent agent) {
return agent.inputGrabber() == this;
}
/**
* Checks if the frame grabs input from any agent registered at the given input handler.
*/
public boolean grabsInput(InputHandler inputHandler) {
for (Agent agent : inputHandler.agents()) {
if (agent.inputGrabber() == this)
return true;
}
return false;
}
@Override
public void performInteraction(BogusEvent event) {
if (event instanceof KeyboardEvent)
performInteraction((KeyboardEvent) event);
if (event instanceof ClickEvent)
performInteraction((ClickEvent) event);
if (event instanceof MotionEvent)
performInteraction((MotionEvent) event);
}
/**
* Calls performInteraction() on the proper motion event:
* {@link remixlab.bias.event.DOF1Event}, {@link remixlab.bias.event.DOF2Event},
* {@link remixlab.bias.event.DOF3Event} or {@link remixlab.bias.event.DOF6Event}.
* <p>
* Override this method when you want the object to perform an interaction from a
* {@link remixlab.bias.event.MotionEvent}.
*/
protected void performInteraction(MotionEvent event) {
if (event instanceof DOF1Event)
performInteraction((DOF1Event) event);
if (event instanceof DOF2Event)
performInteraction((DOF2Event) event);
if (event instanceof DOF3Event)
performInteraction((DOF3Event) event);
if (event instanceof DOF6Event)
performInteraction((DOF6Event) event);
}
/**
* Override this method when you want the object to perform an interaction from a
* {@link remixlab.bias.event.KeyboardEvent}.
*/
protected void performInteraction(KeyboardEvent event) {
}
/**
* Override this method when you want the object to perform an interaction from a
* {@link remixlab.bias.event.ClickEvent}.
*/
protected void performInteraction(ClickEvent event) {
}
/**
* Override this method when you want the object to perform an interaction from a
* {@link remixlab.bias.event.DOF1Event}.
*/
protected void performInteraction(DOF1Event event) {
}
/**
* Override this method when you want the object to perform an interaction from a
* {@link remixlab.bias.event.DOF2Event}.
*/
protected void performInteraction(DOF2Event event) {
}
/**
* Override this method when you want the object to perform an interaction from a
* {@link remixlab.bias.event.DOF3Event}.
*/
protected void performInteraction(DOF3Event event) {
}
/**
* Override this method when you want the object to perform an interaction from a
* {@link remixlab.bias.event.DOF6Event}.
*/
protected void performInteraction(DOF6Event event) {
}
@Override
public boolean checkIfGrabsInput(BogusEvent event) {
if (event instanceof KeyboardEvent)
return checkIfGrabsInput((KeyboardEvent) event);
if (event instanceof ClickEvent)
return checkIfGrabsInput((ClickEvent) event);
if (event instanceof MotionEvent)
return checkIfGrabsInput((MotionEvent) event);
return false;
}
/**
* Calls checkIfGrabsInput() on the proper motion event:
* {@link remixlab.bias.event.DOF1Event}, {@link remixlab.bias.event.DOF2Event},
* {@link remixlab.bias.event.DOF3Event} or {@link remixlab.bias.event.DOF6Event}.
* <p>
* Override this method when you want the object to be picked from a
* {@link remixlab.bias.event.KeyboardEvent}.
*/
public boolean checkIfGrabsInput(MotionEvent event) {
if (event instanceof DOF1Event)
return checkIfGrabsInput((DOF1Event) event);
if (event instanceof DOF2Event)
return checkIfGrabsInput((DOF2Event) event);
if (event instanceof DOF3Event)
return checkIfGrabsInput((DOF3Event) event);
if (event instanceof DOF6Event)
return checkIfGrabsInput((DOF6Event) event);
return false;
}
/**
* Override this method when you want the object to be picked from a
* {@link remixlab.bias.event.KeyboardEvent}.
*/
protected boolean checkIfGrabsInput(KeyboardEvent event) {
return false;
}
/**
* Override this method when you want the object to be picked from a
* {@link remixlab.bias.event.ClickEvent}.
*/
protected boolean checkIfGrabsInput(ClickEvent event) {
return false;
}
/**
* Override this method when you want the object to be picked from a
* {@link remixlab.bias.event.DOF1Event}.
*/
protected boolean checkIfGrabsInput(DOF1Event event) {
return false;
}
/**
* Override this method when you want the object to be picked from a
* {@link remixlab.bias.event.DOF2Event}.
*/
protected boolean checkIfGrabsInput(DOF2Event event) {
return false;
}
/**
* Override this method when you want the object to be picked from a
* {@link remixlab.bias.event.DOF3Event}.
*/
protected boolean checkIfGrabsInput(DOF3Event event) {
return false;
}
/**
* Override this method when you want the object to be picked from a
* {@link remixlab.bias.event.DOF6Event}.
*/
protected boolean checkIfGrabsInput(DOF6Event event) {
return false;
}
}