edu.umd.cs.piccolox.event
Class PSelectionEventHandler

java.lang.Object
  extended by edu.umd.cs.piccolo.event.PBasicInputEventHandler
      extended by edu.umd.cs.piccolo.event.PDragSequenceEventHandler
          extended by edu.umd.cs.piccolox.event.PSelectionEventHandler
All Implemented Interfaces:
PInputEventListener, EventListener

public class PSelectionEventHandler
extends PDragSequenceEventHandler

PSelectionEventHandler provides standard interaction for selection. Clicking selects the object under the cursor. Shift-clicking allows multiple objects to be selected. Dragging offers marquee selection. Pressing the delete key deletes the selection by default.

Version:
1.0
Author:
Ben Bederson

Nested Class Summary
protected  class PSelectionEventHandler.BoundsFilter
          Class used to filter nodes that intersect with the marquee's bounds.
 
Field Summary
(package private) static int DASH_WIDTH
          The default dash width when displaying selection rectangle.
(package private) static int NUM_STROKES
           
static String SELECTION_CHANGED_NOTIFICATION
          Notification name that identifies a change in the selection.
 
Constructor Summary
PSelectionEventHandler(PNode marqueeParent, List selectableParents)
          Creates a selection event handler.
PSelectionEventHandler(PNode marqueeParent, PNode selectableParent)
          Creates a selection event handler.
 
Method Summary
 void addSelectableParent(PNode node)
          Flags the node provided as a selectable parent.
protected  void computeMarqueeSelection(PInputEvent pie)
          Sets the selection to be all nodes under the marquee.
protected  void computeOptionMarqueeSelection(PInputEvent pie)
          Extends the selection to include all nodes under the marquee.
protected  PNodeFilter createNodeFilter(PBounds bounds)
          Creates a node filter that will filter all nodes not touching the bounds provided.
 void decorateSelectedNode(PNode node)
          Adds bound handles to the provided node.
protected  void drag(PInputEvent event)
          Updates the marquee to the new bounds caused by the drag.
protected  void dragActivityStep(PInputEvent aEvent)
          This gets called continuously during the drag, and is used to animate the marquee.
protected  void dragStandardSelection(PInputEvent e)
          Drag selected nodes.
protected  void endDrag(PInputEvent event)
          Ends the selection marquee when the drag is ended.
protected  void endMarqueeSelection(PInputEvent e)
          Removes marquee and clears selection.
protected  void endStandardSelection(PInputEvent e)
          Ends the "pressed" state of the previously pressed node (if any).
protected  PBounds getMarqueeBounds()
          Returns the bounds of the current selection marquee.
 Paint getMarqueePaint()
          Indicates the color used to paint the marquee.
 float getMarqueePaintTransparency()
          Indicates the transparency level for the interior of the marquee.
 Collection getSelectableParents()
          Returns all selectable parents.
 Collection getSelection()
          Returns a copy of the currently selected nodes.
 Collection getSelectionReference()
          Gets a reference to the currently selected nodes.
 boolean getSupportDeleteKey()
          Returns whether the delete key is a supported action.
protected  void init()
          Initializes the PSelectionEventHandler with a marquee stroke.
protected  void initializeMarquee(PInputEvent event)
          Creates an empty marquee child for use in displaying the marquee around the selection.
protected  void initializeSelection(PInputEvent pie)
          Starts a selection based on the provided event.
 boolean isDeleteKeyActive()
          Returns whether the delete key is a supported action.
protected  boolean isMarqueeSelection(PInputEvent pie)
          Tests the input event to see if it is selecting a new node.
 boolean isOptionSelection(PInputEvent pie)
          Used to test whether the event is one that changes the selection.
protected  boolean isSelectable(PNode node)
          Determine if the specified node can be selected (i.e., if it is a child of the one the list of nodes that can be selected).
 boolean isSelected(PNode node)
          Returns true is provided node is selected.
 void keyPressed(PInputEvent e)
          Delete selection when delete key is pressed (if enabled).
 void removeSelectableParent(PNode node)
          Removes the node provided from the set of selectable parents.
 void select(Collection items)
          Marks all items as selected.
 void select(Map items)
          Marks all keys as selected.
 void select(PNode node)
          Selected the provided node if not already selected.
 void setDeleteKeyActive(boolean deleteKeyActive)
          Specifies if the DELETE key should delete the selection.
 void setMarqueePaint(Paint paint)
          Sets the color used to paint the marquee.
 void setMarqueePaintTransparency(float marqueePaintTransparency)
          Sets the transparency level for the interior of the marquee.
 void setSelectableParent(PNode node)
          Sets the node provided as the *only* selectable parent.
 void setSelectableParents(Collection c)
          Sets the collection of selectable parents as the only parents that are selectable.
protected  void startDrag(PInputEvent e)
          Overrides method in PDragSequenceEventHandler so that, selections have marquees.
protected  void startMarqueeSelection(PInputEvent event)
          Invoked at the start of the selection.
protected  void startOptionMarqueeSelection(PInputEvent event)
          Invoked when the marquee is being used to extend the selection.
protected  void startStandardOptionSelection(PInputEvent pie)
          Toggle the current selection on the node that was just pressed, but leave the rest of the selected nodes unchanged.
protected  void startStandardSelection(PInputEvent pie)
          If the pressed node is not selected unselect all nodes and select the pressed node if it allows it.
 void undecorateSelectedNode(PNode node)
          Removes bounds handles from node.
 void unselect(Collection items)
          Removes all nodes provided from the selection.
 void unselect(PNode node)
          Removes node from selection.
 void unselectAll()
          Empties the selection.
protected  void updateMarquee(PInputEvent pie)
          Updates the marquee rectangle as the result of a drag.
 
Methods inherited from class edu.umd.cs.piccolo.event.PDragSequenceEventHandler
dragActivityFinalStep, dragActivityFirstStep, getDragActivity, getMinDragStartDistance, getMousePressedCanvasPoint, isDragging, mouseDragged, mousePressed, mouseReleased, setIsDragging, setMinDragStartDistance, shouldStartDragInteraction, startDragActivity, stopDragActivity
 
Methods inherited from class edu.umd.cs.piccolo.event.PBasicInputEventHandler
acceptsEvent, getEventFilter, keyboardFocusGained, keyboardFocusLost, keyReleased, keyTyped, mouseClicked, mouseEntered, mouseExited, mouseMoved, mouseWheelRotated, mouseWheelRotatedByBlock, paramString, processEvent, setEventFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SELECTION_CHANGED_NOTIFICATION

public static final String SELECTION_CHANGED_NOTIFICATION
Notification name that identifies a change in the selection. Used with PNotificationCenter.

See Also:
Constant Field Values

DASH_WIDTH

static final int DASH_WIDTH
The default dash width when displaying selection rectangle.

See Also:
Constant Field Values

NUM_STROKES

static final int NUM_STROKES
See Also:
Constant Field Values
Constructor Detail

PSelectionEventHandler

public PSelectionEventHandler(PNode marqueeParent,
                              PNode selectableParent)
Creates a selection event handler.

Parameters:
marqueeParent - The node to which the event handler dynamically adds a marquee (temporarily) to represent the area being selected.
selectableParent - The node whose children will be selected by this event handler.

PSelectionEventHandler

public PSelectionEventHandler(PNode marqueeParent,
                              List selectableParents)
Creates a selection event handler.

Parameters:
marqueeParent - The node to which the event handler dynamically adds a marquee (temporarily) to represent the area being selected.
selectableParents - A list of nodes whose children will be selected by this event handler.
Method Detail

init

protected void init()
Initializes the PSelectionEventHandler with a marquee stroke.


select

public void select(Collection items)
Marks all items as selected.

Parameters:
items - collection of items to be selected

select

public void select(Map items)
Marks all keys as selected.

Parameters:
items - map where keys are to be selected

select

public void select(PNode node)
Selected the provided node if not already selected.

Parameters:
node - node to be selected

decorateSelectedNode

public void decorateSelectedNode(PNode node)
Adds bound handles to the provided node.

Parameters:
node - node to be decorated

unselect

public void unselect(Collection items)
Removes all nodes provided from the selection.

Parameters:
items - items to remove form the selection

unselect

public void unselect(PNode node)
Removes node from selection.

Parameters:
node - node to be removed from selection

undecorateSelectedNode

public void undecorateSelectedNode(PNode node)
Removes bounds handles from node.

Parameters:
node - to have handles removed from

unselectAll

public void unselectAll()
Empties the selection.


isSelected

public boolean isSelected(PNode node)
Returns true is provided node is selected.

Parameters:
node - - node to be tested
Returns:
true if succeeded

getSelection

public Collection getSelection()
Returns a copy of the currently selected nodes.

Returns:
copy of selection

getSelectionReference

public Collection getSelectionReference()
Gets a reference to the currently selected nodes. You should not modify or store this collection.

Returns:
direct reference to selection

isSelectable

protected boolean isSelectable(PNode node)
Determine if the specified node can be selected (i.e., if it is a child of the one the list of nodes that can be selected).

Parameters:
node - node being tested
Returns:
true if node can be selected

addSelectableParent

public void addSelectableParent(PNode node)
Flags the node provided as a selectable parent. This makes it possible to select its children.

Parameters:
node - to flag as selectable

removeSelectableParent

public void removeSelectableParent(PNode node)
Removes the node provided from the set of selectable parents. This makes its impossible to select its children.

Parameters:
node - to remove from selectable parents

setSelectableParent

public void setSelectableParent(PNode node)
Sets the node provided as the *only* selectable parent.

Parameters:
node - node to become the 1 and only selectable parent

setSelectableParents

public void setSelectableParents(Collection c)
Sets the collection of selectable parents as the only parents that are selectable.

Parameters:
c - nodes to become selectable parents.

getSelectableParents

public Collection getSelectableParents()
Returns all selectable parents.

Returns:
selectable parents

startDrag

protected void startDrag(PInputEvent e)
Overrides method in PDragSequenceEventHandler so that, selections have marquees.

Overrides:
startDrag in class PDragSequenceEventHandler
Parameters:
e - the event that started the drag

