Java Code Examples for javax.swing.event.DocumentEvent#getOffset()

The following examples show how to use javax.swing.event.DocumentEvent#getOffset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockView.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 2
Source File: TableView.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
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();
    }
}
 
Example 3
Source File: BlockView.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
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();
    }
}
 
Example 4
Source File: XMLSyntaxSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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) {
    }
}
 
Example 5
Source File: EditorCaret.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 6
Source File: TableView.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 7
Source File: BlockView.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 8
Source File: BlockView.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 9
Source File: BoxView.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 10
Source File: BlockView.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 11
Source File: BoxView.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 12
Source File: BoxView.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 13
Source File: BoxView.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 14
Source File: BoxView.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 15
Source File: BoxView.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 16
Source File: GuardedBlocksHighlighting.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void removeUpdate(DocumentEvent e) {
    int changeStart = e.getOffset();
    int changeEnd = e.getOffset() + e.getLength();

    if (isAffectedByChange(changeStart, changeEnd)) {
        fireHighlightsChange(changeStart, changeEnd);
    }
}
 
Example 17
Source File: HRuleView.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 18
Source File: TextAreaDemo.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
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;
    }
}
 
Example 19
Source File: FoldHierarchyExecution.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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());
}
 
Example 20
Source File: EditHistory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}