|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.umd.cs.jazz.event.ZFilteredEventHandler
ZFilteredEventHandler is an abstract implementation of ZEventHandler. This class provides flexible event filtering. This allows one to easily filter the events that this event handler will receive without modifying the event handler source code.
This class automatically handles the task of registering and unregistering with its filtered event sources. These sources (a key event source and mouse event source) are specified as arguments to this class's constructor or with setKeyEventSource
and setMouseEventSource
. The normal behavior when this class is set to active is to register as a KeyListener with the filtered key event souce if it is not null, and to register as a ZMouseListener and a ZMouseMotionListener with the filtered mouse event source if it is not null. This behavior can be customized by overriding these methods:
protected boolean wantsKeyEvents()
protected boolean wantsMouseEvents()
protected boolean wantsMouseMotionEvents()
Filtering is supported by the ZMouseFilter class together with the following template methods that subclasses should override if they are interested in that event.
protected void filteredKeyPressed(KeyEvent e)
protected void filteredKeyReleased(KeyEvent e)
protected void filteredKeyTyped(KeyEvent e)
protected void filteredMouseClicked(ZMouseEvent e)
protected void filteredMouseDragged(ZMouseEvent e)
protected void filteredMouseEntered(ZMouseEvent e)
protected void filteredMouseExited(ZMouseEvent e)
protected void filteredMouseMoved(ZMouseEvent e)
protected void filteredMousePressed(ZMouseEvent e)
protected void filteredMouseReleased(ZMouseEvent e)
These methods will only be called if the the event filter assocaited with this event handler first accepts the incoming event.
Filters can be used in two ways. An external application can use them to modify the behavior of a existing event handler. For example an application can tell a ZPanEventHandler to only accept ZMouseEvents that have the shift modifier pressed, and this will cause the panning to occur only when the shift key is down.
// Example of using a mouse filter externally.
...
// Get a reference to the pan event handlers filter.
ZMouseFilter panFilter = canvas.getPanEventHandler().getMouseFilter();
// Set the filters andMask to contain button1 and shift. This means that
// an event must have both button1 and shift in its modifiers to be accepted by
// the filter. The panning action will now only occur when those modifiers are both set.
panFilter.setAndMask(InputEvent.BUTTON1_MASK | InputEvent.SHIFT_MASK);
...
Filters can also be used internally by an event handlers implementation. For example a event handler can determine on a filtered mouse down event that it is not appropriate for it to act in the current context and can then set its filter to accept nothing but the next filtered mouse down event that it sees. This can get rid of testing code in other methods such as mouse moved and mouse released that determines if the event handler should really act in that context or not.
// Example of using a mouse filter internally.
protected void filteredMousePressed(ZMouseEvent e) {
if (shouldStartHandlingEvents(e)) { // This may test for the type of node that the mouse
// is over or any other contextual information.
// Since the event handler wants to handle events for this context it
// must tell its filter to accept all incoming events.
getMouseFilter().acceptAllEventTypes();
} else {
// Since the event handler does not want to handle events for this context it
// must tell its filter to reject all incoming events.
getMouseFilter().rejectAllEventTypes();
// But then it must tell its event handler to accept mouse pressed events so that
// it will have a chance to handle the next filtered mouse down event that will bring a
// new context with it.
getMouseFilter().setIsAcceptingMousePressed(true);
}
}
ZMouseFilter
Nested Class Summary | |
class |
ZFilteredEventHandler.ZFilteredEventDispatcher ZFilteredEventDispatcher is used internally to register with the filtered event sources. |
Field Summary | |
protected ZFilteredEventHandler.ZFilteredEventDispatcher |
fFilteredEventDispatcher |
protected ZMouseFilter |
fMouseFilter |
Constructor Summary | |
ZFilteredEventHandler(ZSceneGraphObject aFilteredMouseEventSource) Constructs a new ZFilteredEventHandler. |
|
ZFilteredEventHandler(ZSceneGraphObject aFilteredMouseEventSource, ZCanvas aFilteredKeyEventSource) Constructs a new ZFilteredEventHandler. |
Method Summary | |
protected void |
filteredKeyPressed(java.awt.event.KeyEvent e) Invoked when a key is pressed on the key event souce and the event filter accepts the event. |
protected void |
filteredKeyReleased(java.awt.event.KeyEvent e) Invoked when a key is released on the key event souce and the event filter accepts the event. |
protected void |
filteredKeyTyped(java.awt.event.KeyEvent e) Invoked when a key is typed on the key event souce and the event filter accepts the event. |
protected void |
filteredMouseClicked(ZMouseEvent e) Invoked when the is clicked the mouse event souce and the current event filter accepts the event. |
protected void |
filteredMouseDragged(ZMouseEvent e) Invoked when a mouse button is pressed on the mouse event source and then dragged if the current event filter accepts the event. |
protected void |
filteredMouseEntered(ZMouseEvent e) Invoked when the mouse enters the mouse event souce and the current event filter accepts the event. |
protected void |
filteredMouseExited(ZMouseEvent e) Invoked when the mouse exits the mouse event souce and the current event filter accepts the event. |
protected void |
filteredMouseMoved(ZMouseEvent e) Invoked when the mouse button is moved on the event source (with no buttons no down) and the current event filter accepts the event. |
protected void |
filteredMousePressed(ZMouseEvent e) Invoked when the mouse button is pressed on the event source and the current event filter accepts the event. |
protected void |
filteredMouseReleased(ZMouseEvent e) Invoked when the mouse button is released on the event source and the current event filter accepts the event. |
ZMouseEvent |
getCurrentFilteredMouseEvent() Return the current filtered mouse event. |
java.util.Collection |
getCurrentSelection() Utility method for use by subclasses that operate on the current selection. |
ZFilteredEventHandler.ZFilteredEventDispatcher |
getFilteredEventDispatcher() Return the event dispatcher being used by this filtered event handler. |
ZCanvas |
getFilteredKeyEventSource() Return the current source for filtered key events. |
ZSceneGraphObject |
getFilteredMouseEventSource() Return the current source for mouse events. |
ZCamera |
getInteractionCamera() Return the camera that should be used for camera interactions for the current event. |
ZMouseFilter |
getMouseFilter() Returns the filter currently in effect for this event handler. |
ZCamera |
getTopCamera() Return the to camera for the current event. |
boolean |
isActive() Determines if this event handler is active. |
void |
setActive(boolean active) Specifies whether this event handler is active or not. |
void |
setFilteredKeyEventSource(ZCanvas aFilteredKeyEventSource) Set the current source for key events. |
void |
setFilteredMouseEventSource(ZSceneGraphObject aFilteredMouseEventSource) Set the current source for mouse events. |
void |
setMouseFilter(ZMouseFilter aMouseFilter) Set the mouse filter that is used to filter events before they are delivered to this event handler's "filtered*" methods. |
protected boolean |
wantsKeyEvents() Return true if the event handler should register with the key event source for KeyEvents. |
protected boolean |
wantsMouseEvents() Return true if the event handler should register with the mouse event source for ZMouseEvents. |
protected boolean |
wantsMouseMotionEvents() Return true if the event handler should register with the mouse event source for ZMouseMotionEvents. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected ZFilteredEventHandler.ZFilteredEventDispatcher fFilteredEventDispatcher
protected ZMouseFilter fMouseFilter
Constructor Detail |
public ZFilteredEventHandler(ZSceneGraphObject aFilteredMouseEventSource)
aFilteredMouseEventSource
- the source for filtered ZMouseEvents and ZMouseMotionEvents. See the class comment to customize this behavior.public ZFilteredEventHandler(ZSceneGraphObject aFilteredMouseEventSource, ZCanvas aFilteredKeyEventSource)
aFilteredMouseEventSource
- the source for filtered ZMouseEvents and ZMouseMotionEvents. See the class comment to customize this behavior.aFilteredKeyEventSource
- the source for filtered KeyEvents. See the class comment to customize this behavior.Method Detail |
public void setMouseFilter(ZMouseFilter aMouseFilter)
aMouseFilter
- the new filter for this event handler to use.public ZMouseFilter getMouseFilter()
protected boolean wantsKeyEvents()
setActive
to determine if this event handler should register with the key event source.
protected boolean wantsMouseEvents()
setActive
to determine if this event handler should register for mouse events from the mouse event source.
protected boolean wantsMouseMotionEvents()
setActive
to determine if this event handler should register for mouse motion events from the mouse event source.
public ZSceneGraphObject getFilteredMouseEventSource()
public void setFilteredMouseEventSource(ZSceneGraphObject aFilteredMouseEventSource)
public ZCanvas getFilteredKeyEventSource()
public void setFilteredKeyEventSource(ZCanvas aFilteredKeyEventSource)
public boolean isActive()
isActive
in interface ZEventHandler
true
if active.public void setActive(boolean active)
setActive
in interface ZEventHandler
active
- true
to make this event handler active.public ZMouseEvent getCurrentFilteredMouseEvent()
public java.util.Collection getCurrentSelection()
public ZCamera getInteractionCamera()
public ZCamera getTopCamera()
public ZFilteredEventHandler.ZFilteredEventDispatcher getFilteredEventDispatcher()
protected void filteredKeyPressed(java.awt.event.KeyEvent e)
e
- the filtered key pressed event accepted by the event filter.protected void filteredKeyReleased(java.awt.event.KeyEvent e)
e
- the filtered key released event accepted by the event filter.protected void filteredKeyTyped(java.awt.event.KeyEvent e)
e
- the filtered key typed event accepted by the event filter.protected void filteredMouseClicked(ZMouseEvent e)
e
- the filtered key typed event accepted by the event filter.protected void filteredMouseDragged(ZMouseEvent e)
Mouse drag events will continue to be delivered to the event source until the mouse button is released (regardless of whether the mouse position is within the bounds of the event source).
e
- the filtered mouse dragged event.protected void filteredMouseEntered(ZMouseEvent e)
e
- the filtered mouse entered event.protected void filteredMouseExited(ZMouseEvent e)
e
- the filtered mouse exited event.protected void filteredMouseMoved(ZMouseEvent e)
e
- the filtered mouse moved event.protected void filteredMousePressed(ZMouseEvent e)
e
- the filtered mouse pressed event.protected void filteredMouseReleased(ZMouseEvent e)
e
- the filtered mouse released event.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |