y.view
Class EdgeRealizer

java.lang.Object
  |
  +--y.view.EdgeRealizer
All Implemented Interfaces:
EdgeLayout
Direct Known Subclasses:
ArcEdgeRealizer, BezierEdgeRealizer, PolyLineEdgeRealizer, SplineEdgeRealizer

public abstract class EdgeRealizer
extends Object
implements EdgeLayout

Abstract graphical representation of an edge. This class provides methods to draw an edge. For this to happen an edge must be bound to the realizer. This can be done by calling Graph2D.setRealizer(Edge,EdgeRealizer)

An edge realizer allows the use of control points, so called bends. These bends influence the graphical path of the edge.


Field Summary
protected  BendList bends
          The list where bends are stored.
protected  GeneralPath path
          The graphical path of this realizer that will be drawn.
 
Constructor Summary
EdgeRealizer()
          Instantiates a new EdgeRealizer with default values.
EdgeRealizer(EdgeRealizer argEdgeRealizer)
          Instantiates a new EdgeRealizer as a copy of the given edge realizer.
 
Method Summary
 void addLabel(EdgeLabel label)
          Adds the given edge label to this realizer.
 void addPoint(double x, double y)
          EdgeLayout interface implementation.
 Bend appendBend(double x, double y)
          Appends a newly created bend with location (x,y) to the list of bends.
 void bendChanged(Bend b, double oldX, double oldY)
          Informs the edge, that a bend has changed position By default this method does nothing.
 int bendCount()
          Returns the number of bends of this realizer.
 int bendPos(Bend b)
          Returns the index of the bend in the bend sequence.
 BendCursor bends()
          Returns a cursor over all bends of this realizer.
protected  void bindEdge(Edge e)
          Binds an actual edge to this realizer. without a bound edge this realizer is NOT fully functional.
protected abstract  void calculatePath()
          Calculates the visible path of this realizer.
 void calcUnionRect(Rectangle2D r)
          Calculates the union of rectangle enclosed by this realizer and r.
 void clearBends()
          Removes all bends from this realizer.
 void clearPoints()
          EdgeLayout interface implementation.
 boolean contains(double x, double y)
          Query if the visible path of this realizer contains the point (x,y).
 int containsSeg(double dx, double dy)
          like contains(), but returns number of the hit segment, 0 otherwise.
abstract  Bend createBend(double x, double y, Bend refBend, int dir)
          Adds a new bend to the edge.
 EdgeRealizer createCopy()
          Returns a copy of this realizer.
abstract  EdgeRealizer createCopy(EdgeRealizer er)
          Get a copy of this realizer, with basic (EdgeRealizer) features adopted from er.
 EdgeLabel createEdgeLabel()
          Creates a new edge label that can be added to this realizer.
 Bend firstBend()
          Returns the first bend of the edge, null if the edge has none.
 Arrow getArrow()
          Returns the arrow type at the target location of the edge path.
 Bend getBend(int index)
          Returns the bend at the given positional index.
 Edge getEdge()
          Returns the edge bound to this realizer.
static Color getHighlightedBendColor()
          Returns the color of all highlighed bends By default the color Color.green is returned.
 EdgeLabel getLabel()
          Returns the first label associated with this realizer.
 EdgeLabel getLabel(int i)
          Returns the i-th label of this realizer.
 String getLabelText()
          Returns the text of the assiciated label of this realizer.
 byte getLayer()
          Returns the logical graphical layer for this realizer.
 Color getLineColor()
          Returns the line color of the edge path.
 LineType getLineType()
          Returns the line type of the edge path.
 int getMinBendCount()
          Returns the minimal number of bends the edge must have.
 GeneralPath getPath()
          Returns the visible path of the edge as it will be drawn on a graphics context.
 YPoint getPoint(int index)
          EdgeLayout interface implementation.
static Color getSelectionColor()
          Returns the color of all selected edges.
static Stroke getSelectionStroke()
          Returns the stroke of the selected edge.
 Arrow getSourceArrow()
          Returns the arrow at the source location of the edge path.
 Point2D getSourceIntersection()
          Returns the intersection point between this realizer and the source node realizer.
 YPoint getSourcePoint()
          EdgeLayout interface implementation.
 Port getSourcePort()
          Returns the source port of this edge realizer.
 NodeRealizer getSourceRealizer()
          Returns the node realizer that is bound to the source node of the underlying edge.
 Arrow getTargetArrow()
          Same as EdgeRealizer.getArrow().
 Point2D getTargetIntersection()
          Returns the intersection point between this realizer and the target node realizer.
 YPoint getTargetPoint()
          EdgeLayout interface implementation.
 Port getTargetPort()
          Returns the target port of this edge realizer.
 NodeRealizer getTargetRealizer()
          Returns the node realizer that is bound to the target node of the underlying edge.
abstract  Bend insertBend(double x, double y)
          Adds a new bend to this realizer and returns it.
 boolean intersects(Rectangle2D box)
           
protected  boolean isDirty()
          Whether or not this realizer requires an update of it's graphical representation.
 boolean isSelected()
          Returns the selected state of this realizer.
 boolean isVisible()
          Returns the visibility state of this realizer.
 int labelCount()
          Returns the number of labels associated with this realizer.
 Bend lastBend()
          Returns the last bend of the edge, null if the edge has none.
 void paint(Graphics2D g)
          Paints this realizer on the given graphics context.
protected  void paintArrows(Graphics2D g)
          Paints the arrows of this realizer.
protected  void paintHighlightedBends(Graphics2D gfx)
          Paints the bends if this realizer is in a selected state
protected  void paintLabels(Graphics2D gfx)
          Paints the labels belonging to this realizer.
protected  void paintPorts(Graphics2D gfx)
          Paints the ports of this realizer.
 void paintSloppy(Graphics2D g)
          Paints this realizer in a quick and rather sloppy way.
 boolean pathIntersects(Rectangle2D box, boolean considerLabels)
          This method complements the EdgeRealizer.contains(double,double) method.
 int pointCount()
          EdgeLayout interface implementation.
 void read(ObjectInputStream in)
          Reads in the serialized form of this realizer.
protected  void recalculateFeatures()
          Recalculates all features.
abstract  void reInsertBend(Bend bend, Bend refBend, int dir)
          Reinserts a bend to the edge which had been removed before.
abstract  Bend removeBend(Bend b)
          Removes a Bend of this realizer.
 void removeLabel(EdgeLabel label)
          Removes the given edge label from this realizer.
 void setArrow(Arrow arrow)
          Sets the arrow type at the target location of the edge path.
 void setDirty()
          Marks this realizer as dirty.
static void setHighlightedBendColor(Color color)
          Sets the color of all highlighed bends By default the color Color.green is set.
 void setLabelText(String label)
          Sets the text of the associated label for this realizer.
 void setLayer(byte l)
          Sets the logical graphical layer for this realizer.
 void setLineColor(Color c)
          Sets the line color of the edge path.
 void setLineType(LineType t)
          Sets the line type for the edge path.
 void setPoint(int index, double x, double y)
          EdgeLayout interface implementation.
 void setPorts(Port sourceP, Port targetP)
          Sets the specified source- and target-port for this edge realizer.
 void setSelected(boolean s)
          Sets the selected state of this realizer.
static void setSelectionColor(Color color)
          Sets the color of all selected edges.
static void setSelectionStroke(LineType t)
          Sets the stroke of a selected edges.
 void setSourceArrow(Arrow arrow)
          Sets the arrow at the source location of the edge path.
 void setSourcePoint(YPoint point)
          EdgeLayout interface implementation.
 void setSourcePort(Port p)
          Sets the specified source port to this edge realizer.
 void setTargetArrow(Arrow arrow)
          Same as EdgeRealizer.setArrow(Arrow).
 void setTargetPoint(YPoint point)
          EdgeLayout interface implementation.
 void setTargetPort(Port p)
          Sets the specified target port to this edge realizer.
 void setVisible(boolean visible)
          Sets the visiblility state of this realizer.
 void write(ObjectOutputStream out)
          Writes out this realizer in a serialized form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bends

protected BendList bends
The list where bends are stored.


path

protected GeneralPath path
The graphical path of this realizer that will be drawn.

Constructor Detail

EdgeRealizer

public EdgeRealizer()
Instantiates a new EdgeRealizer with default values.


EdgeRealizer

public EdgeRealizer(EdgeRealizer argEdgeRealizer)
Instantiates a new EdgeRealizer as a copy of the given edge realizer.

Method Detail

createCopy

public EdgeRealizer createCopy()
Returns a copy of this realizer.


createCopy

