    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[])
    086                    libraries.toArray(new Library[libraries.size()]);
    087
    088            final String baseName = "org.jfree.ui.about.resources.AboutResources";
    089            final ResourceBundle resources = ResourceBundle.getBundle(baseName);
    090
    091            this.nameColumnLabel = resources.getString("libraries-table.column.name");
    092            this.versionColumnLabel = resources.getString("libraries-table.column.version");
    093            this.licenceColumnLabel = resources.getString("libraries-table.column.licence");
    094            this.infoColumnLabel = resources.getString("libraries-table.column.info");
    095
    096        }
    097
    098        /**
    099         * 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 getColumnName(final int column) {
    125
    126            String 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 getValueAt(final int row, final int column) {
    157
    158            Object 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    }