edu.umd.cs.jazz.event
Class ZMouseFilter

java.lang.Object
  |
  +--edu.umd.cs.jazz.event.ZMouseFilter

public class ZMouseFilter
extends java.lang.Object

ZMouseFilter is used by ZFilteredEventHandler to filter (accept or reject) mouse events. It is intended to separate event test code from event handlers so that it's easy to change the events that drive a event handlers behavior without needing to subclass or modifying the event handler.

An events type, click count, and modifier field can be used to filter the event. The filter can optionally consume any events that it accepts. This consuming behavior is off by default.


      // ZMouseFilter examples.

      ZMouseFilter filter = new ZMouseFilter();
      // A new filter accepts all events.

      filter.setAndMask(InputEvent.BUTTON1_MASK);
      // The filter will now only accept events that have the button1 modifier

      filter.setNotMask(InputEvent.SHIFT_MASK);
      // The filter will now only accept events that have the button1 modifier
      // and do not have the shift modifier.

      filter.rejectAllEventTypes();
      // The filter will now reject all events based on the type of the event. The
      // andMask and notMask set previously are still preserved.

      filter.setAcceptsMousePressed(true);
      // The filter will now only accept mouse pressed events
      // that have the button1 modifier
      // and do not have the shift modifier.

      filter.setAndMask(0); // don't require any modifiers for acceptance.
      filter.setNotMask(0); // don't reject on the presence of any modifiers.
      filter.acceptAllEventTypes(); // don't reject based on event type.
      filter.setOrMask(InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK);
      // The filter will now accept any event that has either the button1 modifier or
      // the button2 modifier or both.

      filter.setOrMask(ALL_MODIFIERS_MASK);
      // The filter will now accept all events once again.

 

Author:
Jesse Grosjean
See Also:
ZFilteredEventHandler

Field Summary
static int ALL_MODIFIERS_MASK
          A mask containing all modifiers.
 
Constructor Summary
ZMouseFilter()
          Constructs a new ZMouseFilter that accepts all events.
ZMouseFilter(int aAndMask)
          Constructs a new ZMouseFilter that accepts only events that have all the modifiers that are specified in the AND mask parameter.
ZMouseFilter(int aAndMask, int aNotMask)
          Constructs a new ZMouseFilter that accepts only events that have all the modifiers that are specified in the AND mask parameter, and none of the modifiers specified in the NOT mask parameter.
 
Method Summary
 boolean accept(ZMouseEvent aEvent)
          Return true if the event should be accepted, false if it should not.
 void acceptAllClickCounts()
          Make it so that this event filter accepts all click counts.
 void acceptAllEventTypes()
          Make the filter accept all event types.
 void acceptEverything()
          Make the filter accept all events.
 boolean getAcceptsMouseClicked()
          Returns true if the filter is accepting mouse clicked events.
 boolean getAcceptsMouseDragged()
          Returns true if the filter is accepting mouse dragged events.
 boolean getAcceptsMouseEntered()
          Returns true if the filter is accepting mouse entered events.
 boolean getAcceptsMouseExited()
          Returns true if the filter is accepting mouse exited events.
 boolean getAcceptsMouseMoved()
          Returns true if the filter is accepting mouse moved events.
 boolean getAcceptsMousePressed()
          Returns true if the filter is accepting mouse pressed events.
 boolean getAcceptsMouseReleased()
          Returns true if the filter is accepting mouse released events.
 boolean getConsumes()
          Returns true if this event filter consumes accepted events.
 void rejectAllClickCounts()
          Make it so that this event filter rejects all click counts.
 void rejectAllEventTypes()
          Make the filter reject all event types.
 void setAcceptClickCount(short aClickCount)
          Set the click count to be accepted.
 void setAcceptsMouseClicked(boolean aBoolean)
          Set if the filter is accepting mouse clicked events.
 void setAcceptsMouseDragged(boolean aBoolean)
          Set if the filter is accepting mouse dragged events.
 void setAcceptsMouseEntered(boolean aBoolean)
          Set if the filter is accepting mouse entered events.
 void setAcceptsMouseExited(boolean aBoolean)
          Set if the filter is accepting mouse exited events.
 void setAcceptsMouseMoved(boolean aBoolean)
          Set if the filter is accepting mouse moved events.
 void setAcceptsMousePressed(boolean aBoolean)
          Set if the filter is accepting mouse pressed events.
 void setAcceptsMouseReleased(boolean aBoolean)
          Set if the filter is accepting mouse released events.
 void setAndMask(int aAndMask)
          Set the AND bitmask.
 void setConsumes(boolean aBoolean)
          Make it so that this event filter consumes all events that it accepts.
 void setNotMask(int aNotMask)
          Set the NOT bitmask.
 void setOrMask(int aOrMask)
          Set the OR bitmask.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALL_MODIFIERS_MASK

public static int ALL_MODIFIERS_MASK
A mask containing all modifiers. This is most useful for setting the orMask so that it will accept anything.

Constructor Detail

ZMouseFilter

public ZMouseFilter()
Constructs a new ZMouseFilter that accepts all events.


ZMouseFilter

public ZMouseFilter(int aAndMask)
Constructs a new ZMouseFilter that accepts only events that have all the modifiers that are specified in the AND mask parameter.

Parameters:
aAndMask - a bitmask specifying the flags that must be present for the event to be accepted.

ZMouseFilter

public ZMouseFilter(int aAndMask,
                    int aNotMask)
Constructs a new ZMouseFilter that accepts only events that have all the modifiers that are specified in the AND mask parameter, and none of the modifiers specified in the NOT mask parameter.

Parameters:
aAndMask - a bitmask specifying the flags that must be present for the event to be accepted.
aNotMask - a bitmask specifying the flags that must not be present for the event to be accepted.
Method Detail

setAndMask

public void setAndMask(int aAndMask)
Set the AND bitmask. This mask specifies the modifiers that must be present in a event for the event to be accepted by the filter.

Parameters:
aAndMask - a bitmask specifying the flags that must be present for the event to be accepted.

setOrMask

public void setOrMask(int aOrMask)
Set the OR bitmask. A event must have at least one of the modifiers specified in the or mask to be accepted by the filter.

Parameters:
aOrMask - a bitmask specifying the OR flags, at least one must be present in an event for the event to be accepted by the filter.

setNotMask

public void setNotMask(int aNotMask)
Set the NOT bitmask. This mask specifies the modifiers that must not be present in a event for the event to be accepted by the filter.

Parameters:
aNotMask - a bitmask specifying the flags that must not be present for the event to be accepted.

setAcceptClickCount

public void setAcceptClickCount(short aClickCount)
Set the click count to be accepted. The click count of an event must equal this click count for that event to be accepted. A value of -1 for click count will accept all event click counts.

Parameters:
aClickCount - the click count required of an event for it to be accepted.

acceptAllClickCounts

public void acceptAllClickCounts()
Make it so that this event filter accepts all click counts.


rejectAllClickCounts

public void rejectAllClickCounts()
Make it so that this event filter rejects all click counts.


setConsumes

public void setConsumes(boolean aBoolean)
Make it so that this event filter consumes all events that it accepts. If an event is not accepted it will not be consumed. The default value for this is false.

Parameters:
aBoolean - true if this filter consumes accepted events.

getConsumes

public boolean getConsumes()
Returns true if this event filter consumes accepted events.

Returns:
true if the filter is consuming events that it accepts.

getAcceptsMouseClicked

public boolean getAcceptsMouseClicked()
Returns true if the filter is accepting mouse clicked events.


setAcceptsMouseClicked

public void setAcceptsMouseClicked(boolean aBoolean)
Set if the filter is accepting mouse clicked events.

Parameters:
aBoolean - true if the filter is accepting mouse clicked events.

getAcceptsMouseEntered

public boolean getAcceptsMouseEntered()
Returns true if the filter is accepting mouse entered events.


setAcceptsMouseEntered

public void setAcceptsMouseEntered(boolean aBoolean)
Set if the filter is accepting mouse entered events.

Parameters:
aBoolean - true if the filter is accepting mouse entered events.

getAcceptsMouseExited

public boolean getAcceptsMouseExited()
Returns true if the filter is accepting mouse exited events.


setAcceptsMouseExited

public void setAcceptsMouseExited(boolean aBoolean)
Set if the filter is accepting mouse exited events.

Parameters:
aBoolean - true if the filter is accepting mouse exited events.

getAcceptsMousePressed

public boolean getAcceptsMousePressed()
Returns true if the filter is accepting mouse pressed events.


setAcceptsMousePressed

public void setAcceptsMousePressed(boolean aBoolean)
Set if the filter is accepting mouse pressed events.

Parameters:
aBoolean - true if the filter is accepting mouse pressed events.

getAcceptsMouseReleased

public boolean getAcceptsMouseReleased()
Returns true if the filter is accepting mouse released events.


setAcceptsMouseReleased

public void setAcceptsMouseReleased(boolean aBoolean)
Set if the filter is accepting mouse released events.

Parameters:
aBoolean - true if the filter is accepting mouse released events.

getAcceptsMouseDragged

public boolean getAcceptsMouseDragged()
Returns true if the filter is accepting mouse dragged events.


setAcceptsMouseDragged

public void setAcceptsMouseDragged(boolean aBoolean)
Set if the filter is accepting mouse dragged events.

Parameters:
aBoolean - true if the filter is accepting mouse dragged events.

getAcceptsMouseMoved

public boolean getAcceptsMouseMoved()
Returns true if the filter is accepting mouse moved events.


setAcceptsMouseMoved

public void setAcceptsMouseMoved(boolean aBoolean)
Set if the filter is accepting mouse moved events.

Parameters:
aBoolean - true if the filter is accepting mouse moved events.

rejectAllEventTypes

public void rejectAllEventTypes()
Make the filter reject all event types. (MOUSE_PRESSED, MOUSE_RELEASED ...)


acceptAllEventTypes

public void acceptAllEventTypes()
Make the filter accept all event types. (MOUSE_PRESSED, MOUSE_RELEASED ...)


acceptEverything

public void acceptEverything()
Make the filter accept all events. Accept all types, modifiers, and clickcounts.


accept

public boolean accept(ZMouseEvent aEvent)
Return true if the event should be accepted, false if it should not. This method takes into consideration: