    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.3 2005/10/18 13:19:13 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 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 List 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 = libraries;
    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.size();
    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 = (Library) this.libraries.get(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    }