net.sourceforge.toscanaj.model.diagram
Class SimpleLineDiagram

java.lang.Object
  extended bynet.sourceforge.toscanaj.model.diagram.SimpleLineDiagram
All Implemented Interfaces:
Diagram2D, WriteableDiagram2D, XMLizable
Direct Known Subclasses:
NDimDiagram, NestedLineDiagram

public class SimpleLineDiagram
extends java.lang.Object
implements WriteableDiagram2D

This class is an abstraction of all diagram related information. We assume that the first node we get is the top node of the diagram. The order of all other nodes and the order of the lines does not matter. The coordinate system given can use y-coordinates either pointing upwards (the usual mathematical system) or downwards (the usual computer coordinates). The first call to getNode() or getBounds() will make sure that the coordinates will be pointing downwards when reading.


Field Summary
protected  org.tockit.events.EventBroker eventBroker
           
 
Fields inherited from interface net.sourceforge.toscanaj.model.diagram.Diagram2D
DESCRIPTION_ELEMENT_NAME, DIAGRAM_ELEMENT_NAME, EXTRA_CANVAS_ITEMS_ELEMENT_NAME, MINIMUM_STEEPNESS, TITLE_ATTRIBUTE_NAME
 
Constructor Summary
SimpleLineDiagram()
          The default constructor creates a diagram with just nothing in it at all.
SimpleLineDiagram(Diagram2D diagram)
          A copy constructor creating a duplicate of given diagram.
SimpleLineDiagram(org.jdom.Element element)
           
 
Method Summary
 void addExtraCanvasItem(org.tockit.canvas.CanvasItem item)
           
 void addLine(DiagramNode from, DiagramNode to)
          Adds a line to the diagram (at the end of the list).
 void addNode(DiagramNode node)
          Adds a node to the diagram (at the end of the list).
protected  void checkCoordinateSystem()
          Makes sure the y-coordinates increase in the downward direction.
protected  DiagramNode createNewDiagramNode(org.jdom.Element diagramNode)
           
 LabelInfo getAttributeLabel(int nodeNumber)
          Returns the information on the attribute label of the diagram.
 Concept getBottomConcept()
          Finds the bottom concept in the underlying lattice.
 java.awt.geom.Rectangle2D getBounds()
          Calculates a rectangle that includes all points.
 org.jdom.Element getDescription()
          Returns the XML Element describing the diagram (if available, null otherwise).
 org.tockit.events.EventBroker getEventBroker()
          Returns the event broker this diagram sends change events to.
 java.util.List getExtraCanvasItems()
           
 java.awt.geom.Point2D getFromPosition(int lineNumber)
          Returns the coordinates of a starting point of a line.
 DiagramLine getLine(int lineNumber)
          Implements Diagram2D.getLine(int).
 java.util.Iterator getLines()
           
 DiagramNode getNode(int nodeNumber)
          Returns a node in the diagram.
 DiagramNode getNode(java.lang.String identifier)
           
 DiagramNode getNodeForConcept(Concept concept)
          Finds the node representing the concept given.
 java.util.Iterator getNodes()
          Returns the list of all nodes in the diagram.
 int getNumberOfLines()
          Returns the number of lines in the diagram.
 int getNumberOfNodes()
          Returns the number of nodes in the diagram.
 LabelInfo getObjectLabel(int nodeNumber)
          Returns the information on the object label of the diagram.
 java.lang.String getTitle()
          Returns the title of the diagram.
 Concept getTopConcept()
          Finds the top concept in the underlying lattice.
 java.awt.geom.Point2D getToPosition(int lineNumber)
          Returns the coordinates of an end point of a line.
 boolean isHasseDiagram()
          Returns true if the diagram is layouted as Hasse diagram.
 void readXML(org.jdom.Element elem)
          Read this element as the content of elem.
static void registerExtraCanvasItemFactory(java.lang.String tagName, ExtraCanvasItemFactory factory)
           
 void removeExtraCanvasItems()
           
 void sendChangeEvent()
          Sends a notification about a change into the broker attached.
 void setDescription(org.jdom.Element desc)
          Gives the diagram a description.
 void setEventBroker(org.tockit.events.EventBroker eventBroker)
          Sets an event broker to send DiagramChangeEvents to.
 void setTitle(java.lang.String title)
          Change the title of the diagram.
 org.jdom.Element toXML()
          Write this element as the content of elem.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eventBroker

protected org.tockit.events.EventBroker eventBroker
Constructor Detail

SimpleLineDiagram

public SimpleLineDiagram()
The default constructor creates a diagram with just nothing in it at all.


SimpleLineDiagram

public SimpleLineDiagram(org.jdom.Element element)
                  throws XMLSyntaxError

SimpleLineDiagram

public SimpleLineDiagram(Diagram2D diagram)
A copy constructor creating a duplicate of given diagram. Makes a reasonably deep copy. Does not handle subclasses and at least NDimDiagram/NDimDiagramNode are not yet supported.

To do:
add support for copying n-dim diagrams. Assumptions: Assuming that ConceptImplementation is used for Concept interface and that the objects and attributes are FCAObject(s) and Attribute(s). When making a copy of the diagram node, copying all properties, except: - identifiers. Assumption is that if we are copying diagrams and identifiers are unique within each diagram - it should be ok to keep the same identifiers for nodes in a copied diagram.
Method Detail

toXML

public org.jdom.Element toXML()
Description copied from interface: XMLizable
Write this element as the content of elem.

Specified by:
toXML in interface XMLizable

readXML

public void readXML(org.jdom.Element elem)
             throws XMLSyntaxError
Description copied from interface: XMLizable
Read this element as the content of elem.

