y.view
Class NodeLabel

java.lang.Object
  |
  +--y.view.YLabel
        |
        +--y.view.NodeLabel
All Implemented Interfaces:
LabelLayout, NodeLabelLayout

public class NodeLabel
extends YLabel
implements NodeLabelLayout

This class represents a label associated with a NodeRealizer.

NodeLabel has special label models and positions that are suitable for placing the label relative to a node.


Field Summary
static byte ANYWHERE
          Node label position specifier for label model NodeLabel.FREE.
static byte AUTOSIZE_CONTENT
          Autosize policy specifier.
static byte AUTOSIZE_NODE_HEIGHT
          Autosize policy specifier.
static byte AUTOSIZE_NODE_WIDTH
          Autosize policy specifier.
static byte BOTTOM
          Node label position specifier for label model NodeLabel.INTERNAL.
static byte BOTTOM_LEFT
          Node label position specifier for label model NodeLabel.INTERNAL.
static byte BOTTOM_RIGHT
          Node label position specifier for label model NodeLabel.INTERNAL.
static byte CENTER
          Node label position specifier for label model NodeLabel.INTERNAL.
static byte CENTER_X
          Node label position specifier for label model NodeLabel.INTERNAL.
static byte CORNERS
          Node label model specifier.
static byte DYNAMIC
          Node label position specifier for label model NodeLabel.EDGE_OPPOSITE.
static byte E
          Node label position specifier for label model NodeLabel.SIDES and NodeLabel.EIGHT_POS.
static byte EDGE_OPPOSITE
          Node label model specifier.
static byte EIGHT_POS
          Node label model specifier.
static byte FREE
          Node label model specifier.
static byte INTERNAL
          Node label model specifier.
static byte LEFT
          Node label position specifier for label model NodeLabel.INTERNAL.
static byte N
          Node label position specifier for label model NodeLabel.SIDES, NodeLabel.SANDWICH and NodeLabel.EIGHT_POS.
static byte NE
          Node label position specifier for label model NodeLabel.CORNERS and NodeLabel.EIGHT_POS.
static byte NW
          Node label position specifier for label model NodeLabel.CORNERS and NodeLabel.EIGHT_POS.
static byte RIGHT
          Node label position specifier for label model NodeLabel.INTERNAL.
static byte S
          Node label position specifier for label model NodeLabel.SIDES, NodeLabel.SANDWICH and NodeLabel.EIGHT_POS.
static byte SANDWICH
          Node label model specifier.
static byte SE
          Node label position specifier for label model NodeLabel.CORNERS and NodeLabel.EIGHT_POS.
static byte SIDES
          Node label model specifier.
static byte SW
          Node label position specifier for label model NodeLabel.CORNERS and NodeLabel.EIGHT_POS.
static byte TOP
          Node label position specifier for label model NodeLabel.INTERNAL.
static byte TOP_LEFT
          Node label position specifier for label model NodeLabel.INTERNAL.
static byte TOP_RIGHT
          Node label position specifier for label model NodeLabel.INTERNAL.
static byte UNDEFINED
          Dummy node label position specifier.
static byte W
          Node label position specifier for label model NodeLabel.SIDES and NodeLabel.EIGHT_POS.
 
Fields inherited from class y.view.YLabel
ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, defaultInsets, height, model, offsetDirty, offsetX, offsetY, placement, sizeDirty, width
 
Constructor Summary
NodeLabel()
          Instantiates a new NodeLabel.
NodeLabel(String str)
          Instantiates a new NodeLabel with the given text and centered label position.
NodeLabel(String st, byte mode)
          Instantiates a new NodeLabel with a given text and model.
 
Method Summary
 void adoptValues(YLabel label)
          Adopts the values from the given label.
static Vector availablePositions(Byte model)
          Returns a vector of all valid positions for the given model The positions are wrapped in Byte objects.
 void bindRealizer(NodeRealizer r)
          Binds the given node realizer to this label.
 void calculateOffset()
          Calculates the offset of this label.
 void calculateSize(FontRenderContext frc)
          Calculates the size of this label with the help of the given FontRenderContext.
 void calcUnionRect(Rectangle2D r)
          Enlarges the given rectangle such that it will contain the bounding box of this label
 Object clone()
          Creates an unbound copy of this NodeLabel.
 byte getAutoSizePolicy()
          Returns the currently set autosize policy for this label.
 YRectangle getBox()
          NodeLabelLayout implementation.
 double getDistance()
          Returns the distance of the label to the node.
 Graph2D getGraph2D()
          Returns the graph this node label is bound to.
 NodeLabelModel getLabelModel()
          NodeLabelModel implementation.
 YPoint getLocation()
          Returns the absolute coordinates of the labels location.
 Object getModelParameter()
          NodeLabelModel implementation.
static byte[] getModelPositions(byte model)
          Returns a byte array containing all valid positions for the given model specifier.
 Node getNode()
          Returns the node that is bound to this node label
 byte getPosition()
          Returns the position of this label.
 NodeRealizer getRealizer()
          Returns the node realizer that is bound to this node label
 boolean hasFreePositioning()
          Whether of not the label has a free position, i.e. one that is solely dictated by the offset coordinates.
 boolean intersects(double x, double y, double width, double height)
          Returns true iff the bounding box of this label intersects with the given box.
 boolean isOffsetDirty()
          Returns true if the label offset is not valid yet.
static Map modelToStringMap()
          Returns a map that whose keys are the known label model specifiers wrapped in Byte objects.
static Map positionToStringMap()
          Returns a map that whose keys are the known label position specifiers wrapped in Byte objects.
 void read(ObjectInputStream in)
          Reads in the serialized form of this label.
 void setAutoSizePolicy(byte autoSize)
          Sets the autosize policy for this label.
 void setDistance(double _distance)
          Sets the distance of the label to the node.
 void setFreeOffset(double x, double y)
          Sets the free offset for this label.
 void setLabelModel(NodeLabelModel m)
          Sets the NodeLabelModel implementation.
 void setModel(byte mo)
          Set the label model.
 void setModelParameter(Object param)
          NodeLabelModel implementation.
 void setOffset(double x, double y)
          Sets the offset coordinats of this label.
 void setOffsetDirty()
          Marks the label offsets as dirty.
 void setPosition(byte p)
          Sets the position of this label.
 void setText(String text)
          Sets the text of this node label.
 void write(ObjectOutputStream out)
          Writes out this label in a serialized form.
 
Methods inherited from class y.view.YLabel
calculateSize, getAlignment, getBackgroundColor, getFont, getFontName, getFontSize, getFontStyle, getHeight, getIcon, getInsets, getLineColor, getModel, getOffsetX, getOffsetY, getText, getTextColor, getTextLocation, getWidth, isBackgroundOn, isBackgroundPainted, isSizeDirty, isVisible, paint, setAlignment, setBackground, setBackgroundColor, setBackgroundPainted, setFont, setFontName, setFontSize, setFontStyle, setIcon, setInsets, setLineColor, setOffsetX, setOffsetY, setOldStyleDrawer, setSize, setSizeDirty, setTextColor, setVisible, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CENTER

public static final byte CENTER
Node label position specifier for label model NodeLabel.INTERNAL. Places the label in the center of the node.

See Also:
Constant Field Values

BOTTOM

public static final byte BOTTOM
Node label position specifier for label model NodeLabel.INTERNAL. Places the label inside the node at the bottom of it.

See Also:
Constant Field Values

TOP

public static final byte TOP
Node label position specifier for label model NodeLabel.INTERNAL. Places the label inside the node at the top of it.

See Also:
Constant Field Values

TOP_LEFT

public static final byte TOP_LEFT
Node label position specifier for label model NodeLabel.INTERNAL. Places the label in the top left corner of a node.

See Also:
Constant Field Values

TOP_RIGHT

public static final byte TOP_RIGHT
Node label position specifier for label model NodeLabel.INTERNAL. Places the label in the top right corner of a node.

See Also:
Constant Field Values

BOTTOM_LEFT

public static final byte BOTTOM_LEFT
Node label position specifier for label model NodeLabel.INTERNAL. Places the label in the bottom left corner of a node.

See Also:
Constant Field Values

BOTTOM_RIGHT

public static final byte BOTTOM_RIGHT
Node label position specifier for label model NodeLabel.INTERNAL. Places the label in the bottom right corner of a node.

See Also:
Constant Field Values

LEFT

public static final byte LEFT
Node label position specifier for label model NodeLabel.INTERNAL. Places the label inside the node to the left of it.

See Also:
Constant Field Values

RIGHT

public static final byte RIGHT
Node label position specifier for label model NodeLabel.INTERNAL. Places the label inside the node at the right of it.

See Also:
Constant Field Values

CENTER_X

public static final byte CENTER_X
Node label position specifier for label model NodeLabel.INTERNAL. UNCLEAR YET.

See Also:
Constant Field Values

NW

public static final byte NW
Node label position specifier for label model NodeLabel.CORNERS and NodeLabel.EIGHT_POS. Places the label north west of the node.

See Also:
Constant Field Values

NE

public static final byte NE
Node label position specifier for label model NodeLabel.CORNERS and NodeLabel.EIGHT_POS. Places the label north east of the node.

See Also:
Constant Field Values

SE

public static final byte SE
Node label position specifier for label model NodeLabel.CORNERS and NodeLabel.EIGHT_POS. Places the label south east of the node.

See Also:
Constant Field Values

SW

public static final byte SW
Node label position specifier for label model NodeLabel.CORNERS and NodeLabel.EIGHT_POS. Places the label south west of the node.

