KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > plugin > java > CollectionPanel


1 /*====================================================================
2
3 Objectweb Browser Framework
4 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.browser.plugin.java;
28
29 import java.awt.Color JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 import javax.swing.BoxLayout JavaDoc;
34 import javax.swing.JPanel JavaDoc;
35 import javax.swing.JScrollPane JavaDoc;
36 import javax.swing.JTable JavaDoc;
37
38 import org.objectweb.util.browser.api.Panel;
39 import org.objectweb.util.browser.api.TreeView;
40
41 /**
42  * Displays a <code>javax.swing.JTable</code> representing
43  * the given <code>java.util.Collection</code> object.
44  *
45  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>,
46  * <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
47  *
48  * @version 0.1
49  */

50 public class CollectionPanel
51     implements Panel JavaDoc {
52
53     //==================================================================
54
//
55
// Internal states.
56
//
57
//==================================================================
58

59     /** The JPanel to display */
60     protected JPanel JavaDoc panel_;
61
62     //==================================================================
63
//
64
// Constructors.
65
//
66
//==================================================================
67

68     /**
69      * Default constructor.
70      * Creates a empty white panel with <code>BoxLayout</code>.
71      */

72     public CollectionPanel(){
73         panel_ = new JPanel JavaDoc();
74         panel_.setBackground(Color.white);
75         panel_.setLayout(new BoxLayout JavaDoc(panel_, BoxLayout.Y_AXIS));
76     }
77
78     //==================================================================
79
//
80
// No internal method.
81
//
82
//==================================================================
83

84     //==================================================================
85
//
86
// Public methods for Panel interface.
87
//
88
//==================================================================
89

90     /**
91      * Invokes just after instanciation.
92      *
93      * @param treeView A view on the tree.
94      */

95     public void selected(TreeView treeView) {
96         String JavaDoc[] titre = {"Class name","Instance"};
97         Collection JavaDoc collection = (Collection JavaDoc)treeView.getSelectedObject();
98         String JavaDoc[][] contenu = new String JavaDoc[collection.size()][2];
99         Iterator JavaDoc iterator = collection.iterator();
100         int cpt = 0;
101         while (iterator.hasNext()) {
102             Object JavaDoc element = iterator.next();
103             contenu[cpt] = new String JavaDoc[]{element.getClass().getName(), element.toString()};
104             cpt++;
105         }
106         panel_.add(new JScrollPane JavaDoc(new JTable JavaDoc(contenu,titre)));
107     }
108
109     /**
110      * Provides the panel to display.
111      *
112      * @return The panel to display.
113      */

114     public JPanel JavaDoc getPanel() {
115         return panel_;
116     }
117
118     /**
119      * Invokes just before removing.
120      *
121      * @param treeView A view on the tree.
122      */

123     public void unselected(TreeView treeView) {
124         // Noting to do
125
}
126         
127 }
Popular Tags