Example usage for javax.swing.event DocumentEvent getChange

List of usage examples for javax.swing.event DocumentEvent getChange

Introduction

In this page you can find the example usage for javax.swing.event DocumentEvent getChange.

Prototype

public ElementChange getChange(Element elem);

Source Link

Document

Gets the change information for the given element.

Usage

From source file:LiveParenMatcher.java

public void removeUpdate_2(DocumentEvent de) {
    // print some debugging information before matching the parens
    ElementIterator iter = new ElementIterator(de.getDocument());

    for (Element elem = iter.first(); elem != null; elem = iter.next()) {
        DocumentEvent.ElementChange change = de.getChange(elem);
        if (change != null) { // null means there was no change in elem
            System.out.println("Element " + elem.getName() + " (depth " + iter.depth()
                    + ") changed its children: " + change.getChildrenRemoved().length + " children removed, "
                    + change.getChildrenAdded().length + " children added.\n");
        }//  w  ww  . j av  a 2 s  . c  o  m
    }
    SwingUtilities.invokeLater(this); // will call run()
}

From source file:ListenerSample.java

public void printInfo(DocumentEvent documentEvent) {
    System.out.println("Offset: " + documentEvent.getOffset());
    System.out.println("Length: " + documentEvent.getLength());
    DocumentEvent.EventType type = documentEvent.getType();
    String typeString = null;/*from   www. jav  a 2 s . com*/
    if (type.equals(DocumentEvent.EventType.CHANGE)) {
        typeString = "Change";
    } else if (type.equals(DocumentEvent.EventType.INSERT)) {
        typeString = "Insert";
    } else if (type.equals(DocumentEvent.EventType.REMOVE)) {
        typeString = "Remove";
    }
    System.out.println("Type  : " + typeString);
    Document documentSource = documentEvent.getDocument();
    Element rootElement = documentSource.getDefaultRootElement();
    DocumentEvent.ElementChange change = documentEvent.getChange(rootElement);
    System.out.println("Change: " + change);
}