Package diva.canvas.toolbox
Class LabelWrapper
- java.lang.Object
-
- diva.canvas.AbstractFigure
-
- diva.canvas.toolbox.LabelWrapper
-
- All Implemented Interfaces:
CanvasComponent
,Figure
,VisibleComponent
,UserObjectContainer
public class LabelWrapper extends AbstractFigure
A LabelWrapper is a figure that attaches a label to some other figure. The location at which the label is attached can (in this class) be set to the center or to any of the four edges or corners of the bounding box. (Maybe later we'll figure out a way to have the label locate at a site.) In addition, the anchor and padding attributes of the figure itself can be used to adjust the label location relative to the anchoring point on the main figure.Note that this class is intended for use in simple applications where a simple label is attached to something. For more complex applications, such as attaching multiple labels, you will need to implement your own class.
- Version:
- $Id$
- Author:
- John Reekie
-
-
Constructor Summary
Constructors Constructor Description LabelWrapper(Figure f, java.lang.String label)
Construct a new figure with the given child figure and the given string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.geom.Rectangle2D
getBounds()
Get the bounds of this figure.Figure
getChild()
Get the child figureLabelFigure
getLabel()
Get the label.java.awt.Shape
getShape()
Get the shape of this figure.boolean
hit(java.awt.geom.Rectangle2D r)
We are hit if either the child or the figure is hit.void
paint(java.awt.Graphics2D g)
Paint this figurevoid
setAnchor(int anchor)
Set the anchor of the label.void
transform(java.awt.geom.AffineTransform at)
Transform the figure with the supplied transform.-
Methods inherited from class diva.canvas.AbstractFigure
contains, getInteractor, getLayer, getOrigin, getParent, getToolTipText, getTransformContext, getUserObject, intersects, isVisible, paint, repaint, repaint, setInteractor, setParent, setToolTipText, setUserObject, setVisible, translate
-
-
-
-
Constructor Detail
-
LabelWrapper
public LabelWrapper(Figure f, java.lang.String label)
Construct a new figure with the given child figure and the given string.
-
-
Method Detail
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
Get the bounds of this figure.- Specified by:
getBounds
in interfaceFigure
- Overrides:
getBounds
in classAbstractFigure
- Returns:
- the bounding box of this figure.
-
getChild
public Figure getChild()
Get the child figure
-
getLabel
public LabelFigure getLabel()
Get the label. This can be used to adjust the label appearance, anchor, and so on.
-
getShape
public java.awt.Shape getShape()
Get the shape of this figure. This is the shape of the child figure only -- the label is not included in the shape.- Specified by:
getShape
in interfaceFigure
- Specified by:
getShape
in classAbstractFigure
- Returns:
- the outline shape of this figure
-
hit
public boolean hit(java.awt.geom.Rectangle2D r)
We are hit if either the child or the figure is hit.- Specified by:
hit
in interfaceFigure
- Overrides:
hit
in classAbstractFigure
- Parameters:
r
- The rectangle to be checked.- Returns:
- true if the figure is hit by the given rectangle.
-
paint
public void paint(java.awt.Graphics2D g)
Paint this figure- Specified by:
paint
in interfaceVisibleComponent
- Specified by:
paint
in classAbstractFigure
- Parameters:
g
- The 2D graphics object that this object it to be painted upon.
-
setAnchor
public void setAnchor(int anchor)
Set the anchor of the label. The anchor is the position on the child figure at which the label will be located. It can be any of the positioning constants defined in SwingConstants.
-
transform
public void transform(java.awt.geom.AffineTransform at)
Transform the figure with the supplied transform.- Specified by:
transform
in interfaceFigure
- Specified by:
transform
in classAbstractFigure
- Parameters:
at
- The transform to be used.
-
-