JHotDraw 7.0.9

org.jhotdraw.draw
Class LabeledLineConnectionFigure

java.lang.Object
  extended by org.jhotdraw.draw.AbstractFigure
      extended by org.jhotdraw.draw.AbstractAttributedFigure
          extended by org.jhotdraw.draw.BezierFigure
              extended by org.jhotdraw.draw.LineFigure
                  extended by org.jhotdraw.draw.LineConnectionFigure
                      extended by org.jhotdraw.draw.LabeledLineConnectionFigure
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, CompositeFigure, ConnectionFigure, Figure, DOMStorable

public class LabeledLineConnectionFigure
extends LineConnectionFigure
implements CompositeFigure

A LineConnection with labels.

Usage:

 LineConnectionFigure lcf = new LineConnectionFigure();
 lcf.setLayouter(new LocatorLayouter());
 TextFigure label = new TextFigure();
 label.setText("Hello");
 LocatorLayouter.LAYOUT_LOCATOR.set(label, new BezierLabelLocator(0, -Math.PI / 4, 8));
 lcf.add(label);
 

Version:
1.1 2006-02-14 Do not include labels in logical bounds.
1.0 23. Januar 2006 Created.
Author:
Werner Randelshofer
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jhotdraw.draw.BezierFigure
path
 
Fields inherited from class org.jhotdraw.draw.AbstractFigure
changingDepth, listenerList
 
Fields inherited from interface org.jhotdraw.draw.CompositeFigure
LAYOUT_INSETS
 
Constructor Summary
LabeledLineConnectionFigure()
          Creates a new instance.
 
Method Summary
 void add(Figure figure)
          Adds a child to the figure.
 void add(int index, Figure figure)
          Adds a child to the figure at the specified index.
 void addNotify(Drawing drawing)
          This method is invoked, when the Figure is being removed from a Drawing.
 void basicAdd(Figure figure)
          Adds a child to the figure without firing events.
 void basicAdd(int index, Figure figure)
          Adds a child to the figure at the specified index without firing events.
 boolean basicRemove(Figure figure)
          Removes the specified child without firing events.
 void basicRemoveAllChildren()
          Removes all children from the composite figure without firing events.
 Figure basicRemoveChild(int index)
          Removes the child at the specified index without firing events.
 LabeledLineConnectionFigure clone()
          Informs that a figure changed the area of its display box.
 boolean contains(java.awt.geom.Point2D.Double p)
          Checks if a point is contained by the figure.
 void draw(java.awt.Graphics2D g)
          Draw the figure.
 Figure findFigureInside(java.awt.geom.Point2D.Double p)
          Returns the figure that contains the given point.
 java.awt.geom.Rectangle2D.Double getBounds()
          Returns the untransformed logicalbounds of the figure as a Rectangle.
 Figure getChild(int index)
          Returns the child figure at the specified index.
 int getChildCount()
          Returns the number of children.
 java.util.List<Figure> getChildren()
          Returns an unchangeable list view on the children.
 java.util.List<Figure> getChildrenFrontToBack()
          Returns an iterator to iterate in Z-order front to back over the children.
 java.awt.geom.Rectangle2D.Double getDrawingArea()
          Returns the drawing area of the figure as a Rectangle.
 Layouter getLayouter()
          Get a Layouter object which encapsulated a layout algorithm for this figure.
 void invalidate()
          Informs that a figure needs to be redrawn.
protected  void invalidateBounds()
           
 void layout()
          A layout algorithm is used to define how the child components should be laid out in relation to each other.
 void remap(java.util.HashMap<Figure,Figure> oldToNew)
           
 boolean remove(Figure figure)
          Removes the specified child.
 void removeAllChildren()
          Removes all children from the composite figure.
 Figure removeChild(int index)
          Removes the child at the specified index.
 void removeNotify(Drawing drawing)
          This method is invoked, when the Figure is being removed from a Drawing.
 void set(int index, Figure child)
           
 void setAttribute(AttributeKey key, java.lang.Object newValue)
          Sets an attribute of the figure.
 void setBounds(java.awt.geom.Point2D.Double anchor, java.awt.geom.Point2D.Double lead)
          Sets the location of the first and the last BezierPath.Node of the BezierFigure.
 void setLayouter(Layouter newLayouter)
          Set a Layouter object which encapsulated a layout algorithm for this figure.
 void transform(java.awt.geom.AffineTransform tx)
          Transforms the figure.
 void updateConnection()
          Updates the start and end point of the figure and fires figureChanged events.
 void validate()
           
 