Specified by:
readXML in interface XMLizable
Throws:
XMLSyntaxError

createNewDiagramNode

protected DiagramNode createNewDiagramNode(org.jdom.Element diagramNode)
                                    throws XMLSyntaxError
Throws:
XMLSyntaxError

getTitle

public java.lang.String getTitle()
Returns the title of the diagram.

Specified by:
getTitle in interface Diagram2D

setTitle

public void setTitle(java.lang.String title)
Change the title of the diagram.

Specified by:
setTitle in interface WriteableDiagram2D

getNumberOfNodes

public int getNumberOfNodes()
Returns the number of nodes in the diagram.

Specified by:
getNumberOfNodes in interface Diagram2D

getNodes

public java.util.Iterator getNodes()
Description copied from interface: Diagram2D
Returns the list of all nodes in the diagram.

Specified by:
getNodes in interface Diagram2D

getLines

public java.util.Iterator getLines()
Specified by:
getLines in interface Diagram2D

getNumberOfLines

public int getNumberOfLines()
Returns the number of lines in the diagram.

Specified by:
getNumberOfLines in interface Diagram2D

getBounds

public java.awt.geom.Rectangle2D getBounds()
Calculates a rectangle that includes all points.

Specified by:
getBounds in interface Diagram2D

getNode

public DiagramNode getNode(int nodeNumber)
Returns a node in the diagram. Numbers start with zero.

Specified by:
getNode in interface Diagram2D

getNode

public DiagramNode getNode(java.lang.String identifier)
Specified by:
getNode in interface Diagram2D

getNodeForConcept

public DiagramNode getNodeForConcept(Concept concept)
Description copied from interface: Diagram2D
Finds the node representing the concept given. Returns null if no such node exists in this diagram.

Specified by:
getNodeForConcept in interface Diagram2D

getLine

public DiagramLine getLine(int lineNumber)
Implements Diagram2D.getLine(int).

Specified by:
getLine in interface Diagram2D

addNode

public void addNode(DiagramNode node)
Adds a node to the diagram (at the end of the list). The top node of a diagram always has to be added first.

Specified by:
addNode in interface WriteableDiagram2D

getFromPosition

public java.awt.geom.Point2D getFromPosition(int lineNumber)
Returns the coordinates of a starting point of a line. Numbers start with zero.

Specified by:
getFromPosition in interface Diagram2D

getToPosition

public java.awt.geom.Point2D getToPosition(int lineNumber)
Returns the coordinates of an end point of a line. Numbers start with zero.

Specified by:
getToPosition in interface Diagram2D

addLine

public void addLine(DiagramNode from,
                    DiagramNode to)
Adds a line to the diagram (at the end of the list).

Specified by:
addLine in interface WriteableDiagram2D

getObjectLabel

public LabelInfo getObjectLabel(int nodeNumber)
Returns the information on the object label of the diagram.

Specified by:
getObjectLabel in interface Diagram2D

getAttributeLabel

public LabelInfo getAttributeLabel(int nodeNumber)
Returns the information on the attribute label of the diagram.

Specified by:
getAttributeLabel in interface Diagram2D

checkCoordinateSystem

protected void checkCoordinateSystem()
Makes sure the y-coordinates increase in the downward direction.


setDescription

public void setDescription(org.jdom.Element desc)
Description copied from interface: WriteableDiagram2D
Gives the diagram a description.

Specified by:
setDescription in interface WriteableDiagram2D
To do:
in ConceptualSchema.setDescription(Element) we clone the parameter, here we don't --> check why

sendChangeEvent

public void sendChangeEvent()
Description copied from interface: WriteableDiagram2D
Sends a notification about a change into the broker attached. This is a null-operation if the broker is not set.

Specified by:
sendChangeEvent in interface WriteableDiagram2D

getDescription

public org.jdom.Element getDescription()
Description copied from interface: Diagram2D
Returns the XML Element describing the diagram (if available, null otherwise).

Specified by:
getDescription in interface Diagram2D

isHasseDiagram

public boolean isHasseDiagram()
Description copied from interface: Diagram2D
Returns true if the diagram is layouted as Hasse diagram. This means every line is pointing downwards or in other terms: every node is located above all nodes that represent a concept lesser than its concept.

Specified by:
isHasseDiagram in interface Diagram2D

setEventBroker

public void setEventBroker(org.tockit.events.EventBroker eventBroker)
Description copied from interface: WriteableDiagram2D
Sets an event broker to send DiagramChangeEvents to.

Specified by:
setEventBroker in interface WriteableDiagram2D

getTopConcept

public Concept getTopConcept()
Description copied from interface: Diagram2D
Finds the top concept in the underlying lattice.

Specified by:
getTopConcept in interface Diagram2D
To do:
check if we have a lattice

getBottomConcept

public Concept getBottomConcept()
Description copied from interface: Diagram2D
Finds the bottom concept in the underlying lattice.

Specified by:
getBottomConcept in interface Diagram2D
To do:
check if we have a lattice

registerExtraCanvasItemFactory

public static void registerExtraCanvasItemFactory(java.lang.String tagName,
                                                  ExtraCanvasItemFactory factory)

addExtraCanvasItem

public void addExtraCanvasItem(org.tockit.canvas.CanvasItem item)

removeExtraCanvasItems

public void removeExtraCanvasItems()

getExtraCanvasItems

public java.util.List getExtraCanvasItems()

getEventBroker

public org.tockit.events.EventBroker getEventBroker()
Description copied from interface: Diagram2D
Returns the event broker this diagram sends change events to.

Specified by:
getEventBroker in interface Diagram2D
Returns:
The target event broker for the diagram or null if none is available.


The ToscanaJ project