KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > browser > detail > attributes > AbstractAttributeTableModel


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.browser.detail.attributes;
9
10 import org.gjt.jclasslib.browser.detail.ListDetailPane.ColumnCache;
11 import org.gjt.jclasslib.structures.AttributeInfo;
12
13 import javax.swing.table.AbstractTableModel JavaDoc;
14 import javax.swing.table.TableColumnModel JavaDoc;
15
16 /**
17  * Base class for all table models for attributes displayed by a
18  * <tt>AbstractAttributeListDetailPane</tt>.
19  *
20  * @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
21  * @version $Revision: 1.5 $ $Date: 2004/12/28 13:04:30 $
22  */

23 public abstract class AbstractAttributeTableModel extends AbstractTableModel JavaDoc {
24
25     /**
26      * Number of default columns.
27      */

28     protected static final int BASE_COLUMN_COUNT = 1;
29
30     /**
31      * The associated attribute.
32      */

33     protected AttributeInfo attribute;
34
35     private ColumnCache columnCache;
36     private TableColumnModel JavaDoc tableColumnModel;
37
38     /**
39      * Constructor.
40      *
41      * @param attribute the associated attribute.
42      */

43     protected AbstractAttributeTableModel(AttributeInfo attribute) {
44         this.attribute = attribute;
45     }
46
47     public boolean isCellEditable(int rowIndex, int columnIndex) {
48         return false;
49     }
50
51     public String JavaDoc getColumnName(int column) {
52         if (column == 0) {
53             return "Nr.";
54         } else {
55             return doGetColumnName(column);
56         }
57     }
58
59     public Class JavaDoc getColumnClass(int column) {
60         if (column == 0) {
61             return Number JavaDoc.class;
62         } else {
63             return doGetColumnClass(column);
64         }
65     }
66
67     public Object JavaDoc getValueAt(int row, int column) {
68
69         if (column == 0) {
70             return String.valueOf(row);
71         } else {
72             if (columnCache == null) {
73                 columnCache = new ColumnCache(getRowCount(), getColumnCount() - 1);
74             }
75             Object JavaDoc value = columnCache.getValueAt(row, column - 1);
76             if (value == null) {
77                 value = doGetValueAt(row, column);
78                 columnCache.setValueAt(row, column - 1, value);
79             }
80
81             return value;
82         }
83     }
84
85     /**
86      * Get the associated table column model.
87      *
88      * @return the model
89      */

90     public TableColumnModel JavaDoc getTableColumnModel() {
91         return tableColumnModel;
92     }
93
94     /**
95      * Set the associated table column model.
96      *
97      * @param tableColumnModel the model
98      */

99     public void setTableColumnModel(TableColumnModel JavaDoc tableColumnModel) {
100         this.tableColumnModel = tableColumnModel;
101     }
102
103     /**
104      * Get the width of a specified column in pixels.
105      *
106      * @param column the index ofthe column in the table model
107      * @return the width
108      */

109     public abstract int getColumnWidth(int column);
110
111     /**
112      * Attribute specific <tt>getValueAt()</tt>.
113      *
114      * @param row the row number
115      * @param column the column number
116      * @return the value
117      */

118     protected abstract Object JavaDoc doGetValueAt(int row, int column);
119
120     /**
121      * Attribute specific <tt>getColumnName()</tt>.
122      *
123      * @param column the column number
124      * @return the name
125      */

126     protected abstract String JavaDoc doGetColumnName(int column);
127
128     /**
129      * Attribute specific <tt>getColumnClass()</tt>.
130      *
131      * @param column the column number
132      * @return the class
133      */

134     protected abstract Class JavaDoc doGetColumnClass(int column);
135
136
137     /**
138      * Link to the destination described by the target of the hyperlink
139      * contained in a specific cell.
140      *
141      * @param row the row number of the hyperlink
142      * @param column the column number of the hyperlink
143      */

144     public void link(int row, int column) {
145     }
146
147 }
148
Popular Tags