Methods Summary |
---|
public void | changedUpdate(javax.swing.event.DocumentEvent de)
// no insertion or deletion, so do nothing
|
public void | insertUpdate(javax.swing.event.DocumentEvent de)
SwingUtilities.invokeLater(this); // will call run()
|
public void | insertUpdate_2(javax.swing.event.DocumentEvent de)
Document doc = de.getDocument();
int offset = de.getOffset();
int length = de.getLength();
String inserted = "";
try {
inserted = doc.getText(offset, length);
} catch (BadLocationException ble) { }
for (int j=0; j < inserted.length(); j+=1) {
char ch = inserted.charAt(j);
if (ch == '(" || ch == '[" || ch == '{" ||
ch == ')" || ch == ']" || ch == '}" ) {
SwingUtilities.invokeLater(this); // will call run()
return; // no need to check further
}
}
|
public void | insertUpdate_3(javax.swing.event.DocumentEvent de)
Document doc = de.getDocument();
int offset = de.getOffset();
int length = de.getLength();
Segment seg = new Segment();
try {
doc.getText(offset, length, seg); // text placed in Segment
} catch (BadLocationException ble) { }
// iterate through the Segment
for (char ch = seg.first(); ch != seg.DONE; ch = seg.next())
if (ch == '(" || ch == '[" || ch == '{" ||
ch == ')" || ch == ']" || ch == '}" ) {
SwingUtilities.invokeLater(this); // will call run()
return; // no need to check further
}
|
public static void | main(java.lang.String[] args)
JFrame frame = new JFrame("LiveParenMatcher");
frame.setContentPane(new JScrollPane(new LiveParenMatcher()));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
frame.setVisible(true);
|
public void | removeUpdate(javax.swing.event.DocumentEvent de)
SwingUtilities.invokeLater(this); // will call run()
|
public void | removeUpdate_2(javax.swing.event.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");
}
}
SwingUtilities.invokeLater(this); // will call run()
|