/** * Sets the document this text area is editing. * @param document The document */ public void setDocument(SyntaxDocument document) { if(this.document == document) return; if(this.document != null) this.document.removeDocumentListener(documentHandler); this.document = document; document.addDocumentListener(documentHandler); select(0,0); updateScrollBars(); painter.repaint(); }
@Override public void setText(String t) { this.getDocument().removeUndoableEditListener(this.undoListener); try { super.setText(t); } finally { this.getDocument().addUndoableEditListener(this.undoListener); } }
/** * Sets the entire text of this text area. */ public void setText(String text) { try { document.beginCompoundEdit(); document.remove(0,document.getLength()); document.insertString(0,text,null); } catch(BadLocationException bl) { bl.printStackTrace(); } finally { document.endCompoundEdit(); } }
/** * Reparses the document, by passing all lines to the token * marker. This should be called after the document is first * loaded. */ public void tokenizeLines() { tokenizeLines(0,getDefaultRootElement().getElementCount()); }
@Override public void addDocumentListener(DocumentListener listener) { editor.getDocument().addDocumentListener(listener); }
@Override public void removeDocumentListener(DocumentListener listener) { editor.getDocument().removeDocumentListener(listener); }
/** * Returns the number of lines in the document. */ public final int getLineCount() { return document.getDefaultRootElement().getElementCount(); }
/** * Reparses the document, by passing the specified lines to the * token marker. This should be called after a large quantity of * text is first inserted. * @param start The first line to parse * @param len The number of lines, after the first one to parse */ public void tokenizeLines(int start, int len) { if(tokenMarker == null || !tokenMarker.supportsMultilineTokens()) return; Segment lineSegment = new Segment(); Element map = getDefaultRootElement(); len += start; try { for(int i = start; i < len; i++) { Element lineElement = map.getElement(i); int lineStart = lineElement.getStartOffset(); getText(lineStart,lineElement.getEndOffset() - lineStart - 1,lineSegment); tokenMarker.markTokens(lineSegment,i); } } catch(BadLocationException bl) { bl.printStackTrace(); } }
/** * Returns the length of the document. Equivalent to calling * <code>getDocument().getLength()</code>. */ public final int getDocumentLength() { return document.getLength(); }
DEFAULTS.document = new SyntaxDocument(); DEFAULTS.editable = true;
JEditTextAreaUndoable() { this.undoListener = new JTextFieldUndoListener(new JEditTextAreaUndoableAdapter(this)); this.getDocument().addUndoableEditListener(this.undoListener); }
painter.invalidateLineRange(newStartLine,newEndLine); document.addUndoableEdit(new CaretUndo( selectionStart,selectionEnd));
@Override public void addDocumentListener(DocumentListener listener) { editor.getDocument().addDocumentListener(listener); }
@Override public void removeDocumentListener(DocumentListener listener) { editor.getDocument().removeDocumentListener(listener); }
/** * Returns the line containing the specified offset. * @param offset The offset */ public final int getLineOfOffset(int offset) { return document.getDefaultRootElement().getElementIndex(offset); }
/** * Sets the token marker that is to be used to split lines of * this document up into tokens. May throw an exception if * this is not supported for this type of document. * @param tm The new token marker */ public void setTokenMarker(TokenMarker tm) { tokenMarker = tm; if(tm == null) return; tokenMarker.insertLines(0,getDefaultRootElement() .getElementCount()); tokenizeLines(); }
editor.getDocument().removeDocumentListener(this); editor.getDocument().addDocumentListener(this); isModified = false; return true;
document.beginCompoundEdit(); document.remove(caret,str.length()); document.insertString(caret,str,null); document.endCompoundEdit();
/** * Returns the start offset of the specified line. * @param line The line * @return The start offset of the specified line, or -1 if the line is * invalid */ public int getLineStartOffset(int line) { Element lineElement = document.getDefaultRootElement() .getElement(line); if(lineElement == null) return -1; else return lineElement.getStartOffset(); }