javax.swing.event.DocumentEvent#getLength()源码实例Demo

下面列出了javax.swing.event.DocumentEvent#getLength() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: InstantRefactoringPerformer.java
@Override
   public synchronized void insertUpdate(DocumentEvent e) {
if (inSync)
    return ;

       //check for modifications outside the first region:
       if (e.getOffset() < region.getFirstRegionStartOffset() || (e.getOffset() + e.getLength()) > region.getFirstRegionEndOffset()) {
           release(true);
           return;
       }
       
       inSync = true;
       region.sync();
       span = region.getFirstRegionLength();
       ui.updateInput(getRegionText(0));
       inSync = false;
       
       requestRepaint();
   }
 
源代码2 项目: rapidminer-studio   文件: JEditTextArea.java
@Override
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);
}
 
源代码3 项目: netbeans   文件: GuardedBlocksHighlighting.java
public void insertUpdate(DocumentEvent e) {
    int changeStart = e.getOffset();
    int changeEnd = e.getOffset() + e.getLength();

    if (isAffectedByChange(changeStart, changeEnd)) {
        fireHighlightsChange(changeStart, changeEnd);
    }
}
 
源代码4 项目: hottub   文件: TableView.java
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
    super.changedUpdate(e, a, f);
    int pos = e.getOffset();
    if (pos <= getStartOffset() && (pos + e.getLength()) >=
        getEndOffset()) {
        RowView.this.setPropertiesFromAttributes();
    }
}
 
源代码5 项目: dragonwell8_jdk   文件: HRuleView.java
public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
    super.changedUpdate(changes, a, f);
    int pos = changes.getOffset();
    if (pos <= getStartOffset() && (pos + changes.getLength()) >=
        getEndOffset()) {
        setPropertiesFromAttributes();
    }
}
 
源代码6 项目: jdk8u_jdk   文件: TableView.java
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
    super.changedUpdate(e, a, f);
    int pos = e.getOffset();
    if (pos <= getStartOffset() && (pos + e.getLength()) >=
        getEndOffset()) {
        RowView.this.setPropertiesFromAttributes();
    }
}
 
源代码7 项目: dragonwell8_jdk   文件: TableView.java
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
    super.changedUpdate(e, a, f);
    int pos = e.getOffset();
    if (pos <= getStartOffset() && (pos + e.getLength()) >=
        getEndOffset()) {
        RowView.this.setPropertiesFromAttributes();
    }
}
 
源代码8 项目: netbeans   文件: DocumentModel.java
private void documentChanged(DocumentEvent documentEvent) {
    if(!documentDirty) {
        fireSourceChanged();
    }
    //indicate that the synchronization between document content and the element may be broken
    //not used by the model logic itself but by the "resortElements" method.
    documentDirty = true;
    
    try {
        //test whether a new text was inserted before or after the root element boundaries (positions)
        if(getRootElement().getStartOffset() > 0 || getRootElement().getEndOffset() < getDocument().getLength()) {
            getRootElement().setStartPosition(0);
            getRootElement().setEndPosition(getDocument().getLength());
        }
        
        //TODO: here we have to decide whether the document change affects
        //the model and how.
        int change_offset = documentEvent.getOffset();
        int change_length = documentEvent.getLength();
        
        int type = documentEvent.getType().equals(EventType.REMOVE) ? DocumentChange.REMOVE : DocumentChange.INSERT;
        DocumentChange dchi = new DocumentChange(getDocument().createPosition(change_offset), change_length, type);
        documentChanges.add(dchi);
        if(debug) System.out.println(dchi);
    }catch(BadLocationException e) {
        e.printStackTrace();
    }
    
    requestModelUpdate(false);
}
 
源代码9 项目: TencentKona-8   文件: TableView.java
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
    super.changedUpdate(e, a, f);
    int pos = e.getOffset();
    if (pos <= getStartOffset() && (pos + e.getLength()) >=
        getEndOffset()) {
        RowView.this.setPropertiesFromAttributes();
    }
}
 
源代码10 项目: jdk8u60   文件: HRuleView.java
public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
    super.changedUpdate(changes, a, f);
    int pos = changes.getOffset();
    if (pos <= getStartOffset() && (pos + changes.getLength()) >=
        getEndOffset()) {
        setPropertiesFromAttributes();
    }
}
 
