|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.odftoolkit.simple.common.navigation.Selection
org.odftoolkit.simple.common.navigation.TextSelection
public class TextSelection
TextSelection
describes a sub element in a paragraph element or
a heading element. It is recognized by the container element, which type
should be OdfTextParagraph
or
OdfTextHeading
, the start index of text content in container element and the
text content of this Selection
.
Field Summary |
---|
Fields inherited from class org.odftoolkit.simple.common.navigation.Selection |
---|
search |
Method Summary | |
---|---|
void |
addComment(String content,
String creator)
Add a comment to the selection. |
void |
addHref(URL url)
Add a hypertext reference to the selection. |
void |
applyStyle(OdfStyleBase style)
Apply a style to the selection so that the text style of this selection will append the specified style. |
TextSpanElement |
createSpanElement()
Create a span element for this text selection. |
void |
cut()
Delete the selection from the document the other matched selection in the same container element will be updated automatically because the start index of the following selections will be changed when the previous selection has been deleted. |
OdfElement |
getContainerElement()
Get the paragraph element or heading element that contains this text. |
OdfElement |
getElement()
Get the paragraph element or heading element that contains this TextSelection . |
int |
getIndex()
Get the start index of the text content of its container element. |
String |
getText()
Get the text content of this TextSelection . |
TextNavigation |
getTextNavigation()
|
boolean |
isSelectionReplaced()
|
static TextSelection |
newTextSelection(Navigation search,
String text,
OdfElement containerElement,
int index)
Create a new TextSelection . |
void |
pasteAtEndOf(Selection positionItem)
Paste this selection just after a specific selection. |
void |
pasteAtFrontOf(Selection positionItem)
Paste this selection just before a specific selection. |
protected void |
refresh(int offset)
A quick method to update the index of this Selection . |
protected void |
refreshAfterFrontalDelete(Selection deleteItem)
When a selected item has been deleted, the Selection s after
this deleted Selection should be refreshed, as these
Selection s index have been changed. |
protected void |
refreshAfterFrontalInsert(Selection pasteItem)
When a selected item has been inserted, the Selection after
the inserted item should be refresh, as these Selection s
index have been changed. |
Field |
replaceWith(Field orgField)
Replace the content with a Field |
Image |
replaceWith(Image newImage)
Replace the text content of selection with a new Image. |
Paragraph |
replaceWith(Paragraph newParagraph)
Replace the content with a paragraph, the paragraph can be in the same TextDocument or in a different Document. |
void |
replaceWith(String newText)
Replace the text content of selection with a new string. |
Table |
replaceWith(Table newTable)
Replace the text content of selection with a new Table. |
void |
replaceWith(TextDocument newTextDocument)
Replace the content with a TextDocument with Styles. |
Image |
replaceWith(URI imageUri)
Replace the text content of selection with a new Image. |
void |
setSelectionReplaced(boolean b)
|
String |
toString()
return a String Object representing this selection value the text content of the selection, start index in the container element and the text content of the container element will be provided. |
Methods inherited from class org.odftoolkit.simple.common.navigation.Selection |
---|
getNavigation |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public TextNavigation getTextNavigation()
public static TextSelection newTextSelection(Navigation search, String text, OdfElement containerElement, int index)
TextSelection
.
text
- the text content of this TextSelection
containerElement
- the paragraph element or heading element that contains this
TextSelection
index
- the start index of the text content in container elementpublic OdfElement getElement()
TextSelection
.
getElement
in class Selection
public OdfElement getContainerElement()
public int getIndex()
getIndex
in class Selection
public String getText()
TextSelection
.
public void cut() throws InvalidNavigationException
cut
in class Selection
InvalidNavigationException
- if the selection is unavailable.public void applyStyle(OdfStyleBase style) throws InvalidNavigationException
style
- the style can be from the current document or user defined
InvalidNavigationException
- if the selection is unavailable.public void replaceWith(String newText) throws InvalidNavigationException
newText
- the replace text String
InvalidNavigationException
- if the selection is unavailable.public Table replaceWith(Table newTable) throws InvalidNavigationException
newTable
- the replace Table
InvalidNavigationException
- if the selection is unavailable.public Image replaceWith(Image newImage) throws InvalidNavigationException
newImage
- the replace Image
InvalidNavigationException
- if the selection is unavailable.public Image replaceWith(URI imageUri) throws InvalidNavigationException
imageUri
- the replace Image URI
InvalidNavigationException
- if the selection is unavailable.public Field replaceWith(Field orgField) throws InvalidNavigationException
orgField
- the reference Field to replace.
InvalidNavigationException
- if the selection is unavailable.public Paragraph replaceWith(Paragraph newParagraph) throws InvalidNavigationException
newParagraph
- the reference paragraph to replace.
InvalidNavigationException
- if the selection is unavailable.public void replaceWith(TextDocument newTextDocument) throws InvalidNavigationException
search = new TextNavigation("SIMPLE", doc);
TextSelection currtenTextSelection,nextTextSelection=null;
while (search.hasNext()) {
if(nextTextSelection!=null){
currtenTextSelection=nextTextSelection;
}else {
currtenTextSelection = (TextSelection) search.nextSelection();
}
nextTextSelection = (TextSelection) search.nextSelection();
if(currtenTextSelection!=null){
try {
nextTextSelection.replaceWithTextDocument(sourcedoc);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if(nextTextSelection!=null){
try {
nextTextSelection.replaceWithTextDocument(sourcedoc);
} catch (Exception e) {
e.printStackTrace();
}
}
newTextDocument
- the reference TextDocument to replace.
InvalidNavigationException
public TextSpanElement createSpanElement() throws InvalidNavigationException
InvalidNavigationException
- if the selection is unavailable.public void pasteAtFrontOf(Selection positionItem) throws InvalidNavigationException
pasteAtFrontOf
in class Selection
positionItem
- a selection that is used to point out the position
InvalidNavigationException
- if the selection is unavailable.public void pasteAtEndOf(Selection positionItem) throws InvalidNavigationException
pasteAtEndOf
in class Selection
positionItem
- a selection that is used to point out the position
InvalidNavigationException
- if the selection is unavailable.public void setSelectionReplaced(boolean b)
public boolean isSelectionReplaced()
public void addHref(URL url) throws InvalidNavigationException
url
- the URL of this hypertext reference
InvalidNavigationException
- if the selection is unavailable.public void addComment(String content, String creator) throws InvalidNavigationException
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.
InvalidNavigationException
- if the selection is unavailable.public String toString()
toString
in class Object
TextSelection
protected void refreshAfterFrontalDelete(Selection deleteItem)
Selection
Selection
s after
this deleted Selection
should be refreshed, as these
Selection
s index have been changed.
refreshAfterFrontalDelete
in class Selection
deleteItem
- the deleted Selection
protected void refreshAfterFrontalInsert(Selection pasteItem)
Selection
Selection
after
the inserted item should be refresh, as these Selection
s
index have been changed.
refreshAfterFrontalInsert
in class Selection
pasteItem
- the inserted Selection
protected void refresh(int offset)
Selection
Selection
.
refresh
in class Selection
offset
- the offset that the index should be added.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |