KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > table > AbstractTableItemTableModel


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.table;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24
25 /**
26  * Abstract implementation of a {@link com.sslexplorer.table.TableModel} that
27  * maintains a list of {@link com.sslexplorer.table.TableItem} objects as
28  * its datasource.
29  *
30  * @author Brett Smith <brett@3sp.com>
31  */

32 public abstract class AbstractTableItemTableModel implements TableItemModel {
33     
34     protected List JavaDoc items;
35
36     public AbstractTableItemTableModel() {
37         super();
38         items = new ArrayList JavaDoc();
39     }
40     
41     public abstract int getColumnWidth(int col);
42     
43     public String JavaDoc[] getColumnNames() {
44         String JavaDoc[] cols = new String JavaDoc[getColumnCount()];
45         for(int i = getColumnCount() - 1; i >= 0 ; i--) {
46             cols[i] = getColumnName(i);
47         }
48         return cols;
49     }
50     
51     public List JavaDoc getItems() {
52         return items;
53     }
54     
55     public void addItem(TableItem item) {
56         items.add(item);
57     }
58
59     public void clear() {
60         items.clear();
61     }
62
63     public void removeItem(TableItem item) {
64         items.remove(item);
65     }
66
67     public int getRowCount() {
68         return items.size();
69     }
70
71     public Object JavaDoc getValue(int row, int col) {
72         return getItem(row).getColumnValue(col);
73     }
74
75     public TableItem getItem(int row) {
76         return (TableItem)items.get(row);
77     }
78     
79     public boolean contains(TableItem item) {
80         return items.contains(item);
81     }
82     
83     public boolean getEmpty() {
84         return items.size() == 0;
85     }
86 }
87
Popular Tags