net.sf.vex.layout
Class RootBox

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

public class RootBox
extends AbstractBox
implements BlockBox

A wrapper for the top level BlockElementBox that applies its margins.


Constructor Summary
RootBox()
          Class constructor.
 
Method Summary
 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.
 LineBox getFirstLine()
          Returns the first LineBox contained by this block, or null if the block contains no lines.
 LineBox getLastLine()
          Returns the last LineBox contained by this block, or null if the block contains no lines.
 int getLineEndOffset(int offset)
          Returns the offset of the end of the line containing the given offset.
 int getLineStartOffset(int offset)
          Returns the offset of the start of the line containing the given offset.
 int getMarginBottom()
          Returns the bottom margin of this box.
 int getMarginTop()
          Returns the top margin of this box.
 int getNextLineOffset(LayoutContext context, int offset, int x)
          Returns the offset on the next line that is closest to the given x coordinate.
 int getPreviousLineOffset(LayoutContext context, int offset, int x)
          Returns the offset on the previous line that is closest to the given x coordinate.
 int getStartOffset()
          Returns the offset of the start of the content that the box covers.
 void layout(LayoutContext context, int width, boolean force)
          Layout this box.
 void setChild(BlockElementBox childBox)
          Sets the child of the root box.
 int viewToModel(LayoutContext context, int x, int y)
          Returns the offset in the content closest to the given view position.
 
Methods inherited from class net.sf.vex.layout.AbstractBox
containsOffset, getHeight, getWidth, getX, getY, hasContent, paint, setHeight, setWidth, setX, setY, skipPaint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.vex.layout.Box
containsOffset, getHeight, getWidth, getX, getY, hasContent, paint, setX, setY
 

Constructor Detail

RootBox

public RootBox()
Class constructor.

Method Detail

getCaretShapes

public java.awt.Shape[] getCaretShapes(LayoutContext context,
                                       int offset)
Description copied from interface: Box
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.

Specified by:
getCaretShapes in interface Box
Overrides:
getCaretShapes in class AbstractBox
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()
Description copied from interface: Box
Returns an array of this box's children.

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

getElement

public Element getElement()
Description copied from interface: Box
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.

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

getEndOffset

public int getEndOffset()
Description copied from interface: Box
Returns the offset of the end of the content that the box covers.

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

getFirstLine

public LineBox getFirstLine()
Description copied from interface: BlockBox
Returns the first LineBox contained by this block, or null if the block contains no lines.

Specified by:
getFirstLine in interface BlockBox
See Also:
BlockBox.getFirstLine()

getLastLine

public LineBox getLastLine()
Description copied from interface: BlockBox
Returns the last LineBox contained by this block, or null if the block contains no lines.

Specified by:
getLastLine in interface BlockBox
See Also:
BlockBox.getLastLine()

getLineEndOffset

public int getLineEndOffset(int offset)
Description copied from interface: BlockBox
Returns the offset of the end of the line containing the given offset.

Specified by:
getLineEndOffset in interface BlockBox
Parameters:
offset - offset identifying the current line.

getLineStartOffset

public int getLineStartOffset(int offset)
Description copied from interface: BlockBox
Returns the offset of the start of the line containing the given offset.

Specified by:
getLineStartOffset in interface BlockBox
Parameters:
offset - offset identifying the current line.

getMarginBottom

public int getMarginBottom()
Description copied from interface: BlockBox
Returns the bottom margin of this box. The actual bottom margin may be different than specified by the style sheet since it may be increased by a child box.

Specified by:
getMarginBottom in interface BlockBox
See Also:
BlockBox.getMarginBottom()

getMarginTop

public int getMarginTop()
Description copied from interface: BlockBox
Returns the top margin of this box. The actual top margin may be different than specified by the style sheet since it may be increased by a child box.

Specified by:
getMarginTop in interface BlockBox
See Also:
BlockBox.getMarginTop()

getNextLineOffset

public int getNextLineOffset(LayoutContext context,
                             int offset,
                             int x)
Description copied from interface: BlockBox
Returns the offset on the next line that is closest to the given x coordinate. The given offset may be before the start of this box in which case this method should return the offset of the first line in this box.

Specified by:
getNextLineOffset in interface BlockBox
Parameters:
context - LayoutContext used for the layout
offset - the current offset
x - the x coordinate

getPreviousLineOffset

public int getPreviousLineOffset(LayoutContext context,
                                 int offset,
                                 int x)
Description copied from interface: BlockBox
Returns the offset on the previous line that is closest to the given x coordinate. The given offset may be after the end of this box in which case this method should return the offset of the last line in this box.

Specified by:
getPreviousLineOffset in interface BlockBox
Parameters:
context - LayoutContext used for the layout
offset - the current offset
x - the x coordinate

getStartOffset

public int getStartOffset()
Description copied from interface: Box
Returns the offset of the start of the content that the box covers.

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

layout

public void layout(LayoutContext context,
                   int width,
                   boolean force)
Description copied from interface: BlockBox
Layout this box. This method is responsible for the following.

Boxes with no children should simply calculate their width and height here

Specified by:
layout in interface BlockBox
Parameters:
context - The layout context to be used.
width - Width available for this box. This is typically ignored by inline-formatted boxes.

setChild

public void setChild(BlockElementBox childBox)
Sets the child of the root box.

Parameters:
childBox - The root's child.

viewToModel

public int viewToModel(LayoutContext context,
                       int x,
                       int y)
Description copied from interface: Box
Returns the offset in the content closest to the given view position.

Specified by:
viewToModel in interface Box
Overrides:
viewToModel in class AbstractBox
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.