Methods inherited from class org.jhotdraw.draw.LineConnectionFigure
canConnect, canConnect, canConnect, createHandles, getBezierPath, getEndConnector, getEndFigure, getLiner, getStartConnector, getStartFigure, handleConnect, handleDisconnect, handleMouseClick, lineout, read, readLiner, readPoints, remap, reverseConnection, setEndConnector, setEndPoint, setLiner, setNode, setPoint, setStartConnector, setStartPoint, write, writeLiner, writePoints
 
Methods inherited from class org.jhotdraw.draw.BezierFigure
addNode, addNode, chop, drawCaps, drawFill, drawStroke, findCompatibleConnector, findConnector, findNode, findSegment, getCappedPath, getCenter, getEndPoint, getNode, getNodeCount, getOutermostPoint, getPoint, getPoint, getPointOnPath, getStartPoint, getTransformRestoreData, isClosed, joinSegments, joinSegments, removeAllNodes, removeNode, restoreTransformTo, setBezierPath, setClosed, setPoint, splitSegment, splitSegment
 
Methods inherited from class org.jhotdraw.draw.AbstractAttributedFigure
applyAttributesTo, drawText, getAttribute, getAttributeKey, getAttributes, getAttributesRestoreData, getStroke, getStrokeMiterLimitFactor, hasAttribute, isAttributeEnabled, readAttributes, removeAttribute, restoreAttributesTo, setAttributeEnabled, setAttributes, writeAttributes
 
Methods inherited from class org.jhotdraw.draw.AbstractFigure
addFigureListener, basicClone, changed, fireAreaInvalidated, fireAreaInvalidated, fireAttributeChanged, fireFigureAdded, fireFigureChanged, fireFigureChanged, fireFigureChanged, fireFigureHandlesChanged, fireFigureRemoved, fireFigureRequestRemove, fireUndoableEditHappened, getActions, getChangingDepth, getConnectors, getCursor, getDecomposition, getDrawing, getFontRenderContext, getLayer, getLock, getPreferredSize, getTool, getToolTipText, handleDrop, includes, isChanging, isInteractive, isVisible, removeFigureListener, requestRemove, setBounds, setInteractive, setVisible, toString, willChange
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jhotdraw.draw.Figure
addFigureListener, canConnect, changed, createHandles, findCompatibleConnector, findConnector, getActions, getAttribute, getAttributes, getAttributesRestoreData, getConnectors, getCursor, getDecomposition, getEndPoint, getLayer, getPreferredSize, getStartPoint, getTool, getToolTipText, getTransformRestoreData, handleDrop, handleMouseClick, includes, isInteractive, isVisible, remap, removeFigureListener, requestRemove, restoreAttributesTo, restoreTransformTo, setVisible, willChange
 
Methods inherited from interface org.jhotdraw.xml.DOMStorable
read, write
 
Methods inherited from interface org.jhotdraw.draw.ConnectionFigure
getEndPoint, getNode, getNodeCount, getPoint, getStartPoint
 

Constructor Detail

LabeledLineConnectionFigure

public LabeledLineConnectionFigure()
Creates a new instance.

Method Detail

draw

public void draw(java.awt.Graphics2D g)
Draw the figure. This method is delegated to the encapsulated presentation figure.

Specified by:
draw in interface Figure
Overrides:
draw in class AbstractAttributedFigure
Parameters:
g - The Graphics2D to draw to.

transform

public void transform(java.awt.geom.AffineTransform tx)
Transforms the figure.

Specified by:
transform in interface Figure
Overrides:
transform in class LineConnectionFigure
Parameters:
tx - The transformation.
See Also:
Figure.getTransformRestoreData(), Figure.restoreTransformTo(java.lang.Object)

