001: /*
002: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package org.mandarax.examples.family;
019:
020: import java.util.List;
021: import java.util.Vector;
022:
023: import javax.swing.tree.TreeModel;
024: import javax.swing.tree.TreePath;
025:
026: import org.mandarax.kernel.DerivationNode;
027:
028: /**
029: * Tree model for derivations.
030: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
031: * @version 3.4 <7 March 05>
032: * @since 1.2
033: */
034: class ProofStructure implements TreeModel {
035:
036: private DerivationNode root = null;
037:
038: /**
039: * Constructor.
040: * @param aRoot the root node of the derivation
041: */
042: public ProofStructure(DerivationNode aRoot) {
043: super ();
044:
045: root = aRoot;
046: }
047:
048: /**
049: * Not implemented method from the tree model interface.
050: */
051: public void addTreeModelListener(
052: javax.swing.event.TreeModelListener l) {
053: }
054:
055: /**
056: * Get the child at the position.
057: * @param parent the parent node
058: * @param index the index
059: * @return the child at the index
060: */
061: public Object getChild(Object parent, int index) {
062: return getChildren(parent).get(index);
063: }
064:
065: /**
066: * Get the number of children.
067: * @param parent a node
068: * @return the number of chilkren
069: */
070: public int getChildCount(Object parent) {
071: return getChildren(parent).size();
072: }
073:
074: /**
075: * Get a list of children of the parent.
076: * @return a list of children
077: * @param parent the parent node
078: */
079: private List getChildren(Object parent) {
080: try {
081: DerivationNode node = (DerivationNode) parent;
082:
083: return node.getSubNodes();
084: } catch (Throwable t) {
085: return new Vector();
086: }
087: }
088:
089: /**
090: * Get the index of a certain child.
091: * @param parent the parent
092: * @param child the child
093: * @return the index
094: *
095: */
096: public int getIndexOfChild(Object parent, Object child) {
097: return getChildren(parent).indexOf(child);
098: }
099:
100: /**
101: * Get the root node.
102: * @return the root node of the tree
103: */
104: public Object getRoot() {
105: return root;
106: }
107:
108: /**
109: * Indicates whether the object represents a leaf.
110: */
111: public boolean isLeaf(Object node) {
112: return false;
113: }
114:
115: /**
116: * Not implemented method from the tree model interface.
117: */
118: public void removeTreeModelListener(
119: javax.swing.event.TreeModelListener l) {
120: }
121:
122: /**
123: * Not implemented method from the tree model interface.
124: */
125: public void valueForPathChanged(TreePath path, Object newValue) {
126: }
127: }
|