KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > ui > about > LibraryTableModel


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ----------------------
28  * LibraryTableModel.java
29  * ----------------------
30  * (C) Copyright 2002-2004, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: LibraryTableModel.java,v 1.5 2006/03/23 19:47:05 taqua Exp $
36  *
37  * Changes
38  * -------
39  * 28-Feb-2002 : Version 1 (DG);
40  * 15-Mar-2002 : Modified to use ResourceBundle for elements that require localisation (DG);
41  * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG);
42  *
43  */

44
45 package org.jfree.ui.about;
46
47 import java.util.List JavaDoc;
48 import java.util.ResourceBundle JavaDoc;
49
50 import javax.swing.table.AbstractTableModel JavaDoc;
51
52 import org.jfree.base.Library;
53
54 /**
55  * A table model containing a list of libraries used in a project.
56  * <P>
57  * Used in the LibraryPanel class.
58  *
59  * @author David Gilbert
60  */

61 public class LibraryTableModel extends AbstractTableModel JavaDoc {
62
63     /** Storage for the libraries. */
64     private Library[] libraries;
65
66     /** Localised name column label. */
67     private String JavaDoc nameColumnLabel;
68
69     /** Localised version column label. */
70     private String JavaDoc versionColumnLabel;
71
72     /** Localised licence column label. */
73     private String JavaDoc licenceColumnLabel;
74
75     /** Localised info column label. */
76     private String JavaDoc infoColumnLabel;
77
78     /**
79      * Constructs a LibraryTableModel.
80      *
81      * @param libraries the libraries.
82      */

83     public LibraryTableModel(final List JavaDoc libraries) {
84
85         this.libraries = (Library[])
86                 libraries.toArray(new Library[libraries.size()]);
87
88         final String JavaDoc baseName = "org.jfree.ui.about.resources.AboutResources";
89         final ResourceBundle JavaDoc resources = ResourceBundle.getBundle(baseName);
90
91         this.nameColumnLabel = resources.getString("libraries-table.column.name");
92         this.versionColumnLabel = resources.getString("libraries-table.column.version");
93         this.licenceColumnLabel = resources.getString("libraries-table.column.licence");
94         this.infoColumnLabel = resources.getString("libraries-table.column.info");
95
96     }
97
98     /**
99      * Returns the number of rows in the table model.
100      *
101      * @return the number of rows.
102      */

103     public int getRowCount() {
104         return this.libraries.length;
105     }
106
107     /**
108      * Returns the number of columns in the table model. In this case, there are always four
109      * columns (name, version, licence and other info).
110      *
111      * @return the number of columns in the table model.
112      */

113     public int getColumnCount() {
114         return 4;
115     }
116
117     /**
118      * Returns the name of a column in the table model.
119      *
120      * @param column the column index (zero-based).
121      *
122      * @return the name of the specified column.
123      */

124     public String JavaDoc getColumnName(final int column) {
125
126         String JavaDoc result = null;
127
128         switch (column) {
129
130             case 0: result = this.nameColumnLabel;
131                      break;
132
133             case 1: result = this.versionColumnLabel;
134                      break;
135
136             case 2: result = this.licenceColumnLabel;
137                      break;
138
139             case 3: result = this.infoColumnLabel;
140                      break;
141
142         }
143
144         return result;
145
146     }
147
148     /**
149      * Returns the value for a cell in the table model.
150      *
151      * @param row the row index (zero-based).
152      * @param column the column index (zero-based).
153      *
154      * @return the value.
155      */

156     public Object JavaDoc getValueAt(final int row, final int column) {
157
158         Object JavaDoc result = null;
159         final Library library = this.libraries[row];
160
161         if (column == 0) {
162             result = library.getName();
163         }
164         else if (column == 1) {
165             result = library.getVersion();
166         }
167         else if (column == 2) {
168             result = library.getLicenceName();
169         }
170         else if (column == 3) {
171             result = library.getInfo();
172         }
173         return result;
174
175     }
176
177     public Library[] getLibraries() {
178       return (Library[]) libraries.clone();
179     }
180 }
181
Popular Tags