setBounds

public void setBounds(java.awt.geom.Point2D.Double anchor,
                      java.awt.geom.Point2D.Double lead)
Description copied from class: BezierFigure
Sets the location of the first and the last BezierPath.Node of the BezierFigure. If the BezierFigure has not at least two nodes, nodes are added to the figure until the BezierFigure has at least two nodes.

Specified by:
setBounds in interface Figure
Overrides:
setBounds in class BezierFigure
Parameters:
anchor - the start point of the bounds
lead - the end point of the bounds
See Also:
Figure.getBounds()

getBounds

public java.awt.geom.Rectangle2D.Double getBounds()
Description copied from interface: Figure
Returns the untransformed logicalbounds of the figure as a Rectangle. The handle bounds are used by Handle objects for adjusting the figure and for aligning the figure on a grid.

Specified by:
getBounds in interface Figure
Overrides:
getBounds in class BezierFigure

getDrawingArea

public java.awt.geom.Rectangle2D.Double getDrawingArea()
Description copied from interface: Figure
Returns the drawing area of the figure as a Rectangle. The drawing area is used to improve the performance of GraphicView, for example for clipping of repaints and for clipping of mouse events.

The drawing area needs to be large enough, to take line width, line caps and other decorations into account that exceed the bounds of the Figure.

Specified by:
getDrawingArea in interface Figure
Overrides:
getDrawingArea in class BezierFigure

contains

public boolean contains(java.awt.geom.Point2D.Double p)
Description copied from interface: Figure
Checks if a point is contained by the figure.

This is used for hit testing by Tool's.

Specified by:
contains in interface Figure
Overrides:
contains in class BezierFigure

invalidateBounds

protected void invalidateBounds()

setAttribute

public void setAttribute(AttributeKey key,
                         java.lang.Object newValue)
Sets an attribute of the figure. AttributeKey name and semantics are defined by the class implementing the figure interface.

Specified by:
setAttribute in interface Figure
Overrides:
setAttribute in class BezierFigure
See Also:
AttributeKey.basicSet(org.jhotdraw.draw.Figure, T)

findFigureInside

public Figure findFigureInside(java.awt.geom.Point2D.Double p)
Description copied from interface: Figure
Returns the figure that contains the given point.

Specified by:
findFigureInside in interface Figure
Overrides:
findFigureInside in class AbstractFigure

updateConnection

public void updateConnection()
Description copied from interface: ConnectionFigure
Updates the start and end point of the figure and fires figureChanged events.

Specified by:
updateConnection in interface ConnectionFigure
Overrides:
updateConnection in class LineConnectionFigure

getChildren

public java.util.List<Figure> getChildren()
Description copied from interface: CompositeFigure
Returns an unchangeable list view on the children.

Specified by:
getChildren in interface CompositeFigure

getChildCount

public int getChildCount()
Description copied from interface: CompositeFigure
Returns the number of children.

Specified by:
getChildCount in interface CompositeFigure

getChild

public Figure getChild(int index)
Description copied from interface: CompositeFigure
Returns the child figure at the specified index.

Specified by:
getChild in interface CompositeFigure

set

public void set(int index,
                Figure child)

getChildrenFrontToBack

public java.util.List<Figure> getChildrenFrontToBack()
Returns an iterator to iterate in Z-order front to back over the children.


add

public void add(Figure figure)
Description copied from interface: CompositeFigure
Adds a child to the figure. This is a convenience method for add(getChildCount(), child);

Specified by:
add in interface CompositeFigure

add

public void add(int index,
                Figure figure)
Description copied from interface: CompositeFigure
Adds a child to the figure at the specified index.

Specified by:
add in interface CompositeFigure

basicAdd

public void basicAdd(Figure figure)
Description copied from interface: CompositeFigure
Adds a child to the figure without firing events. This is a convenience method for basicAdd(getChildCount(), child);

Specified by:
basicAdd in interface CompositeFigure

basicAdd

public void basicAdd(int index,
                     Figure figure)
Description copied from interface: CompositeFigure
Adds a child to the figure at the specified index without firing events.

