Frames | No Frames |
1: /* ======================================================================== 2: * JCommon : a free general purpose class library for the Java(tm) platform 3: * ======================================================================== 4: * 5: * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jcommon/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * ---------------------- 28: * LibraryTableModel.java 29: * ---------------------- 30: * (C) Copyright 2002-2008, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * $Id: LibraryTableModel.java,v 1.8 2008/12/18 09:57:32 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 28-Feb-2002 : Version 1 (DG); 40: * 15-Mar-2002 : Modified to use ResourceBundle for elements that require 41: * localisation (DG); 42: * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG); 43: * 18-Dec-2008 : Use ResourceBundleWrapper - see JFreeChart patch 1607918 by 44: * Jess Thrysoee (DG); 45: * 46: */ 47: 48: package org.jfree.ui.about; 49: 50: import java.util.List; 51: import java.util.ResourceBundle; 52: 53: import javax.swing.table.AbstractTableModel; 54: 55: import org.jfree.base.Library; 56: import org.jfree.util.ResourceBundleWrapper; 57: 58: /** 59: * A table model containing a list of libraries used in a project. 60: * <P> 61: * Used in the LibraryPanel class. 62: * 63: * @author David Gilbert 64: */ 65: public class LibraryTableModel extends AbstractTableModel { 66: 67: /** Storage for the libraries. */ 68: private Library[] libraries; 69: 70: /** Localised name column label. */ 71: private String nameColumnLabel; 72: 73: /** Localised version column label. */ 74: private String versionColumnLabel; 75: 76: /** Localised licence column label. */ 77: private String licenceColumnLabel; 78: 79: /** Localised info column label. */ 80: private String infoColumnLabel; 81: 82: /** 83: * Constructs a LibraryTableModel. 84: * 85: * @param libraries the libraries. 86: */ 87: public LibraryTableModel(final List libraries) { 88: 89: this.libraries = (Library[]) 90: libraries.toArray(new Library[libraries.size()]); 91: 92: final String baseName = "org.jfree.ui.about.resources.AboutResources"; 93: final ResourceBundle resources = ResourceBundleWrapper.getBundle( 94: baseName); 95: 96: this.nameColumnLabel = resources.getString( 97: "libraries-table.column.name"); 98: this.versionColumnLabel = resources.getString( 99: "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: }