    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.6 2007/11/02 17:50:36 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    import javax.swing.table.AbstractTableModel;
    050
    051    import org.jfree.base.Library;
    052
    053    /**
    054     * A table model containing a list of libraries used in a project.
    055     * <P>
    056     * Used in the LibraryPanel class.
    057     *
    058     * @author David Gilbert
    059     */
    060    public class LibraryTableModel extends AbstractTableModel {
    061
    062        /** Storage for the libraries. */
    063        private Library[] libraries;
    064
    065        /** Localised name column label. */
    066        private String nameColumnLabel;
    067
    068        /** Localised version column label. */
    069        private String versionColumnLabel;
    070
    071        /** Localised licence column label. */
    072        private String licenceColumnLabel;
    073
    074        /** Localised info column label. */
    075        private String infoColumnLabel;
    076
    077        /**
    078         * Constructs a LibraryTableModel.
    079         *
    080         * @param libraries  the libraries.
    081         */
    082        public LibraryTableModel(final List libraries) {
    083
    084            this.libraries = (Library[])
    085                    libraries.toArray(new Library[libraries.size()]);
    086
    087            final String baseName = "org.jfree.ui.about.resources.AboutResources";
    088            final ResourceBundle resources = ResourceBundle.getBundle(baseName);
    089
    090            this.nameColumnLabel = resources.getString("libraries-table.column.name");
    091            this.versionColumnLabel = resources.getString("libraries-table.column.version");
    092            this.licenceColumnLabel = resources.getString("libraries-table.column.licence");
    093            this.infoColumnLabel = resources.getString("libraries-table.column.info");
    094
    095        }
    096
    097        /**
    098         * Returns the number of rows in the table model.
    099         *
    100         * @return the number of rows.
    101         */
    102        public int getRowCount() {
    103            return this.libraries.length;
    104        }
    105
    106        /**
    107         * Returns the number of columns in the table model.  In this case, there are always four
    108         * columns (name, version, licence and other info).
    109         *
    110         * @return the number of columns in the table model.
    111         */
    112        public int getColumnCount() {
    113            return 4;
    114        }
    115
    116        /**
    117         * Returns the name of a column in the table model.
    118         *
    119         * @param column  the column index (zero-based).
    120         *
    121         * @return the name of the specified column.
    122         */
    123        public String getColumnName(final int column) {
    124
    125            String result = null;
    126
    127            switch (column) {
    128
    129                case 0:  result = this.nameColumnLabel;
    130                         break;
    131
    132                case 1:  result = this.versionColumnLabel;
    133                         break;
    134
    135                case 2:  result = this.licenceColumnLabel;
    136                         break;
    137
    138                case 3:  result = this.infoColumnLabel;
    139                         break;
    140
    141            }
    142
    143            return result;
    144
    145        }
    146
    147        /**
    148         * Returns the value for a cell in the table model.
    149         *
    150         * @param row  the row index (zero-based).
    151         * @param column  the column index (zero-based).
    152         *
    153         * @return the value.
    154         */
    155        public Object getValueAt(final int row, final int column) {
    156
    157            Object result = null;
    158            final Library library = this.libraries[row];
    159
    160            if (column == 0) {
    161                result = library.getName();
    162            }
    163            else if (column == 1) {
    164                result = library.getVersion();
    165            }
    166            else if (column == 2) {
    167                result = library.getLicenceName();
    168            }
    169            else if (column == 3) {
    170                result = library.getInfo();
    171            }
    172            return result;
    173
    174        }
    175
    176        public Library[] getLibraries() {
    177          return (Library[]) libraries.clone();
    178        }
    179    }