Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

TAbstractTreeTableModel.java

00001 /*
00002 *  Name:        TAbstractCellEditor.java
00003 *  Author:      Philip Milne
00004 *  Maintainer:  Rafael Jesus Alcantara Perez
00005 *  Summary:     Abstract tree-table model.
00006 *  Date:        $Date: 2003/09/28 23:27:56 $
00007 *  Revision:    $Revision: 1.3 $
00008 *
00009 *  Copyright (C) 2003  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00010 *
00011 *  This program is free software; you can redistribute it and/or modify
00012 *  it under the terms of the GNU General Public License as published by
00013 *  the Free Software Foundation; either version 2 of the License, or
00014 *  (at your option) any later version.
00015 *
00016 *  This program is distributed in the hope that it will be useful,
00017 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 *  GNU General Public License for more details.
00020 *
00021 *  You should have received a copy of the GNU General Public License
00022 *  along with this program; if not, write to the Free Software
00023 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024 *  MA 02111-1307, USA.
00025 *
00026 *
00027 *  Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
00028 *
00029 *  Redistribution and use in source and binary forms, with or
00030 *  without modification, are permitted provided that the following
00031 *  conditions are met:
00032 *
00033 *  - Redistributions of source code must retain the above copyright
00034 *    notice, this list of conditions and the following disclaimer.
00035 *
00036 *  - Redistribution in binary form must reproduce the above
00037 *    copyright notice, this list of conditions and the following
00038 *    disclaimer in the documentation and/or other materials
00039 *    provided with the distribution.
00040 *
00041 *  Neither the name of Sun Microsystems, Inc. or the names of
00042 *  contributors may be used to endorse or promote products derived
00043 *  from this software without specific prior written permission.
00044 *
00045 *  This software is provided "AS IS," without a warranty of any
00046 *  kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
00047 *  WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
00048 *  FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
00049 *  EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
00050 *  DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
00051 *  RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
00052 *  ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
00053 *  FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
00054 *  SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
00055 *  CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
00056 *  THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
00057 *  BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00058 *
00059 *  You acknowledge that this software is not designed, licensed or
00060 *  intended for use in the design, construction, operation or
00061 *  maintenance of any nuclear facility.
00062 */
00063 
00065 package org.mpcl.nui.treetable;
00066 
00067 import javax.swing.event.EventListenerList;
00068 import javax.swing.event.TreeModelEvent;
00069 import javax.swing.event.TreeModelListener;
00070 import javax.swing.tree.TreePath;
00071 
00072  
00084 public abstract class TAbstractTreeTableModel implements ITreeTableModel
00085 {
00086 
00088   protected EventListenerList   tEventListenerList;
00089 
00091   protected Object   tRootNode;
00092 
00093 
00094   //
00095   //  C O N S T R U C T O R S
00096   //
00097 
00102   public TAbstractTreeTableModel (Object tROOT_NODE)
00103   {
00104     tRootNode          = tROOT_NODE;
00105     tEventListenerList = new EventListenerList();
00106   }
00107 
00113   public void addTreeModelListener (TreeModelListener tTREE_MODEL_LISTENER)
00114   {
00115     tEventListenerList.add (TreeModelListener.class, tTREE_MODEL_LISTENER);
00116   }
00117 
00123   public void removeTreeModelListener (TreeModelListener tTREE_MODEL_LISTENER)
00124   {
00125     tEventListenerList.remove (TreeModelListener.class, tTREE_MODEL_LISTENER);
00126   }
00127 
00135   public void setValueAt (Object tVALUE, Object tNODE, int iCOLUMN) {}
00136 
00145   public void valueForPathChanged (TreePath tTREE_PATH, Object newValue) {}
00146 
00147 
00148   //
00149   //   S E L E C T O R S
00150   //
00151 
00157   protected void fireTreeNodesChanged (TreePath tTREE_PATH)
00158   {
00159 
00160     Object[]         aListenerTypeListenerPair;
00161     TreeModelEvent   tTreeModelEvent = null;
00162 
00163     //
00164     //  The getListenerList()  method is guaranteed to return a non-null array.
00165     //  Processes  the  listeners  last  to first,  notifying  those  that  are
00166     //  interested in this event.  The \a ChangeEvent object is created lazily.
00167     //
00168     aListenerTypeListenerPair = tEventListenerList.getListenerList();
00169     for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00170     {
00171       if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00172       {
00173         if ( tTreeModelEvent == null )
00174         {
00175           tTreeModelEvent = new TreeModelEvent (this, tTREE_PATH);
00176         }
00177         ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeNodesChanged (tTreeModelEvent);
00178       }          
00179     }
00180 
00181   }  // fireTreeNodesChanged()
00182 
00201   protected void fireTreeNodesChanged ( Object   tSOURCE         ,
00202                                         Object[] atPATH          ,
00203                                         int[]    aiCHILD_INDICES ,
00204                                         Object[] atCHILDREN      )
00205   {
00206 
00207     Object[]         aListenerTypeListenerPair;
00208     TreeModelEvent   tTreeModelEvent = null;
00209 
00210     //
00211     //  The getListenerList()  method is guaranteed to return a non-null array.
00212     //  Processes  the  listeners  last  to first,  notifying  those  that  are
00213     //  interested in this event.  The \a ChangeEvent object is created lazily.
00214     //
00215     aListenerTypeListenerPair = tEventListenerList.getListenerList();
00216     for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00217     {
00218       if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00219       {
00220         if ( tTreeModelEvent == null )
00221         {
00222           tTreeModelEvent = new TreeModelEvent (tSOURCE, atPATH, aiCHILD_INDICES, atCHILDREN);
00223         }
00224         ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeNodesChanged (tTreeModelEvent);
00225       }          
00226     }
00227 
00228   }  // fireTreeNodesChanged()
00229 
00248   protected void fireTreeNodesInserted ( Object   tSOURCE         ,
00249                                          Object[] atPATH          ,
00250                                          int[]    aiCHILD_INDICES ,
00251                                          Object[] atCHILDREN      )
00252   {
00253 
00254     Object[]         aListenerTypeListenerPair;
00255     TreeModelEvent   tTreeModelEvent = null;
00256 
00257     //
00258     //  The getListenerList()  method is guaranteed to return a non-null array.
00259     //  Processes  the  listeners  last  to first,  notifying  those  that  are
00260     //  interested in this event.  The \a ChangeEvent object is created lazily.
00261     //
00262     aListenerTypeListenerPair = tEventListenerList.getListenerList();
00263     for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00264     {
00265       if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00266       {
00267         if ( tTreeModelEvent == null )
00268         {
00269           tTreeModelEvent = new TreeModelEvent (tSOURCE, atPATH, aiCHILD_INDICES, atCHILDREN);
00270         }
00271         ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeNodesInserted (tTreeModelEvent);
00272       }
00273     }
00274 
00275   }  // fireTreeNodesInserted()
00276 
00277   /*
00278   *  Notifies all listeners  that have registered interest for  notification on
00279   *  this event type.
00280   *  @param tSOURCE
00281   *         The object  responsible  for  generating the  event  (typically the
00282   *         creator of the event object passes this for its value).
00283   *  @param atPATH
00284   *         An  array of \a Object  identifying  the path to the  parent of the
00285   *         modified  item(s),  where the  first  element of  the array  is the
00286   *         object stored at the root node  and the last  element is the object
00287   *         stored at the parent node.
00288   *  @param aiCHILD_INDICES
00289   *         An array of \a int that  specifies the index  values of the removed
00290   *         items. The indices must be in sorted order, from lowest to highest.
00291   *  @param atCHILDREN
00292   *         An array of \a Object containing the inserted,  removed, or changed
00293   *         objects.
00294   */
00295   protected void fireTreeNodesRemoved ( Object   tSOURCE         ,
00296                                         Object[] atPATH          ,
00297                                         int[]    aiCHILD_INDICES ,
00298                                         Object[] atCHILDREN      )
00299   {
00300 
00301     Object[]         aListenerTypeListenerPair;
00302     TreeModelEvent   tTreeModelEvent = null;
00303 
00304     //
00305     //  The getListenerList()  method is guaranteed to return a non-null array.
00306     //  Processes  the  listeners  last  to first,  notifying  those  that  are
00307     //  interested in this event.  The \a ChangeEvent object is created lazily.
00308     //
00309     aListenerTypeListenerPair = tEventListenerList.getListenerList();
00310     for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00311     {
00312       if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00313       {
00314         if ( tTreeModelEvent == null )
00315         {
00316           tTreeModelEvent = new TreeModelEvent (tSOURCE, atPATH, aiCHILD_INDICES, atCHILDREN);
00317         }
00318         ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeNodesRemoved (tTreeModelEvent);
00319       }
00320     }
00321 
00322   }  // fireTreeNodesRemoved()
00323 
00329   protected void fireTreeStructureChanged (TreePath tTREE_PATH)
00330   {
00331 
00332     Object[]         aListenerTypeListenerPair;
00333     TreeModelEvent   tTreeModelEvent = null;
00334 
00335     //
00336     //  The getListenerList()  method is guaranteed to return a non-null array.
00337     //  Processes  the  listeners  last  to first,  notifying  those  that  are
00338     //  interested in this event.  The \a ChangeEvent object is created lazily.
00339     //
00340     aListenerTypeListenerPair = tEventListenerList.getListenerList();
00341     for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00342     {
00343       if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00344       {
00345         if ( tTreeModelEvent == null )
00346         {
00347           tTreeModelEvent = new TreeModelEvent (this, tTREE_PATH);
00348         }
00349         ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeStructureChanged (tTreeModelEvent);
00350       }          
00351     }
00352 
00353   }  // fireTreeStructureChanged()
00354 
00373   protected void fireTreeStructureChanged ( Object   tSOURCE         ,
00374                                             Object[] atPATH          ,
00375                                             int[]    aiCHILD_INDICES ,
00376                                             Object[] atCHILDREN      )
00377   {
00378 
00379     Object[]         aListenerTypeListenerPair;
00380     TreeModelEvent   tTreeModelEvent = null;
00381 
00382     //
00383     //  The getListenerList()  method is guaranteed to return a non-null array.
00384     //  Processes  the  listeners  last  to first,  notifying  those  that  are
00385     //  interested in this event.  The \a ChangeEvent object is created lazily.
00386     //
00387     aListenerTypeListenerPair = tEventListenerList.getListenerList();
00388     for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00389     {
00390       if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00391       {
00392         if ( tTreeModelEvent == null )
00393         {
00394           tTreeModelEvent = new TreeModelEvent (tSOURCE, atPATH, aiCHILD_INDICES, atCHILDREN);
00395         }
00396         ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeStructureChanged (tTreeModelEvent);
00397       }
00398     }
00399 
00400   }  // fireTreeStructureChanged()
00401 
00402 
00403   //
00404   //  S E L E C T O R S
00405   //
00406 
00415   public Class getColumnClass (int iCOLUMN)
00416   {
00417     return Object.class;
00418   }
00419 
00428   public int getIndexOfChild (Object tPARENT_NODE, Object tCHILD_NODE)
00429   {
00430     int   iChildNodeIndex = -1;
00431 
00432     for (int I = 0; ( I < getChildCount (tPARENT_NODE) ) ;++I)
00433     {
00434       if ( getChild (tPARENT_NODE, I).equals (tCHILD_NODE) )
00435       {
00436         iChildNodeIndex = I;
00437         break;
00438       }
00439     }
00440     return iChildNodeIndex;
00441   }
00442 
00448   public Object getRoot()
00449   {
00450     return tRootNode;
00451   }
00452 
00463   public boolean isCellEditable (Object tNODE, int iCOLUMN)
00464   { 
00465     return ( getColumnClass (iCOLUMN) == ITreeTableModel.class );
00466   }
00467 
00477   public boolean isLeaf (Object tNODE)
00478   {
00479     return ( getChildCount (tNODE) == 0 );
00480   }
00481 
00482 }  // class TAbstractTreeTableModel

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18