Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| JGraph v5.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jgraph.graph
Class DefaultGraphSelectionModel

    java.lang.Object
      |
      +--org.jgraph.graph.DefaultGraphSelectionModel

All Implemented Interfaces:
  Cloneable, GraphSelectionModel, Serializable

Direct Known Subclasses:
  JGraph.EmptySelectionModel

public class DefaultGraphSelectionModel
extends Object
implements GraphSelectionModel, Cloneable, Serializable

Default implementation of GraphSelectionModel. Listeners are notified

See Also:
  Serialized Form

Nested Class Summary
`protected class` | `DefaultGraphSelectionModel.CellPlaceHolder` Holds a path and whether or not it is new.

Field Summary
`protected Map` | `cellStates` Maps the cells to their selection state.
`protected SwingPropertyChangeSupport` | `changeSupport` Used to message registered listeners.
`protected boolean` | `childrenSelectable` Boolean that indicates if the model allows stepping-into groups.
`protected JGraph` | `graph` Reference to the parent graph.
`protected EventListenerList` | `listenerList` Event listener list.
`static int` | `SELECTED` Value that represents selected state in cellStates.
`protected List` | `selection` List that contains the selected items.
`static String` | `SELECTION_MODE_PROPERTY` Property name for selectionMode.
`protected int` | `selectionMode` Mode for the selection, will be either SINGLE_TREE_SELECTION, CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
`static Integer` | `UNSELECTED` 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
`DefaultGraphSelectionModel(JGraph graph)` Constructs a DefaultGraphSelectionModel for the specified graph.

