001: package persistence.antlr.debug.misc;
002:
003: /* ANTLR Translator Generator
004: * Project led by Terence Parr at http://www.jGuru.com
005: * Software rights: http://www.antlr.org/license.html
006: *
007: */
008:
009: import persistence.antlr.collections.AST;
010:
011: import javax.swing.*;
012: import javax.swing.event.*;
013: import javax.swing.tree.*;
014:
015: public class JTreeASTModel implements TreeModel {
016:
017: AST root = null;
018:
019: public JTreeASTModel(AST t) {
020: if (t == null) {
021: throw new IllegalArgumentException("root is null");
022: }
023: root = t;
024: }
025:
026: public void addTreeModelListener(TreeModelListener l) {
027: }
028:
029: public Object getChild(Object parent, int index) {
030: if (parent == null) {
031: return null;
032: }
033: AST p = (AST) parent;
034: AST c = p.getFirstChild();
035: if (c == null) {
036: throw new ArrayIndexOutOfBoundsException(
037: "node has no children");
038: }
039: int i = 0;
040: while (c != null && i < index) {
041: c = c.getNextSibling();
042: i++;
043: }
044: return c;
045: }
046:
047: public int getChildCount(Object parent) {
048: if (parent == null) {
049: throw new IllegalArgumentException("root is null");
050: }
051: AST p = (AST) parent;
052: AST c = p.getFirstChild();
053: int i = 0;
054: while (c != null) {
055: c = c.getNextSibling();
056: i++;
057: }
058: return i;
059: }
060:
061: public int getIndexOfChild(Object parent, Object child) {
062: if (parent == null || child == null) {
063: throw new IllegalArgumentException("root or child is null");
064: }
065: AST p = (AST) parent;
066: AST c = p.getFirstChild();
067: if (c == null) {
068: throw new ArrayIndexOutOfBoundsException(
069: "node has no children");
070: }
071: int i = 0;
072: while (c != null && c != child) {
073: c = c.getNextSibling();
074: i++;
075: }
076: if (c == child) {
077: return i;
078: }
079: throw new java.util.NoSuchElementException(
080: "node is not a child");
081: }
082:
083: public Object getRoot() {
084: return root;
085: }
086:
087: public boolean isLeaf(Object node) {
088: if (node == null) {
089: throw new IllegalArgumentException("node is null");
090: }
091: AST t = (AST) node;
092: return t.getFirstChild() == null;
093: }
094:
095: public void removeTreeModelListener(TreeModelListener l) {
096: }
097:
098: public void valueForPathChanged(TreePath path, Object newValue) {
099: System.out.println("heh, who is calling this mystery method?");
100: }
101: }
|