Search this API

y.view
Class ShapeNodeRealizer

java.lang.Object
  extended by y.view.NodeRealizer
      extended by y.view.ShapeNodeRealizer
All Implemented Interfaces:
NodeLayout
Direct Known Subclasses:
Graph2DNodeRealizer, GroupNodeRealizer, ProxyShapeNodeRealizer

public class ShapeNodeRealizer
extends NodeRealizer

A node realizer that displays a node as a geometric shape. Possible shapes are rectangle, ellipse, rounded rectangle, triangle, octagon, hexagon, diamond and parallelogram.

 

Field Summary
static byte DIAMOND
          Shape type constant.
static byte ELLIPSE
          Shape type constant.
static byte FAT_ARROW
          Shape type constant.
static byte FAT_ARROW_2
          Shape type constant.
static byte HEXAGON
          Shape type constant.
static java.awt.RenderingHints.Key KEY_SLOPPY_RECT_PAINTING
          Sloppy rect painting hint key.
static byte OCTAGON
          Shape type constant.
static byte PARALLELOGRAM
          Shape type constant.
static byte PARALLELOGRAM_2
          Shape type constant.
static byte RECT
          Shape type constant.
static byte RECT_3D
          Shape type constant.
static byte ROUND_RECT
          Shape type constant.
protected  java.awt.Shape shape
          The graphical shape representation that gets painted.
static byte STAR5
          Shape type constant.
static byte STAR6
          Shape type constant.
static byte STAR8
          Shape type constant.
static byte TRAPEZOID
          Shape type constant.
static byte TRAPEZOID_2
          Shape type constant.
static byte TRIANGLE
          Shape type constant.
static byte TRIANGLE_2
          Shape type constant.
static java.lang.Object VALUE_SLOPPY_RECT_PAINTING_OFF
          Sloppy rect painting hint value --- rendering in sloppy mode paints a ShapeNodeRealizer instance's actual shape.
 
Fields inherited from class y.view.NodeRealizer
height, HOTSPOT_E, HOTSPOT_N, HOTSPOT_NE, HOTSPOT_NONE, HOTSPOT_NW, HOTSPOT_S, HOTSPOT_SE, HOTSPOT_SW, HOTSPOT_W, width, x, y
 
Constructor Summary
ShapeNodeRealizer()
          Initializes a new ShapeNodeRealizer instance at position (0,0) with rectangular shape and an empty label.
ShapeNodeRealizer(byte type)
          Initializes a new ShapeNodeRealizer instance at position (x,y) with the specified shape type and an empty label.
ShapeNodeRealizer(byte type, double x, double y, java.lang.String label)
          Initializes a new ShapeNodeRealizer instance at the specified position, with the given shape type and label.
ShapeNodeRealizer(NodeRealizer argNodeRealizer)
          Initializes a new ShapeNodeRealizer instance as a copy of the given realizer.
 
Method Summary
 void calcUnionRect(java.awt.geom.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 and its drop shadow.
 boolean contains(double x, double y)
          Evaluate hit test on the node realizer.
 NodeRealizer createCopy(NodeRealizer nr)
          Creates a copy of this realizer type that will be initialized with the values found in the given realizer.
protected  java.awt.Color createSelectionColor(java.awt.Color original)
          Callback function that calculates/modifies a given Color instance for the selected use case.
 boolean findIntersection(double ix, double iy, double ox, double oy, java.awt.geom.Point2D result)
          Special Intersection handling for some types of shape.
 java.awt.Color getDropShadowColor()
           
 byte getDropShadowOffsetX()
          Returns the horizontal offset of the drop shadow.
 byte getDropShadowOffsetY()
          Returns the vertical offset of the drop shadow.
 byte getShapeType()
          Returns shape type of this realizer
 byte hotSpotHit(double hx, double hy)
          Adjusted hitSpotHit that takes drop shadows into account.
 boolean isDropShadowVisible()
          Queries whether or not the drop shadow is visible.
 boolean isRaisedBorderEnabled()
          Determines if the realizer's border is painted before or after node ports and labels.
 void moveBy(double dx, double dy)
          Moves this realizer by the vector (dx,dy).
protected  void paint3DBorder(java.awt.Graphics2D gfx, boolean raised)
          Responsible for painting a 3D border for a shape node of type RECT_3D.
protected  void paintFilledShape(java.awt.Graphics2D gfx)
          Responsible for painting the filled shape of this realizer using a specific color or paint.
 void paintHotSpots(java.awt.Graphics2D gfx)
          Paints graphical hotspots around this realizer.
protected  void paintNode(java.awt.Graphics2D gfx)
          Paints the node.
protected  void paintShadow(java.awt.Graphics2D gfx)
          Paints a shadow for the shape node.
protected  void paintShapeBorder(java.awt.Graphics2D gfx)
          Responsible for painting the border or outline of the shape of this realizer.
 void read(java.io.ObjectInputStream in)
          Deprecated. Use the GraphML format instead.
 void setCenter(double x, double y)
          Sets the center location of this realizer
 void setDropShadowColor(java.awt.Color shadowColor)
           
 void setDropShadowOffsetX(byte shadowOffsetX)
          Set the horizontal offset of the drop shadow.
 void setDropShadowOffsetY(byte shadowOffsetY)
          Set the vertical offset of the drop shadow.
 void setLocation(double x, double y)
          Sets the upper left corner location of this realizer.
 void setRaisedBorderEnabled(boolean enabled)
          Specifies if the realizer's border is painted before or after node ports and labels.
 void setShapeType(byte type)
          Sets the shape type of this realizer.
 void setSize(double w, double h)
          Sets the size of the realizer.
static java.util.Map shapeTypeToStringMap()
          Returns a map whose keys are the shape type specifiers wrapped in Byte objects.
 void write(java.io.ObjectOutputStream out)
          Deprecated. Use the GraphML format instead.
 
Methods inherited from class y.view.NodeRealizer
addLabel, addPort, boundsChanged, calcUnionRect, calcUnionRectImpl, calcUnionRectLabels, calcUnionRectPorts, createCopy, createNodeLabel, findBBIntersection, getAutoBoundsFeature, getBoundingBox, getCenterX, getCenterY, getFillColor, getFillColor2, getHeight, getHotSpotColor, getLabel, getLabel, getLabelText, getLayer, getLineColor, getLineType, getMouseInputEditorProvider, getNode, getPort, getPortCandidates, getSizeConstraintProvider, getSloppySelectionColor, getWidth, getX, getY, intersects, invalidatePortPositions, isInBox, isSelected, isTransparent, isVisible, labelBoundsChanged, labelCount, paint, paintLayer, paintLayerSloppy, paintPorts, paintSloppy, paintText, portCount, removeLabel, removeLabel, removePort, removePort, repaint, setCenterX, setCenterY, setEdgesDirty, setFillColor, setFillColor2, setFrame, setFrame, setHeight, setHotSpotColor, setLabel, setLabelText, setLayer, setLayer, setLineColor, setLineType, setSelected, setSloppySelectionColor, setTransparent, setVisible, setWidth, setX, setY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_SLOPPY_RECT_PAINTING

public static final java.awt.RenderingHints.Key KEY_SLOPPY_RECT_PAINTING
Sloppy rect painting hint key. The SLOPPY_RECT_PAINTING hint controls whether rendering in sloppy mode paints a ShapeNodeRealizer instance's rectangular bounds or its actual shape. The key's associated value must be either null or VALUE_SLOPPY_RECT_PAINTING_OFF. If the associated value is VALUE_SLOPPY_RECT_PAINTING_OFF, a ShapeNodeRealizer instance's actual shape is painted in sloppy mode.

See Also:
VALUE_SLOPPY_RECT_PAINTING_OFF, NodeRealizer.paintSloppy(java.awt.Graphics2D)

VALUE_SLOPPY_RECT_PAINTING_OFF

public static final java.lang.Object VALUE_SLOPPY_RECT_PAINTING_OFF
Sloppy rect painting hint value --- rendering in sloppy mode paints a ShapeNodeRealizer instance's actual shape.

See Also:
KEY_SLOPPY_RECT_PAINTING, NodeRealizer.paintSloppy(java.awt.Graphics2D)

RECT

public static final byte RECT
Shape type constant. Specifies a rectangular shape.

See Also:
setShapeType(byte), Constant Field Values

ROUND_RECT

public static final byte ROUND_RECT
Shape type constant. Specifies a rectangular shape whose corners are rounded.

See Also:
setShapeType(byte), Constant Field Values

ELLIPSE

public static final byte ELLIPSE
Shape type constant. Specifies an oval (ellipsoid) shape.

See Also:
setShapeType(byte), Constant Field Values

PARALLELOGRAM

public static final byte PARALLELOGRAM
Shape type constant. Specifies a rhomboidal shape, whose upper right corner is further to the right than its lower right corner.

See Also:
setShapeType(byte), Constant Field Values

HEXAGON

public static final byte HEXAGON
Shape type constant. Specifies a hexagonal shape, i.e, a shape with six corners.

See Also:
setShapeType(byte), Constant Field Values

TRIANGLE

public static final byte TRIANGLE
Shape type constant. Specifies a triangular shape, i.e, a shape with three corners.

See Also:
setShapeType(byte), Constant Field Values

RECT_3D

public static final byte RECT_3D
Shape type constant. Specifies a rectangular shape with 3D-ish looks.

See Also:
setShapeType(byte), Constant Field Values

OCTAGON

public static final byte OCTAGON
Shape type constant. Specifies an octagonal shape, i.e, a shape with eight corners.

See Also:
setShapeType(byte), Constant Field Values

DIAMOND

public static final byte DIAMOND
Shape type constant. Specifies a diamond shape, i.e, a shape with four corners and diagonally sloped sides.

See Also:
setShapeType(byte), Constant Field Values

TRAPEZOID

public static final byte TRAPEZOID
Shape type constant. Specifies a trapezoidal shape, whose upper line is half as long as its lower line.

See Also:
setShapeType(byte), Constant Field Values

TRAPEZOID_2

public static final byte TRAPEZOID_2
Shape type constant. Specifies a trapezoidal shape, whose lower line is half as long as its upper line.

See Also:
setShapeType(byte), Constant Field Values

TRIANGLE_2

public static final byte TRIANGLE_2
Shape type constant. Specifies a triangular shape that points downwards.

See Also:
setShapeType(byte), Constant Field Values

PARALLELOGRAM_2

public static final byte PARALLELOGRAM_2
Shape type constant. Specifies a rhomboidal shape, whose upper left corner is further to the left than its lower left corner.

See Also:
setShapeType(byte), Constant Field Values

STAR5

public static final byte STAR5
Shape type constant. Specifies a 5-pointed star shape.

See Also:
setShapeType(byte), Constant Field Values

STAR6

public static final byte STAR6
Shape type constant. Specifies a 6-pointed star shape.

See Also:
setShapeType(byte), Constant Field Values

STAR8

public static final byte STAR8
Shape type constant. Specifies an 8-pointed star shape.

See Also:
setShapeType(byte), Constant Field Values

FAT_ARROW

public static final byte FAT_ARROW
Shape type constant. Specifies an arrow-like shape that points to the right.

See Also:
setShapeType(byte), Constant Field Values

FAT_ARROW_2

public static final byte FAT_ARROW_2
Shape type constant. Specifies an arrow-like shape that points to the left.

See Also:
setShapeType(byte), Constant Field Values

shape

protected java.awt.Shape shape
The graphical shape representation that gets painted.

Constructor Detail

ShapeNodeRealizer

public ShapeNodeRealizer()
Initializes a new ShapeNodeRealizer instance at position (0,0) with rectangular shape and an empty label.


ShapeNodeRealizer

public ShapeNodeRealizer(byte type)
Initializes a new ShapeNodeRealizer instance at position (x,y) with the specified shape type and an empty label.

Parameters:
type - one of

ShapeNodeRealizer

public ShapeNodeRealizer(byte type,
                         double x,
                         double y,
                         java.lang.String label)
Initializes a new ShapeNodeRealizer instance at the specified position, with the given shape type and label.

Parameters:
type - one of
x - x-Coordinate of the node
y - y-Coordinate of the node
label - The label of the node

ShapeNodeRealizer

public ShapeNodeRealizer(NodeRealizer argNodeRealizer)
Initializes a new ShapeNodeRealizer instance as a copy of the given realizer. If the given realizer is not of type ShapeNodeRealizer, a rectangular shape will be used as default.

Method Detail

createCopy

public NodeRealizer createCopy(NodeRealizer nr)
Creates a copy of this realizer type that will be initialized with the values found in the given realizer.

Specified by:
createCopy in class NodeRealizer
Parameters:
nr - the prototype realizer whose attributes will be copied.

setCenter

public void setCenter(double x,
                      double y)
Sets the center location of this realizer

Overrides:
setCenter in class NodeRealizer
See Also:
NodeRealizer.setLocation(double, double)

setLocation

public void setLocation(double x,
                        double y)
Sets the upper left corner location of this realizer.

Specified by:
setLocation in interface NodeLayout
Overrides:
setLocation in class NodeRealizer
Parameters:
x - the x-coordinates of the upper left corner.
y - the y-coordinates of the upper left corner.
See Also:
NodeRealizer.setCenter(double, double)

moveBy

public void moveBy(double dx,
                   double dy)
Moves this realizer by the vector (dx,dy).

Overrides:
moveBy in class NodeRealizer

setSize

public void setSize(double w,
                    double h)
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
Overrides:
setSize in class NodeRealizer
Parameters:
w - the new width of the node
h - the new height of the node

isRaisedBorderEnabled

public boolean isRaisedBorderEnabled()
Determines if the realizer's border is painted before or after node ports and labels.

By default, the realizer's border is painted after node ports and labels.

Returns:
true if the realizer's border is painted after node ports and labels and false otherwise.
See Also:
setRaisedBorderEnabled(boolean), paintNode(Graphics2D)

setRaisedBorderEnabled

public void setRaisedBorderEnabled(boolean enabled)
Specifies if the realizer's border is painted before or after node ports and labels.

By default, the realizer's border is painted after node ports and labels.

Parameters:
enabled - if true, the realizer's border is painted after node ports and labels; otherwise the realizer's border is painted before node ports and labels.
See Also:
isRaisedBorderEnabled(), paintNode(Graphics2D)

setShapeType

public void setShapeType(byte type)
Sets the shape type of this realizer.

Parameters:
type - one of

getShapeType

public byte getShapeType()
Returns shape type of this realizer

See Also:
setShapeType(byte)

getDropShadowColor

public java.awt.Color getDropShadowColor()
Returns:
Returns the color of the shadow.

setDropShadowColor

public void setDropShadowColor(java.awt.Color shadowColor)
Parameters:
shadowColor - The drop shadow color to set. If no color is set then no drop shadow will be drawn.

getDropShadowOffsetY

public byte getDropShadowOffsetY()
Returns the vertical offset of the drop shadow.

Returns:
Returns the drop shadow offset

setDropShadowOffsetY

public void setDropShadowOffsetY(byte shadowOffsetY)
Set the vertical offset of the drop shadow. A positive offset causes the drop shadow to be drawn below the node. A negative offset causes the drop shadow to be drawn above the node.

Parameters:
shadowOffsetY - The drop shadow offset to set.

getDropShadowOffsetX

public byte getDropShadowOffsetX()
Returns the horizontal offset of the drop shadow.

Returns:
Returns the horizontal drop shadow offset.

setDropShadowOffsetX

public void setDropShadowOffsetX(byte shadowOffsetX)
Set the horizontal offset of the drop shadow. A positive offset causes the drop shadow to be drawn to the right of the node. A negative offset causes the drop shadow to be drawn to the left of the node.

Parameters:
shadowOffsetX - The shadow offset to set.

isDropShadowVisible

public boolean isDropShadowVisible()
Queries whether or not the drop shadow is visible. Visibility depends on the offset and color of the drop shadow.


paintNode

protected void paintNode(java.awt.Graphics2D gfx)
Paints the node. Internally, painting is performed by calling the following protected methods in the given order:
  1. paintHotSpots(Graphics2D) (only when selected)
  2. paintShadow(Graphics2D)
  3. paintFilledShape(Graphics2D)
  4. NodeRealizer.paintPorts(Graphics2D)
  5. NodeRealizer.paintText(Graphics2D)
  6. paintShapeBorder(Graphics2D)
If raised border painting is disabled, paintShapeBorder(Graphics2D) is called before NodeRealizer.paintPorts(Graphics2D) instead of after NodeRealizer.paintText(Graphics2D).

Specified by:
paintNode in class NodeRealizer

paintShapeBorder

protected void paintShapeBorder(java.awt.Graphics2D gfx)
Responsible for painting the border or outline of the shape of this realizer. This method is utilized by paintNode(Graphics2D gfx).


paintFilledShape

protected void paintFilledShape(java.awt.Graphics2D gfx)
Responsible for painting the filled shape of this realizer using a specific color or paint.


createSelectionColor

protected java.awt.Color createSelectionColor(java.awt.Color original)
Callback function that calculates/modifies a given Color instance for the selected use case.

Parameters:
original - the color to transform to for the selected case
Returns:
the new color

paint3DBorder

protected void paint3DBorder(java.awt.Graphics2D gfx,
                             boolean raised)
Responsible for painting a 3D border for a shape node of type RECT_3D. This method is utilized by method paintShapeBorder(java.awt.Graphics2D).

Parameters:
gfx - the graphics context to use
raised - a boolean that determines whether the surrounded rectangle appears to be raised above the surface or sunk into the surface.

paintShadow

protected void paintShadow(java.awt.Graphics2D gfx)
Paints a shadow for the shape node.


contains

public boolean contains(double x,
                        double y)
Evaluate hit test on the node realizer. When a node is transparent, only its boundary is evaluated for the hit test.

Overrides:
contains in class NodeRealizer
Parameters:
x - the x-coordinate of the point to check.
y - the y-coordinate of the point to check.
Returns:
true if the position (x,y) is part of the node false otherwise.

findIntersection

public boolean findIntersection(double ix,
                                double iy,
                                double ox,
                                double oy,
                                java.awt.geom.Point2D result)
Special Intersection handling for some types of shape. When shape is an ellipse or an rectangle, the intersection point is calculated, not iteratively determined.

Overrides:
findIntersection in class NodeRealizer
Parameters:
ix - the x-coordinate of a point inside the realizer's visual bounds.
iy - the y-coordinate of a point inside the realizer's visual bounds.
ox - the x-coordinate of a point outside the realizer's visual bounds.
oy - the y-coordinate of a point outside the realizer's visual bounds.
result - output parameter for the absolute world coordinates of the calculated intersection point.
Returns:
true if (ix,iy) lies inside and (ox,oy) lies outside this realizer's visual bounds; false otherwise.
See Also:
NodeRealizer.contains(double, double)

calcUnionRect

public void calcUnionRect(java.awt.geom.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 and its drop shadow.

Overrides:
calcUnionRect in class NodeRealizer

paintHotSpots

public void paintHotSpots(java.awt.Graphics2D gfx)
Description copied from class: NodeRealizer
Paints graphical hotspots around this realizer. The hotspots mark regions on which hit tests can be performed.

Overrides:
paintHotSpots in class NodeRealizer

hotSpotHit

public byte hotSpotHit(double hx,
                       double hy)
Adjusted hitSpotHit that takes drop shadows into account.

Overrides:
hotSpotHit in class NodeRealizer

write

public void write(java.io.ObjectOutputStream out)
           throws java.io.IOException
Deprecated. Use the GraphML format instead.

Writes this realizer in a serialized form to the given stream.

Overrides:
write in class NodeRealizer
Throws:
java.io.IOException

read

public void read(java.io.ObjectInputStream in)
          throws java.io.IOException,
                 java.lang.ClassNotFoundException
Deprecated. Use the GraphML format instead.

Reads in the serialized form of this realizer. The realizer must have been written out before by it's write(ObjectOutputStream) method.

Overrides:
read in class NodeRealizer
Throws:
java.io.IOException
java.lang.ClassNotFoundException

shapeTypeToStringMap

public static java.util.Map shapeTypeToStringMap()
Returns a map whose keys are the shape type specifiers wrapped in Byte objects. The value for each key is a String that describes the shape type.


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