Document java source code

Document java source code

Registers the given observer to begin receiving notifications when undoable edits are made to the document.

Returns the root element that views should be based upon, unless some other mechanism for assigning views to element structures is provided.

Unregisters the given observer from the notification list so it will no longer receive change updates.

Allows the model to be safely rendered in the presence of concurrency, if the model supports being updated asynchronously.

Field Detail

StreamDescriptionProperty

static final String StreamDescriptionProperty

The property name for the description of the stream used to initialize the document. This should be used if the document was initialized from a stream and anything is known about the stream.

TitleProperty

Method Detail

getLength

addDocumentListener

removeDocumentListener

Unregisters the given observer from the notification list so it will no longer receive change updates.

addUndoableEditListener

Registers the given observer to begin receiving notifications when undoable edits are made to the document.

removeUndoableEditListener

getProperty

putProperty

Associates a property with the document. Two standard property keys provided are: StreamDescriptionProperty and TitleProperty . Other properties, such as author, may also be defined.

remove

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 by createPosition 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. If the Document structure changed as result of the removal, the details of what Elements were inserted and removed in response to the change will also be contained in the generated DocumentEvent. It is up to the implementation of a Document to decide how the structure should change in response to a remove. If the Document supports undo/redo, an UndoableEditEvent will also be generated.

insertString

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. If the Document structure changed as result of the insertion, the details of what Elements were inserted and removed in response to the change will also be contained in the generated DocumentEvent. It is up to the implementation of a Document to decide how the structure should change in response to an insertion. If the Document supports undo/redo, an UndoableEditEvent will also be generated.

Читайте также:  Можно ли на javascript разрабатывать бэкенд

getText

String getText(int offset, int length) throws BadLocationException

getText

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; >

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.

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.

createPosition

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.

Читайте также:  Java guid or uuid

getRootElements

  • Text direction.
  • Lexical token streams.
  • Parse trees.
  • Conversions to formats other than the native format.
  • Modification specifications.
  • Annotations.

getDefaultRootElement

Returns the root element that views should be based upon, unless some other mechanism for assigning views to element structures is provided.

render

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.

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

Источник

Оцените статью