org.jscience.architecture.traffic.infrastructure
Class Road

java.lang.Object
  extended by org.jscience.architecture.traffic.infrastructure.Road
All Implemented Interfaces:
Selectable, SelectionStarter, TwoStageLoader, XMLSerializable

public class Road
extends java.lang.Object
implements Selectable, XMLSerializable, TwoStageLoader

Basic Road.


Field Summary
protected  Drivelane[] alphaLanes
          Lanes where Roadusers move towards alphaNode.
protected  Node alphaNode
          Alpha Node of this Road.
protected  Drivelane[] betaLanes
          Lanes where Roadusers move towards betaNode.
protected  Node betaNode
          Beta Node of this Road.
protected  int length
          Length of this Road in blocks.
protected  org.jscience.architecture.traffic.infrastructure.Road.TwoStageLoaderData loadData
          Container object to 1tranfer information from the first stage loader to the second stage loader.
protected  java.lang.String parentName
          DOCUMENT ME!
protected  int roadId
          Id of this Road.
protected  Turn[] turns
          Turns in the Road.
 
Constructor Summary
Road()
          Empty constructor for loading
Road(Node _alpha, Node _beta, int _length)
          Constructs a new Road
 
Method Summary
 void addAlphaLane(Drivelane l)
          Adds a Drivelane leading to the alpha node
 void addBetaLane(Drivelane l)
          Adds a Drivelane leading to the beta node
 void addLane(Drivelane lane, Node to)
          Adds a Drivelane to this road
 void addTurn(Turn t)
          Adds a Turn to this road
 Drivelane[] getAllLanes()
          Returns an array of Drivelanes which are part of this road
 Drivelane[] getAlphaLanes()
          Returns the Drivelanes where Roadusers move towards the alphaNode
 Node getAlphaNode()
          Returns the alpha Node of this road
 Drivelane[] getBetaLanes()
          Returns the Drivelanes where Roadusers move towards the betaNode
 Node getBetaNode()
          Returns the beta Node of this road
 java.awt.Rectangle getBounds()
          Returns the bounding box of this Selectable
 java.awt.Point getCenterPoint()
          DOCUMENT ME!
 java.util.Enumeration getChildren()
          DOCUMENT ME!
 java.awt.Shape getComplexBounds()
          DOCUMENT ME!
 int getDistance(java.awt.Point p)
          DOCUMENT ME!
protected  int[] getDrivelaneIdList(Drivelane[] list)
          DOCUMENT ME!
 int getId()
          Returns the Id of this Road
 Drivelane[] getInboundLanes(Node n)
          Returns an array of Drivelanes which are inbound on the node given.
 int getLength()
          Returns the length of this Road in blocks
 java.lang.String getName()
          Returns the name of this road.
 int getNumAllLanes()
          Returns the number of total Drivelanes in this road
 int getNumAlphaLanes()
          DOCUMENT ME!
 int getNumBetaLanes()
          DOCUMENT ME!
 int getNumInboundLanes(Node n)
          Returns the number of Drivelanes that are inbound on the given node
 int getNumOutboundLanes(Node n)
          Returns the number of Drivelanes that are outbound from the given node
 Node getOtherNode(Node seenfrom)
          Returns the other node this road is connected to, seen from the given node
 Drivelane[] getOutboundLanes(Node n)
          Returns an array of Drivelanes which are outbound from the given node.
 java.awt.Point getSelectionPoint()
          DOCUMENT ME!
 java.awt.Point[] getSelectionPoints()
          DOCUMENT ME!
 Turn[] getTurns()
          Returns the Turns that this Road makes in the representation
 int getWidth()
          Returns the width of this road in number of lanes
 java.lang.String getXMLName()
          DOCUMENT ME!
 boolean hasChildren()
          DOCUMENT ME!
 boolean isSelectable()
          DOCUMENT ME!
 void load(XMLElement myElement, XMLLoader loader)
          Load this XMLSerializable
 void loadSecondStage(java.util.Dictionary dictionaries)
          DOCUMENT ME!
 void paint(java.awt.Graphics g)
          DOCUMENT ME!
 void paint(java.awt.Graphics g, int x, int y, float zf)
          Draws this Road, with all it's DriveLanes and Roadusers onto a Graphics object, mostly a View
 void paint(java.awt.Graphics g, int x, int y, float zf, double bogus)
          Paint this road with it's roadusers
 void paintDrivelaneAttributes(java.awt.Graphics g, java.awt.Point p, double a, Drivelane d)
          DOCUMENT ME!
 java.awt.Shape paintDrivelaneSegment(java.awt.Graphics g, java.awt.Point p1_1, java.awt.Point p1_2, java.awt.Point p2_1, java.awt.Point p2_2, double a1, double a2, Drivelane dl)
          Paints an arbitrary segment of a drivelane and returns the outlines of this segment as a Shape
 void paintRoaduser(java.awt.Graphics g, Roaduser r, java.awt.Point p1, java.awt.Point p2, double a1, double a2, int pos)
          Draws a Roaduser on a (segment of a) Drivelane
 void paintRoaduserOnNode(java.awt.Graphics g, Roaduser ru, Node node, java.awt.Point p, int pos, Drivelane d)
          Draws a Roaduser on a Node
 void remAlphaLane(Drivelane l)
          Removes a Drivelane leading to the alpha node
 void remBetaLane(Drivelane l)
          Removes a Drivelane leading to the beta node
 void remLane(Drivelane lane)
          Removes a Drivelane from this road
 void remTurn(Turn t)
          Removes a Turn from this road
 void reset()
          Resets the road.
 void saveChilds(XMLSaver saver)
          DOCUMENT ME!
 XMLElement saveSelf()
          DOCUMENT ME!
 void setAlphaLanes(Drivelane[] l)
          Sets the Drivelanes where Roadusers move towards the alphaNode
 void setAlphaNode(Node n)
          Sets the alpha Node of this road
 void setBetaLanes(Drivelane[] l)
          Sets the Drivelanes where Roadusers move towards the betaNode
 void setBetaNode(Node n)
          Sets the beta Node of this road
 void setId(int id)
          Sets the Id of this Road
 void setLength(int l)
          Sets the length of this Road in blocks
 void setParentName(java.lang.String parentName)
          DOCUMENT ME!
 void setTurns(Turn[] t)
          Sets the Turns that this Road makes in the representation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

roadId

protected int roadId
Id of this Road.


length

protected int length
Length of this Road in blocks.


alphaNode

protected Node alphaNode
Alpha Node of this Road.


betaNode

protected Node betaNode
Beta Node of this Road.


alphaLanes

protected Drivelane[] alphaLanes
Lanes where Roadusers move towards alphaNode.


betaLanes

protected Drivelane[] betaLanes
Lanes where Roadusers move towards betaNode.


turns

protected Turn[] turns
Turns in the Road.


loadData

protected org.jscience.architecture.traffic.infrastructure.Road.TwoStageLoaderData loadData
Container object to 1tranfer information from the first stage loader to the second stage loader.


parentName

protected java.lang.String parentName
DOCUMENT ME!

Constructor Detail

Road

public Road(Node _alpha,
            Node _beta,
            int _length)
Constructs a new Road

Parameters:
_alpha - The alpha node of this road
_beta - The beta node of this road
_length - The length of this road

Road

public Road()
Empty constructor for loading

Method Detail

load

public void load(XMLElement myElement,
                 XMLLoader loader)
          throws XMLTreeException,
                 java.io.IOException,
                 XMLInvalidInputException
Description copied from interface: XMLSerializable
Load this XMLSerializable

Specified by:
load in interface XMLSerializable
Parameters:
myElement - The XMLElement which represents this object in the XML tree. It can contain attributes which hold information about the object.
loader - The XMLLoader which this XMLSerializable can use to load child objects.
Throws:
XMLTreeException - The parser can throw this exception if it is called by the XMLSerializable. The XMLSerializable should NOT throw this exception by itself and preferrably not catch it too.
java.io.IOException - Thrown in case of an read error in the XML file.
XMLInvalidInputException - The XMLSerializable can throw this exception if it cannot load itself or one of its child objects for whatever reason.

saveSelf

public XMLElement saveSelf()
                    throws XMLCannotSaveException
DOCUMENT ME!

Specified by:
saveSelf in interface XMLSerializable
Returns:
DOCUMENT ME!
Throws:
XMLCannotSaveException - DOCUMENT ME!

saveChilds

public void saveChilds(XMLSaver saver)
                throws XMLTreeException,
                       java.io.IOException,
                       XMLCannotSaveException
DOCUMENT ME!

Specified by:
saveChilds in interface XMLSerializable
Parameters:
saver - DOCUMENT ME!
Throws:
XMLTreeException - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!
XMLCannotSaveException - DOCUMENT ME!

getXMLName

public java.lang.String getXMLName()
DOCUMENT ME!

Specified by:
getXMLName in interface XMLSerializable
Returns:
DOCUMENT ME!

setParentName

public void setParentName(java.lang.String parentName)
DOCUMENT ME!

Specified by:
setParentName in interface XMLSerializable
Parameters:
parentName - DOCUMENT ME!

getDrivelaneIdList

protected int[] getDrivelaneIdList(Drivelane[] list)
DOCUMENT ME!

Parameters:
list - DOCUMENT ME!
Returns:
DOCUMENT ME!

loadSecondStage

public void loadSecondStage(java.util.Dictionary dictionaries)
                     throws XMLInvalidInputException,
                            XMLTreeException
DOCUMENT ME!

Specified by:
loadSecondStage in interface TwoStageLoader
Parameters:
dictionaries - DOCUMENT ME!
Throws:
XMLInvalidInputException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!

getId

public int getId()
Returns the Id of this Road

Returns:
DOCUMENT ME!

setId

public void setId(int id)
Sets the Id of this Road

Parameters:
id - DOCUMENT ME!

getAlphaNode

public Node getAlphaNode()
Returns the alpha Node of this road

Returns:
DOCUMENT ME!

setAlphaNode

public void setAlphaNode(Node n)
Sets the alpha Node of this road

Parameters:
n - DOCUMENT ME!

getBetaNode

public Node getBetaNode()
Returns the beta Node of this road

Returns:
DOCUMENT ME!

setBetaNode

public void setBetaNode(Node n)
Sets the beta Node of this road

Parameters:
n - DOCUMENT ME!

getLength

public int getLength()
Returns the length of this Road in blocks

Returns:
DOCUMENT ME!

setLength

public void setLength(int l)
Sets the length of this Road in blocks

Parameters:
l - DOCUMENT ME!

getTurns

public Turn[] getTurns()
Returns the Turns that this Road makes in the representation

Returns:
DOCUMENT ME!

setTurns

public void setTurns(Turn[] t)
Sets the Turns that this Road makes in the representation

Parameters:
t - DOCUMENT ME!

getAlphaLanes

public Drivelane[] getAlphaLanes()
Returns the Drivelanes where Roadusers move towards the alphaNode

Returns:
DOCUMENT ME!

setAlphaLanes

public void setAlphaLanes(Drivelane[] l)
Sets the Drivelanes where Roadusers move towards the alphaNode

Parameters:
l - DOCUMENT ME!

getBetaLanes

public Drivelane[] getBetaLanes()
Returns the Drivelanes where Roadusers move towards the betaNode

Returns:
DOCUMENT ME!

setBetaLanes

public void setBetaLanes(Drivelane[] l)
Sets the Drivelanes where Roadusers move towards the betaNode

Parameters:
l - DOCUMENT ME!

getName

public java.lang.String getName()
Returns the name of this road. The name of a road is unique in an infrastructure.

Returns:
DOCUMENT ME!

getBounds

public java.awt.Rectangle getBounds()
Description copied from interface: Selectable
Returns the bounding box of this Selectable

Specified by:
getBounds in interface Selectable
Returns:
DOCUMENT ME!

getComplexBounds

public java.awt.Shape getComplexBounds()
DOCUMENT ME!

Specified by:
getComplexBounds in interface Selectable
Returns:
DOCUMENT ME!

getDistance

public int getDistance(java.awt.Point p)
DOCUMENT ME!

Specified by:
getDistance in interface Selectable
Parameters:
p - DOCUMENT ME!
Returns:
DOCUMENT ME!

getSelectionPoint

public java.awt.Point getSelectionPoint()
DOCUMENT ME!

Specified by:
getSelectionPoint in interface Selectable
Returns:
DOCUMENT ME!

getSelectionPoints

public java.awt.Point[] getSelectionPoints()
DOCUMENT ME!

Specified by:
getSelectionPoints in interface Selectable
Returns:
DOCUMENT ME!

getCenterPoint

public java.awt.Point getCenterPoint()
DOCUMENT ME!

Specified by:
getCenterPoint in interface Selectable
Returns:
DOCUMENT ME!

hasChildren

public boolean hasChildren()
DOCUMENT ME!

Specified by:
hasChildren in interface SelectionStarter
Returns:
DOCUMENT ME!

isSelectable

public boolean isSelectable()
DOCUMENT ME!

Specified by:
isSelectable in interface Selectable
Returns:
DOCUMENT ME!

getChildren

public java.util.Enumeration getChildren()
DOCUMENT ME!

Specified by:
getChildren in interface SelectionStarter
Returns:
DOCUMENT ME!

reset

public void reset()
Resets the road. This will reset all Drivelanes.

See Also:
Drivelane.reset()

addAlphaLane

public void addAlphaLane(Drivelane l)
                  throws InfraException
Adds a Drivelane leading to the alpha node

Parameters:
l - The drivelane to add
Throws:
InfraException - if l is null

remAlphaLane

public void remAlphaLane(Drivelane l)
                  throws InfraException
Removes a Drivelane leading to the alpha node

Parameters:
l - The drivelane to remove
Throws:
InfraException - if l is null

addBetaLane

public void addBetaLane(Drivelane l)
                 throws InfraException
Adds a Drivelane leading to the beta node

Parameters:
l - The drivelane to add
Throws:
InfraException - if l is null

remBetaLane

public void remBetaLane(Drivelane l)
                 throws InfraException
Removes a Drivelane leading to the beta node

Parameters:
l - The drivelane to remove
Throws:
InfraException - if l is null

addTurn

public void addTurn(Turn t)
             throws InfraException
Adds a Turn to this road

Parameters:
t - The turn to add
Throws:
InfraException - if t is null

remTurn

public void remTurn(Turn t)
             throws InfraException
Removes a Turn from this road

Parameters:
t - The turn to remove
Throws:
InfraException - if t is null

addLane

public void addLane(Drivelane lane,
                    Node to)
             throws InfraException
Adds a Drivelane to this road

Parameters:
lane - The drivelane to add
to - The Node this Drivelane leads to
Throws:
InfraException - if lane or to is null

remLane

public void remLane(Drivelane lane)
             throws InfraException
Removes a Drivelane from this road

Parameters:
lane - The drivelane to remove
Throws:
InfraException - if lane is null

getOtherNode

public Node getOtherNode(Node seenfrom)
Returns the other node this road is connected to, seen from the given node

Parameters:
seenfrom - DOCUMENT ME!
Returns:
DOCUMENT ME!

getWidth

public int getWidth()
Returns the width of this road in number of lanes

Returns:
DOCUMENT ME!

getNumAllLanes

public int getNumAllLanes()
Returns the number of total Drivelanes in this road

Returns:
DOCUMENT ME!

getNumAlphaLanes

public int getNumAlphaLanes()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getNumBetaLanes

public int getNumBetaLanes()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getNumOutboundLanes

public int getNumOutboundLanes(Node n)
                        throws InfraException
Returns the number of Drivelanes that are outbound from the given node

Parameters:
n - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
InfraException - if n is null

