fdda.graphics.java2d
Class Line

java.lang.Object
  |
  +--fdda.graphics.java2d.Component
        |
        +--fdda.graphics.java2d.Container
              |
              +--fdda.graphics.java2d.Line
All Implemented Interfaces:
Cloneable, Component, Container, Line, PropertyHolder, WorkingPart

public class Line
extends Container
implements Line

A line between two nodes. The line consists of one or more segments, leading from the start node through one ore more intermediate points to the end node. Implemented is the line as a container in which both the segments and the points (which are components) are stored. Since the points must be drawn after the segments (to be above them), the storage order is LineSegment (LineSegment Point)*; i.e. a point is always directly after the two segments it connects. The coordinates of a line are the coordinates of its start point

Author:
Jörg Rüdenauer

Field Summary
static double NORM_DIST_PER_CYCLE
          norm value for the speed of messages
 
Fields inherited from class fdda.graphics.java2d.Container
elements
 
Fields inherited from class fdda.graphics.java2d.Component
COLOR_NORMAL, COLOR_SELECTED, dirtyShape, selected, shape, x, y
 
Fields inherited from interface fdda.graphics.Component
SEL_ALL, SEL_EQUALS, SEL_MOVABLES, SEL_NOTHING
 
Constructor Summary
Line(double startX, double startY, double endX, double endY)
          Constructor.
 
Method Summary
 Point addPoint(double x, double y)
          Adds a point to the line.
 void addProperty(Property property)
          Adds a property to the holder.
 void addPropertyListener(PropertyListener pl)
          Adds a PropertyListener (Observer pattern).
 void calcShape()
          Recalculates the shape.
 void changeProperty(Property property)
          Changes a property of the holder - i.e., replaces the property with the name of the parameter property with the parameter.
 Object clone()
          Clones the component
 void deselect()
          Deselects only the line segments
 void draw(Graphics2D graphContext)
          Draws all elements in the container.
 void firePropertyChanged(Property property)
          Informs the listeners that a property has been changed.
 Color getColor()
          Returns the color of the line.
 Connection getConnection()
          Returns the connection that is symbolized by this line.
 double getEndX()
          Returns the x coordinate of the end point of the line
 double getEndY()
          Returns the y coordinate of the end point of the line
 double getLength()
          Returns the length of the line
 double getMessageDistancePerCycle()
          Returns how far a message moves in one cycle.
 double getMessageEndX()
          Returns the x coordinate of the end point for messages
 double getMessageEndY()
          Returns the y coordinate of the end point for messages
 double getMessageStartX()
          Returns the x coordinate of start end point for messages
 double getMessageStartY()
          Returns the y coordinate of the start point for messages
 Iterator getProperties()
          Returns an Iterator over the properties of the holder.
 Property getProperty(String name)
          Returns a property of the holder.
 double getX()
          Overwritten again since the container class changes default implementation.
 double getY()
          Overwritten again since the container class changes default implementation.
 boolean isDirected()
          Returns whether the line is directed.
 boolean isFlatteningAllowed()
          Returns false.
 boolean isMovable()
          Returns false.
 boolean isWorking()
          Returns whether the component is working.
 void move(double x, double y)
          Moves all line segments and all points.
 void moveEndPoint(double x, double y)
          Moves the end point of the line
 void moveMessage(Message message)
          Moves a message on the line.
 void moveStartPoint(double x, double y)
          Moves the start point of the line.
 void pointMoved(Point point)
          Informs the line that a point has been moved.
 void removePoint(Point point)
          Removes a point from the line.
 void removeProperty(Property property)
          Removes a property from the holder.
 void removePropertyListener(PropertyListener listener)
          Removes a PropertyListener (Observer pattern).
 void select()
          Selects only the line segements
 int selectableWith()
          Returns SEL_EQUALS
 void setColor(Color color)
          Sets the color of the line.
 void setConnection(Connection connection)
          Sets the connection that is symbolized by this line.
 void setDirected(boolean directed)
          Sets whether the line is directed.
 void setEndXY(double x, double y)
          Sets the end point of the line
 void setWorking(boolean working)
          Sets whether the component is working.
 void setXY(double x, double y)
          Sets the coordinates of the component (or of its most prominent point).
 
Methods inherited from class fdda.graphics.java2d.Container
addElement, clear, flatten, getIterator, getSize, hasElement, removeElement, setGraphicalSystem, visit
 
Methods inherited from class fdda.graphics.java2d.Component
getGraphicalSystem, getShape, isSelected, recalculateShape, setGraphicalSystem
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fdda.graphics.Component
getGraphicalSystem, getShape, isSelected, recalculateShape, setGraphicalSystem, visit
 

Field Detail

