Class FormulaDocument
- java.lang.Object
-
- org.pentaho.openformula.ui.model2.FormulaDocument
-
-
Field Summary
-
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
-
-
Constructor Summary
Constructors Constructor Description FormulaDocument()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDocumentListener(DocumentListener listener)
Registers the given observer to begin receiving notifications when changes are made to the document.void
addUndoableEditListener(UndoableEditListener listener)
Registers the given observer to begin receiving notifications when undoable edits are made to the document.Position
createPosition(int offs)
This method allows an application to mark a place in a sequence of character content.protected void
fireChangeEvent(DocumentEvent event)
protected void
fireInsertEvent(DocumentEvent event)
protected void
fireRemoveEvent(DocumentEvent event)
Element
getDefaultRootElement()
Returns the root element that views should be based upon, unless some other mechanism for assigning views to element structures is provided.FormulaElement
getElementAtPosition(int index)
Retrieve the element at specified position.Position
getEndPosition()
Returns a position that represents the end of the document.FunctionInformation
getFunctionForPosition(int offset)
int
getLength()
Returns number of characters of content currently in the document.Object
getProperty(Object key)
Gets the properties associated with the document.FormulaRootElement
getRootElement()
Element[]
getRootElements()
Returns all of the root elements that are defined.Position
getStartPosition()
Returns a position that represents the start of the document.String
getText()
String
getText(int offset, int length)
Fetches the text contained within the given portion of the document.void
getText(int offset, int length, Segment txt)
Fetches the text contained within the given portion of the document.void
insertString(int offset, String str, AttributeSet a)
Inserts a string of content.void
putProperty(Object key, Object value)
Associates a property with the document.void
remove(int offs, int len)
Removes a portion of the content of the document.void
removeDocumentListener(DocumentListener listener)
Unregisters the given observer from the notification list so it will no longer receive change updates.void
removeUndoableEditListener(UndoableEditListener listener)
Unregisters the given observer from the notification list so it will no longer receive updates.void
render(Runnable r)
Allows the model to be safely rendered in the presence of concurrency, if the model supports being updated asynchronously.void
revalidateStructure()
void
setText(String text)
-
-
-
Method Detail
-
getLength
public int getLength()
Returns number of characters of content currently in the document.
-
addDocumentListener
public void addDocumentListener(DocumentListener listener)
Registers the given observer to begin receiving notifications when changes are made to the document.- Specified by:
addDocumentListener
in interfaceDocument
- Parameters:
listener
- the observer to register- See Also:
Document.removeDocumentListener(javax.swing.event.DocumentListener)
-
removeDocumentListener
public void removeDocumentListener(DocumentListener listener)
Unregisters the given observer from the notification list so it will no longer receive change updates.- Specified by:
removeDocumentListener
in interfaceDocument
- Parameters:
listener
- the observer to register- See Also:
Document.addDocumentListener(javax.swing.event.DocumentListener)
-
fireInsertEvent
protected void fireInsertEvent(DocumentEvent event)
-
fireRemoveEvent
protected void fireRemoveEvent(DocumentEvent event)
-
fireChangeEvent
protected void fireChangeEvent(DocumentEvent event)
-
addUndoableEditListener
public void addUndoableEditListener(UndoableEditListener listener)
Registers the given observer to begin receiving notifications when undoable edits are made to the document.- Specified by:
addUndoableEditListener
in interfaceDocument
- Parameters:
listener
- the observer to register- See Also:
UndoableEditEvent
-
removeUndoableEditListener
public void removeUndoableEditListener(UndoableEditListener listener)
Unregisters the given observer from the notification list so it will no longer receive updates.- Specified by:
removeUndoableEditListener
in interfaceDocument
- Parameters:
listener
- the observer to register- See Also:
UndoableEditEvent
-
getProperty
public Object getProperty(Object key)
Gets the properties associated with the document.- Specified by:
getProperty
in interfaceDocument
- Parameters:
key
- a non-null
property key- Returns:
- the properties
- See Also:
putProperty(Object, Object)
-
putProperty
public void putProperty(Object key, Object value)
Associates a property with the document. Two standard property keys provided are:StreamDescriptionProperty
andTitleProperty
. Other properties, such as author, may also be defined.- Specified by:
putProperty
in interfaceDocument
- Parameters:
key
- the non-null
property keyvalue
- the property value- See Also:
getProperty(Object)
-
getStartPosition
public Position getStartPosition()
Returns a position that represents the start of the document. The position returned can be counted on to track change and stay located at the beginning of the document.- Specified by:
getStartPosition
in interfaceDocument
- Returns:
- the position
-
getEndPosition
public Position getEndPosition()
Returns a position that represents the end of the document. The position returned can be counted on to track change and stay located at the end of the document.- Specified by:
getEndPosition
in interfaceDocument
- Returns:
- the position
-
createPosition
public Position createPosition(int offs) throws BadLocationException
This method allows an application to mark a place in a sequence of character content. This mark can then be used to tracks change as insertions and removals are made in the content. The policy is that insertions always occur prior to the current position (the most common case) unless the insertion location is zero, in which case the insertion is forced to a position that follows the original position.- Specified by:
createPosition
in interfaceDocument
- Parameters:
offs
- the offset from the start of the document >= 0- Returns:
- the position
- Throws:
BadLocationException
- if the given position does not represent a valid location in the associated document
-
getRootElements
public Element[] getRootElements()
Returns all of the root elements that are defined.Typically there will be only one document structure, but the interface supports building an arbitrary number of structural projections over the text data. The document can have multiple root elements to support multiple document structures. Some examples might be:
- Text direction.
- Lexical token streams.
- Parse trees.
- Conversions to formats other than the native format.
- Modification specifications.
- Annotations.
- Specified by:
getRootElements
in interfaceDocument
- Returns:
- the root element
-
getDefaultRootElement
public Element getDefaultRootElement()
Returns the root element that views should be based upon, unless some other mechanism for assigning views to element structures is provided.- Specified by:
getDefaultRootElement
in interfaceDocument
- Returns:
- the root element
-
getRootElement
public FormulaRootElement getRootElement()
-
render
public void render(Runnable r)
Allows the model to be safely rendered in the presence of concurrency, if the model supports being updated asynchronously. The given runnable will be executed in a way that allows it to safely read the model with no changes while the runnable is being executed. The runnable itself may not make any mutations.
-
remove
public void remove(int offs, int len) throws BadLocationException
Removes a portion of the content of the document. This will cause a DocumentEvent of type DocumentEvent.EventType.REMOVE to be sent to the registered DocumentListeners, unless an exception is thrown. The notification will be sent to the listeners by calling the removeUpdate method on the DocumentListeners. To ensure reasonable behavior in the face of concurrency, the event is dispatched after the mutation has occurred. This means that by the time a notification of removal is dispatched, the document has already been updated and any marks created bycreatePosition
have already changed. For a removal, the end of the removal range is collapsed down to the start of the range, and any marks in the removal range are collapsed down to the start of the range.- Specified by:
remove
in interfaceDocument
- Parameters:
offs
- the offset from the beginning >= 0len
- the number of characters to remove >= 0- Throws:
BadLocationException
- some portion of the removal range was not a valid part of the document. The location in the exception is the first bad position encountered.- See Also:
DocumentEvent
,DocumentListener
,UndoableEditEvent
,UndoableEditListener
-
insertString
public void insertString(int offset, String str, AttributeSet a) throws BadLocationException
Inserts a string of content. This will cause a DocumentEvent of type DocumentEvent.EventType.INSERT to be sent to the registered DocumentListers, unless an exception is thrown. The DocumentEvent will be delivered by calling the insertUpdate method on the DocumentListener. The offset and length of the generated DocumentEvent will indicate what change was actually made to the Document.- Specified by:
insertString
in interfaceDocument
- Parameters:
offset
- the offset into the document to insert the content >= 0. All positions that track change at or after the given location will move.str
- the string to inserta
- the attributes to associate with the inserted content. This may be null if there are no attributes.- Throws:
BadLocationException
- the given insert position is not a valid position within the document- See Also:
DocumentEvent
,DocumentListener
,UndoableEditEvent
,UndoableEditListener
-
getText
public String getText(int offset, int length) throws BadLocationException
Fetches the text contained within the given portion of the document.- Specified by:
getText
in interfaceDocument
- Parameters:
offset
- the offset into the document representing the desired start of the text >= 0length
- the length of the desired string >= 0- Returns:
- the text, in a String of length >= 0
- Throws:
BadLocationException
- some portion of the given range was not a valid part of the document. The location in the exception is the first bad position encountered.
-
getText
public String getText()
-
getText
public void getText(int offset, int length, Segment txt) throws BadLocationException
Fetches the text contained within the given portion of the document. If the partialReturn property on the txt parameter is false, the data returned in the Segment will be the entire length requested and may or may not be a copy depending upon how the data was stored. If the partialReturn property is true, only the amount of text that can be returned without creating a copy is returned. Using partial returns will give better performance for situations where large parts of the document are being scanned. The following is an example of using the partial return to access the entire document:int nleft = doc.getDocumentLength(); Segment text = new Segment(); int offs = 0; text.setPartialReturn(true); while (nleft > 0) { doc.getText(offs, nleft, text); // do someting with text nleft -= text.count; offs += text.count; }
- Specified by:
getText
in interfaceDocument
- Parameters:
offset
- the offset into the document representing the desired start of the text >= 0length
- the length of the desired string >= 0txt
- the Segment object to return the text in- Throws:
BadLocationException
- Some portion of the given range was not a valid part of the document. The location in the exception is the first bad position encountered.
-
getFunctionForPosition
public FunctionInformation getFunctionForPosition(int offset)
-
setText
public void setText(String text)
-
getElementAtPosition
public FormulaElement getElementAtPosition(int index)
Retrieve the element at specified position. Note, the index is not the cursor index but rather the tokenized element position. So '=COUNT(1;2;3)' would contain 9 elements starting with element '=' at 0 index upto ')' at index 8.- Parameters:
index
-- Returns:
- FormulaElement specified at index. If index is invalid then return null.
-
revalidateStructure
public void revalidateStructure()
-
-