public abstract EdgeRealizer createCopy(EdgeRealizer er)
Get a copy of this realizer, with basic (EdgeRealizer) features adopted from er.


bindEdge

protected void bindEdge(Edge e)
Binds an actual edge to this realizer. without a bound edge this realizer is NOT fully functional.


getTargetRealizer

public NodeRealizer getTargetRealizer()
Returns the node realizer that is bound to the target node of the underlying edge. This method is only valid if an edge is bound to this realizer.


getSourceRealizer

public NodeRealizer getSourceRealizer()
Returns the node realizer that is bound to the source node of the underlying edge. This method is only valid if an edge is bound to this realizer.


getEdge

public Edge getEdge()
Returns the edge bound to this realizer.


setPorts

public void setPorts(Port sourceP,
                     Port targetP)
Sets the specified source- and target-port for this edge realizer.


setSourcePort

public void setSourcePort(Port p)
Sets the specified source port to this edge realizer.


setTargetPort

public void setTargetPort(Port p)
Sets the specified target port to this edge realizer.


getSourcePort

public Port getSourcePort()
Returns the source port of this edge realizer.


getTargetPort

public Port getTargetPort()
Returns the target port of this edge realizer.


createBend

public abstract Bend createBend(double x,
                                double y,
                                Bend refBend,
                                int dir)
Adds a new bend to the edge.

Parameters:
x - X-coordinate of the Bend
y - Y-coordinate of the Bend
refBend - Bend which should be neighbour
dir - indicates if the new Bend should be added before (Graph.BEFORE) or after (Graph.AFTER) the refBend in the bend sequence of the edge

reInsertBend

public abstract void reInsertBend(Bend bend,
                                  Bend refBend,
                                  int dir)
Reinserts a bend to the edge which had been removed before.

Parameters:
bend - the bend to be reinserted
refBend - reference bend already contained in this realizer
dir - indicates whether the bend should be inserted before or after the reference bend.Allowed values are Graph.AFTER and Graph.BEFORE.

insertBend

public abstract Bend insertBend(double x,
                                double y)
Adds a new bend to this realizer and returns it. If the given coordinate lies on an visible segment of the path, then the bend will be inserted in such a way that the segemnts splits in two parts. Otherwise the bend will be appended to the list of bends.

Parameters:
x - X-coordinates of the bend
y - Y-coordinates of the bend

removeBend

public abstract Bend removeBend(Bend b)
Removes a Bend of this realizer.

Parameters:
b - Bend to be removed

bendChanged

public void bendChanged(Bend b,
                        double oldX,
                        double oldY)
Informs the edge, that a bend has changed position By default this method does nothing.

Parameters:
b - Bend which has changed position
oldX - previous x-coordinate
oldY - previous y-coordinate

appendBend

public Bend appendBend(double x,
                       double y)
Appends a newly created bend with location (x,y) to the list of bends.

Parameters:
x - X-coordinates of bend
y - Y-coordinates of bend

bendPos

public int bendPos(Bend b)
Returns the index of the bend in the bend sequence. If the bend is not part of the edge a value < 0 is returned.

Parameters:
b - the bend in question

bendCount

public int bendCount()
Returns the number of bends of this realizer.


getBend

public Bend getBend(int index)
Returns the bend at the given positional index. The first bend in the sequence has index 0 and consequently the last bend has index bendCount() - 1.

Parameters:
index - position of the Bend in the bend sequence

bends

public BendCursor bends()
Returns a cursor over all bends of this realizer.


firstBend

public Bend firstBend()
Returns the first bend of the edge, null if the edge has none.


lastBend

public Bend lastBend()
Returns the last bend of the edge, null if the edge has none.


getMinBendCount

public int getMinBendCount()
Returns the minimal number of bends the edge must have. The return value defaults to 0.


clearBends

public void clearBends()
Removes all bends from this realizer.


getPoint

public YPoint getPoint(int index)
EdgeLayout interface implementation.

Specified by:
getPoint in interface EdgeLayout
Parameters:
index - position of the control point in the control point sequence.
Returns:
the absolute coordinates the the control point at the given index
See Also:
EdgeLayout.getPoint(int)

pointCount

public int pointCount()
EdgeLayout interface implementation.

Specified by:
pointCount in interface EdgeLayout
Returns:
the number of control points
See Also:
EdgeLayout.pointCount()

getSourcePoint

public YPoint getSourcePoint()
EdgeLayout interface implementation. The source point will be mapped onto the source port of this realizer.

Specified by:
getSourcePoint in interface EdgeLayout
Returns:
the relative coordinates of the source point.
See Also:
EdgeLayout.getSourcePoint()

getTargetPoint

public YPoint getTargetPoint()
EdgeLayout interface implementation. The target point will be mapped onto the target port of this realizer.

Specified by:
getTargetPoint in interface EdgeLayout
Returns:
the relative coordinates of the target point.
See Also:
EdgeLayout.getTargetPoint()

setSourcePoint

public void setSourcePoint(YPoint point)
EdgeLayout interface implementation. The source point will be mapped onto the source port of this realizer.

Specified by:
setSourcePoint in interface EdgeLayout
Parameters:
point - the relative coordinates of the source point.
See Also:
EdgeLayout.setSourcePoint(YPoint)

setTargetPoint

public void setTargetPoint(YPoint point)
EdgeLayout interface implementation. The target point will be mapped onto the target port of this realizer.

Specified by:
setTargetPoint in interface EdgeLayout
Parameters:
point - the relative coordinates of the source point.
See Also:
EdgeLayout.setTargetPoint(YPoint)

setPoint

public void setPoint(int index,
                     double x,
                     double y)
EdgeLayout interface implementation. Points will be mapped onto bends of this realizer.

Specified by:
setPoint in interface EdgeLayout
Parameters:
index - position of the control point in the control point sequence.
x - absolute x-coordinate of the control point at the given index.
y - absolute y-coordinate of the control point at the given index.
See Also:
EdgeLayout.setPoint(int,double,double)

addPoint

public void addPoint(double x,
                     double y)
EdgeLayout interface implementation. Points will be mapped onto bends of this realizer.

Specified by:
addPoint in interface EdgeLayout
Parameters:
x - the absolute x-coordinate of the control point.
y - the absolute y-coordinate of the control point.
See Also:
EdgeLayout.addPoint(double,double)

clearPoints

public void clearPoints()
EdgeLayout interface implementation. Points will be mapped onto bends of this realizer.

Specified by:
clearPoints in interface EdgeLayout
See Also:
EdgeLayout.clearPoints()

paintSloppy

public void paintSloppy(Graphics2D g)
Paints this realizer in a quick and rather sloppy way. Useful if a small zoomlevel is applied to the graphics context.


paint

public void paint(Graphics2D g)
Paints this realizer on the given graphics context.


paintHighlightedBends

protected void paintHighlightedBends(Graphics2D gfx)
Paints the bends if this realizer is in a selected state


paintPorts

protected void paintPorts(Graphics2D gfx)
Paints the ports of this realizer.


paintArrows

protected void paintArrows(Graphics2D g)
Paints the arrows of this realizer.


paintLabels

protected void paintLabels(Graphics2D gfx)
Paints the labels belonging to this realizer.


calculatePath

protected abstract void calculatePath()
Calculates the visible path of this realizer. Subclasses need to implement this.

See Also:
EdgeRealizer.path

recalculateFeatures

protected final void recalculateFeatures()
Recalculates all features. This should be called before the realizer gets painted in case it is marked as dirty.


getSourceIntersection

public Point2D getSourceIntersection()
Returns the intersection point between this realizer and the source node realizer. Precondition: a bound edge


getTargetIntersection

public Point2D getTargetIntersection()
Returns the intersection point between this realizer and the target node realizer. Precondition: a bound edge


getLineColor

public Color getLineColor()
Returns the line color of the edge path.


setLineColor

public void setLineColor(Color c)
Sets the line color of the edge path. This attribute defaults to Color.black


setSelectionColor

public static void setSelectionColor(Color color)
Sets the color of all selected edges. By default the color Color.cyan is set.


setHighlightedBendColor

public static void setHighlightedBendColor(Color color)
Sets the color of all highlighed bends By default the color Color.green is set.


getHighlightedBendColor

public static Color getHighlightedBendColor()
Returns the color of all highlighed bends By default the color Color.green is returned.


getSelectionColor

public static Color getSelectionColor()
Returns the color of all selected edges.


getLineType

public LineType getLineType()
Returns the line type of the edge path.


setLineType

public void setLineType(LineType t)
Sets the line type for the edge path. This attribute defaults to LineType.LINE_1.


setSelectionStroke

public static void setSelectionStroke(LineType t)
Sets the stroke of a selected edges.


getSelectionStroke

public static Stroke getSelectionStroke()
Returns the stroke of the selected edge.


getArrow

public Arrow getArrow()
Returns the arrow type at the target location of the edge path.


setArrow

public void setArrow(Arrow arrow)
Sets the arrow type at the target location of the edge path. This attribute defaults to Arrow.NONE.


getTargetArrow

public Arrow getTargetArrow()
Same as EdgeRealizer.getArrow().


setTargetArrow

public void setTargetArrow(Arrow arrow)
Same as EdgeRealizer.setArrow(Arrow).


getSourceArrow

public Arrow getSourceArrow()
Returns the arrow at the source location of the edge path.


setSourceArrow

public void setSourceArrow(Arrow arrow)
Sets the arrow at the source location of the edge path. This attribute defaults to Arrow.NONE.


setLayer

public void setLayer(byte l)
Sets the logical graphical layer for this realizer. Layer information can be used by viewers to optimize redraws.

See Also:
Graph2DView.FG_LAYER, Graph2DView.BG_LAYER

getLayer

public byte getLayer()
Returns the logical graphical layer for this realizer. Layer information can be used by viewers to optimize redraws.

See Also:
Graph2DView.FG_LAYER, Graph2DView.BG_LAYER

setVisible

public void setVisible(boolean visible)
Sets the visiblility state of this realizer. A realizer will paint itself if and only if it is visible. By default a realizer is visible.


isVisible

public boolean isVisible()
Returns the visibility state of this realizer.


setSelected

public void setSelected(boolean s)
Sets the selected state of this realizer. A selected edge will be painted in a highlighted fashion. By default a realizer is not selected.


isSelected

public boolean isSelected()
Returns the selected state of this realizer.


setDirty

public void setDirty()
Marks this realizer as dirty. This causes recalculation of the visible path upon paint requests. Typically needed when source or target node of the bound edge changed state or bends changed. Also the label offset has to be recalculated.


isDirty

protected boolean isDirty()
Whether or not this realizer requires an update of it's graphical representation. This method should be called whenever a change occurs that modifies the visible path of the realizer.


getPath

public GeneralPath getPath()
Returns the visible path of the edge as it will be drawn on a graphics context. Precondition: a bound edge


addLabel

public void addLabel(EdgeLabel label)
Adds the given edge label to this realizer.


removeLabel

public void removeLabel(EdgeLabel label)
Removes the given edge label from this realizer.


getLabel

public EdgeLabel getLabel()
Returns the first label associated with this realizer. if no label is associated whith this realizer a default label will be instatiated, added to the realizer and returned.


labelCount

public int labelCount()
Returns the number of labels associated with this realizer.


getLabel

public EdgeLabel getLabel(int i)
Returns the i-th label of this realizer.


setLabelText

public void setLabelText(String label)
Sets the text of the associated label for this realizer.


getLabelText

public String getLabelText()
Returns the text of the assiciated label of this realizer.


createEdgeLabel

public EdgeLabel createEdgeLabel()
Creates a new edge label that can be added to this realizer.


contains

public boolean contains(double x,
                        double y)
Query if the visible path of this realizer contains the point (x,y). Essentially a hit test.


containsSeg

public int containsSeg(double dx,
                       double dy)
like contains(), but returns number of the hit segment, 0 otherwise.


calcUnionRect

public void calcUnionRect(Rectangle2D r)
Calculates the union of rectangle enclosed by this realizer and r. For efficency reasons the result is returned by modifying r.


pathIntersects

public boolean pathIntersects(Rectangle2D box,
                              boolean considerLabels)
This method complements the EdgeRealizer.contains(double,double) method. Its primary use is for checking whether or not an edge lies within the bounds of a selection box.

Parameters:
box - the box that will be used for the intersectiontest
considerLabels - if true, labels will be considered
Returns:
if any segment or label intersects the given box

intersects

public boolean intersects(Rectangle2D box)

write

public void write(ObjectOutputStream out)
           throws IOException
Writes out this realizer in a serialized form.

IOException

read

public void read(ObjectInputStream in)
          throws IOException,
                 ClassNotFoundException
Reads in the serialized form of this realizer. The realizer must have been written out before by it's EdgeRealizer.write(ObjectOutputStream) method.

IOException
ClassNotFoundException

© Copyright 2000-2003,
yWorks GmbH.
All rights reserved.

2003