Method Summary
`void` | `addGraphSelectionListener(GraphSelectionListener x)` Adds x to the list of listeners that are notified each time the set of selected TreePaths changes.
`void` | `addPropertyChangeListener(PropertyChangeListener listener)` Adds a PropertyChangeListener to the listener list.
`void` | `addSelectionCell(Object cell)` Adds path to the current selection.
`void` | `addSelectionCells(Object[] cells)` Adds cells to the current selection.
`void` | `clearSelection()` Empties the current selection.
`Object` | `clone()` Returns a clone of this object with the same selection.
`protected boolean` | `deselect(Object cell)` Deselects a single cell and updates all datastructures.
`protected void` | `fireValueChanged(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 int` | `getSelectedChildCount(Object cell)` Returns the number of selected childs for `cell`.
`Object` | `getSelectionCell()` Returns the first cell in the selection.
`Object[]` | `getSelectionCells()` Returns the cells in the selection.
`int` | `getSelectionCount()` Returns the number of paths that are selected.
`int` | `getSelectionMode()` Returns the selection mode, one of `SINGLE_TREE_SELECTION`, `DISCONTIGUOUS_TREE_SELECTION` or `CONTIGUOUS_TREE_SELECTION`.
`boolean` | `isCellSelected(Object cell)` Returns true if the cell, `cell`, is in the current selection.
`boolean` | `isChildrenSelectable()` 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` | `isSelectionEmpty()` Returns true if the selection is currently empty.
`protected void` | `notifyCellChange(Vector changedCells)` Notifies listeners of a change in path.
`void` | `removeGraphSelectionListener(GraphSelectionListener x)` Removes x from the list of listeners that are notified each time the set of selected TreePaths changes.
`void` | `removePropertyChangeListener(PropertyChangeListener listener)` Removes a PropertyChangeListener from the listener list.
`void` | `removeSelectionCell(Object cell)` Removes path from the selection.
`void` | `removeSelectionCells(Object[] cells)` Removes paths from the selection.
`protected boolean` | `select(List list, Object cell)` 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 for `cell` to `count`.
`void` | `setSelectionCell(Object cell)` Sets the selection to path.
`void` | `setSelectionCells(Object[] cells)` Sets the selection to `cells`.
`void` | `setSelectionMode(int mode)` Sets the selection mode, which must be one of SINGLE_TREE_SELECTION,

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### SELECTION_MODE_PROPERTY

    public static final 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 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 SwingPropertyChangeSupport changeSupport

  Used to message registered listeners.

### listenerList

    protected 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 Map cellStates

  Maps the cells to their selection state.

### selection

    protected List 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:
    `setSelectionMode` in interface `GraphSelectionModel`

### getSelectionMode

    public int getSelectionMode()

  Returns the selection mode, one of `SINGLE_TREE_SELECTION`, `DISCONTIGUOUS_TREE_SELECTION` or `CONTIGUOUS_TREE_SELECTION`.

  Specified by:
    `getSelectionMode` in interface `GraphSelectionModel`

### setChildrenSelectable

    public void setChildrenSelectable(boolean flag)

  Sets if the selection model allows the selection of children.

  Specified by:
    `setChildrenSelectable` in interface `GraphSelectionModel`

### isChildrenSelectable

    public boolean isChildrenSelectable()

  Returns true if the selection model allows the selection of children.

  Specified by:
    `isChildrenSelectable` in interface `GraphSelectionModel`

### isChildrenSelectable

    protected boolean isChildrenSelectable(Object cell)

  Hook for subclassers for fine-grained control over stepping-into cells. This implementation returns `childrenSelectable`.

### setSelectionCell

    public void setSelectionCell(Object cell)

  Sets the selection to path. If this represents a change, then the TreeSelectionListeners are notified. If `path` is null, this has the same effect as invoking `clearSelection`.

  Specified by:
    `setSelectionCell` in interface `GraphSelectionModel`
  Parameters:
    `cell` - new 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.

  If `paths` is null, this has the same effect as invoking `clearSelection`.

  The lead path is set to the last path in `pPaths`.

  If the selection mode is `CONTIGUOUS_TREE_SELECTION`, and adding the new paths would make the selection discontiguous, the selection is reset to the first TreePath in `paths`.

  Specified by:
    `setSelectionCells` in interface `GraphSelectionModel`
  Parameters:
    `cells` - new selection

### addSelectionCell

    public void addSelectionCell(Object cell)

  Adds path to the current selection. If path is not currently in the selection the TreeSelectionListeners are notified. This has no effect if `path` is null.

  Specified by:
    `addSelectionCell` in interface `GraphSelectionModel`
  Parameters:
    `cell` - the new cell to add to the current selection

### addSelectionCells

    public void addSelectionCells(Object[] cells)

  Adds cells to the current selection. If any of the paths in paths are not currently in the selection the TreeSelectionListeners are notified. This has no effect if `paths` is null.

  The lead path is set to the last element in `paths`.

  If the selection mode is `CONTIGUOUS_TREE_SELECTION`, and adding the new paths would make the selection discontiguous. Then two things can result: if the TreePaths in `paths` are contiguous, then the selection becomes these TreePaths, otherwise the TreePaths aren't contiguous and the selection becomes the first TreePath in `paths`.

  Specified by:
    `addSelectionCells` in interface `GraphSelectionModel`
  Parameters:
    `cells` - the new cells to add to the current selection

### removeSelectionCell

    public void removeSelectionCell(Object cell)

  Removes path from the selection. If path is in the selection The TreeSelectionListeners are notified. This has no effect if `path` is null.

  Specified by:
    `removeSelectionCell` in interface `GraphSelectionModel`
  Parameters:
    `cell` - the cell to remove from the selection

### removeSelectionCells

    public void removeSelectionCells(Object[] cells)

  Removes paths from the selection. If any of the paths in paths are in the selection the TreeSelectionListeners are notified. This has no effect if `paths` is null.

  Specified by:
    `removeSelectionCells` in interface `GraphSelectionModel`
  Parameters:
    `cells` - the cells to remove from the selection

### getSelectables

    public Object[] getSelectables()

  Returns the cells that are currently selectable.

  Specified by:
    `getSelectables` in interface `GraphSelectionModel`

### getSelectionCell

    public Object getSelectionCell()

  Returns the first cell in the selection. This is useful if there if only one item currently selected.

  Specified by:
    `getSelectionCell` in interface `GraphSelectionModel`

### getSelectionCells

    public Object[] getSelectionCells()

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

  Specified by:
    `getSelectionCells` in interface `GraphSelectionModel`

### getSelectionCount

    public int getSelectionCount()

  Returns the number of paths that are selected.

  Specified by:
    `getSelectionCount` in interface `GraphSelectionModel`

### isCellSelected

    public boolean isCellSelected(Object cell)

  Returns true if the cell, `cell`, is in the current selection.

  Specified by:
    `isCellSelected` in interface `GraphSelectionModel`

### isChildrenSelected

    public boolean isChildrenSelected(Object cell)

  Returns true if the cell, `cell`, has selected children.

  Specified by:
    `isChildrenSelected` in interface `GraphSelectionModel`

### isSelectionEmpty

    public boolean isSelectionEmpty()

  Returns true if the selection is currently empty.

  Specified by:
    `isSelectionEmpty` in interface `GraphSelectionModel`

### 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 interface `GraphSelectionModel`

### getSelectedChildCount

    protected int getSelectedChildCount(Object cell)

  Returns the number of selected childs for `cell`.

### setSelectedChildCount

    protected void setSelectedChildCount(Object cell,
                                         int count)

  Sets the number of selected childs for `cell` to `count`.

### select

    protected boolean select(List list,
                             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(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:
    `addGraphSelectionListener` in interface `GraphSelectionModel`
  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:
    `removeGraphSelectionListener` in interface `GraphSelectionModel`
  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 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

### 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.

  Specified by:
    `addPropertyChangeListener` in interface `GraphSelectionModel`
  Parameters:
    `listener` - the PropertyChangeListener to be added

### removePropertyChangeListener

    public void removePropertyChangeListener(PropertyChangeListener listener)

  Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

  Specified by:
    `removePropertyChangeListener` in interface `GraphSelectionModel`
  Parameters:
    `listener` - the PropertyChangeListener to be removed

### notifyCellChange

    protected void notifyCellChange(Vector changedCells)

  Notifies listeners of a change in path. changePaths should contain instances of PathPlaceHolder.

### clone

    public Object clone()
                 throws CloneNotSupportedException

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

  Overrides:
    `clone` in class `Object`
  Throws:
    `CloneNotSupportedException` - never thrown by instances of this class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| JGraph v5.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (C) 2003-2004 Gaudenz Alder. All rights reserved.