00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
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
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
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
00140
00141 collapsePath (tPARENT_TREE_PATH);
00142
00143 }
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
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
00173
00174 expandPath (tPARENT_TREE_PATH);
00175
00176 }
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
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
00246
00247
00253 public void paint (Graphics tGRAPHICS)
00254 {
00255 tGRAPHICS.translate (0, -iVisibleRow * getRowHeight());
00256 super.paint (tGRAPHICS);
00257 }
00258
00259 }