Ejemplo n.º 1
0
  /**
   * 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();
  }
Ejemplo n.º 2
0
  protected void documentChanged(DocumentEvent evt) {
    DocumentEvent.ElementChange ch = evt.getChange(document.getDefaultRootElement());

    int count;
    if (ch == null) count = 0;
    else count = ch.getChildrenAdded().length - ch.getChildrenRemoved().length;

    int line = getLineOfOffset(evt.getOffset());
    if (count == 0) {
      painter.invalidateLine(line);
    }
    // do magic stuff
    else if (line < firstLine) {
      setFirstLine(firstLine + count);
    }
    // end of magic stuff
    else {
      painter.invalidateLineRange(line, firstLine + visibleLines);
      updateScrollBars();
    }
  }