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.5 2006/03/23 19:47:05 taqua 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:     public LibraryPanel(final ProjectInfo projectInfo) {
  83:         this(getLibraries(projectInfo));
  84:     }
  85: 
  86:     private static List getLibraries (final ProjectInfo info) {
  87:         if (info == null) {
  88:             return new ArrayList();
  89:         }
  90:         final ArrayList libs = new ArrayList();
  91:         collectLibraries(info, libs);
  92:         return libs;
  93:     }
  94: 
  95:     private static void collectLibraries (final ProjectInfo info,
  96:                                           final List list) {
  97:         org.jfree.base.Library[] libs = info.getLibraries();
  98:         for (int i = 0; i < libs.length; i++) {
  99:             final org.jfree.base.Library lib = libs[i];
 100:             if (list.contains(lib) == false) {
 101:                 // prevent duplicates, they look ugly ..
 102:                 list.add(lib);
 103:                 if (lib instanceof ProjectInfo) {
 104:                     collectLibraries((ProjectInfo) lib, list);
 105:                 }
 106:             }
 107:         }
 108: 
 109:         libs = info.getOptionalLibraries();
 110:         for (int i = 0; i < libs.length; i++) {
 111:             final org.jfree.base.Library lib = libs[i];
 112:             if (list.contains(lib) == false) {
 113:                 // prevent duplicates, they look ugly ..
 114:                 list.add(lib);
 115:                 if (lib instanceof ProjectInfo) {
 116:                     collectLibraries((ProjectInfo) lib, list);
 117:                 }
 118:             }
 119:         }
 120:     }
 121: 
 122:     public LibraryTableModel getModel() {
 123:       return model;
 124:     }
 125: 
 126:     protected JTable getTable() {
 127:       return table;
 128:     }
 129: }