cytoscape.visual.calculators
Class AbstractCalculator

java.lang.Object
  extended by cytoscape.visual.calculators.AbstractCalculator
All Implemented Interfaces:
Calculator, Cloneable
Direct Known Subclasses:
EdgeCalculator, NodeCalculator

public abstract class AbstractCalculator
extends Object
implements Calculator

AbstractCalculator is the top of the tree for the Calculator classes. DO NOT extend this class directly! All calculators should extend one of NodeCalculator or EdgeCalculator AND implement one of the 11 attribute calculator interfaces.


Nested Class Summary
protected  class AbstractCalculator.CalculatorUI
          UI class for the calculator.
protected  class AbstractCalculator.MappingListener
          Listens to changes in the mapping and forwards them on to whatever listeners are attached to the calculator.
 
Field Summary
protected  Vector acceptedDataClasses
          The domain classes accepted by the mappings underlying this calculator.
protected  ChangeEvent changeEvent
          Only one ChangeEvent is needed per calculator instance since the event's only state is the source property.
protected  List changeListeners
          keep track of interested UI classes.
static String ID
          String literal used to refer to the generic "ID" attribute.
protected  Vector mappings
          Vector of all mappings contained by this calculator.
protected  String name
           
 
Constructor Summary
AbstractCalculator(String name, ObjectMapping m)
          Create a calculator with the specified object mapping and name.
 
Method Summary
 void addChangeListener(ChangeListener l)
          Add a ChangeListener to the calcaultor.
 void addMapping(ObjectMapping m)
          Add a mapping to the mappings contained by the calculator.
 Object clone()
          Clone the calculator.
protected  void fireStateChanged()
          Notifies all listeners that have registered interest for notification on this event type.
protected  Map getAttrBundle(String canonicalName, CyAttributes cyAttrs)
          Returns a map of attribute names to single values.
 int getDupeCount()
          Get how many times this calculator has been duplicated.
 ObjectMapping getMapping(int i)
          Get the mapping at a specific index in this calculator.
 Vector getMappings()
          Get all mappings contained by this calculator.
 Properties getProperties(String baseKey)
          Returns a properties description of this calculator.
protected  JPanel getUI(CyAttributes attr, JDialog parent, CyNetwork network)
          Get the UI for calculators.
abstract  JPanel getUI(JDialog parent, CyNetwork network)
          Get the UI for the calculator.
 void removeChangeListener(ChangeListener l)
          Remove a ChangeListener from the calcaultor.
 void setName(String newName)
          Set the name of this calculator.
 String toString()
          Get the name of this calculator.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ID

public static final String ID
String literal used to refer to the generic "ID" attribute.

See Also:
Constant Field Values

mappings

protected Vector mappings
Vector of all mappings contained by this calculator. Usually small. Contains ObjectMapping objects.


acceptedDataClasses

protected Vector acceptedDataClasses
The domain classes accepted by the mappings underlying this calculator. Contains an array of classes - each representing the appropriate domain classes of the mapping in the mappings vector at the same index.


name

protected String name

changeListeners

protected List changeListeners
keep track of interested UI classes.


changeEvent

protected transient ChangeEvent changeEvent
Only one ChangeEvent is needed per calculator instance since the event's only state is the source property.

Constructor Detail

AbstractCalculator

public AbstractCalculator(String name,
                          ObjectMapping m)
Create a calculator with the specified object mapping and name. The object mapping is used to determine what classes of attribute data this calculator can map from. If the object mapping is null, no filtration on the attribute data is performed.

Parameters:
m - Object mapping for this calculator, or null
name - Name of this calculator
Method Detail

addMapping

public void addMapping(ObjectMapping m)
Add a mapping to the mappings contained by the calculator.

Parameters:
m - Mapping to add.

getMappings

public Vector getMappings()
Get all mappings contained by this calculator.

Returns:
Vector of all mappings contained in this calculator

getMapping

public ObjectMapping getMapping(int i)
Get the mapping at a specific index in this calculator.

Parameters:
i - index of mapping to retrieve
Returns:
ObjectMapping at index i

getDupeCount

public int getDupeCount()
Get how many times this calculator has been duplicated.

Returns:
Calculator duplication count

clone

public Object clone()
             throws CloneNotSupportedException
Clone the calculator. AbstractCalculator makes an independent clone of itself but DOES NOT ensure that a unique name is created. Whoever is cloning the calculator should enter the new calculator in the catalog and create an appropriate name for it if needed.

Specified by:
clone in interface Calculator
Overrides:
clone in class Object
Returns:
Clone of this calculator
Throws:
CloneNotSupportedException - if something is seriously borked.

toString

public final String toString()
Get the name of this calculator.

Specified by:
toString in interface Calculator
Overrides:
toString in class Object
Returns:
the calculator's name

setName

public void setName(String newName)
Set the name of this calculator. Should only be done by the CalculatorCatalog after checking that name will not be duplicated.

Specified by:
setName in interface Calculator
Parameters:
newName - the new name for this calculator. Must be unique.

getProperties

public Properties getProperties(String baseKey)
Returns a properties description of this calculator. Adds the keyword ".mapping" to the supplied base key and calls the getProperties method of MappingFactory with the ObjectMapping and the augmented base key.

Specified by:
getProperties in interface Calculator

getUI

public abstract JPanel getUI(JDialog parent,
                             CyNetwork network)
Get the UI for the calculator.

Specified by:
getUI in interface Calculator
Parameters:
parent - Parent JDialog for the UI
network - CyNetwork object containing underlying graph data

getUI

protected JPanel getUI(CyAttributes attr,
                       JDialog parent,
                       CyNetwork network)
Get the UI for calculators. Display a JComboBox with attributes in the given CyAttributes whose data are instances of the classes accepted by each ObjectMapping. The resulting JComboBox calls updateAttribute(String, CyNetwork, int) when frobbed.

Parameters:
attr - CyAttributes to look up attributes from
Returns:
UI with controlling attribute selection facilities

addChangeListener

public void addChangeListener(ChangeListener l)
Add a ChangeListener to the calcaultor. When the state underlying the calculator changes, all ChangeListeners will be notified. This is used in the UI classes to ensure that the UI panes stay consistent with the data held in the mappings.

Specified by:
addChangeListener in interface Calculator
Parameters:
l - ChangeListener to add

removeChangeListener

public void removeChangeListener(ChangeListener l)
Remove a ChangeListener from the calcaultor. When the state underlying the calculator changes, all ChangeListeners will be notified. This is used in the UI classes to ensure that the UI panes stay consistent with the data held in the mappings.

Specified by:
removeChangeListener in interface Calculator
Parameters:
l - ChangeListener to add

fireStateChanged

protected void fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created. UI classes should attach themselves with a listener to the calculator to be notified about changes in the underlying data structures that require the UI classes to fetch a new copy of the UI and display it.


getAttrBundle

protected Map getAttrBundle(String canonicalName,
                            CyAttributes cyAttrs)
Returns a map of attribute names to single values.

Parameters:
canonicalName - The attribute name returned from the CyNode or CyEdge.
Returns:
Map of the attribute names to values.