源代码11 项目: hottub   文件: BlockView.java
public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
    super.changedUpdate(changes, a, f);
    int pos = changes.getOffset();
    if (pos <= getStartOffset() && (pos + changes.getLength()) >=
        getEndOffset()) {
        setPropertiesFromAttributes();
    }
}
 
源代码12 项目: netbeans   文件: BaseDocumentUnitTestCase.java
public void insertUpdate(DocumentEvent e) {
    int offset = e.getOffset();
    int length = e.getLength();
    int newDot = dot;
    short changed = 0;
    if (newDot >= offset) {
        newDot += length;
        changed |= 1;
    }
    int newMark = mark;
    if (newMark >= offset) {
        newMark += length;
        changed |= 2;
    }

    if (changed != 0) {
        if (newMark == newDot) {
            setDot(newDot);
            ensureValidPosition();
        } else {
            setDot(newMark);
            if (getDot() == newMark) {
                moveDot(newDot);
            }
            ensureValidPosition();
        }

    }
}
 
源代码13 项目: netbeans   文件: AbstractOutputPane.java
public final void insertUpdate(DocumentEvent e) {
    //Ensure it is consumed
    e.getLength();
    documentChanged();
    if (e.getOffset() + e.getLength() >= getCaretPos() && (locked || !(e instanceof OutputDocument.DO))) {
        //#119985 only move caret when not in editable section
        OutputDocument doc = (OutputDocument)e.getDocument();
        if (! (e instanceof OutputDocument.DO) && getCaretPos() >= doc.getOutputLength()) {
            return ;
        }
        
        getCaret().setDot(e.getOffset() + e.getLength());
    }
}
 
源代码14 项目: JDKSourceCode1.8   文件: BlockView.java
public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
    super.changedUpdate(changes, a, f);
    int pos = changes.getOffset();
    if (pos <= getStartOffset() && (pos + changes.getLength()) >=
        getEndOffset()) {
        setPropertiesFromAttributes();
    }
}
 
源代码15 项目: openjdk-jdk8u   文件: HRuleView.java
public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
    super.changedUpdate(changes, a, f);
    int pos = changes.getOffset();
    if (pos <= getStartOffset() && (pos + changes.getLength()) >=
        getEndOffset()) {
        setPropertiesFromAttributes();
    }
}
 
源代码16 项目: openjdk-jdk8u   文件: TableView.java
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
    super.changedUpdate(e, a, f);
    int pos = e.getOffset();
    if (pos <= getStartOffset() && (pos + e.getLength()) >=
        getEndOffset()) {
        RowView.this.setPropertiesFromAttributes();
    }
}
 
源代码17 项目: groovy   文件: ConsoleTextEditor.java
public void insertUpdate(DocumentEvent de) {
    lastUpdate = de.getOffset() + de.getLength();
}
 
