KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*====================================================================
2
3 Objectweb Explorer Framework
4 Copyright (C) 2000-2005 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 $Id: MapPanel.java,v 1.2 2005/07/05 09:23:38 moroy Exp $
27 ====================================================================*/

28
29 package org.objectweb.util.explorer.plugin.java.map.swing;
30
31 import java.awt.Color JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import javax.swing.BoxLayout JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36 import javax.swing.JScrollPane JavaDoc;
37 import javax.swing.JTable JavaDoc;
38
39 import org.objectweb.util.explorer.api.Panel;
40 import org.objectweb.util.explorer.api.TreeView;
41
42 /**
43  * Displays a <code>javax.swing.JTable</code> representing
44  * the given <code>java.util.Map</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 MapPanel
52     implements Panel JavaDoc {
53
54     //==================================================================
55
//
56
// Internal states.
57
//
58
//==================================================================
59

60     /**
61      * The JPanel to display
62      */

63     protected JPanel JavaDoc panel_;
64
65     //==================================================================
66
//
67
// Constructors.
68
//
69
//==================================================================
70

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

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

87     //==================================================================
88
//
89
// Public methods for Panel interface.
90
//
91
//==================================================================
92

93     /**
94      * Invokes just after instanciation.
95      *
96      * @param treeView A view on the tree.
97      */

98     public void selected(TreeView treeView) {
99         String JavaDoc[] titre = {"Keys","Values"};
100         Map JavaDoc map = (Map JavaDoc)treeView.getSelectedObject();
101         String JavaDoc[][] contenu = new String JavaDoc[map.size()][2];
102         Object JavaDoc[] keys = map.keySet().toArray();
103         Object JavaDoc[] elements = map.entrySet().toArray();
104         for (int i = 0; i < keys.length; i++) {
105             contenu[i] = new String JavaDoc[]{keys[i].toString(), elements[i].toString()};
106         }
107         panel_.add(new JScrollPane JavaDoc(new JTable JavaDoc(contenu,titre)));
108     }
109
110     /**
111      * Provides the panel to display.
112      *
113      * @return The panel to display.
114      */

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

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