y.view
Class NodeRealizer

java.lang.Object
  |
  +--y.view.NodeRealizer
All Implemented Interfaces:
NodeLayout
Direct Known Subclasses:
ImageNodeRealizer, ShapeNodeRealizer

public abstract class NodeRealizer
extends Object
implements NodeLayout

Abstract graphical representation of a node. This class provides methods to draw a node. For this to happen a node must be bound to the realizer.


Field Summary
protected  double height
           
static byte HOTSPOT_E
          Hotspot type indentifier.
static byte HOTSPOT_N
          Hotspot type indentifier.
static byte HOTSPOT_NE
          Hotspot type indentifier.
static byte HOTSPOT_NONE
          Hotspot type indentifier.
static byte HOTSPOT_NW
          Hotspot type indentifier.
static byte HOTSPOT_S
          Hotspot type indentifier.
static byte HOTSPOT_SE
          Hotspot type indentifier.
static byte HOTSPOT_SW
          Hotspot type indentifier.
static byte HOTSPOT_W
          Hotspot type indentifier.
protected  double width
           
protected  double x
           
protected  double y
           
 
Constructor Summary
NodeRealizer()
          Creates instance of NodeRealizer at location (0,0).
NodeRealizer(double x, double y)
          Creates instance of NodeRealizer at a certain position .
NodeRealizer(double x, double y, String label)
          Creates instance of NodeRealizer at a certain position with given label.
NodeRealizer(NodeRealizer argNodeRealizer)
          Create instance of NodeRealizer and initialize it according to a given NodeRealizer.
 
Method Summary
 void addLabel(NodeLabel nl)
          Add the given label to this realizer.
 void calcUnionRect(Rectangle2D r)
          Enlarges the given rectangle such that it will contain the bounding box of this realizer and the bounding box of the realizer label.
 void calcUnionRect(Rectangle2D r, byte layer)
          Enlarges the given rectangle such that it will contain the bounding box of this realizer and the bounding box of the realizer label.
 boolean contains(double x, double y)
          Returns true iff the bounding box of this realizer contains the given coords.
 NodeRealizer createCopy()
          Returns a copy of this realizer that is not bound to any node.
abstract  NodeRealizer createCopy(NodeRealizer er)
          Returns a realizer of the same type as this realizer, that adopts as many attributes as possible from the given realizer.
 NodeLabel createNodeLabel()
          Creates a new node label that can be added to this realizer.
 boolean findBBIntersection(double ix, double iy, double ox, double oy, Point2D result)
          Returns true iff the coord (ix,iy) is identical with (getCenterX(),getCenterY()) and the coord (ox,oy), lies outside the bounding box of this realizer.
 boolean findIntersection(double ix, double iy, double ox, double oy, Point2D result)
          Returns true iff the coord (ix,iy) lies within the visual shape of this realizer and the coord (ox,oy) lies outside of that shape.
 Rectangle2D.Double getBoundingBox()
          Return the bounding box of this realizer.
 double getCenterX()
          Get X-Coordinate of the center of the node.
 double getCenterY()
          Get Y-Coordinate of the center of the node.
 Color getFillColor()
          Returns the fill color of this realizer.
 Color getFillColor2()
          Returns the fill color of this realizer.
 double getHeight()
          Returns the height of this realizer.
static Color getHotSpotColor()
          Returnsthe color of the hotspot marks for all realizers.
 NodeLabel getLabel()
          Returns the first label associated with this realizer.
 NodeLabel getLabel(int i)
          Returns the i-th label associated with this realizer.
 String getLabelText()
          Returns the text of the first label assiciated with this realizer.
 byte getLayer()
          Returns the logical graphical layer for this realizer.
 Color getLineColor()
          Returns the outline color of this realizer.
 LineType getLineType()
          Returns the line type of this realizer.
 Node getNode()
          Returns the node this realizer is bound to.
 YList getPortCandidates(double gridResolution)
          Returns a list of YPoint that contains absolute(!)
