1 | /*
|
---|
2 | * BerryBasketModel.java
|
---|
3 | * Copyright (C) 2001 New Zealand Digital Library Project
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
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 License
|
---|
16 | * along with this program; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | */
|
---|
19 | package org.nzdl.gsdl.SimpleGraphicalClient;
|
---|
20 |
|
---|
21 |
|
---|
22 | import java.util.*;
|
---|
23 | import javax.swing.event.*;
|
---|
24 | import javax.swing.*;
|
---|
25 | import javax.swing.table.*;
|
---|
26 | import java.awt.*;
|
---|
27 |
|
---|
28 |
|
---|
29 | class BerryBasketModel extends AbstractTableModel {
|
---|
30 |
|
---|
31 | private ArrayList columnTitles;
|
---|
32 | private ArrayList berryBasket;
|
---|
33 |
|
---|
34 | private String DOCUMENT = "Document";
|
---|
35 | private String DATE = "Date";
|
---|
36 |
|
---|
37 |
|
---|
38 | public BerryBasketModel()
|
---|
39 | {
|
---|
40 | super();
|
---|
41 | berryBasket = new ArrayList();
|
---|
42 | columnTitles = new ArrayList();
|
---|
43 | columnTitles.add(DOCUMENT);
|
---|
44 | //columnTitles.add("User");
|
---|
45 | columnTitles.add(DATE);
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void add(Berry berry) {
|
---|
49 | System.out.println("adding to BerryBasketModel: " + berry.toString());
|
---|
50 | berryBasket.add(0, berry);
|
---|
51 | fireTableRowsInserted(0,0);
|
---|
52 | }
|
---|
53 |
|
---|
54 | public int getColumnCount() {
|
---|
55 | return columnTitles.size();
|
---|
56 | }
|
---|
57 |
|
---|
58 | public String getColumnName(int column) {
|
---|
59 | return (String) columnTitles.get(column);
|
---|
60 | }
|
---|
61 |
|
---|
62 | public int getRowCount() {
|
---|
63 | return berryBasket.size();
|
---|
64 | }
|
---|
65 |
|
---|
66 | public Object getValueAt(int row, int column) {
|
---|
67 | // get Berry object
|
---|
68 | // extract document title (say), person, date info from Berry object
|
---|
69 | // depending on column number
|
---|
70 | // column reordering shouldn't matter, all
|
---|
71 | // gets dealt with automatically
|
---|
72 |
|
---|
73 | Berry berry = (Berry) berryBasket.get(row);
|
---|
74 |
|
---|
75 | if (column == columnTitles.indexOf(DOCUMENT)) return berry.toString();
|
---|
76 |
|
---|
77 | if (column == columnTitles.indexOf(DATE)) return berry.getDateAdded();
|
---|
78 |
|
---|
79 | // shouldn't get here but display something anyway
|
---|
80 | return "row" + row + "col" + column;
|
---|
81 | }
|
---|
82 |
|
---|
83 | }
|
---|