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;
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
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
00124
00125 tTreeSelectionModel = new TTreeSelectionModel (tTree);
00126 tTree.setSelectionModel (tTreeSelectionModel);
00127 setSelectionModel (tTreeSelectionModel.getListSelectionModel());
00128
00129
00130
00131
00132 setDefaultRenderer (new TTreeTableCellRenderer (this));
00133 setDefaultEditor (ITreeTableModel.class, new TTreeTableCellEditor (this));
00134
00135
00136
00137
00138 setShowGrid (false);
00139
00140
00141
00142 setIntercellSpacing (new Dimension (0, 0));
00143
00144
00145
00146
00147 if ( tTree.getRowHeight() < 1 )
00148 {
00149
00150
00151
00152 setRowHeight (20);
00153 }
00154
00155 }
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 }
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
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
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
00270
00271 LookAndFeel.installColorsAndFont (this, "Tree.background", "Tree.foreground", "Tree.font");
00272 }
00273
00274 }