KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > menu > BrowserPanel


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
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): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.openccm.explorer.menu;
27
28 /** The java API's imports */
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.JScrollPane JavaDoc;
31 import javax.swing.Box JavaDoc;
32
33 import org.objectweb.util.explorer.api.Entry;
34 import org.objectweb.util.explorer.api.Tree;
35 import org.objectweb.util.explorer.swing.api.Explorer;
36
37 import org.objectweb.fractal.api.Component;
38 import org.objectweb.fractal.api.NoSuchInterfaceException;
39 import org.objectweb.openccm.explorer.CORBA.ConsoleFactory;
40 import org.objectweb.openccm.explorer.menu.TreeDialogSingleton;
41
42 import java.awt.Dimension JavaDoc;
43 import java.io.File JavaDoc;
44
45 /**
46  * This class represents the panel which allows to choose a file and specify a label to the entry
47  *
48  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
49  *
50  * @version 0.1
51  */

52 public class BrowserPanel extends JPanel JavaDoc {
53
54     /** The associated FileChooserPanel */
55     protected FileChooserPanel fileChooserPanel_;
56
57     /** The associated Tree */
58     protected Component tree_;
59
60     /** The Tree interface of the tree component. */
61     protected Tree treeItf_;
62     
63     /**
64      * Default constructor
65      */

66     public BrowserPanel(String JavaDoc nameFieldLabel, String JavaDoc nameBrowserLabel, int fileFilter) {
67
68         fileChooserPanel_ = new FileChooserPanel(nameFieldLabel, nameBrowserLabel, fileFilter);
69
70         Box JavaDoc b = Box.createVerticalBox();
71         b.add(Box.createVerticalGlue());
72
73         b.add(fileChooserPanel_);
74
75         b.add(Box.createVerticalStrut(10));
76
77         try {
78             tree_ = TreeDialogSingleton.getInstance();
79             Explorer explorerItf = (Explorer)tree_.getFcInterface(Explorer.EXPLORER);
80             treeItf_ = (Tree)tree_.getFcInterface(Tree.TREE);
81             Box JavaDoc treeBox = Box.createHorizontalBox();
82             //tree.setPreferredSize(new Dimension(350,150));
83
JScrollPane JavaDoc scroll = new JScrollPane JavaDoc(explorerItf.getTree());
84             scroll.setPreferredSize(new Dimension JavaDoc(350, 150));
85             treeBox.add(scroll);
86             b.add(treeBox);
87
88             b.add(Box.createVerticalGlue());
89
90             add(b);
91         } catch (NoSuchInterfaceException e) {
92             ConsoleFactory.getDebugConsole().add(e.getMessage());
93         }
94     }
95
96     /** Returns the specify label */
97     public String JavaDoc getLabel() {
98         return fileChooserPanel_.getLabel();
99     }
100
101     /** Returns the chosen file */
102     public File JavaDoc getFile() {
103         return fileChooserPanel_.getFile();
104     }
105
106     /** Returns the selected object */
107     public Object JavaDoc getSelectedObject() {
108         if (tree_ != null) {
109             Entry entry = treeItf_.getSelectedEntry();
110             if (entry != null)
111                 return entry.getValue();
112         }
113         return null;
114     }
115
116 }
117
Popular Tags