net.sf.vex.layout
Class BlockElementBox

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

public class BlockElementBox
extends AbstractBox
implements BlockBox

A block box corresponding to a DOM Element. Block boxes lay their children out stacked top to bottom. Block boxes correspond to the display: block; CSS property.


Constructor Summary
BlockElementBox(BlockElementBox parent, Element element)
          Class constructor.
 
Method Summary
 BlockBox[] getBlockChildren()
          Returns this box's children.
 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 effective bottom margin.
 int getMarginTop()
          Returns the effective top margin.
 int getNextLineOffset(LayoutContext context, int offset, int x)
          Returns the offset on the next line that is closest to the given x coordinate.
 BlockElementBox getParent()
           
 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.
 boolean hasContent()
          Returns true if this box represents a portion of the XML document's content.
 void invalidate(boolean direct)
           
 void layout(LayoutContext context, int width, boolean force)
          Layout this box.
 void paint(LayoutContext context, int x, int y)
          Draws the box's content in the given Graphics context.
 java.lang.String toString()
           
 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, setHeight, setWidth, setX, setY, skipPaint
 
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, getHeight, getWidth, getX, getY, setX, setY
 

Constructor Detail

BlockElementBox

public BlockElementBox(BlockElementBox parent,
                       Element element)
Class constructor.

Parameters:
parent - This box's parent box.
element - Element to which this box corresponds.
Method Detail

getBlockChildren

public BlockBox[] getBlockChildren()
Returns this box's children.


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
See Also:
Box.getCaretShapes(net.sf.vex.layout.LayoutContext, int)

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:
net.sf.vex.layout.ElementBox#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.
See Also:
BlockBox.getLineEndOffset(int)

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()
Returns the effective bottom margin. This is the margin after taking the margins of child boxes into account.

Specified by:
getMarginBottom in interface BlockBox

getMarginTop

public int getMarginTop()
Returns the effective top margin. This is the margin after taking the margins of child boxes into account.

Specified by:
getMarginTop in interface BlockBox

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

getParent

public BlockElementBox getParent()

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()

hasContent

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

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

invalidate

public void invalidate(boolean direct)

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.

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

toString

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

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.