|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.text.AbstractDocument javax.swing.text.PlainDocument com.jidesoft.editor.SyntaxDocument com.jidesoft.editor.LazyLoadDocument
public class LazyLoadDocument
This class is to provide lazy loading feature for CodeEditor to edit extremely large document.
Basically, this class will not load everything from the original file to save the memory. It will divide the file to many pages depending ongetPageLineSize()
. It will then load the page on request only. You don't have to
manually load/unload the pages. The loading process is triggered by those methods like getText(int, int)
,
getLineStartOffset(int)
, etc. You could check if a line/offset is already loaded by isLineLoaded(int)
and isOffsetLoaded(int)
. Those two methods will not trigger a page loading/unloading
operation.
You could invoke setMaximumPages(int)
to configure the maximum unmodified page in the memory. The less you
configured, the less memory the document will use. However, you may have more chance to reload a new page, which
takes time for a large file. You could also invoke setPageLineSize(int)
to balance the memory usage and the
performance.
We do provide page loading/loaded event. You could invoke addPageLoadingListener(PageLoadListener)
to listen
to that.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.jidesoft.editor.SyntaxDocument |
---|
SyntaxDocument.MyUndoableEditListener |
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument |
---|
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement |
Field Summary |
---|
Fields inherited from class com.jidesoft.editor.SyntaxDocument |
---|
_compoundEdit, _compoundEditCount, _undoManager, tokenMarker |
Fields inherited from class javax.swing.text.PlainDocument |
---|
lineLimitAttribute, tabSizeAttribute |
Fields inherited from class javax.swing.text.AbstractDocument |
---|
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName |
Fields inherited from interface com.jidesoft.editor.LineBreak |
---|
CR, LF, LINE_BREAK_CODE_EDITOR, LINE_BREAK_MAC, LINE_BREAK_MIXED, LINE_BREAK_PC, LINE_BREAK_UNIX, LINE_BREAK_UNKNOWN, STRING_CR, STRING_CR_LF, STRING_LF |
Fields inherited from interface javax.swing.text.Document |
---|
StreamDescriptionProperty, TitleProperty |
Constructor Summary | |
---|---|
LazyLoadDocument()
Constructor |
Method Summary | |
---|---|
void |
addPageLoadingListener(PageLoadListener listener)
Add page loading listener. |
char |
charAt(int offset)
|
protected DocumentEvent |
createCombinedDocumentEvent(int offset,
DocumentEvent originalEvent)
Create a DocumentEvent to file. |
protected DocumentEvent |
createCombinedDocumentEvent(int offset,
int length,
DocumentEvent.EventType type)
Create a DocumentEvent to file. |
protected AbstractDocument.AbstractElement |
createDefaultRoot()
|
protected void |
firePageLoadedEvent(int startLineIndex,
boolean pageLoadThread)
Fire page loaded event. |
protected void |
firePageStartLoadingEvent(int startLineIndex,
boolean pageLoadThread)
Fire page start loading event. |
Element |
getDefaultRootElement()
|
String |
getFileName()
Get the file name the CodeEditor is currently editing. |
CharSequence |
getLazyLoadText()
Get the lazy load text for search purpose. |
int |
getLength()
|
int |
getLineEndOffset(int line)
|
int |
getLineNumber(int offset)
|
int |
getLineStartOffset(int line)
|
String |
getLineText(int offset)
|
int |
getMaximumPages()
Get maximum pages. |
int |
getPageLineSize()
Get line size in a page. |
PageLoadListener[] |
getPageLoadListeners()
Get all page load listeners. |
String |
getText(int offset,
int length)
Gets a sequence of text from the document. |
void |
getText(int offset,
int length,
Segment txt)
|
void |
insertString(int offs,
String str,
AttributeSet a)
|
boolean |
isLineLoaded(int line)
Check if the line is loaded in memory already. |
boolean |
isOffsetLoaded(int offset)
Check if the offset is loaded in memory already. |
protected boolean |
needUndoRedo(int offs,
int length,
DocumentEvent.EventType type)
Configure if an operation is undoable/redoable. |
void |
remove(int offs,
int len)
|
void |
removePageLoadingListener(PageLoadListener listener)
Remove page loading listener. |
void |
setFileName(String fileName)
Set the file name the CodeEditor is currently editing. |
void |
setMaximumPages(int maximumPages)
Set maximum pages. |
void |
setPageLineSize(int pageLineSize)
Set line size in a page. |
void |
setTokenMarker(TokenMarker tm)
Sets the token marker that is to be used to split lines of this document up into tokens. |
Methods inherited from class com.jidesoft.editor.SyntaxDocument |
---|
addUndoableEdit, beginCompoundEdit, convertLineBreaks, convertLineBreaks, endCompoundEdit, findNext, findNext, findPrevious, findPrevious, fireInsertUpdate, fireRemoveUpdate, fireRemovingUpdate, getLineCount, getLineLength, getLookupBufferSize, getTokenMarker, getUndoManager, isInCommentOrLiteral, isWordChar, redo, removeUpdate, setLookupBufferSize, setUndoManager, tokenizeLines, tokenizeLines, undo |
Methods inherited from class javax.swing.text.PlainDocument |
---|
getParagraphElement, insertUpdate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LazyLoadDocument()
Method Detail |
---|
protected DocumentEvent createCombinedDocumentEvent(int offset, DocumentEvent originalEvent)
offset
- the start offset of the eventoriginalEvent
- the original event from the underlying document
protected DocumentEvent createCombinedDocumentEvent(int offset, int length, DocumentEvent.EventType type)
offset
- the start offset of the eventlength
- the length of the eventtype
- the edit type of the event
public String getFileName()
public void setFileName(String fileName)
fileName
- the file namepublic int getLength()
getLength
in interface Document
getLength
in class AbstractDocument
public Element getDefaultRootElement()
getDefaultRootElement
in interface Document
getDefaultRootElement
in class PlainDocument
protected AbstractDocument.AbstractElement createDefaultRoot()
createDefaultRoot
in class PlainDocument
public int getLineNumber(int offset)
getLineNumber
in class SyntaxDocument
public String getText(int offset, int length) throws BadLocationException
getLazyLoadText()
to get all the texts for searching or other implementations.
getText
in interface Document
getText
in class AbstractDocument
offset
- the starting offset >= 0length
- the number of characters to retrieve >= 0
BadLocationException
- the range given includes a position that is not a valid position within the
documentDocument.getText(int, int)
public void getText(int offset, int length, Segment txt) throws BadLocationException
getText
in interface Document
getText
in class AbstractDocument
BadLocationException
public String getLineText(int offset) throws BadLocationException
getLineText
in class SyntaxDocument
BadLocationException
public int getPageLineSize()
setPageLineSize(int)
public void setPageLineSize(int pageLineSize)
pageLineSize
- the line sizepublic CharSequence getLazyLoadText()
getText(int,
int)
just in case memory is used up if you have an extremely huge file.
public char charAt(int offset) throws BadLocationException
charAt
in class SyntaxDocument
BadLocationException
public void setTokenMarker(TokenMarker tm)
SyntaxDocument
setTokenMarker
in class SyntaxDocument
tm
- The new token markerpublic boolean isLineLoaded(int line)
isOffsetLoaded(int)
. It will not trigger the page loading process. However, if you try to invoke getLineNumber(int)
to get line number for the offset then invoke this method, you will always get true because
the getLineNumber(int)
will trigger page loading process.
isLineLoaded
in class SyntaxDocument
line
- the line index
isOffsetLoaded(int)
public boolean isOffsetLoaded(int offset)
isOffsetLoaded
in class SyntaxDocument
offset
- the offset to check
public int getMaximumPages()
setMaximumPages(int)
public void setMaximumPages(int maximumPages)
maximumPages
- the maximum pages.public void addPageLoadingListener(PageLoadListener listener)
listener
- the listenerremovePageLoadingListener(PageLoadListener)
,
getPageLoadListeners()
public void removePageLoadingListener(PageLoadListener listener)
listener
- the listenerpublic PageLoadListener[] getPageLoadListeners()
protected void firePageStartLoadingEvent(int startLineIndex, boolean pageLoadThread)
startLineIndex
- the start line indexpageLoadThread
- the flag indicating if the event is fired from page load threadprotected void firePageLoadedEvent(int startLineIndex, boolean pageLoadThread)
startLineIndex
- the start line indexpageLoadThread
- the flag indicating if the event is fired from page load threadprotected boolean needUndoRedo(int offs, int length, DocumentEvent.EventType type)
offs
- the start offsetlength
- the lengthtype
- the edit type
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException
insertString
in interface Document
insertString
in class PlainDocument
BadLocationException
public void remove(int offs, int len) throws BadLocationException
remove
in interface Document
remove
in class AbstractDocument
BadLocationException
public int getLineStartOffset(int line)
getLineStartOffset
in class SyntaxDocument
public int getLineEndOffset(int line)
getLineEndOffset
in class SyntaxDocument
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |