diff --git a/core/src/build/conf/checkstyle.xml b/core/src/build/conf/checkstyle.xml
index be1ded8..1c1489b 100644
--- a/core/src/build/conf/checkstyle.xml
+++ b/core/src/build/conf/checkstyle.xml
@@ -137,7 +137,10 @@
paint
or
* paintAfterChildren
instead.
*
@@ -2751,7 +2818,7 @@
* Return a new Image representing this node and all of its children. The
* image size will be equal to the size of this nodes full bounds.
*
- * @return a new image representing this node and its descendents
+ * @return a new image representing this node and its descendants
*/
public Image toImage() {
final PBounds b = getFullBoundsReference();
@@ -2766,9 +2833,12 @@
*
* @param width pixel width of the resulting image
* @param height pixel height of the resulting image
+ * @param backgroundPaint paint to fill the image with before drawing this
+ * node, may be null
+ *
* @return a new image representing this node and its descendents
*/
- public Image toImage(final int width, final int height, final Paint backGroundPaint) {
+ public Image toImage(final int width, final int height, final Paint backgroundPaint) {
BufferedImage result;
if (GraphicsEnvironment.isHeadless()) {
@@ -2780,7 +2850,7 @@
result = graphicsConfiguration.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
}
- return toImage(result, backGroundPaint);
+ return toImage(result, backgroundPaint);
}
/**
@@ -2788,7 +2858,10 @@
* background, paint is null, then the image will not be filled with a color
* prior to rendering
*
- * @return a rendering of this image and its descendents into the specified
+ * @param image Image onto which this node will be painted
+ * @param backGroundPaint will fill background of image with this. May be
+ * null.
+ * @return a rendering of this image and its descendants onto the specified
* image
*/
public Image toImage(final BufferedImage image, final Paint backGroundPaint) {
@@ -2843,6 +2916,8 @@
* @param graphics the context into which the node is drawn
* @param pageFormat the size and orientation of the page
* @param pageIndex the zero based index of the page to be drawn
+ *
+ * @return Either NO_SUCH_PAGE or PAGE_EXISTS
*/
public int print(final Graphics graphics, final PageFormat pageFormat, final int pageIndex) {
if (pageIndex != 0) {
@@ -2962,12 +3037,12 @@
}
/**
- * Try to pick this node and all of its descendents. Most subclasses should
+ * Try to pick this node and all of its descendants. Most subclasses should
* not need to override this method. Instead they should override
* pick
or pickAfterChildren
.
*
* @param pickPath the pick path to add the node to if its picked
- * @return true if this node or one of its descendents was picked.
+ * @return true if this node or one of its descendants was picked.
*/
public boolean fullPick(final PPickPath pickPath) {
if (getVisible() && (getPickable() || getChildrenPickable()) && fullIntersects(pickPath.getPickBounds())) {
@@ -3001,6 +3076,13 @@
return false;
}
+ /**
+ * Finds all descendants of this node that intersect with the given bounds
+ * and adds them to the results array.
+ *
+ * @param fullBounds bounds to compare against
+ * @param results array into which to add matches
+ */
public void findIntersectingNodes(final Rectangle2D fullBounds, final ArrayList results) {
if (fullIntersects(fullBounds)) {
final Rectangle2D localBounds = parentToLocal((Rectangle2D) fullBounds.clone());
@@ -3060,6 +3142,7 @@
* child was previously a child of another node, it is removed from that
* node first.
*
+ * @param index where in the children list to insert the child
* @param child the new child to add to this node
*/
public void addChild(final int index, final PNode child) {
@@ -3094,7 +3177,7 @@
/**
* Return true if this node is an ancestor of the parameter node.
*
- * @param node a possible descendent node
+ * @param node a possible descendant node
* @return true if this node is an ancestor of the given node
*/
public boolean isAncestorOf(final PNode node) {
@@ -3109,7 +3192,7 @@
}
/**
- * Return true if this node is a descendent of the parameter node.
+ * Return true if this node is a descendant of the parameter node.
*
* @param node a possible ancestor node
* @return true if this nodes descends from the given node
@@ -3127,6 +3210,8 @@
/**
* Return true if this node descends from the root.
+ *
+ * @return whether this node descends from root node
*/
public boolean isDescendentOfRoot() {
return getRoot() != null;
@@ -3147,6 +3232,8 @@
/**
* Change the order of this node in its parent's children list so that it
* will draw in front of all of its other sibling nodes.
+ *
+ * @param sibling sibling in back of which this nodes should be moved.
*/
public void moveInBackOf(final PNode sibling) {
final PNode p = parent;
@@ -3172,6 +3259,8 @@
/**
* Change the order of this node in its parent's children list so that it
* will draw before the given sibling node.
+ *
+ * @param sibling sibling in front of which this nodes should be moved.
*/
public void moveInFrontOf(final PNode sibling) {
final PNode p = parent;
@@ -3195,6 +3284,8 @@
/**
* Set the parent of this node. Note this is set automatically when adding
* and removing children.
+ *
+ * @param newParent the parent to which this node should be added
*/
public void setParent(final PNode newParent) {
final PNode old = parent;
@@ -3204,6 +3295,9 @@
/**
* Return the index where the given child is stored.
+ *
+ * @param child child so search for
+ * @return index of child or -1 if not found
*/
public int indexOfChild(final PNode child) {
if (children == null) {
@@ -3389,7 +3483,7 @@
}
/**
- * Return an iterator over this node's direct descendent children.
+ * Return an iterator over this node's direct descendant children.
*
* @return iterator over this nodes children
*/
@@ -3403,6 +3497,9 @@
/**
* Return the root node (instance of PRoot). If this node does not descend
* from a PRoot then null will be returned.
+ *
+ * @return root element of this node, or null if this node does not descend
+ * from a PRoot
*/
public PRoot getRoot() {
if (parent != null) {
@@ -3412,9 +3509,9 @@
}
/**
- * Return a collection containing this node and all of its descendent nodes.
+ * Return a collection containing this node and all of its descendant nodes.
*
- * @return a new collection containing this node and all descendents
+ * @return a new collection containing this node and all descendants
*/
public Collection getAllNodes() {
return getAllNodes(null, null);
@@ -3422,18 +3519,24 @@
/**
* Return a collection containing the subset of this node and all of its
- * descendent nodes that are accepted by the given node filter. If the
+ * descendant nodes that are accepted by the given node filter. If the
* filter is null then all nodes will be accepted. If the results parameter
* is not null then it will be used to collect this subset instead of
* creating a new collection.
*
* @param filter the filter used to determine the subset
- * @return a collection containing this node and all descendents
+ * @param resultantNodes where matching nodes should be added
+ * @return a collection containing this node and all descendants
*/
- public Collection getAllNodes(final PNodeFilter filter, Collection results) {
- if (results == null) {
+ public Collection getAllNodes(final PNodeFilter filter, final Collection resultantNodes) {
+ Collection results;
+ if (resultantNodes == null) {
results = new ArrayList();
}
+ else {
+ results = resultantNodes;
+ }
+
if (filter == null || filter.accept(this)) {
results.add(this);
}
@@ -3457,23 +3560,33 @@
// ****************************************************************
/**
- * Write this node and all of its descendent nodes to the given outputsteam.
+ * Write this node and all of its descendant nodes to the given outputsteam.
* This stream must be an instance of PObjectOutputStream or serialization
* will fail. This nodes parent is written out conditionally, that is it
* will only be written out if someone else writes it out unconditionally.
*
* @param out the output stream to write to, must be an instance of
* PObjectOutputStream
+ * @throws IOException when an error occurs speaking to underlying
+ * ObjectOutputStream
*/
private void writeObject(final ObjectOutputStream out) throws IOException {
+ if (!(out instanceof PObjectOutputStream)) {
+ throw new IllegalArgumentException("PNode.writeObject may only be used with PObjectOutputStreams");
+ }
out.defaultWriteObject();
((PObjectOutputStream) out).writeConditionalObject(parent);
}
/**
- * Read this node and all of its descendents in from the given input stream.
+ * Read this node and all of its descendants in from the given input stream.
*
* @param in the stream to read from
+ *
+ * @throws IOException when an error occurs speaking to underlying
+ * ObjectOutputStream
+ * @throws ClassNotFoundException when a class is desiarialized that no
+ * longer exists. This can happen if it's renamed or deleted.
*/
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
@@ -3482,11 +3595,18 @@
/**
* @deprecated see http://code.google.com/p/piccolo2d/issues/detail?id=99
+ *
+ * @return a string representation of this node's state
*/
protected String paramString() {
return "";
}
+ /**
+ * Returns an array of input event listeners that are attached to this node.
+ *
+ * @return event listeners attached to this node
+ */
public PInputEventListener[] getInputEventListeners() {
if (listenerList == null || listenerList.getListenerCount() == 0) {
return new PInputEventListener[] {};
@@ -3502,25 +3622,25 @@
}
/**
- * PSceneGraphDelegate is an interface to recive low level node
- * events. It together with PNode.SCENE_GRAPH_DELEGATE gives Piccolo users
+ * PSceneGraphDelegate is an interface to receive low level node
+ * events. It together with PNode.SCENE_GRAPH_DELEGATE gives Piccolo2d users
* an efficient way to learn about low level changes in Piccolo's scene
* graph. Most users will not need to use this.
*/
public interface PSceneGraphDelegate {
/**
- * Called to notify delegate that the node needs repainting
+ * Called to notify delegate that the node needs repainting.
*
* @param node node needing repaint
*/
- public void nodePaintInvalidated(PNode node);
+ void nodePaintInvalidated(PNode node);
/**
* Called to notify delegate that the node and all it's children need
- * repainting
+ * repainting.
*
* @param node node needing repaint
*/
- public void nodeFullBoundsInvalidated(PNode node);
+ void nodeFullBoundsInvalidated(PNode node);
}
}
diff --git a/core/src/main/java/edu/umd/cs/piccolo/PRoot.java b/core/src/main/java/edu/umd/cs/piccolo/PRoot.java
index 5f227f4..40ce8cb 100644
--- a/core/src/main/java/edu/umd/cs/piccolo/PRoot.java
+++ b/core/src/main/java/edu/umd/cs/piccolo/PRoot.java
@@ -42,9 +42,9 @@
import edu.umd.cs.piccolo.util.PNodeFilter;
/**
- * PRoot serves as the top node in Piccolo's runtime structure. The PRoot
- * responsible for running the main UI loop that processes input from activities
- * and external events.
+ * PRoot serves as the top node in Piccolo2D's runtime structure. The
+ * PRoot responsible for running the main UI loop that processes input from
+ * activities and external events.
*
*
* @version 1.1
@@ -65,30 +65,59 @@
* input sources, but old value will always be null.
*/
public static final String PROPERTY_INPUT_SOURCES = "inputSources";
- public static final int PROPERTY_CODE_INPUT_SOURCES = 1 << 14;
- public static final String PROPERTY_INTERACTING_CHANGED = "INTERACTING_CHANGED_NOTIFICATION";
- public static final int PROPERTY_CODE_INTERACTING_CHANGED = 1 << 13;
-
- protected transient boolean processingInputs;
- protected transient boolean processInputsScheduled;
-
- private transient int interacting;
- private PInputManager defaultInputManager;
- private transient final List inputSources;
- private transient long globalTime;
- private final PActivityScheduler activityScheduler;
/**
- * This interfaces is for advanced use only. If you want to implement a
- * different kind of input framework then Piccolo provides you can hook it
- * in here.
+ * The property code that identifies a change in the set of this root's
+ * input sources (see {@link InputSource InputSource}). In any property
+ * change event the new value will be a reference to the list of this root's
+ * input sources, but old value will always be null.
*/
- public static interface InputSource {
- /**
- * Causes the system to process any pending Input Events
- */
- public void processInput();
- }
+ public static final int PROPERTY_CODE_INPUT_SOURCES = 1 << 14;
+
+ /**
+ * The property name that identifies a change in this node's interacting
+ * state.
+ */
+ public static final String PROPERTY_INTERACTING_CHANGED = "INTERACTING_CHANGED_NOTIFICATION";
+
+ /**
+ * The property code that identifies a change in this node's interacting
+ * state.
+ */
+ public static final int PROPERTY_CODE_INTERACTING_CHANGED = 1 << 13;
+
+ /** Whether this not is currently processing inputs. */
+ protected transient boolean processingInputs;
+
+ /** Whether this node needs to have its inputs processed. */
+ protected transient boolean processInputsScheduled;
+
+ /** The number of interactions this node is currently participating in. */
+ private transient int interacting;
+
+ /**
+ * The singleton instance of the default input manager.
+ */
+ private PInputManager defaultInputManager;
+
+ /** The Input Sources that are registered to this node. */
+ private final transient List inputSources;
+
+ /**
+ * Used to provide a consistent clock time to activities as they are being
+ * processed.
+ *
+ * Should it happen that an activity step take longer than a millisecond,
+ * the next step will be unaffected by the change in clock had it used
+ * System.currentMillis().
+ */
+ private transient long globalTime;
+
+ /**
+ * Object responsible for scheduling activities, regardless of where in the
+ * scene they take place.
+ */
+ private final PActivityScheduler activityScheduler;
/**
* Construct a new PRoot(). Note the PCanvas already creates a basic scene
@@ -110,6 +139,9 @@
* Activities are given a chance to run during each call to the roots
* processInputs
method. When the activity has finished running
* it will automatically get removed.
+ *
+ * @param activity Activity that should be scheduled
+ * @return whether it has been scheduled (always true)
*/
public boolean addActivity(final PActivity activity) {
getActivityScheduler().addActivity(activity);
@@ -118,6 +150,8 @@
/**
* Get the activity scheduler associated with this root.
+ *
+ * @return associated scheduler
*/
public PActivityScheduler getActivityScheduler() {
return activityScheduler;
@@ -150,12 +184,11 @@
}
}
- // ****************************************************************
- // Basics
- // ****************************************************************
-
/**
- * Return this.
+ * Since getRoot is handled recursively, and root is the lowest point in the
+ * hierarchy, simply returns itself.
+ *
+ * @return itself
*/
public PRoot getRoot() {
return this;
@@ -165,6 +198,8 @@
* Get the default input manager to be used when processing input events.
* PCanvas's use this method when they forward new swing input events to the
* PInputManager.
+ *
+ * @return a singleton instance of PInputManager
*/
public PInputManager getDefaultInputManager() {
if (defaultInputManager == null) {
@@ -196,7 +231,7 @@
* @param isInteracting True if this root has user interaction taking place
* @see PCanvas#setInteracting(boolean)
*/
- public void setInteracting(boolean isInteracting) {
+ public void setInteracting(final boolean isInteracting) {
final boolean wasInteracting = getInteracting();
if (isInteracting) {
@@ -206,8 +241,7 @@
interacting--;
}
- isInteracting = getInteracting();
- if (!isInteracting) {
+ if (!isInteracting && !getInteracting()) {
// force all the child cameras to repaint
for (int i = 0; i < getChildrenCount(); i++) {
final PNode child = getChild(i);
@@ -226,7 +260,9 @@
/**
* Advanced. If you want to add additional input sources to the roots UI
* process you can do that here. You will seldom do this unless you are
- * making additions to the piccolo framework.
+ * making additions to the Piccolo2D framework.
+ *
+ * @param inputSource An input source that should be added
*/
public void addInputSource(final InputSource inputSource) {
inputSources.add(inputSource);
@@ -236,50 +272,63 @@
/**
* Advanced. If you want to remove the default input source from the roots
* UI process you can do that here. You will seldom do this unless you are
- * making additions to the piccolo framework.
+ * making additions to the Piccolo2D framework.
+ *
+ * @param inputSource input source that should no longer be asked about
+ * input events
*/
public void removeInputSource(final InputSource inputSource) {
- inputSources.remove(inputSource);
- firePropertyChange(PROPERTY_CODE_INPUT_SOURCES, PROPERTY_INPUT_SOURCES, null, inputSources);
+ if (inputSources.remove(inputSource)) {
+ firePropertyChange(PROPERTY_CODE_INPUT_SOURCES, PROPERTY_INPUT_SOURCES, null, inputSources);
+ }
}
/**
* Returns a new timer. This method allows subclasses, such as PSWTRoot to
- * create custom timers that will be used transparently by the Piccolo
+ * create custom timers that will be used transparently by the Piccolo2D
* framework.
+ *
+ * @param delay # of milliseconds before action listener is invoked
+ * @param listener listener to be invoked after delay
+ *
+ * @return A new Timer
*/
public Timer createTimer(final int delay, final ActionListener listener) {
return new Timer(delay, listener);
}
// ****************************************************************
- // UI Loop - Methods for running the main UI loop of Piccolo.
+ // UI Loop - Methods for running the main UI loop of Piccolo2D.
// ****************************************************************
/**
- * Get the global Piccolo time. This is set to System.currentTimeMillis() at
- * the beginning of the roots processInputs
method. Activities
- * should usually use this global time instead of System.
+ * Get the global Piccolo2D time. This is set to System.currentTimeMillis()
+ * at the beginning of the roots processInputs
method.
+ * Activities should usually use this global time instead of System.
* currentTimeMillis() so that multiple activities will be synchronized.
+ *
+ * @return time as recorded at the beginning of activity scheduling
*/
public long getGlobalTime() {
return globalTime;
}
/**
- * This is the heartbeat of the Piccolo framework. Pending input events are
- * processed. Activities are given a chance to run, and the bounds caches
- * and any paint damage is validated.
+ * This is the heartbeat of the Piccolo2D framework. Pending input events
+ * are processed. Activities are given a chance to run, and the bounds
+ * caches and any paint damage is validated.
*/
public void processInputs() {
PDebug.startProcessingInput();
processingInputs = true;
globalTime = System.currentTimeMillis();
- final int count = inputSources == null ? 0 : inputSources.size();
- for (int i = 0; i < count; i++) {
- final InputSource each = (InputSource) inputSources.get(i);
- each.processInput();
+ if (inputSources.size() > 0) {
+ final Iterator inputSourceIterator = inputSources.iterator();
+ while (inputSourceIterator.hasNext()) {
+ final InputSource each = (InputSource) inputSourceIterator.next();
+ each.processInput();
+ }
}
activityScheduler.processActivities(globalTime);
@@ -290,26 +339,31 @@
PDebug.endProcessingInput();
}
+ /** {@inheritDoc} */
public void setFullBoundsInvalid(final boolean fullLayoutInvalid) {
super.setFullBoundsInvalid(fullLayoutInvalid);
scheduleProcessInputsIfNeeded();
}
+ /** {@inheritDoc} */
public void setChildBoundsInvalid(final boolean childLayoutInvalid) {
super.setChildBoundsInvalid(childLayoutInvalid);
scheduleProcessInputsIfNeeded();
}
+ /** {@inheritDoc} */
public void setPaintInvalid(final boolean paintInvalid) {
super.setPaintInvalid(paintInvalid);
scheduleProcessInputsIfNeeded();
}
+ /** {@inheritDoc} */
public void setChildPaintInvalid(final boolean childPaintInvalid) {
super.setChildPaintInvalid(childPaintInvalid);
scheduleProcessInputsIfNeeded();
}
+ /** {@inheritDoc} */
public void scheduleProcessInputsIfNeeded() {
/*
* The reason for the special case here (when not in the event dispatch
@@ -319,9 +373,9 @@
*/
if (!SwingUtilities.isEventDispatchThread()) {
/*
- * Piccolo is not thread safe and should amost always be called from
- * the Swing event dispatch thread. It should only reach this point
- * when a new canvas is being created.
+ * Piccolo2D is not thread safe and should almost always be called
+ * from the Swing event dispatch thread. It should only reach this
+ * point when a new canvas is being created.
*/
return;
}
@@ -340,4 +394,14 @@
});
}
}
+
+ /**
+ * This interfaces is for advanced use only. If you want to implement a
+ * different kind of input framework then Piccolo2D provides you can hook it
+ * in here.
+ */
+ public static interface InputSource {
+ /** Causes the system to process any pending Input Events. */
+ void processInput();
+ }
}
diff --git a/core/src/main/java/edu/umd/cs/piccolo/event/PInputEvent.java b/core/src/main/java/edu/umd/cs/piccolo/event/PInputEvent.java
index 6882285..66421bf 100644
--- a/core/src/main/java/edu/umd/cs/piccolo/event/PInputEvent.java
+++ b/core/src/main/java/edu/umd/cs/piccolo/event/PInputEvent.java
@@ -60,23 +60,46 @@
* @author Jesse Grosjean
*/
public class PInputEvent {
-
+ /** The underlying Swing Event. */
private final InputEvent inputEvent;
+
+ /** Path relating to the current mouse event. */
private PPickPath pickPath;
+
+ /** Input manager responsible for the creation of this event. */
private final PInputManager inputManager;
+
+ /** Flag used to identify this event as handled. */
private boolean handled;
+ /**
+ * Create an event with the given inputManager and based on the given swing
+ * event.
+ *
+ * @param inputManager source of PInputEvent
+ * @param event underlying swing event
+ */
public PInputEvent(final PInputManager inputManager, final InputEvent event) {
super();
inputEvent = event;
this.inputManager = inputManager;
}
+ /**
+ * Changes the cursor to the one provided and stores it on the cursor stack
+ * for later retrieval.
+ *
+ * @param cursor
+ */
public void pushCursor(final Cursor cursor) {
final PComponent component = getTopCamera().getComponent();
component.pushCursor(cursor);
}
+ /**
+ * Removes the top most cursor from the cursor stack and sets it as the
+ * current cursor.
+ */
public void popCursor() {
final PComponent component = getTopCamera().getComponent();
component.popCursor();
@@ -98,6 +121,8 @@
* Return the bottom most camera that is currently painting. If you are
* using internal cameras this may be different then what is returned by
* getTopCamera.
+ *
+ * @return the current PickPath's bottom camera.
*/
public PCamera getCamera() {
return getPath().getBottomCamera();
diff --git a/core/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java b/core/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java
index 462e84f..210d127 100644
--- a/core/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java
+++ b/core/src/main/java/edu/umd/cs/piccolo/event/PInputEventFilter.java
@@ -57,51 +57,106 @@
| InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK | InputEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK
| InputEvent.META_MASK;
+ /** If event modifiers don't match this exactly, event it filtered. */
private int andMask;
+
+ /** If event modifiers have no bits from orMask enabled, event is filtered. */
private int orMask;
+
+ /** If event modifier has any of the notMask bits on, it is not accepted. */
private int notMask;
+
+ /** Number of clicks that an incoming event must have to be accepted. */
private short clickCount = -1;
+ /** Whether accepted events should be marked as handled. */
private boolean marksAcceptedEventsAsHandled = false;
+ /** Whether handled events should be immediately filtered. */
private boolean acceptsAlreadyHandledEvents = false;
+
+ /** Whether key pressed events are accepted. */
private boolean acceptsKeyPressed = true;
+
+ /** Whether key released events are accepted. */
private boolean acceptsKeyReleased = true;
+
+ /** Whether key typed events are accepted. */
private boolean acceptsKeyTyped = true;
+ /** Whether mouse clicked events are accepted. */
private boolean acceptsMouseClicked = true;
+
+ /** Whether mouse dragged events are accepted. */
private boolean acceptsMouseDragged = true;
+
+ /** Whether mouse entered events are accepted. */
private boolean acceptsMouseEntered = true;
+
+ /** Whether mouse exited events are accepted. */
private boolean acceptsMouseExited = true;
+
+ /** Whether mouse moved events are accepted. */
private boolean acceptsMouseMoved = true;
+
+ /** Whether mouse pressed events are accepted. */
private boolean acceptsMousePressed = true;
+
+ /** Whether mouse released events are accepted. */
private boolean acceptsMouseReleased = true;
+
+ /** Whether mouse wheel rotated events are accepted. */
private boolean acceptsMouseWheelRotated = true;
+
+ /** Whether focus events are accepted. */
private boolean acceptsFocusEvents = true;
+ /**
+ * Creates a PInputEventFilter that accepts everything.
+ */
public PInputEventFilter() {
acceptEverything();
}
- public PInputEventFilter(final int aAndMask) {
+ /**
+ * Creates a PInputEventFilter that will accept events if they have the
+ * given andMask.
+ *
+ * @param andMask exact pattern event modifiers must be to get accepted
+ */
+ public PInputEventFilter(final int andMask) {
this();
- andMask = aAndMask;
+ this.andMask = andMask;
}
- public PInputEventFilter(final int aAndMask, final int aNotMask) {
- this(aAndMask);
- notMask = aNotMask;
+ /**
+ * Creates a PInputEventFilter that will accept events if they have the
+ * given andMask and do not contain any of the bits in the notMask.
+ *
+ * @param andMask exact pattern event modifiers must be to get accepted
+ * @param notMask if any or these bits are on event is not accepted
+ */
+ public PInputEventFilter(final int andMask, final int notMask) {
+ this(andMask);
+ this.notMask = notMask;
}
- public boolean acceptsEvent(final PInputEvent aEvent, final int type) {
+ /**
+ * Returns true if the passed event is one that is accepted.
+ *
+ * @param event Event under consideration
+ * @param type The type of event encoded as the PInputEvent
+ * @return true if event is accepted
+ */
+ public boolean acceptsEvent(final PInputEvent event, final int type) {
boolean aResult = false;
int modifiers = 0;
- if (!aEvent.isFocusEvent()) {
- modifiers = aEvent.getModifiers();
+ if (!event.isFocusEvent()) {
+ modifiers = event.getModifiers();
}
- if (aEvent.isHandled() && !acceptsAlreadyHandledEvents) {
+ if (event.isHandled() && !acceptsAlreadyHandledEvents) {
return false;
}
@@ -115,7 +170,7 @@
}
}
- if (aEvent.isMouseEvent() && clickCount != -1 && clickCount != aEvent.getClickCount()) {
+ if (event.isMouseEvent() && clickCount != -1 && clickCount != event.getClickCount()) {
return false;
}
@@ -175,16 +230,22 @@
}
if (aResult && getMarksAcceptedEventsAsHandled()) {
- aEvent.setHandled(true);
+ event.setHandled(true);
}
return aResult;
}
+ /**
+ * Makes this filter accept all mouse click combinations.
+ */
public void acceptAllClickCounts() {
clickCount = -1;
}
+ /**
+ * Makes the filter accept all event types.
+ */
public void acceptAllEventTypes() {
acceptsKeyPressed = true;
acceptsKeyReleased = true;
@@ -200,6 +261,9 @@
acceptsFocusEvents = true;
}
+ /**
+ * Makes this filter accept absolutely everything.
+ */
public void acceptEverything() {
acceptAllEventTypes();
setAndMask(0);
@@ -208,66 +272,147 @@
acceptAllClickCounts();
}
+ /**
+ * Returns whether this filter accepts key pressed events.
+ *
+ * @return true if filter accepts key pressed events
+ */
public boolean getAcceptsKeyPressed() {
return acceptsKeyPressed;
}
+ /**
+ * Returns whether this filter accepts key released events.
+ *
+ * @return true if filter accepts key released events
+ */
public boolean getAcceptsKeyReleased() {
return acceptsKeyReleased;
}
+ /**
+ * Returns whether this filter accepts key typed events.
+ *
+ * @return true if filter accepts key typed events
+ */
public boolean getAcceptsKeyTyped() {
return acceptsKeyTyped;
}
+ /**
+ * Returns whether this filter accepts mouse clicked events.
+ *
+ * @return true if filter accepts mouse clicked events
+ */
public boolean getAcceptsMouseClicked() {
return acceptsMouseClicked;
}
+ /**
+ * Returns whether this filter accepts mouse dragged events.
+ *
+ * @return true if filter accepts mouse dragged events
+ */
public boolean getAcceptsMouseDragged() {
return acceptsMouseDragged;
}
+ /**
+ * Returns whether this filter accepts mouse entered events.
+ *
+ * @return true if filter accepts mouse entered events
+ */
public boolean getAcceptsMouseEntered() {
return acceptsMouseEntered;
}
+ /**
+ * Returns whether this filter accepts mouse exited events.
+ *
+ * @return true if filter accepts mouse exited events
+ */
public boolean getAcceptsMouseExited() {
return acceptsMouseExited;
}
+ /**
+ * Returns whether this filter accepts mouse moved events.
+ *
+ * @return true if filter accepts mouse moved events
+ */
public boolean getAcceptsMouseMoved() {
return acceptsMouseMoved;
}
+ /**
+ * Returns whether this filter accepts mouse pressed events.
+ *
+ * @return true if filter accepts mouse pressed events
+ */
public boolean getAcceptsMousePressed() {
return acceptsMousePressed;
}
+ /**
+ * Returns whether this filter accepts mouse released events.
+ *
+ * @return true if filter accepts mouse released events
+ */
public boolean getAcceptsMouseReleased() {
return acceptsMouseReleased;
}
+ /**
+ * Returns whether this filter accepts mouse wheel rotated events.
+ *
+ * @return true if filter accepts mouse wheel rotated events
+ */
public boolean getAcceptsMouseWheelRotated() {
return acceptsMouseWheelRotated;
}
+ /**
+ * Returns whether this filter accepts focus events.
+ *
+ * @return true if filter accepts focus events
+ */
public boolean getAcceptsFocusEvents() {
return acceptsFocusEvents;
}
+ /**
+ * Returns whether this filter accepts events that have already been flagged
+ * as handled.
+ *
+ * @return true if filter accepts events that have already been flagged as
+ * handled
+ */
public boolean getAcceptsAlreadyHandledEvents() {
return acceptsAlreadyHandledEvents;
}
+ /**
+ * Returns whether this filter marks events as handled if they are accepted.
+ *
+ * @return true if filter will mark events as filtered if they are accepted
+ */
public boolean getMarksAcceptedEventsAsHandled() {
return marksAcceptedEventsAsHandled;
}
+ /**
+ * Flags all mouse click events as disallowed, regardless of button
+ * configuration.
+ */
public void rejectAllClickCounts() {
clickCount = Short.MAX_VALUE;
}
+ /**
+ * Configures filter so that no events will ever get accepted. By itself not
+ * terribly useful, but it's a more restrictive starting point than
+ * acceptAllEvents();
+ */
public void rejectAllEventTypes() {
acceptsKeyPressed = false;
acceptsKeyReleased = false;
@@ -283,74 +428,168 @@
acceptsFocusEvents = false;
}
+ /**
+ * Sets the number of clicks that an incoming event must have to be accepted.
+ *
+ * @param aClickCount number clicks that an incoming event must have to be accepted
+ */
public void setAcceptClickCount(final short aClickCount) {
clickCount = aClickCount;
}
+ /**
+ * Sets whether this filter accepts key pressed events.
+ *
+ * @param aBoolean whether filter should accept key pressed events
+ */
public void setAcceptsKeyPressed(final boolean aBoolean) {
acceptsKeyPressed = aBoolean;
}
+ /**
+ * Sets whether this filter accepts key released events.
+ *
+ * @param aBoolean whether filter should accept key released events
+ */
public void setAcceptsKeyReleased(final boolean aBoolean) {
acceptsKeyReleased = aBoolean;
}
+ /**
+ * Sets whether this filter accepts key typed events.
+ *
+ * @param aBoolean whether filter should accept key typed events
+ */
+
public void setAcceptsKeyTyped(final boolean aBoolean) {
acceptsKeyTyped = aBoolean;
}
+ /**
+ * Sets whether this filter accepts mouse clicked events.
+ *
+ * @param aBoolean whether filter should accept mouse clicked events
+ */
public void setAcceptsMouseClicked(final boolean aBoolean) {
acceptsMouseClicked = aBoolean;
}
+ /**
+ * Sets whether this filter accepts mouse dragged events.
+ *
+ * @param aBoolean whether filter should accept mouse dragged events
+ */
public void setAcceptsMouseDragged(final boolean aBoolean) {
acceptsMouseDragged = aBoolean;
}
+ /**
+ * Sets whether this filter accepts mouse entered events.
+ *
+ * @param aBoolean whether filter should accept mouse entered events
+ */
public void setAcceptsMouseEntered(final boolean aBoolean) {
acceptsMouseEntered = aBoolean;
}
+ /**
+ * Sets whether this filter accepts mouse exited events.
+ *
+ * @param aBoolean whether filter should accept mouse exited events
+ */
public void setAcceptsMouseExited(final boolean aBoolean) {
acceptsMouseExited = aBoolean;
}
+ /**
+ * Sets whether this filter accepts mouse moved events.
+ *
+ * @param aBoolean whether filter should accept mouse moved events
+ */
public void setAcceptsMouseMoved(final boolean aBoolean) {
acceptsMouseMoved = aBoolean;
}
+ /**
+ * Sets whether this filter accepts mouse pressed events.
+ *
+ * @param aBoolean whether filter should accept mouse pressed events
+ */
public void setAcceptsMousePressed(final boolean aBoolean) {
acceptsMousePressed = aBoolean;
}
+ /**
+ * Sets whether this filter accepts mouse released events.
+ *
+ * @param aBoolean whether filter should accept mouse released events
+ */
public void setAcceptsMouseReleased(final boolean aBoolean) {
acceptsMouseReleased = aBoolean;
}
+ /**
+ * Sets whether this filter accepts mouse wheel rotation events.
+ *
+ * @param aBoolean whether filter should accept mouse wheel rotated events
+ */
public void setAcceptsMouseWheelRotated(final boolean aBoolean) {
acceptsMouseWheelRotated = aBoolean;
}
+ /**
+ * Sets whether this filter accepts focus events.
+ *
+ * @param aBoolean whether filter should accept focus events
+ */
public void setAcceptsFocusEvents(final boolean aBoolean) {
acceptsFocusEvents = aBoolean;
}
+ /**
+ * Sets and mask used to filter events. All bits of the andMask must be 1s
+ * for the event to be accepted.
+ *
+ * @param aAndMask the and mask to use for filtering events
+ */
public void setAndMask(final int aAndMask) {
andMask = aAndMask;
}
+ /**
+ * Sets whether already handled events should be accepted.
+ *
+ * @param aBoolean whether already handled events should be accepted
+ */
public void setAcceptsAlreadyHandledEvents(final boolean aBoolean) {
acceptsAlreadyHandledEvents = aBoolean;
}
+ /**
+ * Sets whether events will be marked as dirty once accepted.
+ *
+ * @param aBoolean whether events will be marked as dirty once accepted
+ */
public void setMarksAcceptedEventsAsHandled(final boolean aBoolean) {
marksAcceptedEventsAsHandled = aBoolean;
}
+ /**
+ * Sets not mask used to filter events. If any of the not bits are enabled,
+ * then the event is not accepted.
+ *
+ * @param aNotMask the not mask to use for filtering events
+ */
public void setNotMask(final int aNotMask) {
notMask = aNotMask;
}
+ /**
+ * Sets or mask used to filter events. If any of the or bits are enabled,
+ * then the event is accepted.
+ *
+ * @param aOrMask the or mask to use for filtering events
+ */
public void setOrMask(final int aOrMask) {
orMask = aOrMask;
}