Package org.jgraph.graph
Class DefaultGraphSelectionModel
java.lang.Object
org.jgraph.graph.DefaultGraphSelectionModel
- All Implemented Interfaces:
Serializable
,Cloneable
,GraphSelectionModel
- Direct Known Subclasses:
JGraph.EmptySelectionModel
public class DefaultGraphSelectionModel
extends Object
implements GraphSelectionModel, Cloneable, Serializable
Default implementation of GraphSelectionModel. Listeners are notified
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
Holds a path and whether or not it is new. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map
Maps the cells to their selection state.protected SwingPropertyChangeSupport
Used to message registered listeners.protected boolean
Boolean that indicates if the model allows stepping-into groups.protected JGraph
Reference to the parent graph.protected EventListenerList
Event listener list.static final int
Value that represents selected state in cellStates.protected Set
List that contains the selected items.static final String
Property name for selectionMode.protected int
Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.static final Integer
Object value that represents the unselected state in cellStates.Fields inherited from interface org.jgraph.graph.GraphSelectionModel
MULTIPLE_GRAPH_SELECTION, SINGLE_GRAPH_SELECTION
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultGraphSelectionModel
(JGraph graph) Constructs a DefaultGraphSelectionModel for the specified graph. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds x to the list of listeners that are notified each time the set of selected TreePaths changes.void
Adds a PropertyChangeListener to the listener list.void
addSelectionCell
(Object cell) Adds the specified cell to the current selectionvoid
addSelectionCells
(Object[] cells) Adds cells to the current selection.void
Empties the current selection.clone()
Returns a clone of this object with the same selection.protected boolean
Deselects a single cell and updates all datastructures.protected void
Notifies all listeners that are registered for tree selection events on this object.getListeners
(Class listenerType) Returns an array of all the listeners of the given type that were added to this model.Object[]
Returns the cells that are currently selectable.protected int
getSelectedChildCount
(Object cell) Returns the number of selected childs forcell
.Returns the first cell in the selection.Object[]
Returns the cells in the selection.int
Returns the number of paths that are selected.int
Returns the selection mode, one ofSINGLE_TREE_SELECTION
,DISCONTIGUOUS_TREE_SELECTION
orCONTIGUOUS_TREE_SELECTION
.boolean
isCellSelected
(Object cell) Returns true if the cell,cell
, is in the current selection.boolean
Returns true if the selection model allows the selection of children.protected boolean
isChildrenSelectable
(Object cell) Hook for subclassers for fine-grained control over stepping-into cells.boolean
isChildrenSelected
(Object cell) Returns true if the cell,cell
, has selected children.boolean
Returns true if the selection is currently empty.protected void
notifyCellChange
(Vector changedCells) Notifies listeners of a change in path.void
Removes x from the list of listeners that are notified each time the set of selected TreePaths changes.void
Removes a PropertyChangeListener from the listener list.void
removeSelectionCell
(Object cell) Removes the specified cell from the selection.void
removeSelectionCells
(Object[] cells) Removes the specified cells from the selection.protected boolean
Selects a single cell and updates all datastructures.void
setChildrenSelectable
(boolean flag) Sets if the selection model allows the selection of children.protected void
setSelectedChildCount
(Object cell, int count) Sets the number of selected childs forcell
tocount
.void
setSelectionCell
(Object cell) Selects the specified cell.void
setSelectionCells
(Object[] cells) Sets the selection tocells
.void
setSelectionMode
(int mode) Sets the selection mode, which must be one of SINGLE_TREE_SELECTION,
-
Field Details
-
SELECTION_MODE_PROPERTY
Property name for selectionMode.- See Also:
-
SELECTED
public static final int SELECTEDValue that represents selected state in cellStates.- See Also:
-
UNSELECTED
Object value that represents the unselected state in cellStates. -
graph
Reference to the parent graph. Used to find parents and childs. -
changeSupport
Used to message registered listeners. -
listenerList
Event listener list. -
selectionMode
protected int selectionModeMode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION. -
childrenSelectable
protected boolean childrenSelectableBoolean that indicates if the model allows stepping-into groups. -
cellStates
Maps the cells to their selection state. -
selection
List that contains the selected items.
-
-
Constructor Details
-
DefaultGraphSelectionModel
Constructs a DefaultGraphSelectionModel for the specified graph.
-
-
Method Details
-
setSelectionMode
public void setSelectionMode(int mode) Sets the selection mode, which must be one of SINGLE_TREE_SELECTION,- Specified by:
setSelectionMode
in interfaceGraphSelectionModel
-
getSelectionMode
public int getSelectionMode()Returns the selection mode, one ofSINGLE_TREE_SELECTION
,DISCONTIGUOUS_TREE_SELECTION
orCONTIGUOUS_TREE_SELECTION
.- Specified by:
getSelectionMode
in interfaceGraphSelectionModel
-
setChildrenSelectable
public void setChildrenSelectable(boolean flag) Sets if the selection model allows the selection of children.- Specified by:
setChildrenSelectable
in interfaceGraphSelectionModel
-
isChildrenSelectable
public boolean isChildrenSelectable()Returns true if the selection model allows the selection of children.- Specified by:
isChildrenSelectable
in interfaceGraphSelectionModel
-
isChildrenSelectable
Hook for subclassers for fine-grained control over stepping-into cells. This implementation returnschildrenSelectable
&& isCellSelected. -
setSelectionCell
Selects the specified cell.- Specified by:
setSelectionCell
in interfaceGraphSelectionModel
- Parameters:
cell
- the cell to select
-
setSelectionCells
Sets the selection tocells
. 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.- Specified by:
setSelectionCells
in interfaceGraphSelectionModel
- Parameters:
cells
- new selection
-
addSelectionCell
Adds the specified cell to the current selection- Specified by:
addSelectionCell
in interfaceGraphSelectionModel
- Parameters:
cell
- the cell to add to the current selection
-
addSelectionCells
Adds cells to the current selection.- Specified by:
addSelectionCells
in interfaceGraphSelectionModel
- Parameters:
cells
- the cells to be added to the current selection
-
removeSelectionCell
Removes the specified cell from the selection.- Specified by:
removeSelectionCell
in interfaceGraphSelectionModel
- Parameters:
cell
- the cell to remove from the current selection
-
removeSelectionCells
Removes the specified cells from the selection.- Specified by:
removeSelectionCells
in interfaceGraphSelectionModel
- Parameters:
cells
- the cells to remove from the current selection
-
getSelectables
Returns the cells that are currently selectable. The array is ordered so that the top-most cell appears first.- Specified by:
getSelectables
in interfaceGraphSelectionModel
-
getSelectionCell
Returns the first cell in the selection. This is useful if there if only one item currently selected.- Specified by:
getSelectionCell
in interfaceGraphSelectionModel
-
getSelectionCells
Returns the cells in the selection. This will return null (or an empty array) if nothing is currently selected.- Specified by:
getSelectionCells
in interfaceGraphSelectionModel
-
getSelectionCount
public int getSelectionCount()Returns the number of paths that are selected.- Specified by:
getSelectionCount
in interfaceGraphSelectionModel
-
isCellSelected
Returns true if the cell,cell
, is in the current selection.- Specified by:
isCellSelected
in interfaceGraphSelectionModel
-
isChildrenSelected
Returns true if the cell,cell
, has selected children.- Specified by:
isChildrenSelected
in interfaceGraphSelectionModel
-
isSelectionEmpty
public boolean isSelectionEmpty()Returns true if the selection is currently empty.- Specified by:
isSelectionEmpty
in interfaceGraphSelectionModel
-
clearSelection
public void clearSelection()Empties the current selection. If this represents a change in the current selection, the selection listeners are notified.- Specified by:
clearSelection
in interfaceGraphSelectionModel
-
getSelectedChildCount
Returns the number of selected childs forcell
. -
setSelectedChildCount
Sets the number of selected childs forcell
tocount
. -
select
Selects a single cell and updates all datastructures. No listeners are notified. Override this method to control individual cell selection. -
deselect
Deselects a single cell and updates all datastructures. No listeners are notified. -
addGraphSelectionListener
Adds x to the list of listeners that are notified each time the set of selected TreePaths changes.- Specified by:
addGraphSelectionListener
in interfaceGraphSelectionModel
- Parameters:
x
- the new listener to be added
-
removeGraphSelectionListener
Removes x from the list of listeners that are notified each time the set of selected TreePaths changes.- Specified by:
removeGraphSelectionListener
in interfaceGraphSelectionModel
- Parameters:
x
- the listener to remove
-
fireValueChanged
Notifies all listeners that are registered for tree selection events on this object. -
getListeners
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
-
addPropertyChangeListener
Adds a PropertyChangeListener to the listener list. The listener is registered for all properties.A PropertyChangeEvent will get fired when the selection mode changes.
- Specified by:
addPropertyChangeListener
in interfaceGraphSelectionModel
- Parameters:
listener
- the PropertyChangeListener to be added
-
removePropertyChangeListener
Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.- Specified by:
removePropertyChangeListener
in interfaceGraphSelectionModel
- Parameters:
listener
- the PropertyChangeListener to be removed
-
notifyCellChange
Notifies listeners of a change in path.changePaths
should contain instances of PathPlaceHolder. -
clone
Returns a clone of this object with the same selection. This method does not duplicate selection listeners and property listeners.- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
- never thrown by instances of this class
-