KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > adminGui > widget > TableMap


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: TableMap.java,v 1.1 2003/03/07 13:49:45 per_nyfelt Exp $
8
package org.ozoneDB.adminGui.widget;
9
10
11 import javax.swing.event.TableModelEvent JavaDoc;
12 import javax.swing.event.TableModelListener JavaDoc;
13 import javax.swing.table.AbstractTableModel JavaDoc;
14 import javax.swing.table.TableModel JavaDoc;
15 import java.util.Vector JavaDoc;
16
17 /**
18  * In a chain of data manipulators some behaviour is common. TableMap
19  * provides most of this behavour and can be subclassed by filters
20  * that only need to override a handful of specific methods. TableMap
21  * implements TableModel by routing all requests to its model, and
22  * TableModelListener by routing all events to its listeners. Inserting
23  * a TableMap which has not been subclassed into a chain of table filters
24  * should have no effect.
25  *
26  * @author <p align=center>Per Nyfelt
27  * <br>Copyright &copy 1997-@year@ by SMB GmbH. All Rights Reserved.</p>
28  * @author Ibsen Ramos-Bonilla
29  *
30  * @version 1.0
31  *
32  */

33 public class TableMap extends AbstractTableModel JavaDoc implements TableModelListener JavaDoc {
34     /** Contains the instance to the table model. */
35     protected TableModel JavaDoc model;
36     /** Contains the number of columns in panel tables. */
37     protected int columnCount;
38     /** Contains the number of rows in the panel tables. */
39     protected int rowCount;
40     /** Contains the panel tables column names. */
41     protected Vector JavaDoc columnNames = new Vector JavaDoc();
42     /** Contains the panel tables data. */
43     protected Vector JavaDoc data = new Vector JavaDoc();
44
45
46     /**
47      * This method returns a handle for the current table model.
48      *
49      * @return TableModel - the current model handle.
50      */

51     public TableModel JavaDoc getModel() {
52         //return this;
53
return this.model;
54     }
55
56     /**
57      * This method sets the current table model with the designated model.
58      *
59      * @param model - the new table model.
60      */

61     public void setModel(TableModel JavaDoc model) {
62         this.model = model;
63         this.model.addTableModelListener(this);
64         //this.setModel(model);
65
}
66
67     /**
68      * This method returns the value in a specified cell for the current table
69      * model.
70      *
71      * @param row - the row containing the cell to change.
72      * @param column - the column containing the cell to change.
73      * @return Object - the value at the specified table location.
74      */

75     public Object JavaDoc getValueAt(int row, int column) {
76         return ((Object JavaDoc[]) data.elementAt(row))[column];
77     }
78
79     /**
80      * This method sets the value in a specified cell for the current table
81      * model.
82      *
83      * @param aValue - the value to set in the table.
84      * @param aRow - the row containing the cell to change.
85      * @param aColumn - the column containing the cell to change.
86      */

87     public void setValueAt(Object JavaDoc aValue, int aRow, int aColumn) {
88         String JavaDoc value;
89         try {
90             value = (String JavaDoc) aValue;
91         } catch (Exception JavaDoc e) {
92             System.out.println("wrong format");
93             e.printStackTrace();
94             return;
95         }
96
97         ((Object JavaDoc[]) data.elementAt(aRow))[aColumn] = value;
98         fireTableCellUpdated(aRow, aColumn);
99     }
100
101     /**
102      * This method returns the row count in the current table model.
103      *
104      * @return int - the number of rows in the table.
105      */

106     public int getRowCount() {
107         return this.data.size();
108     }
109
110     /**
111      * This method returns the column count in the current table model.
112      *
113      * @return int - the number of columns in tne table.
114      */

115     public int getColumnCount() {
116         return this.columnNames.size();
117     }
118
119     /**
120      * This method returns the title of a column for the current table model.
121      *
122      * @param index - the selected column.
123      * @return String - the column name.
124      */

125     public String JavaDoc getColumnName(int index) {
126         return (String JavaDoc) columnNames.elementAt(index);
127     }
128
129     /**
130      * This method returns the class of objects the given column renders.
131      *
132      * @param index - the selected column.
133      * @return Class - the column's object type.
134      */

135     public Class JavaDoc getColumnClass(int index) {
136         return ((Object JavaDoc[]) data.elementAt(0))[index].getClass();
137     }
138
139     /**
140      * This method clears all the elements from the table.
141      */

142     public void clear() {
143         //first clear everything in the model
144
this.data.clear();
145         this.rowCount = 0;
146     } //----- clear -----//
147

148     /**
149      * This method returns a flag indicating if the cell is editable or not.
150      *
151      * @param row - the row containing the cell to change.
152      * @param column - the column containing the cell to change.
153      * @return boolean - the column's object type.
154      */

155     /*public boolean isCellEditable(int row, int column) {
156         return this.isCellEditable(row, column);
157     }*/

158
159     /**
160      * This method fires an event when the table is changed.
161      *
162      * @param e - table model event.
163      */

164     public void tableChanged(TableModelEvent JavaDoc e) {
165         fireTableChanged(e);
166     }
167 }
168
Popular Tags