示例#1
0
    public void insertUpdate(DocumentEvent evt) {
      documentChanged(evt);

      int offset = evt.getOffset();
      int length = evt.getLength();

      int newStart;
      int newEnd;

      if (selectionStart > offset || (selectionStart == selectionEnd && selectionStart == offset))
        newStart = selectionStart + length;
      else newStart = selectionStart;

      if (selectionEnd >= offset) newEnd = selectionEnd + length;
      else newEnd = selectionEnd;

      select(newStart, newEnd);
    }
示例#2
0
    public void removeUpdate(DocumentEvent evt) {
      documentChanged(evt);

      int offset = evt.getOffset();
      int length = evt.getLength();

      int newStart;
      int newEnd;

      if (selectionStart > offset) {
        if (selectionStart > offset + length) newStart = selectionStart - length;
        else newStart = offset;
      } else newStart = selectionStart;

      if (selectionEnd > offset) {
        if (selectionEnd > offset + length) newEnd = selectionEnd - length;
        else newEnd = offset;
      } else newEnd = selectionEnd;

      select(newStart, newEnd);
    }
示例#3
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();
    }
  }