/** * 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(); }
/** * 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(); } }
/** * Returns the number of lines in the document. */ public final int getLineCount() { return document.getDefaultRootElement().getElementCount(); }
/** * 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()); }
String noWordSep = (String)textArea.getDocument().getProperty("noWordSep"); caret = TextUtilities.findWordEnd(lineText,caret,noWordSep); textArea.getDocument().remove(start, (caret + lineStart) - start);
sourceArea.getDocument().addDocumentListener(new SimpleDocumentAdapter() { @Override public void updated(DocumentEvent e) {
.getDocument().getProperty( PlainDocument.tabSizeAttribute)).intValue(); .getTokenMarker(); int x = textArea.getHorizontalOffset();
/** * 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(); } }
char ch = lineText.charAt(Math.max(0,offset - 1)); String noWordSep = (String)document.getProperty("noWordSep"); if(noWordSep == null) noWordSep = "";
/** * Copies the specified substring of the document into a segment. * If the offsets are invalid, the segment will contain a null string. * @param start The start offset * @param len The length of the substring * @param segment The segment */ public final void getText(int start, int len, Segment segment) { try { document.getText(start,len,segment); } catch(BadLocationException bl) { bl.printStackTrace(); segment.offset = segment.count = 0; } }
/** * Returns the length of the document. Equivalent to calling * <code>getDocument().getLength()</code>. */ public final int getDocumentLength() { return document.getLength(); }
/** * Returns the document's token marker. Equivalent to calling * <code>getDocument().getTokenMarker()</code>. */ public final TokenMarker getTokenMarker() { return document.getTokenMarker(); }
DEFAULTS.document = new SyntaxDocument(); DEFAULTS.editable = true;
painter.invalidateLineRange(newStartLine,newEndLine); document.addUndoableEdit(new CaretUndo( selectionStart,selectionEnd));
/** * 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(); }
String noWordSep = (String)textArea.getDocument().getProperty("noWordSep"); caret = TextUtilities.findWordStart(lineText,caret,noWordSep); textArea.getDocument().remove( caret + lineStart, start - (caret + lineStart));
sourceArea.getDocument().addDocumentListener(new SimpleDocumentAdapter() { @Override public void updated(DocumentEvent e) {
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); int caret = textArea.getCaretPosition(); int line = textArea.getCaretLine(); int lineStart = textArea.getLineStartOffset(line); caret -= lineStart; String lineText = textArea.getLineText(textArea .getCaretLine()); if(caret == lineText.length()) { if(lineStart + caret == textArea.getDocumentLength()) { textArea.getToolkit().beep(); return; } caret++; } else { String noWordSep = (String)textArea.getDocument().getProperty("noWordSep"); caret = TextUtilities.findWordEnd(lineText,caret,noWordSep); } if(select) textArea.select(textArea.getMarkPosition(), lineStart + caret); else textArea.setCaretPosition(lineStart + caret); } }
/** * Returns the specified substring of the document. * @param start The start offset * @param len The length of the substring * @return The substring, or null if the offsets are invalid */ public final String getText(int start, int len) { try { return document.getText(start,len); } catch(BadLocationException bl) { bl.printStackTrace(); return null; } }