KickJava   Java API By Example, From Geeks To Geeks.

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


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

48 public class MapPanel
49     implements Panel JavaDoc {
50
51     //==================================================================
52
//
53
// Internal states.
54
//
55
//==================================================================
56

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

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

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

82     //==================================================================
83
//
84
// Public methods for Panel interface.
85
//
86
//==================================================================
87

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

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

110     public JPanel JavaDoc getPanel() {
111         return panel_;
112     }
113
114     /**
115      * Invokes just before removing.
116      *
117      * @param treeView A view on the tree.
118      */

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