net.sf.vex.layout
Class AbstractBox

java.lang.Object
  |
  +--net.sf.vex.layout.AbstractBox
All Implemented Interfaces:
Box
Direct Known Subclasses:
BlockElementBox, BlockPseudoElementBox, CompositeInlineBox, ParagraphBox, PlaceholderBox, RootBox, ShapeBox, SpaceBox, TextBox

public abstract class AbstractBox
extends java.lang.Object
implements Box

Base implementation of the Box interface, implementing some common methods.


Constructor Summary
AbstractBox()
          Class constructor.
 
Method Summary
 boolean containsOffset(int offset)
          Returns true if the given offset is between startOffset and endOffset, inclusive.
 java.awt.Shape[] getCaretShapes(LayoutContext context, int offset)
          Throws IllegalStateException.
 Box[] getChildren()
          Returns an empty array of children.
 Element getElement()
          Throws IllegalStateException.
 int getEndOffset()
          Throws IllegalStateException.
 int getHeight()
          Returns the height set with setHeight.
 int getStartOffset()
          Throws IllegalStateException.
 int getWidth()
          Returns the width set with setWidth.
 int getX()
          Returns the value set with setX.
 int getY()
          Returns the value set with setY.
 boolean hasContent()
          Returns false.
 void paint(LayoutContext context, int x, int y)
          Paint all children of this box.
protected  void setHeight(int height)
          Sets the height of this box.
protected  void setWidth(int width)
          Sets the width of this box.
 void setX(int x)
          Sets the x-coordinate of the top-left corner of the box.
 void setY(int y)
          Sets the y-coordinate of the top-left corner of the box.
protected  boolean skipPaint(LayoutContext context, int x, int y)
          Returns true if this box is outside the clip region.
 int viewToModel(LayoutContext context, int x, int y)
          Throws IllegalStateException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractBox

public AbstractBox()
Class constructor.

Method Detail

containsOffset

public boolean containsOffset(int offset)
Returns true if the given offset is between startOffset and endOffset, inclusive.

Specified by:
containsOffset in interface Box
Parameters:
offset - the offset to test
See Also:
Box.containsOffset(int)

getCaretShapes

public java.awt.Shape[] getCaretShapes(LayoutContext context,
                                       int offset)
Throws IllegalStateException. Boxes with content must provide an implementation of this method.

Specified by:
getCaretShapes in interface Box
Parameters:
context - LayoutContext to be used
offset - offset for which to retrieve the caret
Returns:
a two-element array of Shape objects
See Also:
Box.getCaretShapes(net.sf.vex.layout.LayoutContext, int)

getChildren

public Box[] getChildren()
Returns an empty array of children.

Specified by:
getChildren in interface Box
See Also:
Box.getChildren()

getElement

public Element getElement()
Throws IllegalStateException. Boxes associated with elements must provide an implementation of this method.

Specified by:
getElement in interface Box
See Also:
Box.getElement()

getEndOffset

public int getEndOffset()
Throws IllegalStateException. Boxes with content must provide an implementation of this method.

Specified by:
getEndOffset in interface Box
See Also:
Box.getEndOffset()

getHeight

public int getHeight()
Returns the height set with setHeight.

Specified by:
getHeight in interface Box
See Also:
Box.getHeight()

getStartOffset

public int getStartOffset()
Throws IllegalStateException. Boxes with content must provide an implementation of this method.

Specified by:
getStartOffset in interface Box
See Also:
Box.getStartOffset()

hasContent

public boolean hasContent()
Returns false. Boxes with content must override this method and return true, and must provide implementations for the following methods.

Specified by:
hasContent in interface Box
See Also:
Box.hasContent()

getWidth

public int getWidth()
Returns the width set with setWidth.

Specified by:
getWidth in interface Box
See Also:
Box.getWidth()

getX

public int getX()
Returns the value set with setX.

Specified by:
getX in interface Box
See Also:
Box.getX()

getY

public int getY()
Returns the value set with setY.

Specified by:
getY in interface Box
See Also:
Box.getY()

paint

public void paint(LayoutContext context,
                  int x,
                  int y)
Paint all children of this box.

Specified by:
paint in interface Box
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)

setHeight

protected void setHeight(int height)
Sets the height of this box.

Parameters:
height - new height of the box

setWidth

protected void setWidth(int width)
Sets the width of this box.

Parameters:
width - new width of the box

setX

public void setX(int x)
Sets the x-coordinate of the top-left corner of the box.

Specified by:
setX in interface Box
Parameters:
x - the new x-coordinate

setY

public void setY(int y)
Sets the y-coordinate of the top-left corner of the box.

Specified by:
setY in interface Box
Parameters:
y - the new y-coordinate

skipPaint

protected boolean skipPaint(LayoutContext context,
                            int x,
                            int y)
Returns true if this box is outside the clip region. Implementations of paint should use this to avoid unnecessary painting.

Parameters:
context - LayoutContext in effect.
x - the x-coordinate at which the box is being painted
y - the y-coordinate at which the box is being painted

viewToModel

public int viewToModel(LayoutContext context,
                       int x,
                       int y)
Throws IllegalStateException. Boxes with content must provide an implementation of this method.

Specified by:
viewToModel in interface Box
Parameters:
context - LayoutContext for this box tree
x - x offset of the view position for which the model offset is to be determined.
y - y offset of the view position for which the model offset is to be determined.
See Also:
Box.viewToModel(net.sf.vex.layout.LayoutContext, int, int)