getNumInboundLanes

public int getNumInboundLanes(Node n)
                       throws InfraException
Returns the number of Drivelanes that are inbound on the given node

Parameters:
n - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
InfraException - if n is null

getOutboundLanes

public Drivelane[] getOutboundLanes(Node n)
                             throws InfraException
Returns an array of Drivelanes which are outbound from the given node.

Parameters:
n - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
InfraException - if n is null

getInboundLanes

public Drivelane[] getInboundLanes(Node n)
                            throws InfraException
Returns an array of Drivelanes which are inbound on the node given.

Parameters:
n - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
InfraException - if n is null

getAllLanes

public Drivelane[] getAllLanes()
Returns an array of Drivelanes which are part of this road

Returns:
DOCUMENT ME!

paint

public void paint(java.awt.Graphics g,
                  int x,
                  int y,
                  float zf)
           throws TrafficException
Draws this Road, with all it's DriveLanes and Roadusers onto a Graphics object, mostly a View

Parameters:
g - The Graphics object of the View
x - The horizontal scroll number of the View
y - The vertical scroll number of the View
zf - The zoom factor of the View
Throws:
TrafficException - DOCUMENT ME!

paint

public void paint(java.awt.Graphics g)
           throws TrafficException
DOCUMENT ME!

Parameters:
g - DOCUMENT ME!
Throws:
TrafficException - DOCUMENT ME!

paintDrivelaneSegment

public java.awt.Shape paintDrivelaneSegment(java.awt.Graphics g,
                                            java.awt.Point p1_1,
                                            java.awt.Point p1_2,
                                            java.awt.Point p2_1,
                                            java.awt.Point p2_2,
                                            double a1,
                                            double a2,
                                            Drivelane dl)
Paints an arbitrary segment of a drivelane and returns the outlines of this segment as a Shape

Parameters:
g - DOCUMENT ME!
p1_1 - DOCUMENT ME!
p1_2 - DOCUMENT ME!
p2_1 - DOCUMENT ME!
p2_2 - DOCUMENT ME!
a1 - DOCUMENT ME!
a2 - DOCUMENT ME!
dl - DOCUMENT ME!
Returns:
DOCUMENT ME!

paintRoaduser

public void paintRoaduser(java.awt.Graphics g,
                          Roaduser r,
                          java.awt.Point p1,
                          java.awt.Point p2,
                          double a1,
                          double a2,
                          int pos)
Draws a Roaduser on a (segment of a) Drivelane

Parameters:
g - The Graphics object to draw onto
r - The Roaduser to draw
p1 - The first point of the segment
p2 - The last point of the segment
a1 - The angle of the first point of the segment
a2 - The angle of the last point of the segment
pos - The position of the Roaduser relative to the start of the segment

paintRoaduserOnNode

public void paintRoaduserOnNode(java.awt.Graphics g,
                                Roaduser ru,
                                Node node,
                                java.awt.Point p,
                                int pos,
                                Drivelane d)
Draws a Roaduser on a Node

Parameters:
g - The Graphics object to draw onto
ru - The Roaduser to draw
node - The Node this Roaduser is on
p - The first point of the new Drivelane the Roaduser will be on
pos - The position of the Roaduser on the Node
d - The new Drivelane

paintDrivelaneAttributes

public void paintDrivelaneAttributes(java.awt.Graphics g,
                                     java.awt.Point p,
                                     double a,
                                     Drivelane d)
DOCUMENT ME!

Parameters:
g - DOCUMENT ME!
p - DOCUMENT ME!
a - DOCUMENT ME!
d - DOCUMENT ME!

paint

public void paint(java.awt.Graphics g,
                  int x,
                  int y,
                  float zf,
                  double bogus)
           throws TrafficException
Paint this road with it's roadusers

Parameters:
g - DOCUMENT ME!
x - DOCUMENT ME!
y - DOCUMENT ME!
zf - DOCUMENT ME!
bogus - DOCUMENT ME!
Throws:
TrafficException - DOCUMENT ME!