See Also:
Constant Field Values

N

public static final byte N
Node label position specifier for label model NodeLabel.SIDES, NodeLabel.SANDWICH and NodeLabel.EIGHT_POS. Places the label north of the node.

See Also:
Constant Field Values

S

public static final byte S
Node label position specifier for label model NodeLabel.SIDES, NodeLabel.SANDWICH and NodeLabel.EIGHT_POS. Places the label south of the node.

See Also:
Constant Field Values

E

public static final byte E
Node label position specifier for label model NodeLabel.SIDES and NodeLabel.EIGHT_POS. Places the label east of the node.

See Also:
Constant Field Values

W

public static final byte W
Node label position specifier for label model NodeLabel.SIDES and NodeLabel.EIGHT_POS. Places the label west of the node.

See Also:
Constant Field Values

DYNAMIC

public static final byte DYNAMIC
Node label position specifier for label model NodeLabel.EDGE_OPPOSITE. Places the label dynamically.

See Also:
Constant Field Values

ANYWHERE

public static final byte ANYWHERE
Node label position specifier for label model NodeLabel.FREE. Places the label at an arbitrary position.

See Also:
Constant Field Values

UNDEFINED

public static final byte UNDEFINED
Dummy node label position specifier.

See Also:
Constant Field Values

CORNERS

public static final byte CORNERS
Node label model specifier. This model places the labels at the corner locations around the node. It accepts NodeLabel.NW, NodeLabel.NE, NodeLabel.SE, NodeLabel.SW as valid positions.

See Also:
Constant Field Values

INTERNAL

public static final byte INTERNAL
Node label model specifier. This model places the labels inside the node. It accepts NodeLabel.CENTER, NodeLabel.BOTTOM, NodeLabel.TOP, NodeLabel.LEFT, NodeLabel.RIGHT, NodeLabel.TOP_LEFT, NodeLabel.TOP_RIGHT, NodeLabel.BOTTOM_LEFT, NodeLabel.BOTTOM_RIGHT and NodeLabel.CENTER_X as valid positions.

See Also:
Constant Field Values

SANDWICH

public static final byte SANDWICH
Node label model specifier. This model places the labels above or below the node. It accepts NodeLabel.N and NodeLabel.S as valid positions.

See Also:
Constant Field Values

SIDES

public static final byte SIDES
Node label model specifier. This model places the labels at the side locations around the node. It accepts NodeLabel.N, NodeLabel.E, NodeLabel.S, NodeLabel.W as valid positions.

See Also:
Constant Field Values

FREE

public static final byte FREE
Node label model specifier. This model places the labels by a specified offset. It accepts NodeLabel.ANYWHERE as valid position.

See Also:
Constant Field Values

EIGHT_POS

public static final byte EIGHT_POS
Node label model specifier. This model places the labels at the corner and side locations around the node. It accepts all positions valid for the models NodeLabel.SIDES and NodeLabel.CORNERS

See Also:
Constant Field Values

EDGE_OPPOSITE

public static final byte EDGE_OPPOSITE
Node label model specifier. This model places the label such that it lies opposite of the directional vector defined by the sum of all adjacent edges of the node.

See Also:
Constant Field Values

AUTOSIZE_CONTENT

public static final byte AUTOSIZE_CONTENT
Autosize policy specifier. Indicates that the size of the label should be determined by the size of its text and icon.

See Also:
Constant Field Values

AUTOSIZE_NODE_WIDTH

public static final byte AUTOSIZE_NODE_WIDTH
Autosize policy specifier. Indicates that the width of the label should be at least the width of the node that owns the label. The height of the label will be determined by the height of the text and icon.

See Also:
Constant Field Values

AUTOSIZE_NODE_HEIGHT

public static final byte AUTOSIZE_NODE_HEIGHT
Autosize policy specifier. Indicates that the height of the label should be at least the height of the node that owns the label. The width of the label will be determined by the width of the text and icon.

See Also:
Constant Field Values
Constructor Detail

NodeLabel

public NodeLabel(String st,
                 byte mode)
Instantiates a new NodeLabel with a given text and model. Default for external is north west. Default for internal is center.


NodeLabel

public NodeLabel(String str)
Instantiates a new NodeLabel with the given text and centered label position.


NodeLabel

public NodeLabel()
Instantiates a new NodeLabel.

Method Detail

clone

public Object clone()
Creates an unbound copy of this NodeLabel.

Overrides:
clone in class Object

adoptValues

public void adoptValues(YLabel label)
Adopts the values from the given label.

Overrides:
adoptValues in class YLabel

setOffset

public void setOffset(double x,
                      double y)
Sets the offset coordinats of this label. Setting the offset directly does only make sense if a free placement model is active.

Overrides:
setOffset in class YLabel

setOffsetDirty

public void setOffsetDirty()
Description copied from class: YLabel
Marks the label offsets as dirty.

Overrides:
setOffsetDirty in class YLabel

setAutoSizePolicy

public void setAutoSizePolicy(byte autoSize)
Sets the autosize policy for this label. By default NodeLabel.AUTOSIZE_CONTENT is set.

Parameters:
autoSize - one of the specifiers NodeLabel.AUTOSIZE_CONTENT, NodeLabel.AUTOSIZE_NODE_WIDTH or NodeLabel.AUTOSIZE_NODE_HEIGHT.

getAutoSizePolicy

public byte getAutoSizePolicy()
Returns the currently set autosize policy for this label.

See Also:
NodeLabel.setAutoSizePolicy(byte).

calculateSize

public void calculateSize(FontRenderContext frc)
Description copied from class: YLabel
Calculates the size of this label with the help of the given FontRenderContext.

Overrides:
calculateSize in class YLabel

setText

public void setText(String text)
Sets the text of this node label. If this label is bound to a Graph2D the a Graph2DEvent with this label as the subject will be emitted to all registered Graph2DListeners.

Overrides:
setText in class YLabel

setDistance

public void setDistance(double _distance)
Sets the distance of the label to the node.


getDistance

public double getDistance()
Returns the distance of the label to the node.


getLabelModel

public NodeLabelModel getLabelModel()
NodeLabelModel implementation. Returns the node label model used.

Specified by:
getLabelModel in interface NodeLabelLayout

setLabelModel

public void setLabelModel(NodeLabelModel m)
Sets the NodeLabelModel implementation.


getModelParameter

public Object getModelParameter()
NodeLabelModel implementation. Returns the current parameters for the node label model.

Specified by:
getModelParameter in interface LabelLayout

setModelParameter

public void setModelParameter(Object param)
NodeLabelModel implementation. Sets the current parameters for the node label model.

Specified by:
setModelParameter in interface LabelLayout
Specified by:
setModelParameter in class YLabel

setModel

public void setModel(byte mo)
Set the label model. If the current positioning is not part of new model, a valid default positioning will be used.

Overrides:
setModel in class YLabel

hasFreePositioning

public boolean hasFreePositioning()
Whether of not the label has a free position, i.e. one that is solely dictated by the offset coordinates.


setPosition

public void setPosition(byte p)
Sets the position of this label. The given position has to be valid in the current label model.

Overrides:
setPosition in class YLabel

getPosition

public byte getPosition()
Returns the position of this label.

Overrides:
getPosition in class YLabel

setFreeOffset

public void setFreeOffset(double x,
                          double y)
Sets the free offset for this label. The model of this node must be NodeLabel.FREE.


getLocation

public YPoint getLocation()
Returns the absolute coordinates of the labels location.

Specified by:
getLocation in class YLabel

modelToStringMap

public static Map modelToStringMap()
Returns a map that whose keys are the known label model specifiers wrapped in Byte objects. The value for each key is a String respresentation of the specifier.


positionToStringMap

public static Map positionToStringMap()
Returns a map that whose keys are the known label position specifiers wrapped in Byte objects. The value for each key is a String respresentation of the specifier.


getModelPositions

public static byte[] getModelPositions(byte model)
Returns a byte array containing all valid positions for the given model specifier.


availablePositions

public static Vector availablePositions(Byte model)
Returns a vector of all valid positions for the given model The positions are wrapped in Byte objects.


isOffsetDirty

public boolean isOffsetDirty()
Returns true if the label offset is not valid yet.

Overrides:
isOffsetDirty in class YLabel

calculateOffset

public void calculateOffset()
Description copied from class: YLabel
Calculates the offset of this label.

Specified by:
calculateOffset in class YLabel

getNode

public Node getNode()
Returns the node that is bound to this node label


getRealizer

public NodeRealizer getRealizer()
Returns the node realizer that is bound to this node label


getGraph2D

public Graph2D getGraph2D()
Returns the graph this node label is bound to.


bindRealizer

public void bindRealizer(NodeRealizer r)
Binds the given node realizer to this label.


getBox

public YRectangle getBox()
NodeLabelLayout implementation. Returns the bounding box of this label.

Specified by:
getBox in interface LabelLayout
Specified by:
getBox in class YLabel

intersects

public boolean intersects(double x,
                          double y,
                          double width,
                          double height)
Description copied from class: YLabel
Returns true iff the bounding box of this label intersects with the given box.

Overrides:
intersects in class YLabel

calcUnionRect

public void calcUnionRect(Rectangle2D r)
Description copied from class: YLabel
Enlarges the given rectangle such that it will contain the bounding box of this label

Overrides:
calcUnionRect in class YLabel

write

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

Overrides:
write in class YLabel
IOException

read

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

Overrides:
read in class YLabel
IOException
ClassNotFoundException

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

2003