01: // Space4J(TM) - Object Persistence in RAM
02: // Copyright (C) 2003 Eduardo Rodrigues
03: // This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
04:
05: package org.space4j.demos.phonebook;
06:
07: import java.util.ArrayList;
08:
09: import javax.swing.table.AbstractTableModel;
10:
11: public class PhoneBookTableModel extends AbstractTableModel {
12:
13: private String columnNames[] = new String[] { "Name", "Tel" };
14: ArrayList names, phones;
15:
16: public PhoneBookTableModel(ArrayList names, ArrayList phones) {
17:
18: this .names = names;
19: this .phones = phones;
20:
21: }
22:
23: public String getColumnName(int column) {
24: return columnNames[column];
25: }
26:
27: public int getColumnCount() {
28: return 2;
29: }
30:
31: public int getRowCount() {
32: if (names.size() != phones.size())
33: return 0;
34: return names.size();
35: }
36:
37: public Object getValueAt(int rowIndex, int columnIndex) {
38:
39: switch (columnIndex) {
40: case 0:
41: return names.get(rowIndex);
42:
43: case 1:
44: return phones.get(rowIndex);
45: }
46:
47: return null;
48: }
49:
50: }
|