001/* ========================================================================
002 * JCommon : a free general purpose class library for the Java(tm) platform
003 * ========================================================================
004 *
005 * (C) Copyright 2000-2008, 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-2008, by Object Refinery Limited.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   -;
034 *
035 * $Id: LibraryTableModel.java,v 1.8 2008/12/18 09:57:32 mungady Exp $
036 *
037 * Changes
038 * -------
039 * 28-Feb-2002 : Version 1 (DG);
040 * 15-Mar-2002 : Modified to use ResourceBundle for elements that require
041 *               localisation (DG);
042 * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG);
043 * 18-Dec-2008 : Use ResourceBundleWrapper - see JFreeChart patch 1607918 by
044 *               Jess Thrysoee (DG);
045 *
046 */
047
048package org.jfree.ui.about;
049
050import java.util.List;
051import java.util.ResourceBundle;
052
053import javax.swing.table.AbstractTableModel;
054
055import org.jfree.base.Library;
056import org.jfree.util.ResourceBundleWrapper;
057
058/**
059 * A table model containing a list of libraries used in a project.
060 * <P>
061 * Used in the LibraryPanel class.
062 *
063 * @author David Gilbert
064 */
065public class LibraryTableModel extends AbstractTableModel {
066
067    /** Storage for the libraries. */
068    private Library[] libraries;
069
070    /** Localised name column label. */
071    private String nameColumnLabel;
072
073    /** Localised version column label. */
074    private String versionColumnLabel;
075
076    /** Localised licence column label. */
077    private String licenceColumnLabel;
078
079    /** Localised info column label. */
080    private String infoColumnLabel;
081
082    /**
083     * Constructs a LibraryTableModel.
084     *
085     * @param libraries  the libraries.
086     */
087    public LibraryTableModel(final List libraries) {
088
089        this.libraries = (Library[])
090                libraries.toArray(new Library[libraries.size()]);
091
092        final String baseName = "org.jfree.ui.about.resources.AboutResources";
093        final ResourceBundle resources = ResourceBundleWrapper.getBundle(
094                baseName);
095
096        this.nameColumnLabel = resources.getString(
097                "libraries-table.column.name");
098        this.versionColumnLabel = resources.getString(
099                "libraries-table.column.version");
100        this.licenceColumnLabel = resources.getString(
101                "libraries-table.column.licence");
102        this.infoColumnLabel = resources.getString(
103                "libraries-table.column.info");
104
105    }
106
107    /**
108     * Returns the number of rows in the table model.
109     *
110     * @return the number of rows.
111     */
112    public int getRowCount() {
113        return this.libraries.length;
114    }
115
116    /**
117     * Returns the number of columns in the table model.  In this case, there
118     * are always four columns (name, version, licence and other info).
119     *
120     * @return the number of columns in the table model.
121     */
122    public int getColumnCount() {
123        return 4;
124    }
125
126    /**
127     * Returns the name of a column in the table model.
128     *
129     * @param column  the column index (zero-based).
130     *
131     * @return the name of the specified column.
132     */
133    public String getColumnName(final int column) {
134
135        String result = null;
136
137        switch (column) {
138
139            case 0:  result = this.nameColumnLabel;
140                     break;
141
142            case 1:  result = this.versionColumnLabel;
143                     break;
144
145            case 2:  result = this.licenceColumnLabel;
146                     break;
147
148            case 3:  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        }
173        else if (column == 1) {
174            result = library.getVersion();
175        }
176        else if (column == 2) {
177            result = library.getLicenceName();
178        }
179        else if (column == 3) {
180            result = library.getInfo();
181        }
182        return result;
183
184    }
185
186    /**
187     * Returns an array of the libraries in the table.
188     *
189     * @return An array of libraries.
190     */
191    public Library[] getLibraries() {
192      return (Library[]) this.libraries.clone();
193    }
194}