org.jgraph.graph

Class DefaultGraphSelectionModel

public class DefaultGraphSelectionModel extends Object implements GraphSelectionModel, Cloneable, Serializable

Default implementation of GraphSelectionModel. Listeners are notified
Nested Class Summary
protected classDefaultGraphSelectionModel.CellPlaceHolder
Holds a path and whether or not it is new.
Field Summary
protected MapcellStates
Maps the cells to their selection state.
protected SwingPropertyChangeSupportchangeSupport
Used to message registered listeners.
protected booleanchildrenSelectable
Boolean that indicates if the model allows stepping-into groups.
protected JGraphgraph
Reference to the parent graph.
protected EventListenerListlistenerList
Event listener list.
protected Setselection
List that contains the selected items.
protected intselectionMode
Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
static intSELECTED
Value that represents selected state in cellStates.
static StringSELECTION_MODE_PROPERTY
Property name for selectionMode.
static IntegerUNSELECTED
Object value that represents the unselected state in cellStates.
Constructor Summary
DefaultGraphSelectionModel(JGraph graph)
Constructs a DefaultGraphSelectionModel for the specified graph.
Method Summary
voidaddGraphSelectionListener(GraphSelectionListener x)
Adds x to the list of listeners that are notified each time the set of selected TreePaths changes.
voidaddPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list.
voidaddSelectionCell(Object cell)
Adds the specified cell to the current selection
voidaddSelectionCells(Object[] cells)
Adds cells to the current selection.
voidclearSelection()
Empties the current selection.
Objectclone()
Returns a clone of this object with the same selection.
protected booleandeselect(Object cell)
Deselects a single cell and updates all datastructures.
protected voidfireValueChanged(GraphSelectionEvent e)
Notifies all listeners that are registered for tree selection events on this object.
EventListener[]getListeners(Class listenerType)
Returns an array of all the listeners of the given type that were added to this model.
Object[]getSelectables()
Returns the cells that are currently selectable.
protected intgetSelectedChildCount(Object cell)
Returns the number of selected childs for cell.
ObjectgetSelectionCell()
Returns the first cell in the selection.
Object[]getSelectionCells()
Returns the cells in the selection.
intgetSelectionCount()
Returns the number of paths that are selected.
intgetSelectionMode()
Returns the selection mode, one of SINGLE_TREE_SELECTION, DISCONTIGUOUS_TREE_SELECTION or CONTIGUOUS_TREE_SELECTION.
booleanisCellSelected(Object cell)
Returns true if the cell, cell, is in the current selection.
booleanisChildrenSelectable()
Returns true if the selection model allows the selection of children.
protected booleanisChildrenSelectable(Object cell)
Hook for subclassers for fine-grained control over stepping-into cells.
booleanisChildrenSelected(Object cell)
Returns true if the cell, cell, has selected children.
booleanisSelectionEmpty()
Returns true if the selection is currently empty.
protected voidnotifyCellChange(Vector changedCells)
Notifies listeners of a change in path.
voidremoveGraphSelectionListener(GraphSelectionListener x)
Removes x from the list of listeners that are notified each time the set of selected TreePaths changes.
voidremovePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list.
voidremoveSelectionCell(Object cell)
Removes the specified cell from the selection.
voidremoveSelectionCells(Object[] cells)
Removes the specified cells from the selection.
protected booleanselect(Set set, Object cell)
Selects a single cell and updates all datastructures.
voidsetChildrenSelectable(boolean flag)
Sets if the selection model allows the selection of children.
protected voidsetSelectedChildCount(Object cell, int count)
Sets the number of selected childs for cell to count.
voidsetSelectionCell(Object cell)
Selects the specified cell.
voidsetSelectionCells(Object[] cells)
Sets the selection to cells.
voidsetSelectionMode(int mode)
Sets the selection mode, which must be one of SINGLE_TREE_SELECTION,

Field Detail

cellStates

protected Map cellStates
Maps the cells to their selection state.

changeSupport

protected SwingPropertyChangeSupport changeSupport
Used to message registered listeners.

childrenSelectable

protected boolean childrenSelectable
Boolean that indicates if the model allows stepping-into groups.

graph

protected JGraph graph
Reference to the parent graph. Used to find parents and childs.

listenerList

protected EventListenerList listenerList
Event listener list.

selection

protected Set selection
List that contains the selected items.

selectionMode

protected int selectionMode
Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.

SELECTED

public static final int SELECTED
Value that represents selected state in cellStates.

SELECTION_MODE_PROPERTY

public static final String SELECTION_MODE_PROPERTY
Property name for selectionMode.

UNSELECTED

public static final Integer UNSELECTED
Object value that represents the unselected state in cellStates.

Constructor Detail

DefaultGraphSelectionModel

public DefaultGraphSelectionModel(JGraph graph)
Constructs a DefaultGraphSelectionModel for the specified graph.

Method Detail

addGraphSelectionListener

public void addGraphSelectionListener(GraphSelectionListener x)
Adds x to the list of listeners that are notified each time the set of selected TreePaths changes.

Parameters: x the new listener to be added

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list. The listener is registered for all properties.

A PropertyChangeEvent will get fired when the selection mode changes.

Parameters: listener the PropertyChangeListener to be added

addSelectionCell

public void addSelectionCell(Object cell)
Adds the specified cell to the current selection

Parameters: cell the cell to add to the current selection

addSelectionCells

public void addSelectionCells(Object[] cells)
Adds cells to the current selection.

Parameters: cells the cells to be added to the current selection

clearSelection

public void clearSelection()
Empties the current selection. If this represents a change in the current selection, the selection listeners are notified.

clone

public Object clone()
Returns a clone of this object with the same selection. This method does not duplicate selection listeners and property listeners.

Throws: CloneNotSupportedException never thrown by instances of this class

deselect

protected boolean deselect(Object cell)
Deselects a single cell and updates all datastructures. No listeners are notified.

fireValueChanged

protected void fireValueChanged(GraphSelectionEvent e)
Notifies all listeners that are registered for tree selection events on this object.

See Also: DefaultGraphSelectionModel EventListenerList

getListeners

public EventListener[] getListeners(Class listenerType)
Returns an array of all the listeners of the given type that were added to this model.

Returns: all of the objects receiving listenerType notifications from this model

Since: 1.3

getSelectables

public Object[] getSelectables()
Returns the cells that are currently selectable. The array is ordered so that the top-most cell appears first.

getSelectedChildCount

protected int getSelectedChildCount(Object cell)
Returns the number of selected childs for cell.

getSelectionCell

public Object getSelectionCell()
Returns the first cell in the selection. This is useful if there if only one item currently selected.

getSelectionCells

public Object[] getSelectionCells()
Returns the cells in the selection. This will return null (or an empty array) if nothing is currently selected.

getSelectionCount

public int getSelectionCount()
Returns the number of paths that are selected.

getSelectionMode

public int getSelectionMode()
Returns the selection mode, one of SINGLE_TREE_SELECTION, DISCONTIGUOUS_TREE_SELECTION or CONTIGUOUS_TREE_SELECTION.

isCellSelected

public boolean isCellSelected(Object cell)
Returns true if the cell, cell, is in the current selection.

isChildrenSelectable

public boolean isChildrenSelectable()
Returns true if the selection model allows the selection of children.

isChildrenSelectable

protected boolean isChildrenSelectable(Object cell)
Hook for subclassers for fine-grained control over stepping-into cells. This implementation returns childrenSelectable&& isCellSelected.

isChildrenSelected

public boolean isChildrenSelected(Object cell)
Returns true if the cell, cell, has selected children.

isSelectionEmpty

public boolean isSelectionEmpty()
Returns true if the selection is currently empty.

notifyCellChange

protected void notifyCellChange(Vector changedCells)
Notifies listeners of a change in path. changePaths should contain instances of PathPlaceHolder.

removeGraphSelectionListener

public void removeGraphSelectionListener(GraphSelectionListener x)
Removes x from the list of listeners that are notified each time the set of selected TreePaths changes.

Parameters: x the listener to remove

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Parameters: listener the PropertyChangeListener to be removed

removeSelectionCell

public void removeSelectionCell(Object cell)
Removes the specified cell from the selection.

Parameters: cell the cell to remove from the current selection

removeSelectionCells

public void removeSelectionCells(Object[] cells)
Removes the specified cells from the selection.

Parameters: cells the cells to remove from the current selection

select

protected boolean select(Set set, Object cell)
Selects a single cell and updates all datastructures. No listeners are notified. Override this method to control individual cell selection.

setChildrenSelectable

public void setChildrenSelectable(boolean flag)
Sets if the selection model allows the selection of children.

setSelectedChildCount

protected void setSelectedChildCount(Object cell, int count)
Sets the number of selected childs for cell to count.

setSelectionCell

public void setSelectionCell(Object cell)
Selects the specified cell.

Parameters: cell the cell to select

setSelectionCells

public void setSelectionCells(Object[] cells)
Sets the selection to cells. If this represents a change the GraphSelectionListeners are notified. Potentially paths will be held by this object; in other words don't change any of the objects in the array once passed in.

Parameters: cells new selection

setSelectionMode

public void setSelectionMode(int mode)
Sets the selection mode, which must be one of SINGLE_TREE_SELECTION,
Copyright (C) 2001-2009 JGraph Ltd. All rights reserved.