Package org.jgraph.graph
Class DefaultGraphSelectionModel
- java.lang.Object
-
- org.jgraph.graph.DefaultGraphSelectionModel
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,GraphSelectionModel
- Direct Known Subclasses:
JGraph.EmptySelectionModel
public class DefaultGraphSelectionModel extends java.lang.Object implements GraphSelectionModel, java.lang.Cloneable, java.io.Serializable
Default implementation of GraphSelectionModel. Listeners are notified- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classDefaultGraphSelectionModel.CellPlaceHolderHolds a path and whether or not it is new.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.MapcellStatesMaps the cells to their selection state.protected javax.swing.event.SwingPropertyChangeSupportchangeSupportUsed to message registered listeners.protected booleanchildrenSelectableBoolean that indicates if the model allows stepping-into groups.protected JGraphgraphReference to the parent graph.protected javax.swing.event.EventListenerListlistenerListEvent listener list.static intSELECTEDValue that represents selected state in cellStates.protected java.util.SetselectionList that contains the selected items.static java.lang.StringSELECTION_MODE_PROPERTYProperty name for selectionMode.protected intselectionModeMode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.static java.lang.IntegerUNSELECTEDObject value that represents the unselected state in cellStates.-
Fields inherited from interface org.jgraph.graph.GraphSelectionModel
MULTIPLE_GRAPH_SELECTION, SINGLE_GRAPH_SELECTION
-
-
Constructor Summary
Constructors Constructor Description DefaultGraphSelectionModel(JGraph graph)Constructs a DefaultGraphSelectionModel for the specified graph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddGraphSelectionListener(GraphSelectionListener x)Adds x to the list of listeners that are notified each time the set of selected TreePaths changes.voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)Adds a PropertyChangeListener to the listener list.voidaddSelectionCell(java.lang.Object cell)Adds the specified cell to the current selectionvoidaddSelectionCells(java.lang.Object[] cells)Adds cells to the current selection.voidclearSelection()Empties the current selection.java.lang.Objectclone()Returns a clone of this object with the same selection.protected booleandeselect(java.lang.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.java.util.EventListener[]getListeners(java.lang.Class listenerType)Returns an array of all the listeners of the given type that were added to this model.java.lang.Object[]getSelectables()Returns the cells that are currently selectable.protected intgetSelectedChildCount(java.lang.Object cell)Returns the number of selected childs forcell.java.lang.ObjectgetSelectionCell()Returns the first cell in the selection.java.lang.Object[]getSelectionCells()Returns the cells in the selection.intgetSelectionCount()Returns the number of paths that are selected.intgetSelectionMode()Returns the selection mode, one ofSINGLE_TREE_SELECTION,DISCONTIGUOUS_TREE_SELECTIONorCONTIGUOUS_TREE_SELECTION.booleanisCellSelected(java.lang.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(java.lang.Object cell)Hook for subclassers for fine-grained control over stepping-into cells.booleanisChildrenSelected(java.lang.Object cell)Returns true if the cell,cell, has selected children.booleanisSelectionEmpty()Returns true if the selection is currently empty.protected voidnotifyCellChange(java.util.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(java.beans.PropertyChangeListener listener)Removes a PropertyChangeListener from the listener list.voidremoveSelectionCell(java.lang.Object cell)Removes the specified cell from the selection.voidremoveSelectionCells(java.lang.Object[] cells)Removes the specified cells from the selection.protected booleanselect(java.util.Set set, java.lang.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(java.lang.Object cell, int count)Sets the number of selected childs forcelltocount.voidsetSelectionCell(java.lang.Object cell)Selects the specified cell.voidsetSelectionCells(java.lang.Object[] cells)Sets the selection tocells.voidsetSelectionMode(int mode)Sets the selection mode, which must be one of SINGLE_TREE_SELECTION,
-
-
-
Field Detail
-
SELECTION_MODE_PROPERTY
public static final java.lang.String SELECTION_MODE_PROPERTY
Property name for selectionMode.- See Also:
- Constant Field Values
-
SELECTED
public static final int SELECTED
Value that represents selected state in cellStates.- See Also:
- Constant Field Values
-
UNSELECTED
public static final java.lang.Integer UNSELECTED
Object value that represents the unselected state in cellStates.
-
graph
protected JGraph graph
Reference to the parent graph. Used to find parents and childs.
-
changeSupport
protected javax.swing.event.SwingPropertyChangeSupport changeSupport
Used to message registered listeners.
-
listenerList
protected javax.swing.event.EventListenerList listenerList
Event listener list.
-
selectionMode
protected int selectionMode
Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
-
childrenSelectable
protected boolean childrenSelectable
Boolean that indicates if the model allows stepping-into groups.
-
cellStates
protected java.util.Map cellStates
Maps the cells to their selection state.
-
selection
protected java.util.Set selection
List that contains the selected items.
-
-
Constructor Detail
-
DefaultGraphSelectionModel
public DefaultGraphSelectionModel(JGraph graph)
Constructs a DefaultGraphSelectionModel for the specified graph.
-
-
Method Detail
-
setSelectionMode
public void setSelectionMode(int mode)
Sets the selection mode, which must be one of SINGLE_TREE_SELECTION,- Specified by:
setSelectionModein interfaceGraphSelectionModel
-
getSelectionMode
public int getSelectionMode()
Returns the selection mode, one ofSINGLE_TREE_SELECTION,DISCONTIGUOUS_TREE_SELECTIONorCONTIGUOUS_TREE_SELECTION.- Specified by:
getSelectionModein interfaceGraphSelectionModel
-
setChildrenSelectable
public void setChildrenSelectable(boolean flag)
Sets if the selection model allows the selection of children.- Specified by:
setChildrenSelectablein interfaceGraphSelectionModel
-
isChildrenSelectable
public boolean isChildrenSelectable()
Returns true if the selection model allows the selection of children.- Specified by:
isChildrenSelectablein interfaceGraphSelectionModel
-
isChildrenSelectable
protected boolean isChildrenSelectable(java.lang.Object cell)
Hook for subclassers for fine-grained control over stepping-into cells. This implementation returnschildrenSelectable&& isCellSelected.
-
setSelectionCell
public void setSelectionCell(java.lang.Object cell)
Selects the specified cell.- Specified by:
setSelectionCellin interfaceGraphSelectionModel- Parameters:
cell- the cell to select
-
setSelectionCells
public void setSelectionCells(java.lang.Object[] cells)
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:
setSelectionCellsin interfaceGraphSelectionModel- Parameters:
cells- new selection
-
addSelectionCell
public void addSelectionCell(java.lang.Object cell)
Adds the specified cell to the current selection- Specified by:
addSelectionCellin interfaceGraphSelectionModel- Parameters:
cell- the cell to add to the current selection
-
addSelectionCells
public void addSelectionCells(java.lang.Object[] cells)
Adds cells to the current selection.- Specified by:
addSelectionCellsin interfaceGraphSelectionModel- Parameters:
cells- the cells to be added to the current selection
-
removeSelectionCell
public void removeSelectionCell(java.lang.Object cell)
Removes the specified cell from the selection.- Specified by:
removeSelectionCellin interfaceGraphSelectionModel- Parameters:
cell- the cell to remove from the current selection
-
removeSelectionCells
public void removeSelectionCells(java.lang.Object[] cells)
Removes the specified cells from the selection.- Specified by:
removeSelectionCellsin interfaceGraphSelectionModel- Parameters:
cells- the cells to remove from the current selection
-
getSelectables
public java.lang.Object[] getSelectables()
Returns the cells that are currently selectable. The array is ordered so that the top-most cell appears first.- Specified by:
getSelectablesin interfaceGraphSelectionModel
-
getSelectionCell
public java.lang.Object getSelectionCell()
Returns the first cell in the selection. This is useful if there if only one item currently selected.- Specified by:
getSelectionCellin interfaceGraphSelectionModel
-
getSelectionCells
public java.lang.Object[] getSelectionCells()
Returns the cells in the selection. This will return null (or an empty array) if nothing is currently selected.- Specified by:
getSelectionCellsin interfaceGraphSelectionModel
-
getSelectionCount
public int getSelectionCount()
Returns the number of paths that are selected.- Specified by:
getSelectionCountin interfaceGraphSelectionModel
-
isCellSelected
public boolean isCellSelected(java.lang.Object cell)
Returns true if the cell,cell, is in the current selection.- Specified by:
isCellSelectedin interfaceGraphSelectionModel
-
isChildrenSelected
public boolean isChildrenSelected(java.lang.Object cell)
Returns true if the cell,cell, has selected children.- Specified by:
isChildrenSelectedin interfaceGraphSelectionModel
-
isSelectionEmpty
public boolean isSelectionEmpty()
Returns true if the selection is currently empty.- Specified by:
isSelectionEmptyin 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:
clearSelectionin interfaceGraphSelectionModel
-
getSelectedChildCount
protected int getSelectedChildCount(java.lang.Object cell)
Returns the number of selected childs forcell.
-
setSelectedChildCount
protected void setSelectedChildCount(java.lang.Object cell, int count)Sets the number of selected childs forcelltocount.
-
select
protected boolean select(java.util.Set set, java.lang.Object cell)Selects a single cell and updates all datastructures. No listeners are notified. Override this method to control individual cell selection.
-
deselect
protected boolean deselect(java.lang.Object cell)
Deselects a single cell and updates all datastructures. No listeners are notified.
-
addGraphSelectionListener
public void addGraphSelectionListener(GraphSelectionListener x)
Adds x to the list of listeners that are notified each time the set of selected TreePaths changes.- Specified by:
addGraphSelectionListenerin interfaceGraphSelectionModel- Parameters:
x- the new listener to be added
-
removeGraphSelectionListener
public void removeGraphSelectionListener(GraphSelectionListener x)
Removes x from the list of listeners that are notified each time the set of selected TreePaths changes.- Specified by:
removeGraphSelectionListenerin interfaceGraphSelectionModel- Parameters:
x- the listener to remove
-
fireValueChanged
protected void fireValueChanged(GraphSelectionEvent e)
Notifies all listeners that are registered for tree selection events on this object.- See Also:
addGraphSelectionListener(org.jgraph.event.GraphSelectionListener),EventListenerList
-
getListeners
public java.util.EventListener[] getListeners(java.lang.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
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.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.
- Specified by:
addPropertyChangeListenerin interfaceGraphSelectionModel- Parameters:
listener- the PropertyChangeListener to be added
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.- Specified by:
removePropertyChangeListenerin interfaceGraphSelectionModel- Parameters:
listener- the PropertyChangeListener to be removed
-
notifyCellChange
protected void notifyCellChange(java.util.Vector changedCells)
Notifies listeners of a change in path.changePathsshould contain instances of PathPlaceHolder.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionReturns a clone of this object with the same selection. This method does not duplicate selection listeners and property listeners.- Overrides:
clonein classjava.lang.Object- Throws:
java.lang.CloneNotSupportedException- never thrown by instances of this class
-
-