KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > explorer > plugin > java > swing > CollectionPanel


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2004 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): Jerome Moroy, Philippe Merle.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.explorer.plugin.java.swing;
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.explorer.api.Panel;
39 import org.objectweb.util.explorer.api.TreeView;
40
41
42 /**
43  * Displays a <code>javax.swing.JTable</code> representing
44  * the given <code>java.util.Collection</code> object.
45  *
46  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>,
47  * <a HREF="mailto:Jerome.Moroy@lifl.fr">Jérôme Moroy</a>
48  *
49  * @version 0.1
50  */

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

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

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

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

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

91     /* (non-Javadoc)
92      * @see org.objectweb.util.explorer.api.Panel#selected(org.objectweb.util.explorer.api.TreeView)
93      */

94     public void selected(TreeView treeView) {
95         String JavaDoc[] titre = {"Class name","Instance"};
96         Collection JavaDoc collection = (Collection JavaDoc)treeView.getSelectedObject();
97         String JavaDoc[][] contenu = new String JavaDoc[collection.size()][2];
98         Iterator JavaDoc iterator = collection.iterator();
99         int cpt = 0;
100         while (iterator.hasNext()) {
101             Object JavaDoc element = iterator.next();
102             contenu[cpt] = new String JavaDoc[]{element.getClass().getName(), element.toString()};
103             cpt++;
104         }
105         panel_.add(new JScrollPane JavaDoc(new JTable JavaDoc(contenu,titre)));
106     }
107
108     /* (non-Javadoc)
109      * @see org.objectweb.util.explorer.api.Panel#getPanel()
110      */

111     public Object JavaDoc getPanel() {
112         return panel_;
113     }
114
115     /* (non-Javadoc)
116      * @see org.objectweb.util.explorer.api.Panel#unselected(org.objectweb.util.explorer.api.TreeView)
117      */

118     public void unselected(TreeView treeView) {
119         // Noting to do
120
}
121         
122 }
Popular Tags