NORM_DIST_PER_CYCLE

public static final double NORM_DIST_PER_CYCLE
norm value for the speed of messages

See Also:
Constant Field Values
Constructor Detail

Line

public Line(double startX,
            double startY,
            double endX,
            double endY)
Constructor. Line isn't directed.

Parameters:
startX - x coordinate of start point
startY - y coordinate of start point
endX - x coordinate of end point
endY - y coordinate of end point
Method Detail

getX

public double getX()
Overwritten again since the container class changes default implementation.

Specified by:
getX in interface Component
Overrides:
getX in class Container
Returns:
the x coordinate
See Also:
Component.getX()

getY

public double getY()
Overwritten again since the container class changes default implementation.

Specified by:
getY in interface Component
Overrides:
getY in class Container
Returns:
the y coordinate
See Also:
Component.getY()

getLength

public double getLength()
Description copied from interface: Line
Returns the length of the line

Specified by:
getLength in interface Line
Returns:
the length of the line

getEndX

public double getEndX()
Description copied from interface: Line
Returns the x coordinate of the end point of the line

Specified by:
getEndX in interface Line
Returns:
the x coordinate of the end point of the line

getEndY

public double getEndY()
Description copied from interface: Line
Returns the y coordinate of the end point of the line

Specified by:
getEndY in interface Line
Returns:
the y coordinate of the end point of the line

setConnection

public void setConnection(Connection connection)
Description copied from interface: Line
Sets the connection that is symbolized by this line.

Specified by:
setConnection in interface Line
Parameters:
connection - the connection

getConnection

public Connection getConnection()
Description copied from interface: Line
Returns the connection that is symbolized by this line.

Specified by:
getConnection in interface Line
Returns:
the connection

setWorking

public void setWorking(boolean working)
Description copied from interface: WorkingPart
Sets whether the component is working.

Specified by:
setWorking in interface WorkingPart
Parameters:
working - whether the component is working

isWorking

public boolean isWorking()
Description copied from interface: WorkingPart
Returns whether the component is working.

Specified by:
isWorking in interface WorkingPart
Returns:
whether the component is working

addPoint

public Point addPoint(double x,
                      double y)
Adds a point to the line. The segment nearest to the new point coordinates is split.

Parameters:
x - the x coordinate of the new point
y - the y coordinate of the new point
Returns:
the newly created point

removePoint

public void removePoint(Point point)
Removes a point from the line. The adjacent segments are merged.

Parameters:
point - the point

select

public void select()
Selects only the line segements

Specified by:
select in interface Component
Overrides:
select in class Container
See Also:
Component.select()

deselect

public void deselect()
Deselects only the line segments

Specified by:
deselect in interface Component
Overrides:
deselect in class Container
See Also:
Component.deselect()

setColor

public void setColor(Color color)
Description copied from interface: Line
Sets the color of the line. May be ignored by the implementation.

Specified by:
setColor in interface Line
Parameters:
color - the color

getColor

public Color getColor()
Description copied from interface: Line
Returns the color of the line.

Specified by:
getColor in interface Line
Returns:
the color of the line

move

public void move(double x,
                 double y)
Moves all line segments and all points. The start and end point have to be moved separately.

Specified by:
move in interface Component
Overrides:
move in class Container
Parameters:
x - offset for move in x direction
y - offset for move in y direction
See Also:
Component.move(double, double)

moveStartPoint

public void moveStartPoint(double x,
                           double y)
Description copied from interface: Line
Moves the start point of the line.

Specified by:
moveStartPoint in interface Line
Parameters:
x - the x offset
y - the y offset

moveEndPoint

public void moveEndPoint(double x,
                         double y)
Description copied from interface: Line
Moves the end point of the line

Specified by:
moveEndPoint in interface Line
Parameters:
x - the x offset
y - the y offset

pointMoved

public void pointMoved(Point point)
Informs the line that a point has been moved. Adjusts the corresponding segments

Parameters:
point - the point

setDirected

public void setDirected(boolean directed)
Description copied from interface: Line
Sets whether the line is directed.

Specified by:
setDirected in interface Line
Parameters:
directed - whether the line is directed

isDirected

public boolean isDirected()
Description copied from interface: Line
Returns whether the line is directed. A directed line corresponds to a connection which can transfer messages only in one direction.

Specified by:
isDirected in interface Line
Returns:
whether the line is directed

clone

public Object clone()
Description copied from interface: Component
Clones the component

Specified by:
clone in interface Component
Overrides:
clone in class Container
Returns:
the clone

draw

public void draw(Graphics2D graphContext)
Description copied from class: Container
Draws all elements in the container. They are drawn in the order of their appearance in the container.

Overrides:
draw in class Container
See Also:
Component.draw(java.awt.Graphics2D)

setEndXY

public void setEndXY(double x,
                     double y)
Description copied from interface: Line
Sets the end point of the line

Specified by:
setEndXY in interface Line
Parameters:
x - the x coordinate
y - the y coordinate

setXY

public void setXY(double x,
                  double y)
Description copied from interface: Component
Sets the coordinates of the component (or of its most prominent point).

Specified by:
setXY in interface Component
Overrides:
setXY in class Component
Parameters:
x - the x coordinate
y - the y coordinate

isFlatteningAllowed

public boolean isFlatteningAllowed()
Returns false.

Specified by:
isFlatteningAllowed in interface Container
Overrides:
isFlatteningAllowed in class Container
See Also:
Container.isFlatteningAllowed()

selectableWith

public int selectableWith()
Returns SEL_EQUALS

Specified by:
selectableWith in interface Component
Overrides:
selectableWith in class Container
Returns:
constant indicating the selection class
See Also:
Component.selectableWith()

isMovable

public boolean isMovable()
Returns false.

Specified by:
isMovable in interface Component
Overrides:
isMovable in class Container
Returns:
true, iff the user can move the component
See Also:
Component.isMovable()

calcShape

public void calcShape()
Description copied from class: Component
Recalculates the shape. Is called by getShape if the flag dirtyShape is set. Must unset the flag after calculation.

Overrides:
calcShape in class Container

getMessageStartX

public double getMessageStartX()
Returns the x coordinate of start end point for messages

Returns:
the x coordinate of start end point for messages

getMessageEndX

public double getMessageEndX()
Returns the x coordinate of the end point for messages

Returns:
the x coordinate of the end point for messages

getMessageStartY

public double getMessageStartY()
Returns the y coordinate of the start point for messages

Returns:
the y coordinate of the start point for messages

getMessageEndY

public double getMessageEndY()
Returns the y coordinate of the end point for messages

Returns:
the y coordinate of the end point for messages

getMessageDistancePerCycle

public double getMessageDistancePerCycle()
Returns how far a message moves in one cycle.

Specified by:
getMessageDistancePerCycle in interface Line
Returns:
the distance a message moves in one cycle

moveMessage

public void moveMessage(Message message)
Moves a message on the line. How far it is moved is determined by the general speed of messages and the special line speed.

Parameters:
message - the message

addProperty

public void addProperty(Property property)
Description copied from interface: PropertyHolder
Adds a property to the holder. If a property with the same name already exists, it is removed.

Specified by:
addProperty in interface PropertyHolder

removeProperty

public void removeProperty(Property property)
Description copied from interface: PropertyHolder
Removes a property from the holder. The key for removal is the name of the property; if no property with that name exists, nothing happens.

Specified by:
removeProperty in interface PropertyHolder
Parameters:
property - the property to be removed, must not be null

changeProperty

public void changeProperty(Property property)
Description copied from interface: PropertyHolder
Changes a property of the holder - i.e., replaces the property with the name of the parameter property with the parameter. If no such property exists, the property is simply added to the holder; in this case, a propertyAdded event instead of a propertyChanged event is fired.

Specified by:
changeProperty in interface PropertyHolder
Parameters:
property - the new property, must not be null

getProperty

public Property getProperty(String name)
Description copied from interface: PropertyHolder
Returns a property of the holder. If no property with the specified name exists, null is returned.

Specified by:
getProperty in interface PropertyHolder
Parameters:
name - the name of the property
Returns:
the property

getProperties

public Iterator getProperties()
Description copied from interface: PropertyHolder
Returns an Iterator over the properties of the holder.

Specified by:
getProperties in interface PropertyHolder
Returns:
an Iterator over the properties

addPropertyListener

public void addPropertyListener(PropertyListener pl)
Description copied from interface: PropertyHolder
Adds a PropertyListener (Observer pattern).

Specified by:
addPropertyListener in interface PropertyHolder
Parameters:
pl - the listener to be added
See Also:
EventListenerList

removePropertyListener

public void removePropertyListener(PropertyListener listener)
Description copied from interface: PropertyHolder
Removes a PropertyListener (Observer pattern).

Specified by:
removePropertyListener in interface PropertyHolder
Parameters:
listener - the listener to be removed
See Also:
EventListenerList

firePropertyChanged

public void firePropertyChanged(Property property)
Description copied from interface: PropertyHolder
Informs the listeners that a property has been changed. Note that the property holder can't determine by himself whether a property is changed internally; therefore, the property must inform its holder of any changes. This method must only be called by implementing classes of either PropertyHolder or Property.

Specified by:
firePropertyChanged in interface PropertyHolder
Parameters:
property - the property that was changed.


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