KickJava   Java API By Example, From Geeks To Geeks.

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


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.JFileChooser JavaDoc;
30 import javax.swing.JTextField JavaDoc;
31 import javax.swing.JLabel JavaDoc;
32 import javax.swing.JButton JavaDoc;
33 import javax.swing.AbstractAction JavaDoc;
34 import javax.swing.Box JavaDoc;
35 import javax.swing.BoxLayout JavaDoc;
36 import javax.swing.SwingConstants JavaDoc;
37
38 import java.awt.Component JavaDoc;
39 import java.awt.Dimension JavaDoc;
40 import java.io.File JavaDoc;
41
42 /**
43  * This class represents the panel which allows to choose a file.
44  *
45  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
46  *
47  * @version 0.1
48  */

49 public class FileChooserBox extends Box JavaDoc {
50
51     // TODO: Maybe obsolete!!!
52

53     /** The file chooser that allow to find the file to load */
54     protected JFileChooser JavaDoc fileChooser_;
55
56     /** The chosen file */
57     protected File JavaDoc file_;
58
59     /**
60      * Default constructor
61      */

62     public FileChooserBox(String JavaDoc label, int fileFilterType) {
63         super(BoxLayout.X_AXIS);
64         fileChooser_ = JFileChooserSingleton.getInstance(fileFilterType);
65         add(Box.createHorizontalGlue());
66         JLabel JavaDoc browserLabel = new JLabel JavaDoc(label, SwingConstants.RIGHT);
67         browserLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);
68         browserLabel.setAlignmentY(Component.CENTER_ALIGNMENT);
69         add(browserLabel);
70         add(Box.createHorizontalStrut(5));
71         JTextField JavaDoc fileName = new JTextField JavaDoc();
72         fileName.setEditable(false);
73         fileName.setPreferredSize(new Dimension JavaDoc(200, 20));
74         fileName.setMaximumSize(new Dimension JavaDoc(200, 20));
75         add(fileName);
76         add(Box.createHorizontalStrut(5));
77         JButton JavaDoc browseButton = new JButton JavaDoc(new BrowseAction(this, fileName));
78         browseButton.setPreferredSize(new Dimension JavaDoc(20, 20));
79         browseButton.setMaximumSize(new Dimension JavaDoc(20, 20));
80         add(browseButton);
81     }
82
83     /** Returns the chosen file */
84     public File JavaDoc getFile() {
85         return file_;
86     }
87
88     /**
89      * Action which
90      */

91     protected class BrowseAction extends AbstractAction JavaDoc {
92
93         /** The parent of the panel */
94         protected Component JavaDoc parent_;
95
96         /** */
97         protected JTextField JavaDoc textField_;
98
99         /**
100          * Default constructor
101          */

102         protected BrowseAction(Component JavaDoc parent, JTextField JavaDoc textField) {
103             super("...", null);
104             parent_ = parent;
105             textField_ = textField;
106         }
107
108         public void actionPerformed(java.awt.event.ActionEvent JavaDoc ae) {
109             int returnVal = fileChooser_.showOpenDialog(parent_);
110             if (returnVal == JFileChooser.APPROVE_OPTION) {
111                 file_ = fileChooser_.getSelectedFile();
112                 textField_.setText(fileChooser_.getSelectedFile().toString());
113             }
114         }
115
116     }
117
118 }
119
Popular Tags