net.sf.vex.layout
Class ParagraphBox

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

public class ParagraphBox
extends AbstractBox
implements BlockBox

A box that wraps inline content into a paragraph.


Method Summary
static ParagraphBox create(LayoutContext context, Element element, InlineBox[] inlines, int width)
          Create a paragraph by word-wrapping a list of inline boxes.
static ParagraphBox create(LayoutContext context, Element element, java.util.List inlines, int width)
          Create a paragraph by word-wrapping a list of inline boxes.
 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.
 LineBox getLineAt(int offset)
          Returns the LineBox at the given offset.
 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.
 boolean hasContent()
          Returns true if this box represents a portion of the XML document's content.
 void layout(LayoutContext context, int width, boolean force)
          Layout this box.
 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, paint, 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, paint, setX, setY
 

Method Detail

create

public static ParagraphBox create(LayoutContext context,
                                  Element element,
                                  java.util.List inlines,
                                  int width)
Create a paragraph by word-wrapping a list of inline boxes.

Parameters:
context - LayoutContext used for this layout.
element - Element that controls the styling for this paragraph.
inlines - List of InlineBox objects to be wrapped
width - width to which the paragraph is to be wrapped
Returns:

create

public static ParagraphBox create(LayoutContext context,
                                  Element element,
                                  InlineBox[] inlines,
                                  int width)
Create a paragraph by word-wrapping a list of inline boxes.

Parameters:
context - LayoutContext used for this layout
element - Element that controls the styling of this paragraph, in particular text alignment.
inlines - Array of InlineBox objects to be wrapped.
width - width to which the paragraph is to be wrapped.

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

getLineAt

public LineBox getLineAt(int offset)
Returns the LineBox at the given offset.

Parameters:
offset - the offset to check.

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

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

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.

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.