org.odftoolkit.simple.text
Class Paragraph

java.lang.Object
  extended by org.odftoolkit.simple.Component
      extended by org.odftoolkit.simple.text.Paragraph
All Implemented Interfaces:
FrameContainer, TextboxContainer, TextHyperlinkContainer

public class Paragraph
extends Component
implements TextboxContainer, TextHyperlinkContainer

This class presents paragraph element in ODF document. It provides methods to manipulate text content, and other child component under the paragraph. Headings and body text paragraphs are collectively referred to as paragraph elements.

Since:
0.5

Method Summary
 void addComment(String content, String creator)
          Creates a comment in the front of this paragraph.
 Textbox addTextbox()
          Add a text box
 Textbox addTextbox(FrameRectangle position)
          Add a text box with a specific size at a specific position
 TextHyperlink appendHyperlink(String text, URI linkto)
          Append a hyperlink at the end of the container
 void appendTextContent(String content)
          Append the text content at the end of this paragraph.
 void appendTextContent(String content, boolean isStyleInherited)
          Append the text content at the end of this paragraph.
 void appendTextContentNotCollapsed(String content)
          Append the text content at the end of this paragraph.
 void applyHeading()
          Formats the paragraph as heading.
 void applyHeading(boolean isHeading, int level)
          Sets the paragraph type, heading or body text paragraph.
 TextHyperlink applyHyperlink(URI linkto)
          Hyperlink support
 Font getFont()
          Returns the font definition for this paragraph.
 OdfElement getFrameContainerElement()
          Get the ODF element which can have as child element directly according to ODF specification.
 int getHeadingLevel()
          Returns outline level of this paragraph.
 StyleTypeDefinitions.HorizontalAlignmentType getHorizontalAlignment()
          Return the horizontal alignment setting of this paragraph.
 Iterator<TextHyperlink> getHyperlinkIterator()
          Get the iterator of hyperlinks within this container element
static Paragraph getInstanceof(TextParagraphElementBase paragraphElement)
          Gets a paragraph instance by an instance of TextParagraphElementBase.
 TextParagraphElementBase getOdfElement()
          Return the TextParagraphElementBase of this paragraph.
 Document getOwnerDocument()
          Get the owner document of this paragraph.
 ParagraphStyleHandler getStyleHandler()
          Get the style handler of this paragraph.
 String getStyleName()
          Get the style name of this paragraph
 Textbox getTextboxByName(String name)
          Return a text box whose name is a given value.
 List<Textbox> getTextboxByUsage(PresentationDocument.PresentationClass usage)
          This method is only useful in presentation slide.
 Iterator<Textbox> getTextboxIterator()
          Return an Iterator of the text objects in this container.
 String getTextContent()
          Return the text content of this paragraph.
 boolean isHeading()
          Returns the paragraph type, heading or body text paragraph.
static Paragraph newParagraph(ParagraphContainer container)
          Create an instance of paragraph
 void remove()
          Remove this paragraph from its container.
 void removeHyperlinks()
          Remove all the hyperlinks in this container element.
 boolean removeTextbox(Textbox box)
          Remove the text box
 void removeTextContent()
          Remove the text content of this paragraph.
 void setFont(Font font)
          Sets font style for this paragraph.
 void setHorizontalAlignment(StyleTypeDefinitions.HorizontalAlignmentType alignType)
          Set the horizontal alignment setting of this paragraph.
 void setStyleName(String styleName)
          Set the style name of this paragraph
 void setTextContent(String content)
          Set the text content of this paragraph.
 void setTextContentNotCollapsed(String content)
          Set the text content of this paragraph.
 
Methods inherited from class org.odftoolkit.simple.Component
getComponentByElement, registerComponent, unregisterComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstanceof

public static Paragraph getInstanceof(TextParagraphElementBase paragraphElement)
Gets a paragraph instance by an instance of TextParagraphElementBase.

Parameters:
paragraphElement - the instance of TextParagraphElementBase.
Returns:
an instance of paragraph.

newParagraph

public static Paragraph newParagraph(ParagraphContainer container)
Create an instance of paragraph

The paragrah will be added at the end of this container.

Parameters:
container - the paragraph container that contains this paragraph.

setTextContent

