Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

AbstractTreeTableModel.java

00001 /*
00002  * %W% %E%
00003  *
00004  * Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
00005  * 
00006  * Redistribution and use in source and binary forms, with or
00007  * without modification, are permitted provided that the following
00008  * conditions are met:
00009  * 
00010  * - Redistributions of source code must retain the above copyright
00011  *   notice, this list of conditions and the following disclaimer. 
00012  *   
00013  * - Redistribution in binary form must reproduce the above
00014  *   copyright notice, this list of conditions and the following
00015  *   disclaimer in the documentation and/or other materials
00016  *   provided with the distribution. 
00017  *   
00018  * Neither the name of Sun Microsystems, Inc. or the names of
00019  * contributors may be used to endorse or promote products derived
00020  * from this software without specific prior written permission.  
00021  * 
00022  * This software is provided "AS IS," without a warranty of any
00023  * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
00024  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
00025  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
00026  * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
00027  * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
00028  * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
00029  * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE 
00030  * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,   
00031  * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER  
00032  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF 
00033  * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS 
00034  * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00035  * 
00036  * You acknowledge that this software is not designed, licensed or
00037  * intended for use in the design, construction, operation or
00038  * maintenance of any nuclear facility.
00039  */
00040 
00041 package GuiComponents.Inspector.TreeTable;
00042 
00043 import javax.swing.tree.*;
00044 import javax.swing.event.*;
00045  
00055 public abstract class AbstractTreeTableModel implements TreeTableModel {
00056     protected Object root;     
00057     protected EventListenerList listenerList = new EventListenerList();
00058   
00059     public AbstractTreeTableModel(Object root) {
00060         this.root = root; 
00061     }
00062 
00063     //
00064     // Default implmentations for methods in the TreeModel interface. 
00065     //
00066 
00067     public Object getRoot() {
00068         return root;
00069     }
00070 
00071     public boolean isLeaf(Object node) {
00072         return getChildCount(node) == 0; 
00073     }
00074 
00075     public void valueForPathChanged(TreePath path, Object newValue) {}
00076 
00077     // This is not called in the JTree's default mode: use a naive implementation. 
00078     public int getIndexOfChild(Object parent, Object child) {
00079         for (int i = 0; i < getChildCount(parent); i++) {
00080             if (getChild(parent, i).equals(child)) { 
00081                 return i; 
00082             }
00083         }
00084         return -1; 
00085     }
00086 
00087     public void addTreeModelListener(TreeModelListener l) {
00088         listenerList.add(TreeModelListener.class, l);
00089     }
00090 
00091     public void removeTreeModelListener(TreeModelListener l) {
00092         listenerList.remove(TreeModelListener.class, l);
00093     }
00094 
00095     /*
00096      * Notify all listeners that have registered interest for
00097      * notification on this event type.  The event instance 
00098      * is lazily created using the parameters passed into 
00099      * the fire method.
00100      * @see EventListenerList
00101      */
00102     protected void fireTreeNodesChanged(Object source, Object[] path, 
00103                                         int[] childIndices, 
00104                                         Object[] children) {
00105         // Guaranteed to return a non-null array
00106         Object[] listeners = listenerList.getListenerList();
00107         TreeModelEvent e = null;
00108         // Process the listeners last to first, notifying
00109         // those that are interested in this event
00110         for (int i = listeners.length-2; i>=0; i-=2) {
00111             if (listeners[i]==TreeModelListener.class) {
00112                 // Lazily create the event:
00113                 if (e == null)
00114                     e = new TreeModelEvent(source, path, 
00115                                            childIndices, children);
00116                 ((TreeModelListener)listeners[i+1]).treeNodesChanged(e);
00117             }          
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 fireTreeNodesInserted(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]).treeNodesInserted(e);
00143             }          
00144         }
00145     }
00146 
00147     /*
00148      * Notify all listeners that have registered interest for
00149      * notification on this event type.  The event instance 
00150      * is lazily created using the parameters passed into 
00151      * the fire method.
00152      * @see EventListenerList
00153      */
00154     protected void fireTreeNodesRemoved(Object source, Object[] path, 
00155                                         int[] childIndices, 
00156                                         Object[] children) {
00157         // Guaranteed to return a non-null array
00158         Object[] listeners = listenerList.getListenerList();
00159         TreeModelEvent e = null;
00160         // Process the listeners last to first, notifying
00161         // those that are interested in this event
00162         for (int i = listeners.length-2; i>=0; i-=2) {
00163             if (listeners[i]==TreeModelListener.class) {
00164                 // Lazily create the event:
00165                 if (e == null)
00166                     e = new TreeModelEvent(source, path, 
00167                                            childIndices, children);
00168                 ((TreeModelListener)listeners[i+1]).treeNodesRemoved(e);
00169             }          
00170         }
00171     }
00172 
00173     /*
00174      * Notify all listeners that have registered interest for
00175      * notification on this event type.  The event instance 
00176      * is lazily created using the parameters passed into 
00177      * the fire method.
00178      * @see EventListenerList
00179      */
00180     protected void fireTreeStructureChanged(Object source, Object[] path, 
00181                                         int[] childIndices, 
00182                                         Object[] children) {
00183         // Guaranteed to return a non-null array
00184         Object[] listeners = listenerList.getListenerList();
00185         TreeModelEvent e = null;
00186         // Process the listeners last to first, notifying
00187         // those that are interested in this event
00188         for (int i = listeners.length-2; i>=0; i-=2) {
00189             if (listeners[i]==TreeModelListener.class) {
00190                 // Lazily create the event:
00191                 if (e == null)
00192                     e = new TreeModelEvent(source, path, 
00193                                            childIndices, children);
00194                 ((TreeModelListener)listeners[i+1]).treeStructureChanged(e);
00195             }          
00196         }
00197     }
00198 
00199     //
00200     // Default impelmentations for methods in the TreeTableModel interface. 
00201     //
00202 
00203     public Class getColumnClass(int column) { return Object.class; }
00204 
00209     public boolean isCellEditable(Object node, int column) { 
00210          return getColumnClass(column) == TreeTableModel.class; 
00211     }
00212 
00213     public void setValueAt(Object aValue, Object node, int column) {}
00214 
00215 
00216     // Left to be implemented in the subclass:
00217 
00218     /* 
00219      *   public Object getChild(Object parent, int index)
00220      *   public int getChildCount(Object parent) 
00221      *   public int getColumnCount() 
00222      *   public String getColumnName(Object node, int column)  
00223      *   public Object getValueAt(Object node, int column) 
00224      */
00225 
00226 }
00227 

Generated on Thu Jul 15 09:55:38 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5