Specified by:
basicAdd in interface CompositeFigure

remove

public boolean remove(Figure figure)
Description copied from interface: CompositeFigure
Removes the specified child. Returns true, if the Figure contained the removed child.

Specified by:
remove in interface CompositeFigure

removeChild

public Figure removeChild(int index)
Description copied from interface: CompositeFigure
Removes the child at the specified index. Returns the removed child figure.

Specified by:
removeChild in interface CompositeFigure

basicRemove

public boolean basicRemove(Figure figure)
Description copied from interface: CompositeFigure
Removes the specified child without firing events. Returns true, if the Figure contained the removed child.

Specified by:
basicRemove in interface CompositeFigure

basicRemoveChild

public Figure basicRemoveChild(int index)
Description copied from interface: CompositeFigure
Removes the child at the specified index without firing events. Returns the removed child figure.

Specified by:
basicRemoveChild in interface CompositeFigure

removeAllChildren

public void removeAllChildren()
Description copied from interface: CompositeFigure
Removes all children from the composite figure.

Specified by:
removeAllChildren in interface CompositeFigure

basicRemoveAllChildren

public void basicRemoveAllChildren()
Description copied from interface: CompositeFigure
Removes all children from the composite figure without firing events.

Specified by:
basicRemoveAllChildren in interface CompositeFigure

getLayouter

public Layouter getLayouter()
Get a Layouter object which encapsulated a layout algorithm for this figure. Typically, a Layouter accesses the child components of this figure and arranges their graphical presentation.

Specified by:
getLayouter in interface CompositeFigure
Returns:
layout strategy used by this figure

setLayouter

public void setLayouter(Layouter newLayouter)
Description copied from interface: CompositeFigure
Set a Layouter object which encapsulated a layout algorithm for this figure. Typically, a Layouter accesses the child components of this figure and arranges their graphical presentation. It is a good idea to set the Layouter in the protected initialize() method so it can be recreated if a GraphicalCompositeFigure is read and restored from a StorableInput stream.

Specified by:
setLayouter in interface CompositeFigure
Parameters:
newLayouter - encapsulation of a layout algorithm.

layout

public void layout()
A layout algorithm is used to define how the child components should be laid out in relation to each other. The task for layouting the child components for presentation is delegated to a Layouter which can be plugged in at runtime.

Specified by:
layout in interface CompositeFigure
Overrides:
layout in class BezierFigure

invalidate

public void invalidate()
Description copied from class: AbstractFigure
Informs that a figure needs to be redrawn.

Specified by:
invalidate in interface Figure
Overrides:
invalidate in class BezierFigure

validate

public void validate()
Overrides:
validate in class LineConnectionFigure

addNotify

public void addNotify(Drawing drawing)
Description copied from class: LineConnectionFigure
This method is invoked, when the Figure is being removed from a Drawing. This method invokes handleConnect, if the Figure is connected.

Specified by:
addNotify in interface Figure
Overrides:
addNotify in class LineConnectionFigure
See Also:
LineConnectionFigure.handleConnect(org.jhotdraw.draw.Connector, org.jhotdraw.draw.Connector)

removeNotify

public void removeNotify(Drawing drawing)
Description copied from class: LineConnectionFigure
This method is invoked, when the Figure is being removed from a Drawing. This method invokes handleDisconnect, if the Figure is connected.

Specified by:
removeNotify in interface Figure
Overrides:
removeNotify in class LineConnectionFigure
See Also:
LineConnectionFigure.handleDisconnect(org.jhotdraw.draw.Connector, org.jhotdraw.draw.Connector)

clone

public LabeledLineConnectionFigure clone()
Informs that a figure changed the area of its display box. / public void changed() { if (isChangingCount == 1) { super.changed(); layout(); fireFigureChanged(getDrawingArea()); } else { invalidateBounds(); } isChangingCount--; }

Specified by:
clone in interface Figure
Overrides:
clone in class LineConnectionFigure

remap

public void remap(java.util.HashMap<Figure,Figure> oldToNew)
Overrides:
remap in class AbstractFigure

Copyright 1996-2007 (c) JHotDraw.org.
Some rights reserved.