KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > 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 JavaDoc;
47 import java.util.ArrayList JavaDoc;
48 import java.util.List JavaDoc;
49 import javax.swing.JPanel JavaDoc;
50 import javax.swing.JScrollPane JavaDoc;
51 import javax.swing.JTable JavaDoc;
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 JavaDoc {
61
62     /** The table. */
63     private JTable JavaDoc 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 JavaDoc libraries) {
74
75         setLayout(new BorderLayout JavaDoc());
76         this.model = new LibraryTableModel(libraries);
77         this.table = new JTable JavaDoc(this.model);
78         add(new JScrollPane JavaDoc(this.table));
79
80     }
81
82     public LibraryPanel(final ProjectInfo projectInfo) {
83         this(getLibraries(projectInfo));
84     }
85
86     private static List JavaDoc getLibraries (final ProjectInfo info) {
87         if (info == null) {
88             return new ArrayList JavaDoc();
89         }
90         final ArrayList JavaDoc libs = new ArrayList JavaDoc();
91         collectLibraries(info, libs);
92         return libs;
93     }
94
95     private static void collectLibraries (final ProjectInfo info,
96                                           final List JavaDoc 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 JavaDoc getTable() {
127       return table;
128     }
129 }
130
Popular Tags