Source for org.jfree.ui.about.LibraryPanel

   1: /* ========================================================================
   2:  * JCommon : a free general purpose class library for the Java(tm) platform
   3:  * ========================================================================
   4:  *
   5:  * (C) Copyright 2000-2005, 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:  * LibraryReferencePanel.java
  29:  * --------------------------
  30:  * (C) Copyright 2002-2004, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: LibraryPanel.java,v 1.6 2008/09/10 09:18:12 mungady Exp $
  36:  *
  37:  * Changes
  38:  * -------
  39:  * 28-Feb-2002 : Version 1 (DG);
  40:  * 08-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  41:  *
  42:  */
  43: 
  44: package org.jfree.ui.about;
  45: 
  46: import java.awt.BorderLayout;
  47: import java.util.ArrayList;
  48: import java.util.List;
  49: import javax.swing.JPanel;
  50: import javax.swing.JScrollPane;
  51: import javax.swing.JTable;
  52: 
  53: /**
  54:  * A panel containing a table that lists the libraries used in a project.
  55:  * <P>
  56:  * Used in the AboutFrame class.
  57:  *
  58:  * @author David Gilbert
  59:  */
  60: public class LibraryPanel extends JPanel {
  61: 
  62:     /** The table. */
  63:     private JTable table;
  64: 
  65:     /** The data. */
  66:     private LibraryTableModel model;
  67: 
  68:     /**
  69:      * Constructs a LibraryPanel.
  70:      *
  71:      * @param libraries  a list of libraries (represented by Library objects).
  72:      */
  73:     public LibraryPanel(final List libraries) {
  74: 
  75:         setLayout(new BorderLayout());
  76:         this.model = new LibraryTableModel(libraries);
  77:         this.table = new JTable(this.model);
  78:         add(new JScrollPane(this.table));
  79: 
  80:     }
  81: 
  82:     /**
  83:      * Creates a new library panel for the specified project.
  84:      *
  85:      * @param projectInfo  the project information.
  86:      */
  87:     public LibraryPanel(final ProjectInfo projectInfo) {
  88:         this(getLibraries(projectInfo));
  89:     }
  90: 
  91:     private static List getLibraries (final ProjectInfo info) {
  92:         if (info == null) {
  93:             return new ArrayList();
  94:         }
  95:         final ArrayList libs = new ArrayList();
  96:         collectLibraries(info, libs);
  97:         return libs;
  98:     }
  99: 
 100:     private static void collectLibraries (final ProjectInfo info,
 101:                                           final List list) {
 102:         org.jfree.base.Library[] libs = info.getLibraries();
 103:         for (int i = 0; i < libs.length; i++) {
 104:             final org.jfree.base.Library lib = libs[i];
 105:             if (list.contains(lib) == false) {
 106:                 // prevent duplicates, they look ugly ..
 107:                 list.add(lib);
 108:                 if (lib instanceof ProjectInfo) {
 109:                     collectLibraries((ProjectInfo) lib, list);
 110:                 }
 111:             }
 112:         }
 113: 
 114:         libs = info.getOptionalLibraries();
 115:         for (int i = 0; i < libs.length; i++) {
 116:             final org.jfree.base.Library lib = libs[i];
 117:             if (list.contains(lib) == false) {
 118:                 // prevent duplicates, they look ugly ..
 119:                 list.add(lib);
 120:                 if (lib instanceof ProjectInfo) {
 121:                     collectLibraries((ProjectInfo) lib, list);
 122:                 }
 123:             }
 124:         }
 125:     }
 126: 
 127:     /**
 128:      * Returns the table model for the library.
 129:      *
 130:      * @return The table model.
 131:      */
 132:     public LibraryTableModel getModel() {
 133:       return this.model;
 134:     }
 135: 
 136:     /**
 137:      * Returns the <code>JTable</code> for the library.
 138:      *
 139:      * @return The table.
 140:      */
 141:     protected JTable getTable() {
 142:       return this.table;
 143:     }
 144: }