001: /* ========================================================================
002: * JCommon : a free general purpose class library for the Java(tm) platform
003: * ========================================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jcommon/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ----------------------
028: * LibraryTableModel.java
029: * ----------------------
030: * (C) Copyright 2002-2004, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: LibraryTableModel.java,v 1.5 2006/03/23 19:47:05 taqua Exp $
036: *
037: * Changes
038: * -------
039: * 28-Feb-2002 : Version 1 (DG);
040: * 15-Mar-2002 : Modified to use ResourceBundle for elements that require localisation (DG);
041: * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG);
042: *
043: */
044:
045: package org.jfree.ui.about;
046:
047: import java.util.List;
048: import java.util.ResourceBundle;
049:
050: import javax.swing.table.AbstractTableModel;
051:
052: import org.jfree.base.Library;
053:
054: /**
055: * A table model containing a list of libraries used in a project.
056: * <P>
057: * Used in the LibraryPanel class.
058: *
059: * @author David Gilbert
060: */
061: public class LibraryTableModel extends AbstractTableModel {
062:
063: /** Storage for the libraries. */
064: private Library[] libraries;
065:
066: /** Localised name column label. */
067: private String nameColumnLabel;
068:
069: /** Localised version column label. */
070: private String versionColumnLabel;
071:
072: /** Localised licence column label. */
073: private String licenceColumnLabel;
074:
075: /** Localised info column label. */
076: private String infoColumnLabel;
077:
078: /**
079: * Constructs a LibraryTableModel.
080: *
081: * @param libraries the libraries.
082: */
083: public LibraryTableModel(final List libraries) {
084:
085: this .libraries = (Library[]) libraries
086: .toArray(new Library[libraries.size()]);
087:
088: final String baseName = "org.jfree.ui.about.resources.AboutResources";
089: final ResourceBundle resources = ResourceBundle
090: .getBundle(baseName);
091:
092: this .nameColumnLabel = resources
093: .getString("libraries-table.column.name");
094: this .versionColumnLabel = resources
095: .getString("libraries-table.column.version");
096: this .licenceColumnLabel = resources
097: .getString("libraries-table.column.licence");
098: this .infoColumnLabel = resources
099: .getString("libraries-table.column.info");
100:
101: }
102:
103: /**
104: * Returns the number of rows in the table model.
105: *
106: * @return the number of rows.
107: */
108: public int getRowCount() {
109: return this .libraries.length;
110: }
111:
112: /**
113: * Returns the number of columns in the table model. In this case, there are always four
114: * columns (name, version, licence and other info).
115: *
116: * @return the number of columns in the table model.
117: */
118: public int getColumnCount() {
119: return 4;
120: }
121:
122: /**
123: * Returns the name of a column in the table model.
124: *
125: * @param column the column index (zero-based).
126: *
127: * @return the name of the specified column.
128: */
129: public String getColumnName(final int column) {
130:
131: String result = null;
132:
133: switch (column) {
134:
135: case 0:
136: result = this .nameColumnLabel;
137: break;
138:
139: case 1:
140: result = this .versionColumnLabel;
141: break;
142:
143: case 2:
144: result = this .licenceColumnLabel;
145: break;
146:
147: case 3:
148: result = this .infoColumnLabel;
149: break;
150:
151: }
152:
153: return result;
154:
155: }
156:
157: /**
158: * Returns the value for a cell in the table model.
159: *
160: * @param row the row index (zero-based).
161: * @param column the column index (zero-based).
162: *
163: * @return the value.
164: */
165: public Object getValueAt(final int row, final int column) {
166:
167: Object result = null;
168: final Library library = this .libraries[row];
169:
170: if (column == 0) {
171: result = library.getName();
172: } else if (column == 1) {
173: result = library.getVersion();
174: } else if (column == 2) {
175: result = library.getLicenceName();
176: } else if (column == 3) {
177: result = library.getInfo();
178: }
179: return result;
180:
181: }
182:
183: public Library[] getLibraries() {
184: return (Library[]) libraries.clone();
185: }
186: }
|