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

TTree.java

00001 /*
00002 *  Name:        TTree.java
00003 *  Author:      Philip Milne
00004 *               Scott Violet
00005 *  Maintainer:  Rafael Jesus Alcantara Perez
00006 *  Summary:     Tree used to render tree columns.
00007 *  Date:        $Date: 2003/09/28 23:22:05 $
00008 *  Revision:    $Revision: 1.2 $
00009 *
00010 *  Copyright (C) 2003  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00011 *
00012 *  This program is free software; you can redistribute it and/or modify
00013 *  it under the terms of the GNU General Public License as published by
00014 *  the Free Software Foundation; either version 2 of the License, or
00015 *  (at your option) any later version.
00016 *
00017 *  This program is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  You should have received a copy of the GNU General Public License
00023 *  along with this program; if not, write to the Free Software
00024 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00025 *  MA 02111-1307, USA.
00026 *
00027 *
00028 *  Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
00029 *
00030 *  Redistribution and use in source and binary forms, with or
00031 *  without modification, are permitted provided that the following
00032 *  conditions are met:
00033 *
00034 *  - Redistributions of source code must retain the above copyright
00035 *    notice, this list of conditions and the following disclaimer.
00036 *
00037 *  - Redistribution in binary form must reproduce the above
00038 *    copyright notice, this list of conditions and the following
00039 *    disclaimer in the documentation and/or other materials
00040 *    provided with the distribution.
00041 *
00042 *  Neither the name of Sun Microsystems, Inc. or the names of
00043 *  contributors may be used to endorse or promote products derived
00044 *  from this software without specific prior written permission.
00045 *
00046 *  This software is provided "AS IS," without a warranty of any
00047 *  kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
00048 *  WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
00049 *  FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
00050 *  EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
00051 *  DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
00052 *  RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
00053 *  ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
00054 *  FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
00055 *  SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
00056 *  CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
00057 *  THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
00058 *  BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00059 *
00060 *  You acknowledge that this software is not designed, licensed or
00061 *  intended for use in the design, construction, operation or
00062 *  maintenance of any nuclear facility.
00063 */
00064 
00066 package org.mpcl.nui.treetable;
00067 
00068 import java.awt.Color;
00069 import java.awt.Component;
00070 import java.awt.Graphics;
00071 import java.util.Enumeration;
00072 import javax.swing.JTable;
00073 import javax.swing.JTree;
00074 import javax.swing.UIManager;
00075 import javax.swing.table.TableCellRenderer;
00076 import javax.swing.tree.DefaultTreeCellRenderer;
00077 import javax.swing.tree.TreeCellRenderer;
00078 import javax.swing.tree.TreeModel;
00079 import javax.swing.tree.TreeNode;
00080 import javax.swing.tree.TreePath;
00081 import org.mpcl.nui.TTreeTable;
00082 
00083 
00085 public class TTree extends JTree
00086 {
00087 
00089   protected int iVisibleRow;
00090 
00092   protected TTreeTable   tTreeTable;
00093 
00094 
00095   //
00096   //  C O N S T R U C T O R S
00097   //
00098 
00105   public TTree (TTreeTable tTREE_TABLE, TreeModel tTREE_MODEL)
00106   {
00107     super (tTREE_MODEL);
00108     tTreeTable = tTREE_TABLE;
00109     setCellRenderer (new TTreeTableCellRenderer (tTREE_TABLE));
00110   }
00111 
00116   public void collapseAll (TreePath tPARENT_TREE_PATH)
00117   {
00118 
00119     Enumeration   I;
00120     TreeNode      tChildNode;
00121     TreePath      tChildPath;
00122     TreeNode      tLastNode = (TreeNode) tPARENT_TREE_PATH.getLastPathComponent();
00123 
00124     if ( tLastNode.getChildCount() > 0 )
00125     {
00126       //
00127       //  Collapses recursively all child nodes.
00128       //
00129       I = tLastNode.children();
00130       while ( I.hasMoreElements() )
00131       {
00132         tChildNode = (TreeNode) I.nextElement();
00133         tChildPath = tPARENT_TREE_PATH.pathByAddingChild (tChildNode);
00134         collapseAll (tChildPath);
00135       }
00136     }
00137 
00138     //
00139     //  Collapse must be done bottom-up.
00140     //
00141     collapsePath (tPARENT_TREE_PATH);
00142 
00143   }  // collapseAll()
00144 
00149   public void expandAll (TreePath tPARENT_TREE_PATH)
00150   {
00151 
00152     Enumeration   I;
00153     TreeNode      tChildNode;
00154     TreePath      tChildPath;
00155     TreeNode      tLastNode = (TreeNode) tPARENT_TREE_PATH.getLastPathComponent();
00156 
00157     if ( tLastNode.getChildCount() > 0 )
00158     {
00159       //
00160       //  Expands recursively all child nodes.
00161       //
00162       I = tLastNode.children();
00163       while ( I.hasMoreElements() )
00164       {
00165         tChildNode = (TreeNode) I.nextElement();
00166         tChildPath = tPARENT_TREE_PATH.pathByAddingChild (tChildNode);
00167         expandAll (tChildPath);
00168       }
00169     }
00170 
00171     //
00172     //  Expansion must be done bottom-up.
00173     //
00174     expandPath (tPARENT_TREE_PATH);
00175 
00176   }  // expandAll()
00177 
00188   public void setBounds (int iX, int iY, int iWIDTH, int iHEIGHT)
00189   {
00190     super.setBounds (iX, 0, iWIDTH, tTreeTable.getHeight());
00191   }
00192 
00199   public void updateUI()
00200   {
00201     super.updateUI();
00202 
00203     //
00204     //  Make the tree's cell renderer use the table's cell selection colors.
00205     //
00206 
00207     DefaultTreeCellRenderer   tDefaultTreeCellRenderer; 
00208     TreeCellRenderer          tTreeCellRenderer = getCellRenderer();
00209 
00210     if ( tTreeCellRenderer instanceof DefaultTreeCellRenderer )
00211     {
00212       tDefaultTreeCellRenderer = (DefaultTreeCellRenderer) tTreeCellRenderer;
00213       tDefaultTreeCellRenderer.setTextSelectionColor (UIManager.getColor ("Table.selectionForeground"));
00214       tDefaultTreeCellRenderer.setBackgroundSelectionColor (UIManager.getColor ("Table.selectionBackground"));
00215     }
00216   }
00217 
00222   public void setLastVisibleRow (int iVISIBLE_ROW)
00223   {
00224     iVisibleRow = iVISIBLE_ROW;
00225   }
00226 
00231   public void setRowHeight (int iROW_HEIGHT)
00232   {
00233     if ( iROW_HEIGHT > 0 )
00234     {
00235       super.setRowHeight (iROW_HEIGHT); 
00236       if ( tTreeTable.getRowHeight() != iROW_HEIGHT )
00237       {
00238         tTreeTable.setRowHeight (getRowHeight()); 
00239       }
00240     }
00241   }
00242 
00243 
00244   //
00245   //  S E L E C T O R S
00246   //
00247 
00253   public void paint (Graphics tGRAPHICS)
00254   {
00255     tGRAPHICS.translate (0, -iVisibleRow * getRowHeight());
00256     super.paint (tGRAPHICS);
00257   }
00258 
00259 }  // class TTree

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