org.odftoolkit.simple.common.navigation
Class FieldSelection

java.lang.Object
  extended by org.odftoolkit.simple.common.navigation.Selection
      extended by org.odftoolkit.simple.common.navigation.FieldSelection

public class FieldSelection
extends Selection

This is a decorator class of TextSelection, which help user replace a text content with field.

Since:
0.5
See Also:
Fields, AuthorField, ChapterField, ConditionField, DateField, PageCountField, PageNumberField, ReferenceField, SubjectField, TimeField, TitleField, VariableField

Constructor Summary
FieldSelection(TextSelection selection)
          Construct a FieldSelection with TextSelection.
 
Method Summary
 void applyStyle(OdfStyleBase style)
          Apply a style to the selection so that the text style of this selection will append the specified style.
 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 Selections after this deleted Selection should be refreshed, as these Selections 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 Selections index have been changed.
 void replaceWith(String newText)
          Replace the text content of selection with a new string.
 ConditionField replaceWithConditionField(String condition, String trueText, String falseText)
          Replace the content with a condition field.
 ConditionField replaceWithHiddenTextField(String condition, String text)
          Replace the content with a hidden text field.
 void replaceWithReferenceField(ReferenceField field, ReferenceField.DisplayType type)
          Replace the content with a reference field.
 Field replaceWithSimpleField(Field.FieldType fieldType)
          Replace the content with a simple field, such as author field, page number field, date field and so on.
 void replaceWithVariableField(VariableField field)
          Replace the content with a variable field.
 
Methods inherited from class org.odftoolkit.simple.common.navigation.Selection
getElement, getIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FieldSelection

public FieldSelection(TextSelection selection)
Construct a FieldSelection with TextSelection. Then user can replace text content with fields.

Parameters:
selection - the TextSelection to be decorated.
Method Detail

replaceWithSimpleField

public Field replaceWithSimpleField(Field.FieldType fieldType)
Replace the content with a simple field, such as author field, page number field, date field and so on.

Parameters:
fieldType - the simple field type to replace.

replaceWithReferenceField

public void replaceWithReferenceField(ReferenceField field,
                                      ReferenceField.DisplayType type)
Replace the content with a reference field.

Parameters:
field - the reference field to replace.

replaceWithVariableField

public void replaceWithVariableField(VariableField field)
Replace the content with a variable field.

Parameters:
field - the variable field to replace.

replaceWithConditionField

public ConditionField replaceWithConditionField(String condition,
                                                String trueText,
                                                String falseText)
Replace the content with a condition field.

Parameters:
condition - the condition that determines which of the two text strings is displayed.
trueText - the text string to display if a condition is true.
falseText - the text string to display if a condition is false.
Returns:
the created condition field.

replaceWithHiddenTextField

public ConditionField replaceWithHiddenTextField(String condition,
                                                 String text)
Replace the content with a hidden text field.

Parameters:
condition - the condition that determines whether the text string is displayed or not.
text - the text string to display.
Returns:
the created condition field.

applyStyle

public void applyStyle(OdfStyleBase style)
                throws InvalidNavigationException
Apply a style to the selection so that the text style of this selection will append the specified style.

Parameters:
style - the style can be from the current document or user defined
Throws:
InvalidNavigationException - if the selection is unavailable.

cut

public void cut()
         throws InvalidNavigationException
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.

Specified by:
cut in class Selection
Throws:
InvalidNavigationException - if the selection is unavailable.

replaceWith

public void replaceWith(String newText)
                 throws InvalidNavigationException
Replace the text content of selection with a new string.

Parameters:
newText - the replace text String
Throws:
InvalidNavigationException - if the selection is unavailable.

pasteAtEndOf

public void pasteAtEndOf(Selection positionItem)
                  throws InvalidNavigationException
Paste this selection just after a specific selection.

Specified by:
pasteAtEndOf in class Selection
Parameters:
positionItem - a selection that is used to point out the position
Throws:
InvalidNavigationException - if the selection is unavailable.

pasteAtFrontOf

public void pasteAtFrontOf(Selection positionItem)
                    throws InvalidNavigationException
Paste this selection just before a specific selection.

Specified by:
pasteAtFrontOf in class Selection
Parameters:
positionItem - a selection that is used to point out the position
Throws:
InvalidNavigationException - if the selection is unavailable.

refresh

protected void refresh(int offset)
Description copied from class: Selection
A quick method to update the index of this Selection.

Specified by:
refresh in class Selection
Parameters:
offset - the offset that the index should be added.

refreshAfterFrontalDelete

protected void refreshAfterFrontalDelete(Selection deletedItem)
Description copied from class: Selection
When a selected item has been deleted, the Selections after this deleted Selection should be refreshed, as these Selections index have been changed.

Specified by:
refreshAfterFrontalDelete in class Selection
Parameters:
deletedItem - the deleted Selection

refreshAfterFrontalInsert

protected void refreshAfterFrontalInsert(Selection insertedItem)
Description copied from class: Selection
When a selected item has been inserted, the Selection after the inserted item should be refresh, as these Selections index have been changed.

Specified by:
refreshAfterFrontalInsert in class Selection
Parameters:
insertedItem - the inserted Selection


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