static Color getSloppySelectionColor()
          Returns the fill color of the node used when drawing a selected node in sloopy mode..
 double getWidth()
          Returns the width of this realizer.
 double getX()
          Get X-Coordinate of the upper left corner of the node.
 double getY()
          Get Y-Coordinate of the upper left corner of the node.
 byte hotSpotHit(double hx, double hy)
          Returns one of the predefined hotspot type constants to signal which hotspot is hit by the given coords.
 boolean intersects(double rx, double ry, double rw, double rh)
          Returns true iff the bounding box of this realizer intersects with the given box.
 boolean isInBox(double xb, double yb, double wb, double hb)
          Returns true iff the bounding box of this realizer lies completely within the given box.
 boolean isSelected()
          Returns the selection state of this realizer.
 boolean isTransparent()
          Returns the transparancy state of this realizer.
 boolean isVisible()
          Returns true iff this realizer is marked as visible.
 int labelCount()
          Returns the number of labels associated with this realizer.
 void moveBy(double dx, double dy)
          Moves the node relatively to the current position.
 void paint(Graphics2D gfx)
          Paints this realizer and its label(s) on the given graphics context.
 void paintHotSpots(Graphics2D g)
          Paints graphical hotspots around this realizer.
 void paintLayer(Graphics2D g, byte layer)
          Requests this realizer to paint itself on the given graphics context under the constraint that the given layer is active.
 void paintLayerSloppy(Graphics2D g, byte layer)
          Paints the realizer in a cheap, uniform and sloppy way on g.
protected abstract  void paintNode(Graphics2D g)
          This method must be implemented by subclasses.
 void paintSloppy(Graphics2D g)
          Paints the realizer in a cheap, uniform and sloppy way on g.
 void paintText(Graphics2D gfx)
          Paints the labels that belong to this realizer
 void read(ObjectInputStream in)
          Reads in the serialized form of this realizer.
 void removeLabel(NodeLabel nl)
          Remove the given label from this realizer.
 void setCenter(double x, double y)
          Set the coordinates of the center of the node.
 void setCenterX(double x)
          Set the x coordinate of the center of the node.
 void setCenterY(double y)
          Set the y coordinate of the center of the node.
 void setEdgesDirty()
          Marks adjacent edge realizers as dirty.
 void setFillColor(Color c)
          Sets the fill color for this realizer.
 void setFillColor2(Color c)
          Sets the second fill color for this realizer.
 void setFrame(double x, double y, double width, double height)
          Sets the frame of the realizer, i.e. its size and its location.
 void setFrame(Rectangle2D frame)
          Sets the frame of the realizer, i.e. its size and its location.
 void setHeight(double height)
          Sets the height of this realizer.
static void setHotSpotColor(Color c)
          Sets the color of the hotspot marks for all realizers.
 void setLabel(NodeLabel nl)
          Sets the first label associated with this realizer.
 void setLabelText(String label)
          Sets the text of the first label associated with this realizer.
 void setLayer(byte l)
          Sets the logical graphical layer for this realizer.
 void setLayer(byte l, boolean adjacentEdgesAsWell)
          Sets the layer this realizer should be painted on.
 void setLineColor(Color c)
          Sets the outline color for this realizer.
 void setLineType(LineType lt)
          Sets the line type for this realizer.
 void setLocation(double x, double y)
          Sets the coordinates of the upper left corner of the node.
 void setSelected(boolean s)
          Sets the selection state of this realizer.
 void setSize(double width, double height)
          Sets the size of the realizer.
static void setSloppySelectionColor(Color c)
          Sets the fill color of the node used when drawing a selected node in sloopy mode..
 void setTransparent(boolean b)
          Sets the transparancy of the realizer.
 void setVisible(boolean b)
          Sets the visibility state of this realizer.
 void setWidth(double width)
          Sets the width of this realizer.
 void setX(double xp)
          Sets the X-Coordinate of the upper left corner of the node.
 void setY(double yp)
          Sets the Y-Coordinate of the upper left corner of the node.
 void write(ObjectOutputStream out)
          Writes this realizer in a serialized form to the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HOTSPOT_NW

public static final byte HOTSPOT_NW
Hotspot type indentifier. Identifies the hotspot located north west of this realizer.

See Also:
NodeRealizer.hotSpotHit(double,double), Constant Field Values

HOTSPOT_N

public static final byte HOTSPOT_N
Hotspot type indentifier. Identifies the hotspot located north of this realizer.

See Also:
NodeRealizer.hotSpotHit(double,double), Constant Field Values

HOTSPOT_NE

public static final byte HOTSPOT_NE
Hotspot type indentifier. Identifies the hotspot located north east of this realizer.

See Also:
NodeRealizer.hotSpotHit(double,double), Constant Field Values

HOTSPOT_SW

public static final byte HOTSPOT_SW
Hotspot type indentifier. Identifies the hotspot located south west of this realizer.

See Also:
NodeRealizer.hotSpotHit(double,double), Constant Field Values

HOTSPOT_S

public static final byte HOTSPOT_S
Hotspot type indentifier. Identifies the hotspot located south of this realizer.

See Also:
NodeRealizer.hotSpotHit(double,double), Constant Field Values

HOTSPOT_SE

public static final byte HOTSPOT_SE
Hotspot type indentifier. Identifies the hotspot located south east of this realizer.

See Also:
NodeRealizer.hotSpotHit(double,double), Constant Field Values

HOTSPOT_W

public static final byte HOTSPOT_W
Hotspot type indentifier. Identifies the hotspot located west of this realizer.

See Also:
NodeRealizer.hotSpotHit(double,double), Constant Field Values

HOTSPOT_E

public static final byte HOTSPOT_E
Hotspot type indentifier. Identifies the hotspot located east of this realizer.

See Also:
NodeRealizer.hotSpotHit(double,double), Constant Field Values

HOTSPOT_NONE

public static final byte HOTSPOT_NONE
Hotspot type indentifier. This identifier signals that no hotspot was hit.

See Also:
NodeRealizer.hotSpotHit(double,double), Constant Field Values

x

protected double x

y

protected double y

width

protected double width

height

protected double height
Constructor Detail

NodeRealizer

public NodeRealizer()
Creates instance of NodeRealizer at location (0,0).


NodeRealizer

public NodeRealizer(double x,
                    double y)
Creates instance of NodeRealizer at a certain position .

Parameters:
x - X-Position of the center of the node
y - Y-Position of the center of the node

NodeRealizer

public NodeRealizer(double x,
                    double y,
                    String label)
Creates instance of NodeRealizer at a certain position with given label.

Parameters:
x - X-Position of the center of the node
y - Y-Position of the center of the node
label - The label of the node

NodeRealizer

public NodeRealizer(NodeRealizer argNodeRealizer)
Create instance of NodeRealizer and initialize it according to a given NodeRealizer.

Parameters:
argNodeRealizer - A NodeRealizer
Method Detail

createCopy

public NodeRealizer createCopy()
Returns a copy of this realizer that is not bound to any node.

This method simply returns createCopy(this).


createCopy

public abstract NodeRealizer createCopy(NodeRealizer er)
Returns a realizer of the same type as this realizer, that adopts as many attributes as possible from the given realizer.

Subclassed realizers should always implement or overwrite this method, to guarantee correct copy behaviour of the realizer.


getNode

public Node getNode()
Returns the node this realizer is bound to. If this realizer is not bound to any node, then null is returned.


setFillColor

public void setFillColor(Color c)
Sets the fill color for this realizer.


getFillColor

public Color getFillColor()
Returns the fill color of this realizer.


setFillColor2

public void setFillColor2(Color c)
Sets the second fill color for this realizer. If a second fill color is set, then the realizer will be filled with a gradient paint from fillColor to fillColor2. By default this color is not set, i.e. it is null.


getFillColor2

public Color getFillColor2()
Returns the fill color of this realizer.


setLineColor

public void setLineColor(Color c)
Sets the outline color for this realizer.


getLineColor

public Color getLineColor()
Returns the outline color of this realizer.


setLineType

public void setLineType(LineType lt)
Sets the line type for this realizer.


getLineType

public LineType getLineType()
Returns the line type of this realizer.


setTransparent

public void setTransparent(boolean b)
Sets the transparancy of the realizer. Here tranparency means that the node is not filled with a color.


isTransparent

public boolean isTransparent()
Returns the transparancy state of this realizer.


