|
||||||||||
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.TextDocumentSelection
public class TextDocumentSelection
This is a decorator class of TextSelection, which help user replace a text content with a TextDocument, all Styles be included.
Field Summary |
---|
Fields inherited from class org.odftoolkit.simple.common.navigation.Selection |
---|
search |
Constructor Summary | |
---|---|
TextDocumentSelection(TextSelection selection)
Construct a TextDocumentSelection with TextSelection. |
Method Summary | |
---|---|
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. |
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 deletedItem)
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 insertedItem)
When a selected item has been inserted, the Selection after
the inserted item should be refresh, as these Selection s
index have been changed. |
void |
replaceWithTextDocument(TextDocument textDocument)
Replace the Searched Content with a TextDocument with Styles. |
Methods inherited from class org.odftoolkit.simple.common.navigation.Selection |
---|
getElement, getIndex, getNavigation |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TextDocumentSelection(TextSelection selection)
selection
- the TextSelection to be decorated.Method Detail |
---|
public void replaceWithTextDocument(TextDocument textDocument) throws Exception
Note: You need cache the TextNavigation.nextSelection item because after you replace currtenTextSelection with TextDocument, TextNavigation.nextSelection will search from the inserted Content, it will make you into a loop if the Search keyword also can be found in the new inserted Content.
The right way to use this replaceWithTextDocument(TextDocument textDocument) method should like this:
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){
TextDocumentSelection nextParagraphSelection = new TextDocumentSelection(currtenTextSelection);
try {
nextParagraphSelection.replaceWithTextDocument(sourcedoc);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if(nextTextSelection!=null){
TextDocumentSelection nextParagraphSelection = new TextDocumentSelection(nextTextSelection);
try {
nextParagraphSelection.replaceWithTextDocument(sourcedoc);
} catch (Exception e) {
e.printStackTrace();
}
}
textDocument
- the reference TextDocument to replace.
Exception
public void cut() throws InvalidNavigationException
cut
in class Selection
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 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.protected void refresh(int offset)
Selection
Selection
.
refresh
in class Selection
offset
- the offset that the index should be added.protected void refreshAfterFrontalDelete(Selection deletedItem)
Selection
Selection
s after
this deleted Selection
should be refreshed, as these
Selection
s index have been changed.
refreshAfterFrontalDelete
in class Selection
deletedItem
- the deleted Selection
protected void refreshAfterFrontalInsert(Selection insertedItem)
Selection
Selection
after
the inserted item should be refresh, as these Selection
s
index have been changed.
refreshAfterFrontalInsert
in class Selection
insertedItem
- the inserted Selection
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |