jcreek.cke.graph
Class GraphModel

java.lang.Object
  extended byjcreek.cke.graph.GraphModel
All Implemented Interfaces:
CreekModel, java.io.Serializable

public class GraphModel
extends java.lang.Object
implements CreekModel

See Also:
Serialized Form

Field Summary
protected  java.beans.PropertyChangeSupport changeListeners
          List of change listeners.
 double hSpacing
           
protected  boolean suspendChangeNotices
          True if we are to not send out change notifications.
 double vSpacing
           
 
Constructor Summary
GraphModel()
           
 
Method Summary
 void addChangeListener(java.beans.PropertyChangeListener listener)
          Add a property change listener to this model.
 boolean addEntity(VisualEntity node)
           
 boolean addEntityList(VertexList nodes)
          Add the given list of entities to the graph.
 boolean addRelation(VisualRelation relation)
          Add a relation to the graph.
 boolean addRelationList(RelationList relations)
          Add the given list of relations to the graph.
 boolean deleteEntityList(VertexList nodes)
          Delete the given list of entities from the graph.
 boolean deleteRelationList(RelationList edges)
           
 VisualEntity findVisualEntity(Entity e)
           
 VisualRelation findVisualRelation(Relation rel)
           
 void fireChange()
          Let all the change listeners know of a recent change in the model data.
protected  void fireSelection()
          Let all the selection change listeners know of a recent change in the selection of a data object.
 Relation[] getActiveRelations(VisualEntity ved)
          Return the reference to the entity list contained in this graph.
 VisualRelation[] getActiveVisualRelations(VisualEntity ved)
           
 VertexList getEntities()
          Return the reference to the entity list contained in this graph.
 Graph getGraph()
           
 RelationList getRelations()
           
 VisualEntity[] getSelectedEntities()
          Gets the list of the selected entities in the graph.
 void markDirty()
          Utility method to cause a change event to be fired off to all the listeners.
 boolean moveEntityList(VertexList el, int dx, int dy)
          Moves a list of entities to a new location, given by the dx, dy, dz coordinates.
 boolean relationIsActive(VisualRelation vRelation)
           
 void removeChangeListener(java.beans.PropertyChangeListener listener)
          Remove a change listener from the listener list.
 boolean removeEntity(Entity e)
           
 void removeEntity(VisualEntity node)
          Remove a node from the model.
 boolean removeEntityList(Entity[] nodes)
           
 boolean removeEntityList(VertexList nodes)
          Remove a list of nodes from the model.
 boolean removeRelation(Relation rel)
           
 boolean removeRelation(VisualRelation edgeToRemove)
          Remove an relation from the graph.
 boolean removeRelationList(Relation[] edges)
           
 boolean removeRelationList(RelationList edges)
           
 void replace(Graph grp)
           
 void selectRelations(boolean state, RelationList rList)
          Mark all of the edges in the graph as selected.
 void selectVertices(boolean state, VertexList vList)
          Mark all the entities in the List as selected.
 void setSelected(VisualEntity v, boolean s)
          Set the given entity to the selected state given.
 void setSelected(VisualRelation e, boolean s)
          Set the given edge to the selected state given.
protected  boolean suspendChanges(boolean suspend)
          Tells us to suspend sending out change notifications.
 void unselectAllEdges()
          Mark all of the edges in the graph as unselected.
 void unselectAllVertices()
          Mark all the entities in the graph as unselected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

changeListeners

protected transient java.beans.PropertyChangeSupport changeListeners
List of change listeners. Each time the model is changed these listeners are notified via the PropertyChangeEvent. The listeners must implement the PropertyChangeListener interface.


suspendChangeNotices

protected transient boolean suspendChangeNotices
True if we are to not send out change notifications. This is used when we're performing repetitive actions that would normally fire change events.


hSpacing

public double hSpacing

vSpacing

public double vSpacing
Constructor Detail

GraphModel

public GraphModel()
Method Detail

addEntity

public boolean addEntity(VisualEntity node)
Specified by:
addEntity in interface CreekModel

addEntityList

public boolean addEntityList(VertexList nodes)
Add the given list of entities to the graph.

Specified by:
addEntityList in interface CreekModel
Parameters:
nodes - list of entities to add
Returns:
true if entities successfully added to graph

removeEntity

public void removeEntity(VisualEntity node)
Remove a node from the model.

Specified by:
removeEntity in interface CreekModel
Parameters:
node - node to remove
Returns:
true if successful, false if error

removeEntity

public boolean removeEntity(Entity e)
Specified by:
removeEntity in interface CreekModel

removeEntityList

public boolean removeEntityList(VertexList nodes)
Remove a list of nodes from the model.

Specified by:
removeEntityList in interface CreekModel
Parameters:
nodes - list of nodes to remove
Returns:
true if successful, false if error

removeEntityList

public boolean removeEntityList(Entity[] nodes)
Specified by:
removeEntityList in interface CreekModel

deleteEntityList

public boolean deleteEntityList(VertexList nodes)
Delete the given list of entities from the graph.

Specified by:
deleteEntityList in interface CreekModel
Parameters:
nodes - list of entities to remove
Returns:
true if successful, false if error

getEntities

public VertexList getEntities()
Return the reference to the entity list contained in this graph.

Specified by:
getEntities in interface CreekModel
Returns:
list of vertices in graph

getSelectedEntities

public VisualEntity[] getSelectedEntities()
Gets the list of the selected entities in the graph.

Specified by:
getSelectedEntities in interface CreekModel
Returns:
list of selected entities; null if none selected

selectVertices

public void selectVertices(boolean state,
                           VertexList vList)
Mark all the entities in the List as selected. This will cause a change event to be fired and sent to any selection change listeners.

Specified by:
selectVertices in interface CreekModel

setSelected

public void setSelected(VisualEntity v,
                        boolean s)
Set the given entity to the selected state given. This will cause a change event to be fired and sent to any selection change listeners.

Specified by:
setSelected in interface CreekModel
Parameters:
v - entity to select or unselect
s - true to mark entity selected, false unselected

unselectAllVertices

public void unselectAllVertices()
Mark all the entities in the graph as unselected. This will cause a change event to be fired and sent to any selection change listeners.

Specified by:
unselectAllVertices in interface CreekModel

findVisualEntity

public VisualEntity findVisualEntity(Entity e)
Specified by:
findVisualEntity in interface CreekModel

moveEntityList

public boolean moveEntityList(VertexList el,
                              int dx,
                              int dy)
Moves a list of entities to a new location, given by the dx, dy, dz coordinates. Will fire a change notification so listeners will know of the move.

Specified by:
moveEntityList in interface CreekModel
Parameters:
dx - x position change
dy - y position change
Returns:
true if successful, false if error

addRelation

public boolean addRelation(VisualRelation relation)
Add a relation to the graph.

Specified by:
addRelation in interface CreekModel
Parameters:
relation - relation to add to matrix
Returns:
true if relation successfully added to graph

addRelationList

public boolean addRelationList(RelationList relations)
Add the given list of relations to the graph.

Specified by:
addRelationList in interface CreekModel
Parameters:
relations - list of relations to add
Returns:
true if relations successfully added to graph

getRelations

public RelationList getRelations()
Specified by:
getRelations in interface CreekModel

removeRelation

public boolean removeRelation(VisualRelation edgeToRemove)
Remove an relation from the graph.

Specified by:
removeRelation in interface CreekModel
Parameters:
edgeToRemove - the edge to remove from the graph
Returns:
true if successful, false if error

removeRelation

public boolean removeRelation(Relation rel)
Specified by:
removeRelation in interface CreekModel

removeRelationList

public boolean removeRelationList(RelationList edges)
Specified by:
removeRelationList in interface CreekModel

removeRelationList

public boolean removeRelationList(Relation[] edges)
Specified by:
removeRelationList in interface CreekModel

deleteRelationList

public boolean deleteRelationList(RelationList edges)
Specified by:
deleteRelationList in interface CreekModel

setSelected

public void setSelected(VisualRelation e,
                        boolean s)
Set the given edge to the selected state given. This will cause a change event to be fired and sent to any selection change listeners.

Specified by:
setSelected in interface CreekModel
Parameters:
e - edge to select or unselect
s - true to mark edge selected, false unselected

selectRelations

public void selectRelations(boolean state,
                            RelationList rList)
Mark all of the edges in the graph as selected. This will cause a change event to be fired and sent to any selection change listeners.

Specified by:
selectRelations in interface CreekModel

unselectAllEdges

public void unselectAllEdges()
Mark all of the edges in the graph as unselected. This will cause a change event to be fired and sent to any selection change listeners.

Specified by:
unselectAllEdges in interface CreekModel

findVisualRelation

public VisualRelation findVisualRelation(Relation rel)
Specified by:
findVisualRelation in interface CreekModel

relationIsActive

public boolean relationIsActive(VisualRelation vRelation)

getActiveRelations

public Relation[] getActiveRelations(VisualEntity ved)
Return the reference to the entity list contained in this graph. This returns a clone of the actual entity list.

Specified by:
getActiveRelations in interface CreekModel
Returns:
list of vertices in graph

getActiveVisualRelations

public VisualRelation[] getActiveVisualRelations(VisualEntity ved)

getGraph

public Graph getGraph()
Specified by:
getGraph in interface CreekModel

markDirty

public void markDirty()
Utility method to cause a change event to be fired off to all the listeners. Used when someone has changed the graph data at a low level (i.e. by manipulating a single entity) and they want others to know of the change.

Specified by:
markDirty in interface CreekModel

addChangeListener

public void addChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this model. Any time a entity or edge is added, removed or changed in any way via the graph, a "change" event is sent to the change listeners. If an element is selected or deselected, "selection" events are sent.

Specified by:
addChangeListener in interface CreekModel
Parameters:
listener - new listener to add notification list
See Also:
removeChangeListener(java.beans.PropertyChangeListener)

fireChange

public void fireChange()
Let all the change listeners know of a recent change in the model data. This fires off a "change" event.

Specified by:
fireChange in interface CreekModel

fireSelection

protected void fireSelection()
Let all the selection change listeners know of a recent change in the selection of a data object. This fires off a "selection" change event.


removeChangeListener

public void removeChangeListener(java.beans.PropertyChangeListener listener)
Remove a change listener from the listener list.

Specified by:
removeChangeListener in interface CreekModel
Parameters:
listener - listener to remove from notification list
See Also:
addChangeListener(java.beans.PropertyChangeListener)

suspendChanges

protected boolean suspendChanges(boolean suspend)
Tells us to suspend sending out change notifications. Be sure to enable change notifications after you've performed the work that would have otherwise fired many changes. It returns the previous state of the suspend. This can be used like so:
 boolean oldState = suspendChanges( true );
 ...
 suspendChanges( oldState );
 

Parameters:
suspend - true to suspend notifications
Returns:
previous suspend state

replace

public void replace(Graph grp)
Specified by:
replace in interface CreekModel


Created at IDI, NTNU by the Artificial Intelligence and Learning group