Cytoscape 2.6.2 (c) 2006,2007 ISB, MSKCC, UCSD

cytoscape.data
Class SelectFilter

java.lang.Object
  extended by cytoscape.data.SelectFilter
All Implemented Interfaces:
Filter, GraphPerspectiveChangeListener, EventListener

public class SelectFilter
extends Object
implements Filter, GraphPerspectiveChangeListener

This class implements the ability to set the selected state of every node or edge in a GraphPerspective. The state can be either on or off. Methods are provided for inspecting the current state of any graph object, for setting the state, or getting the full set of states for nodes or edges. This functionality is often used to identify a set of interesting nodes or edges in the graph.

A non-null GraphPerspective reference is required to construct an instance of this class. This class will listen to the graph to respond to the removal of graph objects. A currently selected object that is removed from the graph will lose its selected state, even if it is later added back to the graph.

When the selected state of a node or edge is changed, a event of type SelectEvent is fired. When a group of nodes or edges are changed together in a single operation, one event will be fired for the whole group (but separate events for nodes and edges). Note: a listener should not be removed from this object in response to the firing of an event, as this may cause a ConcurrentModificationException.

WARNING: for performance reasons, the set of objects returned by the getSelectedXX methods is the actual data object, not a copy. Users should not directly modify these sets.

Performance note: the implementation is a HashSet of selected objects, so most methods are O(1). Operations on groups of nodes are O(N) where N is either the number of selected objects or the number of objects in the graph, as applicable.


Constructor Summary
SelectFilter(GraphPerspective graph)
          Standard Constructor.
 
Method Summary
 void addSelectEventListener(SelectEventListener listener)
          If the argument is not already a listener to this object, it is added.
 Set getSelectedEdges()
          Returns the set of all selected edges in the referenced GraphPespective.
 Set getSelectedNodes()
          Returns the set of all selected nodes in the referenced GraphPespective.
 List getSelectEventListeners()
          Gets a List of All Registered Listeners.
 void graphPerspectiveChanged(GraphPerspectiveChangeEvent event)
          Implementation of the GraphPerspectiveChangeListener interface.
 boolean isSelected(Edge edge)
          Returns true if the argument is a selected Edge in the referenced GraphPerspective, false otherwise.
 boolean isSelected(Node node)
          Returns true if the argument is a selected Node in the referenced GraphPerspective, false otherwise.
 boolean passesFilter(Object o)
          Implementation of the Filter interface.
 void removeSelectEventListener(SelectEventListener listener)
          If the argument is a listener to this object, removes it from the list of listeners.
 Set selectAllEdges()
          Sets the selected state to true for all Edges in the GraphPerspective.
 Set selectAllNodes()
          Sets the selected state to true for all Nodes in the GraphPerspective.
 boolean setSelected(Edge edge, boolean newState)
          If the first argument is an Edge in the referenced GraphPerspective, sets its selected state to the value of the second argument.
 boolean setSelected(Node node, boolean newState)
          If the first argument is a Node in the referenced GraphPerspective, sets its selected state to the value of the second argument.
 Set<Edge> setSelectedEdges(Collection<Edge> edgesToSet, boolean newState)
          Sets the selected state defined by the second argument for all Edges contained in the first argument, which should be a Collection of Edge objects contained in the referenced GraphPerspective.
 Set<Node> setSelectedNodes(Collection<Node> nodesToSet, boolean newState)
          Sets the selected state defined by the second argument for all Nodes contained in the first argument, which should be a Collection of Node objects contained in the referenced GraphPerspective.
 Set unselectAllEdges()
          Sets the selected state to false for all Edges in the GraphPerspective.
 Set unselectAllNodes()
          Sets the selected state to false for all Nodes in the GraphPerspective.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectFilter

public SelectFilter(GraphPerspective graph)
Standard Constructor. The argument is the graph that this filter will apply to; it cannot be null.

Throws:
NullPointerException - if the argument is null.
Method Detail

getSelectedNodes

public Set getSelectedNodes()
Returns the set of all selected nodes in the referenced GraphPespective.

WARNING: the returned set is the actual data object, not a copy. Don't directly modify this set.


getSelectedEdges

public Set getSelectedEdges()
Returns the set of all selected edges in the referenced GraphPespective.

WARNING: the returned set is the actual data object, not a copy. Don't directly modify this set.


isSelected

public boolean isSelected(Node node)
Returns true if the argument is a selected Node in the referenced GraphPerspective, false otherwise.


isSelected

public boolean isSelected(Edge edge)
Returns true if the argument is a selected Edge in the referenced GraphPerspective, false otherwise.


passesFilter

public boolean passesFilter(Object o)
Implementation of the Filter interface. Returns true if the argument is a selected Node or Edge in the referenced GraphPerspective, false otherwise.

Specified by:
passesFilter in interface Filter
Returns:
true iff the given Object passes the filter.

setSelected

public boolean setSelected(Node node,
                           boolean newState)
If the first argument is a Node in the referenced GraphPerspective, sets its selected state to the value of the second argument. An event will be fired iff the new state is different from the old state.

Returns:
true if an actual change was made, false otherwise

setSelected

public boolean setSelected(Edge edge,
                           boolean newState)
If the first argument is an Edge in the referenced GraphPerspective, sets its selected state to the value of the second argument. An event will be fired iff the new state is different from the old state.

Returns:
true if an actual change was made, false otherwise

setSelectedNodes

public Set<Node> setSelectedNodes(Collection<Node> nodesToSet,
                                  boolean newState)
Sets the selected state defined by the second argument for all Nodes contained in the first argument, which should be a Collection of Node objects contained in the referenced GraphPerspective. One event will be fired for the full set of changes. This method does nothing if the first argument is null.

Returns:
a Set containing the objects for which the selected state changed
Throws:
ClassCastException - if the first argument contains objects other than giny.model.Node objects

setSelectedEdges

public Set<Edge> setSelectedEdges(Collection<Edge> edgesToSet,
                                  boolean newState)
Sets the selected state defined by the second argument for all Edges contained in the first argument, which should be a Collection of Edge objects contained in the referenced GraphPerspective. One event will be fired for the full set of changes. This method does nothing if the first argument is null.

Returns:
a Set containing the objects for which the selected state changed
Throws:
ClassCastException - if the first argument contains objects other than giny.model.Edge objects

selectAllNodes

public Set selectAllNodes()
Sets the selected state to true for all Nodes in the GraphPerspective.


selectAllEdges

public Set selectAllEdges()
Sets the selected state to true for all Edges in the GraphPerspective.


unselectAllNodes

public Set unselectAllNodes()
Sets the selected state to false for all Nodes in the GraphPerspective.


unselectAllEdges

public Set unselectAllEdges()
Sets the selected state to false for all Edges in the GraphPerspective.


graphPerspectiveChanged

public void graphPerspectiveChanged(GraphPerspectiveChangeEvent event)
Implementation of the GraphPerspectiveChangeListener interface. Responds to the removal of nodes and edges by removing them from the set of selected graph objects if needed. Fires an event only if there was an actual change in the current selected set.

Specified by:
graphPerspectiveChanged in interface GraphPerspectiveChangeListener

addSelectEventListener

public void addSelectEventListener(SelectEventListener listener)
If the argument is not already a listener to this object, it is added. Does nothing if the argument is null.


removeSelectEventListener

public void removeSelectEventListener(SelectEventListener listener)
If the argument is a listener to this object, removes it from the list of listeners.


getSelectEventListeners

public List getSelectEventListeners()
Gets a List of All Registered Listeners.

Returns:

www.cytoscape.org