public void setTextContent(String content)
Set the text content of this paragraph.

All the existing text content of this paragraph would be removed, and then new text content would be set. The style of the last character will be inherited.

The white space characters in the content would be collapsed by default. For example, tab character would be replaced with , break line character would be replaced with .

Parameters:
content - - the text content
See Also:
setTextContentNotCollapsed(String content)

removeTextContent

public void removeTextContent()
Remove the text content of this paragraph. The empty hyperlink element will be removed.

The other child elements except text content will not be removed.


getTextContent

public String getTextContent()
Return the text content of this paragraph.

The other child elements except text content will not be returned.

Returns:
- the text content of this paragraph

setTextContentNotCollapsed

public void setTextContentNotCollapsed(String content)
Set the text content of this paragraph.

All the existing text content of this paragraph would be removed, and then new text content would be set.

The white space characters in the content would not be collapsed.

Parameters:
content - - the text content
See Also:
setTextContent(String content)

appendTextContent

public void appendTextContent(String content)
Append the text content at the end of this paragraph. The appended text would follow the style of the last character.

The white space characters in the content would be collapsed by default. For example, tab character would be replaced with , break line character would be replaced with .

Parameters:
content - - the text content
See Also:
appendTextContentNotCollapsed(String content)

appendTextContent

public void appendTextContent(String content,
                              boolean isStyleInherited)
Append the text content at the end of this paragraph. The appended text would follow the style of the last character if the second parameter is set to true; Or else, the appended text would follow the default style of this paragraph.

The white space characters in the content would be collapsed by default. For example, tab character would be replaced with , break line character would be replaced with .

Parameters:
content - - the text content
isStyleInherited - - whether the style would be inherited by the appended text
See Also:
appendTextContentNotCollapsed(String content)

appendTextContentNotCollapsed

public void appendTextContentNotCollapsed(String content)
Append the text content at the end of this paragraph. The appended text would follow the style of the last character.

The white space characters in the content would not be collapsed.

Parameters:
content - - the text content
See Also:
appendTextContent(String content)

setStyleName

public void setStyleName(String styleName)
Set the style name of this paragraph

Parameters:
styleName - - the style name

getStyleName

public String getStyleName()
Get the style name of this paragraph

Returns:
- the style name

getOwnerDocument

public Document getOwnerDocument()
Get the owner document of this paragraph.

Overrides:
getOwnerDocument in class Component
Returns:
the document who owns this paragraph.

remove

public void remove()
Remove this paragraph from its container.

Since:
0.6.5

getStyleHandler

public ParagraphStyleHandler getStyleHandler()
Get the style handler of this paragraph.

The style handler is an instance of ParagraphStyleHandler

Returns:
an instance of ParagraphStyleHandler
See Also:
ParagraphStyleHandler

getOdfElement

public TextParagraphElementBase getOdfElement()
Return the TextParagraphElementBase of this paragraph. Headings and body text paragraphs are collectively referred to as paragraph elements, so the TextParagraphElementBase can be TextHElement element or TextPElement element.

Specified by:
getOdfElement in class Component
Returns:
the TextParagraphElementBase of this paragraph.

addComment

public void addComment(String content,
                       String creator)
Creates a comment in the front of this paragraph.

Parameters:
content - the content of this comment.
creator - the creator of this comment, if creator is null, the value of System.getProperty("user.name") will be used.
Since:
0.6.5

isHeading

public boolean isHeading()
Returns the paragraph type, heading or body text paragraph.

Returns:
the paragraph type, if this paragraph is heading, returns true, otherwise return false.
Since:
0.6.5

getHeadingLevel

public int getHeadingLevel()
Returns outline level of this paragraph.

Returns:
outline level, if this paragraph is a body text paragraph, 0 will be returned.
Since:
0.6.5

applyHeading

public void applyHeading(boolean isHeading,
                         int level)
Sets the paragraph type, heading or body text paragraph.

Parameters:
isHeading - if true, this paragraph would be formatted as heading, otherwise as a body text paragraph.
level - the heading outline level of this paragraph, if isHeading is true.
Since:
0.6.5

applyHeading

public void applyHeading()
Formats the paragraph as heading. Its outline level is 1.

Since:
0.6.5

getFont

public Font getFont()
Returns the font definition for this paragraph.

