KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > qfs > apps > qflog > ViewTable


1 // {{{ copyright
2

3 /********************************************************************
4  *
5  * $Id: ViewTable.java,v 1.7 2000/07/05 14:07:43 gs Exp $
6  *
7  * The contents of this file are subject to the Mozilla Public
8  * License Version 1.1 (the "License"); you may not use this file
9  * except in compliance with the License. You may obtain a copy of
10  * the License at http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14  * implied. See the License for the specific language governing
15  * rights and limitations under the License.
16  *
17  * The Original Code is qfs.de code.
18  *
19  * The Initial Developer of the Original Code is Gregor Schmid.
20  * Portions created by Gregor Schmid are
21  * Copyright (C) 1999 Quality First Software, Gregor Schmid.
22  * All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  *******************************************************************/

27
28 // }}}
29

30 package de.qfs.apps.qflog;
31
32 // {{{ imports
33

34 import java.awt.Component JavaDoc;
35
36 import javax.swing.Icon JavaDoc;
37 import javax.swing.ImageIcon JavaDoc;
38 import javax.swing.JLabel JavaDoc;
39 import javax.swing.JTable JavaDoc;
40 import javax.swing.ListSelectionModel JavaDoc;
41 import javax.swing.event.TableModelEvent JavaDoc;
42 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
43
44 import de.qfs.lib.gui.WholeRowFocusRenderer;
45 import de.qfs.lib.log.Log;
46 import de.qfs.lib.log.Logger;
47
48 import de.qfs.apps.qflog.logview.LogView;
49
50 // }}}
51

52 /**
53  * The table used to display the views. Just sets a few parameters and
54  * uses a special renderer.
55  *
56  * @author Gregor Schmid
57  * @version $Revision: 1.7 $
58  */

59 public class ViewTable extends JTable JavaDoc
60 {
61     // {{{ variables
62

63     /**
64      * The Logger used for logging.
65      */

66     private final static Logger logger = new Logger (ViewTable.class);
67
68     /**
69      * The names of the icon resources.
70      */

71     private final static String JavaDoc iconNames[] = {
72         "logView.icon.file",
73         "logView.icon.connected",
74         "logView.icon.disconnected"
75     };
76
77     /**
78      * The icons to render.
79      */

80     private final static Icon JavaDoc[] icons = new Icon JavaDoc[iconNames.length];
81
82
83     // }}}
84

85     // {{{ ViewTable
86

87     /**
88      * Create a new ViewTable.
89      *
90      * @param model The ViewTableModel for the table.
91      */

92     public ViewTable (Model JavaDoc model)
93     {
94         super (model);
95         if (logger.level >= Log.MTD) {
96             logger.log(Log.MTD, "ViewTable(Model)",
97                        logger.level < Log.MTDDETAIL ? "" :
98                        "model: " + model);
99         }
100
101         initIcons();
102
103         getSelectionModel().setSelectionMode
104             (ListSelectionModel.SINGLE_SELECTION);
105         setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
106         setShowVerticalLines(false);
107         setShowHorizontalLines(false);
108         Renderer JavaDoc renderer = new Renderer JavaDoc ();
109         addFocusListener(renderer);
110         setDefaultRenderer(Object JavaDoc.class, renderer);
111         setDefaultRenderer(Integer JavaDoc.class, renderer);
112         setDefaultRenderer(String JavaDoc.class, renderer);
113         getColumnModel().setColumnMargin(0);
114     }
115
116     // }}}
117

118     // {{{ getViewModel
119

120     /**
121      * Get the original ViewTableModel of the table.
122      */

123     // public final Model getViewModel()
124
// {
125
// return viewModel;
126
// }
127

128     // }}}
129
// {{{ initIcons
130

131     /**
132      * Fetch the icons.
133      */

134     private void initIcons()
135     {
136         if (icons[0] == null) {
137             for (int i = 0; i < icons.length; i++) {
138                 icons[i] = App.getResources().getIcon(iconNames[i], null);
139             }
140         }
141     }
142
143     // }}}
144
// {{{ isManagingFocus
145

146     /**
147      * Signal no interest in internal focu management.
148      *
149      * @return Always false.
150      */

151     public boolean isManagingFocus()
152     {
153         return false;
154     }
155
156     // }}}
157

158     //----------------------------------------------------------------------
159
// Renderer for the table.
160
//----------------------------------------------------------------------
161
// {{{ class Renderer
162

163     /**
164      * Cell renderer for the ViewTable.
165      */

166     private class Renderer extends WholeRowFocusRenderer
167     {
168         /**
169          * Create a new Renderer.
170          */

171         public Renderer()
172         {
173             setStippleBorder();
174         }
175
176         /**
177          * Get the Component to render the table cell. Sets the icon for
178          * the state column.
179          */

180         public Component JavaDoc getTableCellRendererComponent
181             (JTable JavaDoc table, Object JavaDoc value, boolean isSelected,
182              boolean hasFocus, int row, int column) {
183             JLabel JavaDoc label = (JLabel JavaDoc) super.getTableCellRendererComponent
184                 (table,value, isSelected, false, row, column);
185             if (table.convertColumnIndexToModel(column) == Model.COL_STATE) {
186                 switch (((Integer JavaDoc) value).intValue()) {
187                 case LogView.STATE_FILE:
188                     label.setIcon(icons[0]);
189                     label.setText(null);
190                     break;
191                 case LogView.STATE_CONNECTED:
192                     label.setIcon(icons[1]);
193                     label.setText(null);
194                     break;
195                 case LogView.STATE_DISCONNECTED:
196                     label.setIcon(icons[2]);
197                     label.setText(null);
198                     break;
199                 }
200             } else {
201                 label.setIcon(null);
202             }
203             return label;
204         }
205     }
206
207     // }}}
208
}
209
Popular Tags