Java Code Examples for javax.swing.event.DocumentEvent#ElementChange

The following examples show how to use javax.swing.event.DocumentEvent#ElementChange . 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: JEditTextArea.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
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();
	}
}
 
Example 2
Source File: PlainDocumentCompatibilityRandomTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void checkEventsEqual(DocumentEvent testEvent) {
    if (masterEvent.getOffset() != testEvent.getOffset()) {
        fail("masterEvent.getOffset()=" + masterEvent.getOffset()
            + " != testEvent.getOffset()=" + testEvent.getOffset());
    }
    if (masterEvent.getLength() != testEvent.getLength()) {
        fail("masterEvent.getLength()=" + masterEvent.getLength()
            + " != testEvent.getLength()=" + testEvent.getLength());
    }
    if (masterEvent.getType() != testEvent.getType()) {
        fail("masterEvent.getType()=" + masterEvent.getType()
            + " != testEvent.getType()=" + testEvent.getType());
    }
    DocumentEvent.ElementChange masterChange = masterEvent.getChange(masterDoc.getDefaultRootElement());
    DocumentEvent.ElementChange testChange = testEvent.getChange(testDoc.getDefaultRootElement());
    checkElementChangesEqual(masterChange, testChange);
}
 
Example 3
Source File: BaseDocumentEvent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override DocumentEvent.ElementChange getChange(Element elem) {
    // Super of getChange()
    if (changeLookup2 != null) {
        return (DocumentEvent.ElementChange) changeLookup2.get(elem);
    }
    int n = edits.size();
    for (int i = 0; i < n; i++) {
        Object o = edits.elementAt(i);
        if (o instanceof DocumentEvent.ElementChange) {
            DocumentEvent.ElementChange c = (DocumentEvent.ElementChange) o;
            if (c.getElement() == elem) {
                return c;
            }
        }
    }
    return null;
    // End super of getChange()
}
 
Example 4
Source File: BoxView.java    From jdk1.8-source-analysis with Apache License 2.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 5
Source File: TableView.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected void forwardUpdate(DocumentEvent.ElementChange ec,
                             DocumentEvent e, Shape a, ViewFactory f) {
    super.forwardUpdate(ec, e, a, f);
    // A change in any of the table cells usually effects the whole table,
    // so redraw it all!
    if (a != null) {
        Component c = getContainer();
        if (c != null) {
            Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
                               a.getBounds();
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
Example 6
Source File: TableView.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
protected void forwardUpdate(DocumentEvent.ElementChange ec,
                                 DocumentEvent e, Shape a, ViewFactory f) {
    super.forwardUpdate(ec, e, a, f);
    // A change in any of the table cells usually effects the whole table,
    // so redraw it all!
    if (a != null) {
        Component c = getContainer();
        if (c != null) {
            Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
                               a.getBounds();
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
Example 7
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 8
Source File: BoxView.java    From JDKSourceCode1.8 with MIT License 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 9
Source File: BoxView.java    From jdk8u-dev-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 10
Source File: TableView.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void forwardUpdate(DocumentEvent.ElementChange ec,
                                 DocumentEvent e, Shape a, ViewFactory f) {
    super.forwardUpdate(ec, e, a, f);
    // A change in any of the table cells usually effects the whole table,
    // so redraw it all!
    if (a != null) {
        Component c = getContainer();
        if (c != null) {
            Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
                               a.getBounds();
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
Example 11
Source File: BasicTextAreaUI.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
protected boolean updateChildren(DocumentEvent.ElementChange ec,
                                 DocumentEvent e, ViewFactory f) {
    return false;
}
 
Example 12
Source File: BasicTextAreaUI.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected boolean updateChildren(DocumentEvent.ElementChange ec,
                                 DocumentEvent e, ViewFactory f) {
    return false;
}
 
Example 13
Source File: BasicTextAreaUI.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected boolean updateChildren(DocumentEvent.ElementChange ec,
                                 DocumentEvent e, ViewFactory f) {
    return false;
}
 
Example 14
Source File: OutputDocumentTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void assertEventsIdentical (Document styled, OutputDocument doc, DocumentEvent styEvent, DocumentEvent docEvent) throws Exception {
    int docOffset = docEvent.getOffset();
    int styOffset = styEvent.getOffset();
    
    int docLength = docEvent.getLength();
    int styLength = styEvent.getLength();
    
    assertTrue ("OutputDocument event offset is " + docOffset + " but " + 
        "offset of identical change to a StyledDocument is " + styOffset,
        docOffset == styOffset);
    
    assertTrue ("OutputDocument event length is " + docLength + " but " +
        "length from identical change to a StyledDocument is " + 
        styLength, styLength == docLength);
    
    DocumentEvent.ElementChange docEc = docEvent.getChange(doc);
    DocumentEvent.ElementChange styEc = styEvent.getChange(styled.getDefaultRootElement());
    
    int docIndex = docEc.getIndex();
    int styIndex = styEc.getIndex();
    
    Element[] docAdded = docEc.getChildrenAdded();
    Element[] styAdded = styEc.getChildrenAdded();
    
    assertTrue ("Index of change in OutputDocument was " + docIndex + " but" +
    " an identical change on a StyledDocument returns " + styIndex,
    styIndex == docIndex);
    
    /*assertTrue ("OutputDocument returned an array of " + docAdded.length +
        " affected elements, but an identical change on a StyledDocument " +
        "produces an array of " + styAdded.length, styAdded.length == 
        docAdded.length);*/

    for (int i=0; i < styAdded.length; i++) {
        int docStartOffset = docAdded[i].getStartOffset();
        int styStartOffset = styAdded[i].getStartOffset();
        assertTrue ("Start offset of element " + i + " from " +
            "OutputDocument.ODDEvent.EC is " + docStartOffset + " but " +
            "offset from identical change in a StyledDocument is " + 
            styStartOffset, styStartOffset == docStartOffset);
        
        int docEndOffset = docAdded[i].getEndOffset();
        int styEndOffset = styAdded[i].getEndOffset();
        assertTrue ("End offset of element " + i + " from " +
            "OutputDocument.ODDEvent.EC is " + docStartOffset + " but " +
            "offset from identical change in a StyledDocument is " + 
            styEndOffset, styEndOffset == docEndOffset);
        
        String styTxt = styled.getText(styAdded[i].getStartOffset(), styAdded[i].getEndOffset() - styAdded[i].getStartOffset());
        String docTxt = styled.getText(styAdded[i].getStartOffset(), styAdded[i].getEndOffset() - styAdded[i].getStartOffset());
        assertEquals("Element " + i + " text from styled document is " + 
            styTxt + " but OutputDocument return " + docTxt + " for the " +
            "same indices", styTxt, docTxt);
    }
}
 
Example 15
Source File: BasicTextAreaUI.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
protected boolean updateChildren(DocumentEvent.ElementChange ec,
                                 DocumentEvent e, ViewFactory f) {
    return false;
}
 
Example 16
Source File: BasicTextAreaUI.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
protected boolean updateChildren(DocumentEvent.ElementChange ec,
                                 DocumentEvent e, ViewFactory f) {
    return false;
}
 
Example 17
Source File: BasicTextAreaUI.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
protected boolean updateChildren(DocumentEvent.ElementChange ec,
                                 DocumentEvent e, ViewFactory f) {
    return false;
}
 
Example 18
Source File: AsyncBoxView.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Update the layout in response to receiving notification of
 * change from the model.  This is implemented to note the
 * change on the ChildLocator so that offsets of the children
 * will be correctly computed.
 *
 * @param ec changes to the element this view is responsible
 *  for (may be null if there were no changes).
 * @param e the change information from the associated document
 * @param a the current allocation of the view
 * @see #insertUpdate
 * @see #removeUpdate
 * @see #changedUpdate
 */
protected void updateLayout(DocumentEvent.ElementChange ec,
                                DocumentEvent e, Shape a) {
    if (ec != null) {
        // the newly inserted children don't have a valid
        // offset so the child locator needs to be messaged
        // that the child prior to the new children has
        // changed size.
        int index = Math.max(ec.getIndex() - 1, 0);
        ChildState cs = getChildState(index);
        locator.childChanged(cs);
    }
}
 
Example 19
Source File: AsyncBoxView.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Update the layout in response to receiving notification of
 * change from the model.  This is implemented to note the
 * change on the ChildLocator so that offsets of the children
 * will be correctly computed.
 *
 * @param ec changes to the element this view is responsible
 *  for (may be null if there were no changes).
 * @param e the change information from the associated document
 * @param a the current allocation of the view
 * @see #insertUpdate
 * @see #removeUpdate
 * @see #changedUpdate
 */
protected void updateLayout(DocumentEvent.ElementChange ec,
                                DocumentEvent e, Shape a) {
    if (ec != null) {
        // the newly inserted children don't have a valid
        // offset so the child locator needs to be messaged
        // that the child prior to the new children has
        // changed size.
        int index = Math.max(ec.getIndex() - 1, 0);
        ChildState cs = getChildState(index);
        locator.childChanged(cs);
    }
}
 
Example 20
Source File: GapBoxView.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * Update the layout in response to receiving notification of
 * change from the model.
 *
 * @param ec changes to the element this view is responsible
 *  for (may be null if there were no changes).
 * @param e the change information from the associated document
 * @param a the current allocation of the view
 * @see #insertUpdate
 * @see #removeUpdate
 * @see #changedUpdate
 */
protected @Override void updateLayout(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a) {
    
    //super.updateLayout(ec, e, a);
}