fdda.graphics.java2d
Class GraphicalSystem

java.lang.Object
  |
  +--fdda.graphics.java2d.GraphicalSystem
All Implemented Interfaces:
GraphicalSystem

public class GraphicalSystem
extends Object
implements GraphicalSystem

Represents a graphical system - that means mostly nodes and lines. These are stored both in a TreeSet (so the order of their adding is retained) and a HashMap (wrapped in a special class), which allows a fast search. Messages are just stored in a LinkedList, since they must mostly only be run through to move and draw them.

Author:
Jörg Rüdenauer

Nested Class Summary
(package private) static class GraphicalSystem.ComponentWrapper
          Wraps a component: adds an attribute ID, enables comparing of the components so the TreeSet can be used to store them.
(package private) static class GraphicalSystem.WrapperComparator
          Compares two ComponentWrappers by using their IDs.
 
Field Summary
protected  boolean changed
          was the system changed since the last save operation?
protected  Comparator comparator
          Comparator to compare two wrapped components
protected  int lineID
          ID for the next line
protected  HashMap lineMap
          map for fast finding of lines
protected  TreeSet lines
          The lines.
protected  LinkedList messages
          the messages
protected  int nodeID
          ID for the the next node
protected  HashMap nodeMap
          map for fast finding of nodes
protected  TreeSet nodes
          The nodes.
 
Constructor Summary
GraphicalSystem()
          Constructor
 
Method Summary
 void addLine(Line line)
          Adds a line to the system.
 void addMessage(Message message)
          Adds a message to the system
 void addNode(Node node)
          Adds a node to the system.
 void clear()
          Removes all nodes and all lines from the system.
 void clearMessages()
          Removes all messages from the system
 void draw(Graphics2D graphContext)
          Draws the system - first the lines (and their points), than the nodes, finally the messages.
 Collection getAllMessages()
          Returns all messages in the system.
 Component getElementAt(double x, double y)
          Returns the 'topmost' component at a certain point.
 Rectangle2D getEnclosingRectangle()
          Returns a rectangle that just encloses all components in the system.
 GraphicHolder getGraphicHolder()
          Returns the graphic holder for the system
 Component getMovableComponents()
          Returns all movable components in the graphical system.
 Component getMovableComponentsInArea(Area area)
          Returns all movable components that lie in the specified area.
 Project getProject()
          Returns the project which includes this graphical system.
 void recalculateShapes()
          Recalculates the shapes of all components in the system.
 void removeLine(Line line)
          Removes a line from the system.
 void removeMessage(Message message)
          Removes a message from the system
 void removeNode(Node node)
          Removes a node from the system.
 void setChanged(boolean changed)
          Sets whether the system was changed since the last save operation.
 void setGraphicHolder(GraphicHolder holder)
          sets the graphic holder for the system
 void setProject(Project project)
          Sets the project which includes this graphical system.
 boolean wasChanged()
          Returns whether the graphical system was changed since the last save operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodes

protected TreeSet nodes
The nodes. Each node is wrapped in a ComponentWrapper.


lines

protected TreeSet lines
The lines. Each line is wrapped in a ComponentWrapper.


nodeMap

protected HashMap nodeMap
map for fast finding of nodes


lineMap

protected HashMap lineMap
map for fast finding of lines


messages

protected LinkedList messages
the messages


changed

protected boolean changed
was the system changed since the last save operation?


nodeID

protected int nodeID
ID for the the next node


lineID

protected int lineID
ID for the next line


comparator

protected Comparator comparator
Comparator to compare two wrapped components

Constructor Detail

GraphicalSystem

public GraphicalSystem()
Constructor

Method Detail

setProject

public void setProject(Project project)
Description copied from interface: GraphicalSystem
Sets the project which includes this graphical system.

Specified by:
setProject in interface GraphicalSystem
Parameters:
project - the project

getProject

public Project getProject()
Description copied from interface: GraphicalSystem
Returns the project which includes this graphical system.

Specified by:
getProject in interface GraphicalSystem
Returns:
the project

addNode

public void addNode(Node node)
Description copied from interface: GraphicalSystem
Adds a node to the system. No checks for doubles are performed.

Specified by:
addNode in interface GraphicalSystem
Parameters:
node - the node

addLine

public void addLine(Line line)
Description copied from interface: GraphicalSystem
Adds a line to the system. No checks for doubles are performed.

Specified by:
addLine in interface GraphicalSystem
Parameters:
line - the line

removeNode

public void removeNode(Node node)
Description copied from interface: GraphicalSystem
Removes a node from the system. If the node doesn't exist, nothing happens.

Specified by:
removeNode in interface GraphicalSystem
Parameters:
node - the node

removeLine

public void removeLine(Line line)
Description copied from interface: GraphicalSystem
Removes a line from the system. If the line doesn't exist, nothing happens.

Specified by:
removeLine in interface GraphicalSystem
Parameters:
line - the line

getElementAt

public Component getElementAt(double x,
                              double y)
Description copied from interface: GraphicalSystem
Returns the 'topmost' component at a certain point. Lines are always 'higher' than nodes; otherwise components are higher if they were added later.

Specified by:
getElementAt in interface GraphicalSystem
Parameters:
x - the x coordinate of the point
y - the y coordinate of the point
Returns:
the topmost component at the point - or null, if no component is currently at that point

getMovableComponentsInArea

public Component getMovableComponentsInArea(Area area)
Description copied from interface: GraphicalSystem
Returns all movable components that lie in the specified area. They need not lie completely inside, only touching is enough.

Specified by:
getMovableComponentsInArea in interface GraphicalSystem
Parameters:
area - the area
Returns:
all movable components in the area

draw

public void draw(Graphics2D graphContext)
Draws the system - first the lines (and their points), than the nodes, finally the messages.

Parameters:
graphContext - the graphics

getEnclosingRectangle

public Rectangle2D getEnclosingRectangle()
Description copied from interface: GraphicalSystem
Returns a rectangle that just encloses all components in the system.

Specified by:
getEnclosingRectangle in interface GraphicalSystem
Returns:
an enclosing rectangle

getGraphicHolder

public GraphicHolder getGraphicHolder()
Returns the graphic holder for the system

Returns:
the graphic holder

setGraphicHolder

public void setGraphicHolder(GraphicHolder holder)
sets the graphic holder for the system

Parameters:
holder - the graphic holder

recalculateShapes

public void recalculateShapes()
Description copied from interface: GraphicalSystem
Recalculates the shapes of all components in the system.

Specified by:
recalculateShapes in interface GraphicalSystem

clear

public void clear()
Description copied from interface: GraphicalSystem
Removes all nodes and all lines from the system.

Specified by:
clear in interface GraphicalSystem

getMovableComponents

public Component getMovableComponents()
Description copied from interface: GraphicalSystem
Returns all movable components in the graphical system.

Specified by:
getMovableComponents in interface GraphicalSystem
Returns:
all movable components

wasChanged

public boolean wasChanged()
Description copied from interface: GraphicalSystem
Returns whether the graphical system was changed since the last save operation.

Specified by:
wasChanged in interface GraphicalSystem
Returns:
whether the system was changed

setChanged

public void setChanged(boolean changed)
Description copied from interface: GraphicalSystem
Sets whether the system was changed since the last save operation.

Specified by:
setChanged in interface GraphicalSystem
Parameters:
changed - whether the system was changed

addMessage

public void addMessage(Message message)
Description copied from interface: GraphicalSystem
Adds a message to the system

Specified by:
addMessage in interface GraphicalSystem
Parameters:
message - the message

removeMessage

public void removeMessage(Message message)
Description copied from interface: GraphicalSystem
Removes a message from the system

Specified by:
removeMessage in interface GraphicalSystem
Parameters:
message - the message

clearMessages

public void clearMessages()
Description copied from interface: GraphicalSystem
Removes all messages from the system

Specified by:
clearMessages in interface GraphicalSystem

getAllMessages

public Collection getAllMessages()
Description copied from interface: GraphicalSystem
Returns all messages in the system. The returned Collection is not modifiable (read only).

Specified by:
getAllMessages in interface GraphicalSystem
Returns:
all messsages in the system


API documentation for FDDA version 0.9. Generated on 17/02/2004 14:12.