源代码18 项目: netbeans   文件: LineRootElement.java
public void insertUpdate(DocumentEvent evt, UndoableEdit edit, AttributeSet attr) {
        int insertOffset = evt.getOffset();
        int insertEndOffset = insertOffset + evt.getLength();
        CharSequence text = DocumentUtilities.getText(doc);
        if (insertOffset > 0) { // [Swing] marks (and elements) at offset zero do not move up
            insertOffset--;
        }
        try {
            int index = -1; // Index of the elements modification - computed lazily
            List<LineElement> addedLines = null; // Collected added lines
            LineElement removedLine = null; // Removed line element
            Position lastAddedLineEndPos = null;
            for (int offset = insertOffset; offset < insertEndOffset; offset++) {
                if (text.charAt(offset) == '\n') {
                    if (index == -1) { // Not computed yet
                        index = getElementIndex(offset);
                        removedLine = (LineElement)getElement(index);
                        lastAddedLineEndPos = removedLine.getStartPosition();
                        addedLines = new ArrayList<LineElement>(2);
                    }
                    Position lineEndPos = doc.createPosition(offset + 1);
                    addedLines.add(new LineElement(this, lastAddedLineEndPos, lineEndPos));
                    lastAddedLineEndPos = lineEndPos;
                }
            }
            if (index != -1) { // Some lines were added
                // If the text was inserted at the line boundary i.e. right after existing '\n'
                // and the ending char of the inserted text was not '\n' (otherwise
                // it would be a "clean" line insert) then there must be two line elements
                // removed.
                Position removedLineEndPos = removedLine.getEndPosition();
                int removedLineEndOffset = removedLineEndPos.getOffset();
                Element[] removed; // removed line elements
                int lastAddedLineEndOffset = lastAddedLineEndPos.getOffset();
                if (insertEndOffset == removedLineEndOffset
                        && lastAddedLineEndOffset != removedLineEndOffset
//                        && index + 1 < getElementCount()
                ) {
                    LineElement removedLine2 = (LineElement)getElement(index + 1);
                    removed = new Element[] { removedLine, removedLine2 };
                    removedLineEndPos = removedLine2.getEndPosition();
                    removedLineEndOffset = removedLineEndPos.getOffset();
                } else { // just one line removed
                    removed = new Element[] { removedLine };
                }
                if (lastAddedLineEndOffset < removedLineEndOffset) {
                    addedLines.add(new LineElement(this, lastAddedLineEndPos, removedLineEndPos));
                }

                Element[] added = new Element[addedLines.size()];
                addedLines.toArray(added);

                edit.addEdit(new Edit(index, removed, added));
                replace(index, removed.length, added);
            }
        } catch (BadLocationException e) {
            throw new IllegalStateException(e.toString());
        }
    }
 
源代码19 项目: gate-core   文件: LuceneDataStoreSearchGUI.java
@Override
public void removeUpdate(DocumentEvent ev) {
  if(mode == PROGRAMMATIC || mode == INSERT) {
    return;
  }

  int pos = ev.getOffset();

  if(ev.getLength() != 1 || (pos < start || pos > end)) {
    // cancel any autocompletion if the user cut some text
    // or delete outside brackets when in POPUP mode
    cleanup();
    return;
  }
  if(mode == POPUP_TYPES) {
    end = pos;
    String type = getText().substring(start, end);
    if(!type.matches("[a-zA-Z0-9]+")) {
      return;
    }
    for(int i = 0; i < queryList.getModel().getSize(); i++) {
      if(startsWithIgnoreCase(
              queryList.getModel().getElementAt(i), type)) {
        queryPopupWindow.setVisible(true);
        queryList.setSelectedIndex((i));
        queryList.ensureIndexIsVisible(i);
        break;
      }
    }
  } else if(mode == POPUP_FEATURES) {
    end = pos;
    String feature = getText().substring(start, end);
    if(!feature.matches("[a-zA-Z0-9]+")) {
      return;
    }
    for(int i = 0; i < queryList.getModel().getSize(); i++) {
      if(startsWithIgnoreCase(
              queryList.getModel().getElementAt(i), feature)) {
        queryPopupWindow.setVisible(true);
        queryList.setSelectedIndex((i));
        queryList.ensureIndexIsVisible(i);
        break;
      }
    }
  }
}
 
源代码20 项目: marathonv5   文件: TextAreaDemo.java
public void insertUpdate(DocumentEvent ev) {
    if (ev.getLength() != 1) {
        return;
    }

    int pos = ev.getOffset();
    String content = null;
    try {
        content = textArea.getText(0, pos + 1);
    } catch (BadLocationException e) {
        e.printStackTrace();
    }

    // Find where the word starts
    int w;
    for (w = pos; w >= 0; w--) {
        if (!Character.isLetter(content.charAt(w))) {
            break;
        }
    }
    if (pos - w < 2) {
        // Too few chars
        return;
    }

    String prefix = content.substring(w + 1).toLowerCase();
    int n = Collections.binarySearch(words, prefix);
    if (n < 0 && -n <= words.size()) {
        String match = words.get(-n - 1);
        if (match.startsWith(prefix)) {
            // A completion is found
            String completion = match.substring(pos - w);
            // We cannot modify Document from within notification,
            // so we submit a task that does the change later
            SwingUtilities.invokeLater(new CompletionTask(completion, pos + 1));
        }
    } else {
        // Nothing found
        mode = Mode.INSERT;
    }
}