net.sf.vex.layout
Class ShapeBox

java.lang.Object
  |
  +--net.sf.vex.layout.AbstractBox
        |
        +--net.sf.vex.layout.ShapeBox
All Implemented Interfaces:
Box, InlineBox

public class ShapeBox
extends AbstractBox
implements InlineBox

An inline box that draws a shape.


Nested Class Summary
 
Nested classes inherited from class net.sf.vex.layout.InlineBox
InlineBox.Pair
 
Constructor Summary
ShapeBox(java.awt.Shape shape, int padding)
          Class constructor.
 
Method Summary
 boolean canBreakAtEnd()
          Returns true if a line break can occur after this box.
 int getBaseline()
          Returns the distance from the top of the inline box to the baseline.
 java.awt.Color getFillColor()
          Returns the color used to fill the shape, or null if the shape is not to be filled.
 java.awt.Color getLineColor()
          Returns the color used to draw the lines of the shape, or null if the lines are not to be drawn.
 int getPadding()
          Returns the padding around the shape.
 java.awt.Shape getShape()
          Returns the shape to be drawn.
 java.awt.Stroke getStroke()
          Returns the stroke used to draw the shape's lines.
 boolean isAntiAliased()
          Returns true if the shape is to be drawn using anti-aliasing.
 void paint(LayoutContext context, int x, int y)
          Draws the box's content in the given Graphics context.
 void setAntiAliased(boolean antiAliased)
          Sets whether to draw the shape using anti-aliasing.
 void setFillColor(java.awt.Color color)
          Sets the fill color for the shape.
 void setLineColor(java.awt.Color color)
          Sets the line color for the shape.
 void setStroke(java.awt.Stroke stroke)
          Sets the stroke with which the shape is to be drawn.
 InlineBox.Pair split(LayoutContext context, int maxWidth, boolean force)
          Splits this inline box into two.
 java.lang.String toString()
           
 
Methods inherited from class net.sf.vex.layout.AbstractBox
containsOffset, getCaretShapes, getChildren, getElement, getEndOffset, getHeight, getStartOffset, getWidth, getX, getY, hasContent, setHeight, setWidth, setX, setY, skipPaint, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.vex.layout.Box
containsOffset, getCaretShapes, getChildren, getElement, getEndOffset, getHeight, getStartOffset, getWidth, getX, getY, hasContent, setX, setY, viewToModel
 

Constructor Detail

ShapeBox

public ShapeBox(java.awt.Shape shape,
                int padding)
Class constructor.

Parameters:
shape - shape to draw
padding - padding to be applied around the shape
Method Detail

canBreakAtEnd

public boolean canBreakAtEnd()
Description copied from interface: InlineBox
Returns true if a line break can occur after this box. For example, this would be true for text boxes that end with a space.

Specified by:
canBreakAtEnd in interface InlineBox
See Also:
InlineBox.canBreakAtEnd()

getBaseline

public int getBaseline()
Description copied from interface: InlineBox
Returns the distance from the top of the inline box to the baseline.

Specified by:
getBaseline in interface InlineBox
See Also:
InlineBox.getBaseline()

split

public InlineBox.Pair split(LayoutContext context,
                            int maxWidth,
                            boolean force)
Description copied from interface: InlineBox
Splits this inline box into two. If force is false, this method should find a natural split point (e.g. after a space) and return two boxes representing a split at that point. The width of the last box must not exceed maxWidth. If no such natural split exists, null should be returned as the left box and this returned as the right box.

If force is true, it means we are adding the first inline box to a line, therefore we must return something as the left box. In some cases, we may find a suboptimal split (e.g. between characters) that satisfies this. In other cases, this should be returned as the left box even though it exceeds maxWidth.

In both cases, the right box should contain null if this box fits into maxWidth

Specified by:
split in interface InlineBox
Parameters:
context - the layout context to be used.
maxWidth - Maximum width of the left part of the box.
force - if true, force a suboptimal split
See Also:
InlineBox.split(net.sf.vex.layout.LayoutContext, int, boolean)

isAntiAliased

public boolean isAntiAliased()
Returns true if the shape is to be drawn using anti-aliasing.


paint

public void paint(LayoutContext context,
                  int x,
                  int y)
Description copied from interface: Box
Draws the box's content in the given Graphics context.

Specified by:
paint in interface Box
Overrides:
paint in class AbstractBox
Parameters:
context - LayoutContext containing the Graphics object into which the box should be painted
x - the x-offset at which the box should be painted
y - the y-offset at which the box should be painted
See Also:
Box.paint(net.sf.vex.layout.LayoutContext, int, int)

getFillColor

public java.awt.Color getFillColor()
Returns the color used to fill the shape, or null if the shape is not to be filled.


getLineColor

public java.awt.Color getLineColor()
Returns the color used to draw the lines of the shape, or null if the lines are not to be drawn.


getPadding

public int getPadding()
Returns the padding around the shape.


getShape

public java.awt.Shape getShape()
Returns the shape to be drawn.


getStroke

public java.awt.Stroke getStroke()
Returns the stroke used to draw the shape's lines.


setAntiAliased

public void setAntiAliased(boolean antiAliased)
Sets whether to draw the shape using anti-aliasing.

Parameters:
antiAliased - true if the shape is to be drawn using anti-aliasing.

setFillColor

public void setFillColor(java.awt.Color color)
Sets the fill color for the shape. If set to null, the shape is not filled.

Parameters:
color - the new fill color for the shape

setLineColor

public void setLineColor(java.awt.Color color)
Sets the line color for the shape. If set to null, the shape is not stroked.

Parameters:
color - the new line color for the shape

setStroke

public void setStroke(java.awt.Stroke stroke)
Sets the stroke with which the shape is to be drawn. This defaults to a 1-pixel solid line. Note that the shape will only be stroked if lineColor is set non-null.

Parameters:
stroke - Stroke used to stroke the shape

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()