Returns:
font if there is no style definition for this paragraph, null will be returned.
Since:
0.6.5

setFont

public void setFont(Font font)
Sets font style for this paragraph.

Parameters:
font - the font definition of this paragraph
Since:
0.6.5

getHorizontalAlignment

public StyleTypeDefinitions.HorizontalAlignmentType getHorizontalAlignment()
Return the horizontal alignment setting of this paragraph.

Null will returned if there is no explicit style definition for this paragraph.

Default value will be returned if explicit style definition is found but no horizontal alignment is set.

Returns:
the horizontal alignment setting.
Since:
0.6.5

setHorizontalAlignment

public void setHorizontalAlignment(StyleTypeDefinitions.HorizontalAlignmentType alignType)
Set the horizontal alignment setting of this paragraph. If the alignment is set as Default, the explicit horizontal alignment setting is removed.

Parameters:
alignType - the horizontal alignment setting.
Since:
0.6.5

addTextbox

public Textbox addTextbox()
Description copied from interface: TextboxContainer
Add a text box

Specified by:
addTextbox in interface TextboxContainer
Returns:
the object of text box

getTextboxIterator

public Iterator<Textbox> getTextboxIterator()
Description copied from interface: TextboxContainer
Return an Iterator of the text objects in this container.

Specified by:
getTextboxIterator in interface TextboxContainer
Returns:
an Iterator of the text objects in this container

removeTextbox

public boolean removeTextbox(Textbox box)
Description copied from interface: TextboxContainer
Remove the text box

Specified by:
removeTextbox in interface TextboxContainer
Parameters:
box - - the instance of text box
Returns:
true if success, false if fails

getFrameContainerElement

public OdfElement getFrameContainerElement()
Description copied from interface: FrameContainer
Get the ODF element which can have as child element directly according to ODF specification. This Element will help to find the position to insert a new draw:frame element.

Specified by:
getFrameContainerElement in interface FrameContainer
Returns:
the parent of draw:frame

addTextbox

public Textbox addTextbox(FrameRectangle position)
Description copied from interface: TextboxContainer
Add a text box with a specific size at a specific position

Specified by:
addTextbox in interface TextboxContainer
Parameters:
position - - the rectangle (position and size) of this text box
Returns:
the object of text box

getTextboxByName

public Textbox getTextboxByName(String name)
Description copied from interface: TextboxContainer
Return a text box whose name is a given value.

Specified by:
getTextboxByName in interface TextboxContainer
Parameters:
name - - the name of the text box
Returns:
a text box whose name is a given value

getTextboxByUsage

public List<Textbox> getTextboxByUsage(PresentationDocument.PresentationClass usage)
Description copied from interface: TextboxContainer
This method is only useful in presentation slide.

This method will return a list of text boxs by the usage in presentation slides.

Specified by:
getTextboxByUsage in interface TextboxContainer
Parameters:
usage - - the usage description
Returns:
a list of text box Null will be returned if the owner document is not a presentation

applyHyperlink

public TextHyperlink applyHyperlink(URI linkto)
Hyperlink support

Specified by:
applyHyperlink in interface TextHyperlinkContainer
Parameters:
linkto - the hyperlink
Returns:
an instance of TextHyperlink

getHyperlinkIterator

public Iterator<TextHyperlink> getHyperlinkIterator()
Description copied from interface: TextHyperlinkContainer
Get the iterator of hyperlinks within this container element

Specified by:
getHyperlinkIterator in interface TextHyperlinkContainer
Returns:
the iterator of hyperlinks within this container element

removeHyperlinks

public void removeHyperlinks()
Description copied from interface: TextHyperlinkContainer
Remove all the hyperlinks in this container element.

Specified by:
removeHyperlinks in interface TextHyperlinkContainer

appendHyperlink

public TextHyperlink appendHyperlink(String text,
                                     URI linkto)
Description copied from interface: TextHyperlinkContainer
Append a hyperlink at the end of the container

Specified by:
appendHyperlink in interface TextHyperlinkContainer
Parameters:
text - - the text content
linkto - - the URI of this hyperlink
Returns:
an instance of TextHyperlink


Copyright © 2010-2011 The Apache Software Foundation. All Rights Reserved.