org.ceryle.graph
Class SelectionManager

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by javax.swing.DefaultComboBoxModel
          extended by org.ceryle.util.SetModel
              extended by org.ceryle.graph.SelectionManager
All Implemented Interfaces:
Serializable, Iterable, Collection, List, Set, ComboBoxModel, ListModel, MutableComboBoxModel

public class SelectionManager
extends SetModel

Extends the utility class SetModel to serve as a manager/container for the graph selection. This is normally a single node, but multiple selection requires a more complex solution than provided by TouchGraph. This class also provides methods to characterize the state of the contents of the selection, and because SetModel implements the ListDataListener API, it's possible to add listeners for changes to the selection.

The choice of backing storage being a SetModel is so that the contents of the selection can be included in GUI selection lists without being converted or transferred into another container. SetModel is backed by a Vector, which is synchronized.

Since:
JDK1.3
Version:
$Id: SelectionManager.java,v 3.7 2007-06-15 12:09:24 altheim Exp $
Author:
Murray Altheim
See Also:
Serialized Form

Field Summary
static int ANODES
          An int indicating that the selection is composed solely of ANodes.
static int EMPTY
          An int indicating no selection.
static int MIXED
          An int indicating a mixed type selection.
static int ONODES
          An int indicating that the selection is composed solely of ONodes.
static int RNODES
          An int indicating that the selection is composed solely of RNodes.
static int SNODES
          An int indicating that the selection is composed solely of SNodes.
static int TNODES
          An int indicating that the selection is composed solely of TNodes.
 
Fields inherited from class org.ceryle.util.SetModel
EMPTY_SET, modCount
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
SelectionManager(GraphPanel graphpanel)
          Constructs an empty SelectionManager object.
SelectionManager(GraphPanel graphpanel, Object[] items)
          Constructs a SelectionManager object initialized with an array of objects.
SelectionManager(GraphPanel graphpanel, Vector vector)
          Constructs a SelectionManager object initialized with a Vector.
 
Method Summary
 boolean addToSelection(GraphNode node)
          Adds the GraphNode node to the selection, if it is not already part of the Set.
 void clearSelection()
          Clears the selection.
 int count()
          Return the number of selected GraphNodes.
 int getComposition()
          Returns the composition of the selection.
 Iterator getMultiSelected()
          Returns a Iterator over the Set containing all selected GraphNodes.
 GraphNode getSelected()
          Return the selected GraphNode, null if there is no selection.
 boolean isSelected(GraphNode node)
          Returns true if the GraphNode node is part of the current selection.
 void removeFromSelection(GraphNode node)
          Removes the GraphNode node from the selection.
 void setSelected(GraphNode node)
          Sets the selection to the GraphNode node, clearing any previous selection, unless this is already the selected node.
 void setSelected(Set nodes)
          Sets the selection to the Set of GraphNode nodes, clearing any previous selection.
 
Methods inherited from class org.ceryle.util.SetModel
add, add, addAll, addAll, addAll, addElement, addElements, changedElementAt, clear, contains, containsAll, get, getFirstElement, getLastElement, getSelectedItem, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, moveToBeginning, remove, remove, removeAll, retainAll, set, setSelectedItem, size, sort, subList, toArray, toArray
 
Methods inherited from class javax.swing.DefaultComboBoxModel
getElementAt, getIndexOf, getSize, insertElementAt, removeAllElements, removeElement, removeElementAt
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode
 
Methods inherited from interface java.util.List
equals, hashCode
 
Methods inherited from interface javax.swing.MutableComboBoxModel
insertElementAt, removeElement, removeElementAt
 

Field Detail

EMPTY

public static final int EMPTY
An int indicating no selection.

See Also:
Constant Field Values

MIXED

public static final int MIXED
An int indicating a mixed type selection.

See Also:
Constant Field Values

TNODES

public static final int TNODES
An int indicating that the selection is composed solely of TNodes.

See Also:
Constant Field Values

ANODES

public static final int ANODES
An int indicating that the selection is composed solely of ANodes.

See Also:
Constant Field Values

SNODES

public static final int SNODES
An int indicating that the selection is composed solely of SNodes.

See Also:
Constant Field Values

ONODES

public static final int ONODES
An int indicating that the selection is composed solely of ONodes.

See Also:
Constant Field Values

RNODES

public static final int RNODES
An int indicating that the selection is composed solely of RNodes.

See Also:
Constant Field Values
Constructor Detail

SelectionManager

public SelectionManager(GraphPanel graphpanel)
Constructs an empty SelectionManager object.

Parameters:
graphpanel - the GraphPanel whose selection is being managed

SelectionManager

public SelectionManager(GraphPanel graphpanel,
                        Object[] items)
Constructs a SelectionManager object initialized with an array of objects.

Parameters:
graphpanel - the GraphPanel whose selection is being managed
items - an array of Object objects

SelectionManager

public SelectionManager(GraphPanel graphpanel,
                        Vector vector)
Constructs a SelectionManager object initialized with a Vector.

Parameters:
graphpanel - the GraphPanel whose selection is being managed
vector - the Vector object
Method Detail

clearSelection

public void clearSelection()
Clears the selection.


getComposition

public int getComposition()
Returns the composition of the selection. The returned value is one of the following: If the node type is not recognized, returns MIXED.


setSelected

public void setSelected(GraphNode node)
Sets the selection to the GraphNode node, clearing any previous selection, unless this is already the selected node.


setSelected

public void setSelected(Set nodes)
Sets the selection to the Set of GraphNode nodes, clearing any previous selection.


addToSelection

public boolean addToSelection(GraphNode node)
Adds the GraphNode node to the selection, if it is not already part of the Set.

Returns:
returns true if the GraphNode was added.

removeFromSelection

public void removeFromSelection(GraphNode node)
Removes the GraphNode node from the selection. If it is not part of the Set, nothing happens.


getSelected

public GraphNode getSelected()
Return the selected GraphNode, null if there is no selection. If there is a multiple selection, this returns the first GraphNode selected.


isSelected

public boolean isSelected(GraphNode node)
Returns true if the GraphNode node is part of the current selection.


count

public int count()
Return the number of selected GraphNodes.


getMultiSelected

public Iterator getMultiSelected()
Returns a Iterator over the Set containing all selected GraphNodes. This is backed by an unmodifiable Set, so that changes that occur during iteration will cause a ConcurrentModificationException to be thrown.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.