Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

AbstractTreeTableModel.java

00001 package edu.ksu.cis.bandera.abstraction.gui;
00002 
00003 /*
00004  * @(#)AbstractTreeTableModel.java  1.2 98/10/27
00005  *
00006  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
00007  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
00008  * All rights reserved.
00009  *
00010  * This software is the confidential and proprietary information
00011  * of Sun Microsystems, Inc. ("Confidential Information").  You
00012  * shall not disclose such Confidential Information and shall use
00013  * it only in accordance with the terms of the license agreement
00014  * you entered into with Sun.
00015  */
00016 
00017 import javax.swing.tree.*;
00018 import javax.swing.event.*;
00019 
00020 /**
00021  * @version 1.2 10/27/98
00022  * An abstract implementation of the TreeTableModel interface, handling the list 
00023  * of listeners. 
00024  * @author Philip Milne
00025  */
00026 
00027 public abstract class AbstractTreeTableModel extends DefaultTreeModel implements TreeTableModel {
00028     protected AbstractTreeNode root;
00029     protected EventListenerList listenerList = new EventListenerList();
00030 // Left to be implemented in the subclass:
00031 
00032 /* 
00033  *   public Object getChild(Object parent, int index)
00034  *   public int getChildCount(Object parent) 
00035  *   public int getColumnCount() 
00036  *   public String getColumnName(Object node, int column)  
00037  *   public Object getValueAt(Object node, int column) 
00038  */
00039 public AbstractTreeTableModel(AbstractTreeNode root) {
00040     super(root);
00041     this.root = root;
00042 }
00043     public void addTreeModelListener(TreeModelListener l) {
00044         listenerList.add(TreeModelListener.class, l);
00045     }
00046     /*
00047      * Notify all listeners that have registered interest for
00048      * notification on this event type.  The event instance 
00049      * is lazily created using the parameters passed into 
00050      * the fire method.
00051      * @see EventListenerList
00052      */
00053     protected void fireTreeNodesChanged(Object source, Object[] path, 
00054                                         int[] childIndices, 
00055                                         Object[] children) {
00056         // Guaranteed to return a non-null array
00057         Object[] listeners = listenerList.getListenerList();
00058         TreeModelEvent e = null;
00059         // Process the listeners last to first, notifying
00060         // those that are interested in this event
00061         for (int i = listeners.length-2; i>=0; i-=2) {
00062             if (listeners[i]==TreeModelListener.class) {
00063                 // Lazily create the event:
00064                 if (e == null)
00065                     e = new TreeModelEvent(source, path, 
00066                                            childIndices, children);
00067                 ((TreeModelListener)listeners[i+1]).treeNodesChanged(e);
00068             }          
00069         }
00070     }
00071     /*
00072      * Notify all listeners that have registered interest for
00073      * notification on this event type.  The event instance 
00074      * is lazily created using the parameters passed into 
00075      * the fire method.
00076      * @see EventListenerList
00077      */
00078     protected void fireTreeNodesInserted(Object source, Object[] path, 
00079                                         int[] childIndices, 
00080                                         Object[] children) {
00081         // Guaranteed to return a non-null array
00082         Object[] listeners = listenerList.getListenerList();
00083         TreeModelEvent e = null;
00084         // Process the listeners last to first, notifying
00085         // those that are interested in this event
00086         for (int i = listeners.length-2; i>=0; i-=2) {
00087             if (listeners[i]==TreeModelListener.class) {
00088                 // Lazily create the event:
00089                 if (e == null)
00090                     e = new TreeModelEvent(source, path, 
00091                                            childIndices, children);
00092                 ((TreeModelListener)listeners[i+1]).treeNodesInserted(e);
00093             }          
00094         }
00095     }
00096     /*
00097      * Notify all listeners that have registered interest for
00098      * notification on this event type.  The event instance 
00099      * is lazily created using the parameters passed into 
00100      * the fire method.
00101      * @see EventListenerList
00102      */
00103     protected void fireTreeNodesRemoved(Object source, Object[] path, 
00104                                         int[] childIndices, 
00105                                         Object[] children) {
00106         // Guaranteed to return a non-null array
00107         Object[] listeners = listenerList.getListenerList();
00108         TreeModelEvent e = null;
00109         // Process the listeners last to first, notifying
00110         // those that are interested in this event
00111         for (int i = listeners.length-2; i>=0; i-=2) {
00112             if (listeners[i]==TreeModelListener.class) {
00113                 // Lazily create the event:
00114                 if (e == null)
00115                     e = new TreeModelEvent(source, path, 
00116                                            childIndices, children);
00117                 ((TreeModelListener)listeners[i+1]).treeNodesRemoved(e);
00118             }          
00119         }
00120     }
00121     /*
00122      * Notify all listeners that have registered interest for
00123      * notification on this event type.  The event instance 
00124      * is lazily created using the parameters passed into 
00125      * the fire method.
00126      * @see EventListenerList
00127      */
00128     protected void fireTreeStructureChanged(Object source, Object[] path, 
00129                                         int[] childIndices, 
00130                                         Object[] children) {
00131         // Guaranteed to return a non-null array
00132         Object[] listeners = listenerList.getListenerList();
00133         TreeModelEvent e = null;
00134         // Process the listeners last to first, notifying
00135         // those that are interested in this event
00136         for (int i = listeners.length-2; i>=0; i-=2) {
00137             if (listeners[i]==TreeModelListener.class) {
00138                 // Lazily create the event:
00139                 if (e == null)
00140                     e = new TreeModelEvent(source, path, 
00141                                            childIndices, children);
00142                 ((TreeModelListener)listeners[i+1]).treeStructureChanged(e);
00143             }          
00144         }
00145     }
00146 //
00147 // Default impelmentations for methods in the TreeTableModel interface. 
00148 //
00149 
00150 public Class getColumnClass(int column) {
00151     return Object.class;
00152 }
00153     // This is not called in the JTree's default mode: use a naive implementation. 
00154     public int getIndexOfChild(Object parent, Object child) {
00155         for (int i = 0; i < getChildCount(parent); i++) {
00156         if (getChild(parent, i).equals(child)) { 
00157             return i; 
00158         }
00159         }
00160     return -1; 
00161     }
00162     //
00163     // Default implmentations for methods in the TreeModel interface. 
00164     //
00165 
00166     public Object getRoot() {
00167         return root;
00168     }
00169    /** By default, make the column with the Tree in it the only editable one. 
00170     *  Making this column editable causes the JTable to forward mouse 
00171     *  and keyboard events in the Tree column to the underlying JTree. 
00172     */ 
00173     public boolean isCellEditable(Object node, int column) { 
00174          return getColumnClass(column) == TreeTableModel.class; 
00175     }
00176     public boolean isLeaf(Object node) {
00177         return getChildCount(node) == 0; 
00178     }
00179     public void removeTreeModelListener(TreeModelListener l) {
00180         listenerList.remove(TreeModelListener.class, l);
00181     }
00182 /**
00183  * Insert the method's description here.
00184  * Creation date: (5/4/00 3:29:03 PM)
00185  * @param root java.lang.Object
00186  */
00187 public void setRoot(AbstractTreeNode root) {
00188     this.root = root;
00189 }
00190     public void setValueAt(Object aValue, Object node, int column) {}
00191     public void valueForPathChanged(TreePath path, Object newValue) {}
00192 }

Generated at Thu Feb 7 06:36:50 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001