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

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

源代码1 项目: jdk1.8-source-analysis   文件: 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();
    }
}
 
源代码2 项目: netbeans   文件: GuardedBlocksHighlighting.java
public void removeUpdate(DocumentEvent e) {
    int changeStart = e.getOffset();
    int changeEnd = e.getOffset() + e.getLength();

    if (isAffectedByChange(changeStart, changeEnd)) {
        fireHighlightsChange(changeStart, changeEnd);
    }
}
 
源代码3 项目: dragonwell8_jdk   文件: BoxView.java
/**
 * Forwards the given <code>DocumentEvent</code> to the child views
 * that need to be notified of the change to the model.
 * If a child changed its requirements and the allocation
 * was valid prior to forwarding the portion of the box
 * from the starting child to the end of the box will
 * be repainted.
 *
 * @param ec changes to the element this view is responsible
 *  for (may be <code>null</code> if there were no changes)
 * @param e the change information from the associated document
 * @param a the current allocation of the view
 * @param f the factory to use to rebuild if the view has children
 * @see #insertUpdate
 * @see #removeUpdate
 * @see #changedUpdate
 * @since 1.3
 */
protected void forwardUpdate(DocumentEvent.ElementChange ec,
                             DocumentEvent e, Shape a, ViewFactory f) {
    boolean wasValid = isLayoutValid(majorAxis);
    super.forwardUpdate(ec, e, a, f);

    // determine if a repaint is needed
    if (wasValid && (! isLayoutValid(majorAxis))) {
        // Repaint is needed because one of the tiled children
        // have changed their span along the major axis.  If there
        // is a hosting component and an allocated shape we repaint.
        Component c = getContainer();
        if ((a != null) && (c != null)) {
            int pos = e.getOffset();
            int index = getViewIndexAtPosition(pos);
            Rectangle alloc = getInsideAllocation(a);
            if (majorAxis == X_AXIS) {
                alloc.x += majorOffsets[index];
                alloc.width -= majorOffsets[index];
            } else {
                alloc.y += minorOffsets[index];
                alloc.height -= minorOffsets[index];
            }
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
源代码4 项目: openjdk-8   文件: BoxView.java
/**
 * Forwards the given <code>DocumentEvent</code> to the child views
 * that need to be notified of the change to the model.
 * If a child changed its requirements and the allocation
 * was valid prior to forwarding the portion of the box
 * from the starting child to the end of the box will
 * be repainted.
 *
 * @param ec changes to the element this view is responsible
 *  for (may be <code>null</code> if there were no changes)
 * @param e the change information from the associated document
 * @param a the current allocation of the view
 * @param f the factory to use to rebuild if the view has children
 * @see #insertUpdate
 * @see #removeUpdate
 * @see #changedUpdate
 * @since 1.3
 */
protected void forwardUpdate(DocumentEvent.ElementChange ec,
                             DocumentEvent e, Shape a, ViewFactory f) {
    boolean wasValid = isLayoutValid(majorAxis);
    super.forwardUpdate(ec, e, a, f);

    // determine if a repaint is needed
    if (wasValid && (! isLayoutValid(majorAxis))) {
        // Repaint is needed because one of the tiled children
        // have changed their span along the major axis.  If there
        // is a hosting component and an allocated shape we repaint.
        Component c = getContainer();
        if ((a != null) && (c != null)) {
            int pos = e.getOffset();
            int index = getViewIndexAtPosition(pos);
            Rectangle alloc = getInsideAllocation(a);
            if (majorAxis == X_AXIS) {
                alloc.x += majorOffsets[index];
                alloc.width -= majorOffsets[index];
            } else {
                alloc.y += minorOffsets[index];
                alloc.height -= minorOffsets[index];
            }
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
源代码5 项目: jdk8u-jdk   文件: BoxView.java
/**
 * Forwards the given <code>DocumentEvent</code> to the child views
 * that need to be notified of the change to the model.
 * If a child changed its requirements and the allocation
 * was valid prior to forwarding the portion of the box
 * from the starting child to the end of the box will
 * be repainted.
 *
 * @param ec changes to the element this view is responsible
 *  for (may be <code>null</code> if there were no changes)
 * @param e the change information from the associated document
 * @param a the current allocation of the view
 * @param f the factory to use to rebuild if the view has children
 * @see #insertUpdate
 * @see #removeUpdate
 * @see #changedUpdate
 * @since 1.3
 */
protected void forwardUpdate(DocumentEvent.ElementChange ec,
                             DocumentEvent e, Shape a, ViewFactory f) {
    boolean wasValid = isLayoutValid(majorAxis);
    super.forwardUpdate(ec, e, a, f);

    // determine if a repaint is needed
    if (wasValid && (! isLayoutValid(majorAxis))) {
        // Repaint is needed because one of the tiled children
        // have changed their span along the major axis.  If there
        // is a hosting component and an allocated shape we repaint.
        Component c = getContainer();
        if ((a != null) && (c != null)) {
            int pos = e.getOffset();
            int index = getViewIndexAtPosition(pos);
            Rectangle alloc = getInsideAllocation(a);
            if (majorAxis == X_AXIS) {
                alloc.x += majorOffsets[index];
                alloc.width -= majorOffsets[index];
            } else {
                alloc.y += minorOffsets[index];
                alloc.height -= minorOffsets[index];
            }
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
源代码6 项目: jdk8u-jdk   文件: BoxView.java
/**
 * Forwards the given <code>DocumentEvent</code> to the child views
 * that need to be notified of the change to the model.
 * If a child changed its requirements and the allocation
 * was valid prior to forwarding the portion of the box
 * from the starting child to the end of the box will
 * be repainted.
 *
 * @param ec changes to the element this view is responsible
 *  for (may be <code>null</code> if there were no changes)
 * @param e the change information from the associated document
 * @param a the current allocation of the view
 * @param f the factory to use to rebuild if the view has children
 * @see #insertUpdate
 * @see #removeUpdate
 * @see #changedUpdate
 * @since 1.3
 */
protected void forwardUpdate(DocumentEvent.ElementChange ec,
                             DocumentEvent e, Shape a, ViewFactory f) {
    boolean wasValid = isLayoutValid(majorAxis);
    super.forwardUpdate(ec, e, a, f);

    // determine if a repaint is needed
    if (wasValid && (! isLayoutValid(majorAxis))) {
        // Repaint is needed because one of the tiled children
        // have changed their span along the major axis.  If there
        // is a hosting component and an allocated shape we repaint.
        Component c = getContainer();
        if ((a != null) && (c != null)) {
            int pos = e.getOffset();
            int index = getViewIndexAtPosition(pos);
            Rectangle alloc = getInsideAllocation(a);
            if (majorAxis == X_AXIS) {
                alloc.x += majorOffsets[index];
                alloc.width -= majorOffsets[index];
            } else {
                alloc.y += minorOffsets[index];
                alloc.height -= minorOffsets[index];
            }
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
源代码7 项目: TencentKona-8   文件: BoxView.java
/**
 * Forwards the given <code>DocumentEvent</code> to the child views
 * that need to be notified of the change to the model.
 * If a child changed its requirements and the allocation
 * was valid prior to forwarding the portion of the box
 * from the starting child to the end of the box will
 * be repainted.
 *
 * @param ec changes to the element this view is responsible
 *  for (may be <code>null</code> if there were no changes)
 * @param e the change information from the associated document
 * @param a the current allocation of the view
 * @param f the factory to use to rebuild if the view has children
 * @see #insertUpdate
 * @see #removeUpdate
 * @see #changedUpdate
 * @since 1.3
 */
protected void forwardUpdate(DocumentEvent.ElementChange ec,
                             DocumentEvent e, Shape a, ViewFactory f) {
    boolean wasValid = isLayoutValid(majorAxis);
    super.forwardUpdate(ec, e, a, f);

    // determine if a repaint is needed
    if (wasValid && (! isLayoutValid(majorAxis))) {
        // Repaint is needed because one of the tiled children
        // have changed their span along the major axis.  If there
        // is a hosting component and an allocated shape we repaint.
        Component c = getContainer();
        if ((a != null) && (c != null)) {
            int pos = e.getOffset();
            int index = getViewIndexAtPosition(pos);
            Rectangle alloc = getInsideAllocation(a);
            if (majorAxis == X_AXIS) {
                alloc.x += majorOffsets[index];
                alloc.width -= majorOffsets[index];
            } else {
                alloc.y += minorOffsets[index];
                alloc.height -= minorOffsets[index];
            }
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
源代码8 项目: TencentKona-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();
    }
}
 
源代码9 项目: 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();
    }
}
 
源代码10 项目: jdk8u60   文件: BoxView.java
/**
 * Forwards the given <code>DocumentEvent</code> to the child views
 * that need to be notified of the change to the model.
 * If a child changed its requirements and the allocation
 * was valid prior to forwarding the portion of the box
 * from the starting child to the end of the box will
 * be repainted.
 *
 * @param ec changes to the element this view is responsible
 *  for (may be <code>null</code> if there were no changes)
 * @param e the change information from the associated document
 * @param a the current allocation of the view
 * @param f the factory to use to rebuild if the view has children
 * @see #insertUpdate
 * @see #removeUpdate
 * @see #changedUpdate
 * @since 1.3
 */
protected void forwardUpdate(DocumentEvent.ElementChange ec,
                             DocumentEvent e, Shape a, ViewFactory f) {
    boolean wasValid = isLayoutValid(majorAxis);
    super.forwardUpdate(ec, e, a, f);

    // determine if a repaint is needed
    if (wasValid && (! isLayoutValid(majorAxis))) {
        // Repaint is needed because one of the tiled children
        // have changed their span along the major axis.  If there
        // is a hosting component and an allocated shape we repaint.
        Component c = getContainer();
        if ((a != null) && (c != null)) {
            int pos = e.getOffset();
            int index = getViewIndexAtPosition(pos);
            Rectangle alloc = getInsideAllocation(a);
            if (majorAxis == X_AXIS) {
                alloc.x += majorOffsets[index];
                alloc.width -= majorOffsets[index];
            } else {
                alloc.y += minorOffsets[index];
                alloc.height -= minorOffsets[index];
            }
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
源代码11 项目: openjdk-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();
    }
}
 
源代码12 项目: openjdk-jdk8u   文件: 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();
    }
}
 
源代码13 项目: jdk8u60   文件: 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();
    }
}
 
源代码14 项目: netbeans   文件: EditorCaret.java
public @Override void removeUpdate(DocumentEvent evt) {
    JTextComponent c = component;
    if (c != null) {
        int offset = evt.getOffset();
        runTransaction(CaretTransaction.RemoveType.DOCUMENT_REMOVE, offset, null, null);
        modifiedUpdate(evt, offset, offset, offset);
    }
}
 
源代码15 项目: netbeans   文件: XMLSyntaxSupport.java
public void insertUpdate(DocumentEvent e) {
    int start = e.getOffset();
    int len = e.getLength();
    try {
        String s = e.getDocument().getText(start + len - 1, 1);
        lastInsertedChar = s.charAt(0);
    } catch (BadLocationException e1) {
    }
}
 
源代码16 项目: 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();
    }
}
 
源代码17 项目: JDKSourceCode1.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();
    }
}
 
源代码18 项目: 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;
    }
}
 
源代码19 项目: netbeans   文件: EditHistory.java
/**
 * Notify the EditHistory of a document edit (insert).
 */
public void insertUpdate(final DocumentEvent e) {
    int pos = e.getOffset();
    int length = e.getLength();
    insertUpdate(pos, length);
}
 
源代码20 项目: netbeans   文件: FoldHierarchyExecution.java
void preRemoveCheckDamaged(Fold fold, DocumentEvent evt, Collection damaged) {
    int removeOffset = evt.getOffset();
    int endRemove = removeOffset + evt.getLength();
    
    int childIndex = FoldUtilitiesImpl.findFoldStartIndex(fold, removeOffset, true);
    if (childIndex == -1) {
        if (fold.getFoldCount() == 0) {
            return;
        }
        Fold first = fold.getFold(0);
        if (first.getStartOffset() <= endRemove) {
            childIndex = 0;
        } else {
            return;
        }
    }
    // Check if previous fold was affected too
    if (childIndex >= 1) {
        Fold prevChildFold = fold.getFold(childIndex - 1);
        if (prevChildFold.getEndOffset() == removeOffset) {
            preRemoveCheckDamaged(prevChildFold, evt, damaged);
        }
    }
    boolean removed;
    boolean startsWithin = false;
    do {
        int flag;
        
        Fold childFold = fold.getFold(childIndex);
        startsWithin = childFold.getStartOffset() < removeOffset && 
                       childFold.getEndOffset() <= endRemove;
        removed = false;
        if (FoldUtilitiesImpl.becomesEmptyAfterRemove(childFold, evt)) {
            damaged.add(OPERATION_EMPTY | FoldUtilitiesImpl.FLAG_START_DAMAGED | FoldUtilitiesImpl.FLAG_END_DAMAGED);
            damaged.add(childFold);
            preRemoveCheckDamaged(childFold, evt, damaged); // nest prior removing
            removed = true;

            if (LOG.isLoggable(Level.FINER)) {
                LOG.finer("preRemoveCheck: removed empty " // NOI18N
                + childFold + '\n');
            }

        } else if ((flag = FoldUtilitiesImpl.becomesDamagedByRemove(childFold, evt, false)) != 0) {
            damaged.add(OPERATION_DAMAGE | flag);
            damaged.add(childFold);
            preRemoveCheckDamaged(childFold, evt, damaged); // nest prior removing
            removed = true;

            if (LOG.isLoggable(Level.FINE)) {
                LOG.finer("preRemoveCheck: removed damaged " // NOI18N
                + childFold + '\n');
            }

        } else if (childFold.getFoldCount() > 0) { // check children
            // Some children could be damaged even if this one was not
            preRemoveCheckDamaged(childFold, evt, damaged);
        }

        // Check whether the expand is necessary
        if (!removed) { // only if not removed yet
            if (childFold.isCollapsed() && ((flag = FoldUtilitiesImpl.becomesDamagedByRemove(childFold, evt, true)) > 0)) {
                damaged.add(OPERATION_COLLAPSE | flag);
                damaged.add(childFold);
                if (LOG.isLoggable(Level.FINER)) {
                    LOG.finer("preRemoveCheck: expansion needed " // NOI18N
                    + childFold + '\n');
                }
            } else {
                damaged.add(OPERATION_UPDATE);
                damaged.add(childFold);
                if (LOG.isLoggable(Level.FINER)) {
                    LOG.finer("preRemoveCheck: removeUpdate call " // NOI18N
                    + childFold + '\n');
                }
            }
        }

        childIndex++;
    } while ((startsWithin || removed) && childIndex < fold.getFoldCount());
}