net.sf.vex.layout
Interface Box

All Known Subinterfaces:
BlockBox, InlineBox
All Known Implementing Classes:
AbstractBox, BlockElementBox, BlockPseudoElementBox, CompositeInlineBox, ParagraphBox, PlaceholderBox, RootBox, ShapeBox, SpaceBox, TextBox

public interface Box

Represents a rectangular area in the layout.


Method Summary
 boolean containsOffset(int offset)
          Returns true if this box contains the given offset.
 java.awt.Shape[] getCaretShapes(LayoutContext context, int offset)
          Returns shapes for the primary and secondary carets for the given offset.
 Box[] getChildren()
          Returns an array of this box's children.
 Element getElement()
          Returns the Element with which this box is associated, or null if there is no such box.
 int getEndOffset()
          Returns the offset of the end of the content that the box covers.
 int getHeight()
          Returns the height of the box.
 int getStartOffset()
          Returns the offset of the start of the content that the box covers.
 int getWidth()
          Returns the height of the box.
 int getX()
          Returns the x-coordinate of the box's top left corner, relative to its parent.
 int getY()
          Returns the y-coordinate of the box's top left corner, relative to its parent.
 boolean hasContent()
          Returns true if this box represents a portion of the XML document's content.
 void paint(LayoutContext context, int x, int y)
          Draws the box's content in the given Graphics context.
 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.
 int viewToModel(LayoutContext context, int x, int y)
          Returns the offset in the content closest to the given view position.
 

Method Detail

containsOffset

public boolean containsOffset(int offset)
Returns true if this box contains the given offset.

Parameters:
offset - the offset to test

getCaretShapes

public java.awt.Shape[] getCaretShapes(LayoutContext context,
                                       int offset)
Returns shapes for the primary and secondary carets for the given offset. A two-element array is returned, with the first entry being the primary caret and the second being the secondary caret. The second entry will be null if there is no secondary caret at the given offset. The position of the carets is relative to the top-left corner of the box.

Parameters:
context - LayoutContext to be used
offset - offset for which to retrieve the caret
Returns:
a two-element array of Shape objects

getChildren

public Box[] getChildren()
Returns an array of this box's children.


getElement

public Element getElement()
Returns the Element with which this box is associated, or null if there is no such box. The box may directly represent the Element, or simply use it for formatting information.


getEndOffset

public int getEndOffset()
Returns the offset of the end of the content that the box covers.


getHeight

public int getHeight()
Returns the height of the box.


getStartOffset

public int getStartOffset()
Returns the offset of the start of the content that the box covers.


getWidth

public int getWidth()
Returns the height of the box.


getX

public int getX()
Returns the x-coordinate of the box's top left corner, relative to its parent.


getY

public int getY()
Returns the y-coordinate of the box's top left corner, relative to its parent.


hasContent

public boolean hasContent()
Returns true if this box represents a portion of the XML document's content. If false is returned, the following methods are not supported by this box.


paint

public void paint(LayoutContext context,
                  int x,
                  int y)
Draws the box's content in the given Graphics context.

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

setX

public void setX(int x)
Sets the x-coordinate of the top-left corner of the 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.

Parameters:
y - the new y-coordinate

viewToModel

public int viewToModel(LayoutContext context,
                       int x,
                       int y)
Returns the offset in the content closest to the given view position.

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.