KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > table > DefaultTableModel


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.table;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.Collection JavaDoc;
17
18 /**
19  * a simple table model. Its implemented as an ArrayList containing TableRow objects
20  */

21
22 public class DefaultTableModel extends ArrayList JavaDoc implements TableModel {
23   private String JavaDoc title;
24   private String JavaDoc[] columnTitles;
25   TableModelChangeSupport changeSupport;
26
27   public DefaultTableModel() {
28     this.changeSupport = new TableModelChangeSupport(this);
29   }
30
31   public DefaultTableModel(Collection JavaDoc rows, String JavaDoc[] columnTitles) {
32     this.addAll(rows);
33     this.columnTitles = columnTitles;
34     this.changeSupport = new TableModelChangeSupport(this);
35   }
36
37   public String JavaDoc getTitle() {
38     return title;
39   }
40   public void setTitle(String JavaDoc newTitle) {
41     title = newTitle;
42   }
43
44   public int getRowCount() {
45     return size();
46   }
47
48   public TableRow getRow(int rowIndex) {
49     return (TableRow) get(rowIndex);
50   }
51   
52   public void setColumnTitles(String JavaDoc[] newColumnTitles) {
53     columnTitles = newColumnTitles;
54   }
55   
56   public String JavaDoc[] getColumnTitles() {
57     return columnTitles;
58   }
59   
60   public String JavaDoc getColumnTitle(int i) {
61     return columnTitles[i];
62   }
63   
64   public void setColumnTitle(int i, String JavaDoc newColumnTitle) {
65     columnTitles[i] = newColumnTitle;
66   }
67   
68   public int getColumnCount() {
69     if (columnTitles == null)
70       return 0;
71     return columnTitles.length;
72   }
73
74   public void addTableModelChangeListener(TableModelChangeListener listener) {
75     changeSupport.addTableModelChangeListener(listener);
76   }
77
78   public void removeTableModelChangeListener(TableModelChangeListener listener) {
79     changeSupport.removeTableModelChangeListener(listener);
80   }
81
82   public void fireModelChanged(boolean identityChanged) {
83     changeSupport.fireModelChanged(identityChanged);
84   }
85
86 }
Popular Tags