public abstract class Agent extends Object
BogusEvent
) for third party objects (
Grabber
objects) to consume them (
handle(BogusEvent)
). Agents thus effectively open up a channel between all
kinds of input data sources and user-space objects. To add/remove a grabber to/from the
grabbers()
collection issue addGrabber(Grabber)
/
removeGrabber(Grabber)
calls. Derive from this agent and either call
handle(BogusEvent)
or override handleFeed()
.
The agent may send bogus-events to its inputGrabber()
which may be regarded as
the agent's grabber target. The inputGrabber()
may be set by querying each
grabber object in grabbers()
to check if its
Grabber.checkIfGrabsInput(BogusEvent)
) condition is met (see
updateTrackedGrabber(BogusEvent)
, updateTrackedGrabberFeed()
). The
first grabber meeting the condition, namely the trackedGrabber()
), will then
be set as the inputGrabber()
. When no grabber meets the condition, the
trackedGrabber()
is then set to null. In this case, a non-null
inputGrabber()
may still be set with setDefaultGrabber(Grabber)
(see
also defaultGrabber()
).
Constructor and Description |
---|
Agent(InputHandler inputHandler)
Constructs an Agent and registers is at the given inputHandler.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addGrabber(Grabber grabber)
Adds the grabber in
grabbers() . |
Grabber |
defaultGrabber()
Default
inputGrabber() returned when trackedGrabber() is null and
set with setDefaultGrabber(Grabber) . |
void |
disableTracking()
Disables tracking.
|
void |
enableTracking()
Enables tracking so that the
inputGrabber() may be updated when calling
updateTrackedGrabber(BogusEvent) . |
List<Grabber> |
grabbers()
Returns the list of grabber (and interactive-grabber) objects handled by this agent.
|
boolean |
hasGrabber(Grabber grabber)
Returns true if the grabber is currently in the agents
grabbers() list. |
Grabber |
inputGrabber()
If
trackedGrabber() is non null, returns it. |
InputHandler |
inputHandler()
Returns the
InputHandler this agent is registered to. |
boolean |
isInputGrabber(Grabber g)
Returns true if
g is the agent's inputGrabber() and false otherwise. |
boolean |
isTracking()
Returns
true if this agent is tracking its grabbers. |
boolean |
removeGrabber(Grabber grabber)
Removes the grabber from the
grabbers() list. |
void |
removeGrabbers()
Clears the
grabbers() list. |
void |
resetTrackedGrabber()
Sets the
trackedGrabber() to null . |
float[] |
sensitivities(MotionEvent event)
Returns the sensitivities used in
handle(BogusEvent) to
MotionEvent.modulate(float[]) . |
boolean |
setDefaultGrabber(Grabber grabber)
Sets the
defaultGrabber() |
void |
setTracking(boolean enable)
Sets the
isTracking() value. |
boolean |
shiftDefaultGrabber(Grabber g1,
Grabber g2)
Same as
defaultGrabber() != g1 ? setDefaultGrabber(g1) ? true : setDefaultGrabber(g2) : setDefaultGrabber(g2)
which is ubiquitous among the examples. |
void |
toggleTracking()
Calls
setTracking(boolean) to toggle the isTracking() value. |
Grabber |
trackedGrabber()
Returns the grabber set after
updateTrackedGrabber(BogusEvent) is called. |
public Agent(InputHandler inputHandler)
public boolean removeGrabber(Grabber grabber)
grabbers()
list.removeGrabbers()
,
addGrabber(Grabber)
,
hasGrabber(Grabber)
,
grabbers()
public void removeGrabbers()
grabbers()
list.public List<Grabber> grabbers()
public boolean hasGrabber(Grabber grabber)
grabbers()
list.public boolean addGrabber(Grabber grabber)
grabbers()
.public InputHandler inputHandler()
InputHandler
this agent is registered to.public float[] sensitivities(MotionEvent event)
handle(BogusEvent)
to
MotionEvent.modulate(float[])
.public Grabber inputGrabber()
trackedGrabber()
is non null, returns it. Otherwise returns the
defaultGrabber()
.trackedGrabber()
public boolean isInputGrabber(Grabber g)
g
is the agent's inputGrabber()
and false otherwise.public boolean isTracking()
true
if this agent is tracking its grabbers.
You may need to enableTracking()
first.
public void enableTracking()
inputGrabber()
may be updated when calling
updateTrackedGrabber(BogusEvent)
.disableTracking()
public void disableTracking()
enableTracking()
public void setTracking(boolean enable)
isTracking()
value.public void toggleTracking()
setTracking(boolean)
to toggle the isTracking()
value.public Grabber trackedGrabber()
updateTrackedGrabber(BogusEvent)
is called. It
may be null.public Grabber defaultGrabber()
inputGrabber()
returned when trackedGrabber()
is null and
set with setDefaultGrabber(Grabber)
.inputGrabber()
,
trackedGrabber()
public boolean shiftDefaultGrabber(Grabber g1, Grabber g2)
defaultGrabber() != g1 ? setDefaultGrabber(g1) ? true : setDefaultGrabber(g2) : setDefaultGrabber(g2)
which is ubiquitous among the examples.public boolean setDefaultGrabber(Grabber grabber)
defaultGrabber()
public void resetTrackedGrabber()
trackedGrabber()
to null
.Processing Library proscene by Jean Pierre Charalambos. (c) 2014-2017 National University of Colombia