setLabelText

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

Parameters:
label - the text of the label

getLabelText

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


createNodeLabel

public NodeLabel createNodeLabel()
Creates a new node label that can be added to this realizer.


setLabel

public void setLabel(NodeLabel nl)
Sets the first label associated with this realizer.


addLabel

public void addLabel(NodeLabel nl)
Add the given label to this realizer. By default a node realizer is associated with one label. By calling this method more labels can be added to the realizer.


removeLabel

public void removeLabel(NodeLabel nl)
Remove the given label from this realizer. Removing a label is only permitted if it is not the last label associated with this realizer.


getLabel

public NodeLabel getLabel()
Returns the first label associated with this realizer.


getLabel

public NodeLabel getLabel(int i)
Returns the i-th label associated with this realizer.


labelCount

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


getCenterX

public double getCenterX()
Get X-Coordinate of the center of the node.


getCenterY

public double getCenterY()
Get Y-Coordinate of the center of the node.


setCenter

public void setCenter(double x,
                      double y)
Set the coordinates of the center of the node.


setCenterX

public void setCenterX(double x)
Set the x coordinate of the center of the node.


setCenterY

public void setCenterY(double y)
Set the y coordinate of the center of the node.


getX

public double getX()
Get X-Coordinate of the upper left corner of the node.

Specified by:
getX in interface NodeLayout

getY

public double getY()
Get Y-Coordinate of the upper left corner of the node.

Specified by:
getY in interface NodeLayout

setLocation

public void setLocation(double x,
                        double y)
Sets the coordinates of the upper left corner of the node.

Specified by:
setLocation in interface NodeLayout
Parameters:
x - the x-coordinates of the upper left corner.
y - the y-coordinates of the upper left corner.

setX

public void setX(double xp)
Sets the X-Coordinate of the upper left corner of the node.


setY

public void setY(double yp)
Sets the Y-Coordinate of the upper left corner of the node.


moveBy

public void moveBy(double dx,
                   double dy)
Moves the node relatively to the current position.


getWidth

public double getWidth()
Returns the width of this realizer.

Specified by:
getWidth in interface NodeLayout

getHeight

public double getHeight()
Returns the height of this realizer.

Specified by:
getHeight in interface NodeLayout

setFrame

public void setFrame(double x,
                     double y,
                     double width,
                     double height)
Sets the frame of the realizer, i.e. its size and its location.


setFrame

public void setFrame(Rectangle2D frame)
Sets the frame of the realizer, i.e. its size and its location.


setSize

public void setSize(double width,
                    double height)
Sets the size of the realizer. Note that this method resizes the node in a way that the center location of this realizer won't change. The upper left corner of this realizer *will* change though.

Specified by:
setSize in interface NodeLayout
Parameters:
width - the width of the node.
height - the heigth of the node.

setWidth

public void setWidth(double width)
Sets the width of this realizer. This method delegates to NodeRealizer.setSize(double, double).


setHeight

public void setHeight(double height)
Sets the height of this realizer. This method delegates to NodeRealizer.setSize(double,double).


setVisible

public void setVisible(boolean b)
Sets the visibility state of this realizer. By default a realizer is visible.


isVisible

public boolean isVisible()
Returns true iff this realizer is marked as visible. Invisible realizers won't paint themselves on a graphics context.


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

setLayer

public void setLayer(byte l,
                     boolean adjacentEdgesAsWell)
Sets the layer this realizer should be painted on. The layer of the adjacent edges will be set as well if the second argument has value true.


setSelected

public void setSelected(boolean s)
Sets the selection state of this realizer. Selected realizers will paint themselves in a highlighted fashion on a graphics context.


isSelected

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


setHotSpotColor

public static void setHotSpotColor(Color c)
Sets the color of the hotspot marks for all realizers. By default Color.gr

See Also:
NodeRealizer.paintHotSpots(Graphics2D)

getHotSpotColor

public static Color getHotSpotColor()
Returnsthe color of the hotspot marks for all realizers.

See Also:
NodeRealizer.setHotSpotColor(Color)

setSloppySelectionColor

