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

TTreeTable.java

00001 /*
00002 *  Name:        TTreeTable.java
00003 *  Author:      Philip Milne
00004 *               Scott Violet
00005 *  Maintainer:  Rafael Jesus Alcantara Perez
00006 *  Summary:     A table that can hold a tree column.
00007 *  Date:        $Date: 2003/09/29 10:27:05 $
00008 *  Revision:    $Revision: 1.3 $
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;
00067 
00068 import java.awt.Component;
00069 import java.awt.Dimension;
00070 import java.awt.Graphics;
00071 import java.awt.event.MouseEvent;
00072 import java.util.Enumeration;
00073 import java.util.EventObject;
00074 import javax.swing.JTable;
00075 import javax.swing.LookAndFeel;
00076 import javax.swing.tree.TreePath;
00077 import org.mpcl.nui.treetable.ITreeTableCellRenderer;
00078 import org.mpcl.nui.treetable.ITreeTableModel;
00079 import org.mpcl.nui.treetable.TTree;
00080 import org.mpcl.nui.treetable.TTreeSelectionModel;
00081 import org.mpcl.nui.treetable.TTreeTableCellEditor;
00082 import org.mpcl.nui.treetable.TTreeTableCellRenderer;
00083 import org.mpcl.nui.treetable.TTreeTableModelToTableModelAdapter;
00084 
00085 
00090 public class TTreeTable extends JTable
00091 {
00092 
00094   protected TTree   tTree;
00095 
00100   protected ITreeTableModel   tTreeTableModel;
00101 
00102 
00103   //
00104   //  C O N S T R U C T O R S
00105   //
00106 
00111   public TTreeTable (ITreeTableModel tTREE_TABLE_MODEL)
00112   {
00113 
00114     super();
00115 
00116     TTreeSelectionModel   tTreeSelectionModel;
00117 
00118     tTreeTableModel = tTREE_TABLE_MODEL;
00119     tTree           = new TTree (this, tTreeTableModel);
00120     super.setModel (new TTreeTableModelToTableModelAdapter (tTreeTableModel, tTree));
00121 
00122     //
00123     //  Forces the JTable and JTree to share their row selection models.
00124     //
00125     tTreeSelectionModel = new TTreeSelectionModel (tTree);
00126     tTree.setSelectionModel (tTreeSelectionModel);
00127     setSelectionModel (tTreeSelectionModel.getListSelectionModel()); 
00128 
00129     //
00130     //  Installs the tree cell renderer and editor.
00131     //
00132     setDefaultRenderer (new TTreeTableCellRenderer (this));
00133     setDefaultEditor (ITreeTableModel.class, new TTreeTableCellEditor (this));
00134 
00135     //
00136     //  Shows no grid.
00137     //
00138     setShowGrid (false);
00139 
00140     //
00141     //  Sets no intercell spacing.
00142     setIntercellSpacing (new Dimension (0, 0)); 
00143 
00144     //
00145     //  And updates the height of the trees row to match that of the table.
00146     //
00147     if ( tTree.getRowHeight() < 1 )
00148     {
00149       //
00150       //  Metal looks better like this.
00151       //
00152       setRowHeight (20);
00153     }
00154 
00155   }  // TTreeTable()
00156 
00158   public void collapseTreeAll()
00159   {
00160     tTree.collapseAll (new TreePath (tTree.getModel().getRoot()));
00161   }
00162 
00164   public void expandTreeAll()
00165   {
00166     tTree.expandAll (new TreePath (tTree.getModel().getRoot()));
00167   }
00168 
00176   public void setDefaultRenderer (ITreeTableCellRenderer tTREE_TABLE_CELL_RENDERER)
00177   {
00178 
00179     ITreeTableCellRenderer   tTreeTableCellRenderer;
00180 
00181     if ( tTREE_TABLE_CELL_RENDERER != null )
00182     {
00183       tTree.setCellRenderer (tTREE_TABLE_CELL_RENDERER);
00184       setDefaultRenderer (ITreeTableModel.class, tTREE_TABLE_CELL_RENDERER);
00185     }
00186     else
00187     {
00188       tTreeTableCellRenderer = new TTreeTableCellRenderer (this);
00189       tTree.setCellRenderer (tTreeTableCellRenderer);
00190       setDefaultRenderer (ITreeTableModel.class, tTreeTableCellRenderer);
00191     }
00192 
00193   }  // setDefaultRenderer()
00194 
00199   public void setLastVisibleRow (int iLAST_VISIBLE_ROW)
00200   {
00201     tTree.setLastVisibleRow (iLAST_VISIBLE_ROW);
00202   }
00203 
00209   public void setRowHeight (int iROW_HEIGHT)
00210   { 
00211     super.setRowHeight (iROW_HEIGHT); 
00212     if ( ( tTree != null ) && ( tTree.getRowHeight() != iROW_HEIGHT ) )
00213     {
00214       tTree.setRowHeight (getRowHeight());
00215     }
00216   }
00217 
00218 
00219   //
00220   //  S E L E C T O R S
00221   //
00222 
00223   /*
00224   *  Workaround for BasicTableUI anomaly. Make sure the UI never tries to paint
00225   *  the editor. The UI currently uses different techniques to paint the
00226   *  renderers and editors and overriding \a setBounds() below is not the right
00227   *  thing to do for an editor.  Returning -1 for the editing row in this case,
00228   *  ensures the editor is never painted.
00229   *  @return The editing row.
00230   *  @see javax.swing.JTable#getEditingRow()
00231   */
00232   public int getEditingRow()
00233   {
00234     return ( getColumnClass (editingColumn) == ITreeTableModel.class ) ? -1 : editingRow;
00235   }
00236 
00241   public TTree getTree()
00242   {
00243     return tTree;
00244   }
00245 
00250   public ITreeTableModel getTreeTableModel()
00251   {
00252     return tTreeTableModel;
00253   }
00254 
00260   public void updateUI()
00261   {
00262     super.updateUI();
00263     if ( tTree != null )
00264     {
00265       tTree.updateUI();
00266     }
00267 
00268     //
00269     //  Use the tree's default foreground and background colors in the table.
00270     //
00271     LookAndFeel.installColorsAndFont (this, "Tree.background", "Tree.foreground", "Tree.font");
00272   }
00273 
00274 }  // class TTreeTable

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