drag

protected void drag(PInputEvent event)
Updates the marquee to the new bounds caused by the drag.

Overrides:
drag in class PDragSequenceEventHandler
Parameters:
event - drag event

endDrag

protected void endDrag(PInputEvent event)
Ends the selection marquee when the drag is ended.

Overrides:
endDrag in class PDragSequenceEventHandler
Parameters:
event - the event responsible for ending the drag

isOptionSelection

public boolean isOptionSelection(PInputEvent pie)
Used to test whether the event is one that changes the selection.

Parameters:
pie - The event under test
Returns:
true if event changes the selection

isMarqueeSelection

protected boolean isMarqueeSelection(PInputEvent pie)
Tests the input event to see if it is selecting a new node.

Parameters:
pie - event under test
Returns:
true if there is no current selection

initializeSelection

protected void initializeSelection(PInputEvent pie)
Starts a selection based on the provided event.

Parameters:
pie - event used to populate the selection

initializeMarquee

protected void initializeMarquee(PInputEvent event)
Creates an empty marquee child for use in displaying the marquee around the selection.

Parameters:
event - event responsible for the initialization

startOptionMarqueeSelection

protected void startOptionMarqueeSelection(PInputEvent event)
Invoked when the marquee is being used to extend the selection.

Parameters:
event - event causing the option selection

startMarqueeSelection

protected void startMarqueeSelection(PInputEvent event)
Invoked at the start of the selection. Removes any selections.

Parameters:
event - event causing a new marquee selection

startStandardSelection

protected void startStandardSelection(PInputEvent pie)
If the pressed node is not selected unselect all nodes and select the pressed node if it allows it.

Parameters:
pie - event that started the selection

startStandardOptionSelection

protected void startStandardOptionSelection(PInputEvent pie)
Toggle the current selection on the node that was just pressed, but leave the rest of the selected nodes unchanged.

Parameters:
pie - event responsible for the change in selection

updateMarquee

protected void updateMarquee(PInputEvent pie)
Updates the marquee rectangle as the result of a drag.

Parameters:
pie - event responsible for the change in the marquee

computeMarqueeSelection

protected void computeMarqueeSelection(PInputEvent pie)
Sets the selection to be all nodes under the marquee.

Parameters:
pie - event responsible for the new selection

computeOptionMarqueeSelection

protected void computeOptionMarqueeSelection(PInputEvent pie)
Extends the selection to include all nodes under the marquee.

Parameters:
pie - event responsible for the change in selection

createNodeFilter

protected PNodeFilter createNodeFilter(PBounds bounds)
Creates a node filter that will filter all nodes not touching the bounds provided.

Parameters:
bounds - will be used to filter matches
Returns:
newly created filter

getMarqueeBounds

protected PBounds getMarqueeBounds()
Returns the bounds of the current selection marquee.

Returns:
bounds of current selection marquee

dragStandardSelection

protected void dragStandardSelection(PInputEvent e)
Drag selected nodes.

Parameters:
e - event responsible for the drag

endMarqueeSelection

protected void endMarqueeSelection(PInputEvent e)
Removes marquee and clears selection.

Parameters:
e - event responsible for the end of the selection

endStandardSelection

protected void endStandardSelection(PInputEvent e)
Ends the "pressed" state of the previously pressed node (if any).

Parameters:
e - event responsible for the end in the selection

dragActivityStep

protected void dragActivityStep(PInputEvent aEvent)
This gets called continuously during the drag, and is used to animate the marquee.

Overrides:
dragActivityStep in class PDragSequenceEventHandler
Parameters:
aEvent - event responsible for this step in the drag sequence

keyPressed

public void keyPressed(PInputEvent e)
Delete selection when delete key is pressed (if enabled).

Overrides:
keyPressed in class PBasicInputEventHandler
Parameters:
e - the key press event

getSupportDeleteKey

public boolean getSupportDeleteKey()
Returns whether the delete key is a supported action.

Returns:
true if delete is allowed

isDeleteKeyActive

public boolean isDeleteKeyActive()
Returns whether the delete key is a supported action.

Returns:
true if delete is allowed

setDeleteKeyActive

public void setDeleteKeyActive(boolean deleteKeyActive)
Specifies if the DELETE key should delete the selection.

Parameters:
deleteKeyActive - state to set for the delete action true = enabled

getMarqueePaint

public Paint getMarqueePaint()
Indicates the color used to paint the marquee.

Returns:
the paint for interior of the marquee

setMarqueePaint

public void setMarqueePaint(Paint paint)
Sets the color used to paint the marquee.

Parameters:
paint - the paint color

getMarqueePaintTransparency

public float getMarqueePaintTransparency()
Indicates the transparency level for the interior of the marquee.

Returns:
Returns the marquee paint transparency, zero to one

setMarqueePaintTransparency

public void setMarqueePaintTransparency(float marqueePaintTransparency)
Sets the transparency level for the interior of the marquee.

Parameters:
marqueePaintTransparency - The marquee paint transparency to set.


Copyright © 1995-2010 Piccolo2D. All Rights Reserved.