public static void setSloppySelectionColor(Color c)
Sets the fill color of the node used when drawing a selected node in sloopy mode.. By default Color.gray is used.

See Also:
NodeRealizer.paintSloppy(Graphics2D)

getSloppySelectionColor

public static Color getSloppySelectionColor()
Returns the fill color of the node used when drawing a selected node in sloopy mode..

See Also:
NodeRealizer.paintSloppy(Graphics2D)

getBoundingBox

public Rectangle2D.Double getBoundingBox()
Return the bounding box of this realizer. The bounding box does not necessarily contain the bounding box of the realizer label.


hotSpotHit

public byte hotSpotHit(double hx,
                       double hy)
Returns one of the predefined hotspot type constants to signal which hotspot is hit by the given coords.


findBBIntersection

public boolean findBBIntersection(double ix,
                                  double iy,
                                  double ox,
                                  double oy,
                                  Point2D result)
Returns true iff the coord (ix,iy) is identical with (getCenterX(),getCenterY()) and the coord (ox,oy), lies outside the bounding box of this realizer. In that case the intersection point of the line (ix,iy) - (ox,oy) with the bounding box of this realizer will be stored in the given point.


findIntersection

public boolean findIntersection(double ix,
                                double iy,
                                double ox,
                                double oy,
                                Point2D result)
Returns true iff the coord (ix,iy) lies within the visual shape of this realizer and the coord (ox,oy) lies outside of that shape. In that case the intersection point of the line (ix,iy) - (ox,oy) with that shape will be stored in the given point.


calcUnionRect

public void calcUnionRect(Rectangle2D r,
                          byte layer)
Enlarges the given rectangle such that it will contain the bounding box of this realizer and the bounding box of the realizer label. The given layer indicates for which graphics layer clipping information is collected by doing this call.


calcUnionRect

public void calcUnionRect(Rectangle2D r)
Enlarges the given rectangle such that it will contain the bounding box of this realizer and the bounding box of the realizer label.


intersects

public boolean intersects(double rx,
                          double ry,
                          double rw,
                          double rh)
Returns true iff the bounding box of this realizer intersects with the given box.


contains

public boolean contains(double x,
                        double y)
Returns true iff the bounding box of this realizer contains the given coords.


isInBox

public boolean isInBox(double xb,
                       double yb,
                       double wb,
                       double hb)
Returns true iff the bounding box of this realizer lies completely within the given box.


getPortCandidates

public YList getPortCandidates(double gridResolution)
Returns a list of YPoint that contains absolute(!) coordinates of port candidate locations that are suitable for the given grid resolution.


paintNode

protected abstract void paintNode(Graphics2D g)
This method must be implemented by subclasses. It defines in wich way the realizer paints itself on a graphics context.


paintHotSpots

public void paintHotSpots(Graphics2D g)
Paints graphical hotspots around this realizer. The hotspots mark regions on which hit tests can be performed.


paintLayer

public void paintLayer(Graphics2D g,
                       byte layer)
Requests this realizer to paint itself on the given graphics context under the constraint that the given layer is active. By default this method will do nothing if the given layer does not match the layer of this realizer. Otherwise the regular paint method will be invoked.


paintLayerSloppy

public void paintLayerSloppy(Graphics2D g,
                             byte layer)
Paints the realizer in a cheap, uniform and sloppy way on g. The given layer indicates what kind of layer objects should be painted. By default this method does nothing if layer != this.getLayer(). Otherwise paintSloppy gets called.


paintSloppy

public void paintSloppy(Graphics2D g)
Paints the realizer in a cheap, uniform and sloppy way on g. By default this call draws a rectangle with this realizer's bounds and colors. No label will be painted.


paint

public void paint(Graphics2D gfx)
Paints this realizer and its label(s) on the given graphics context. this method will do nothing if the realizer is marked as invisible.


paintText

public void paintText(Graphics2D gfx)
Paints the labels that belong to this realizer


setEdgesDirty

public void setEdgesDirty()
Marks adjacent edge realizers as dirty. Dirty realizers will definitely recalculate their features before painting themselves.


write

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

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 NodeRealizer.write(ObjectOutputStream) method.

IOException
ClassNotFoundException

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

2003