KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > externaltools > LocationStep


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.gui.externaltools;
17
18 import java.awt.BorderLayout JavaDoc;
19 import java.awt.FlowLayout JavaDoc;
20 import java.awt.Font JavaDoc;
21 import java.awt.GridLayout JavaDoc;
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.io.File JavaDoc;
25
26 import javax.swing.JButton JavaDoc;
27 import javax.swing.JComponent JavaDoc;
28 import javax.swing.JFileChooser JavaDoc;
29 import javax.swing.JLabel JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31 import javax.swing.UIManager JavaDoc;
32
33 import net.javaprog.ui.wizard.AbstractStep;
34 import net.javaprog.ui.wizard.DataLookup;
35 import net.javaprog.ui.wizard.DataModel;
36
37 import org.columba.core.gui.base.ButtonWithMnemonic;
38 import org.columba.core.gui.base.LabelWithMnemonic;
39 import org.columba.core.gui.base.MultiLineLabel;
40 import org.columba.core.gui.base.WizardTextField;
41 import org.columba.core.resourceloader.GlobalResourceLoader;
42
43
44 /**
45  * Asks the user about the location of an executable file.
46  * <p>
47  * Usually this should should include a short explanation about
48  * what the tool does, where to download, etc.
49  *
50  * @author fdietz
51  */

52 class LocationStep extends AbstractStep implements ActionListener JavaDoc {
53     private static final String JavaDoc RESOURCE_PATH = "org.columba.core.i18n.dialog";
54     protected DataModel data;
55     protected JButton JavaDoc sourceButton;
56     protected File JavaDoc sourceFile;
57
58     /**
59  * @param arg0
60  * @param arg1
61  */

62     public LocationStep(DataModel data) {
63         super(GlobalResourceLoader.getString(RESOURCE_PATH, "externaltools",
64                 "LocationStep.title"),
65             GlobalResourceLoader.getString(RESOURCE_PATH, "externaltools",
66                 "LocationStep.description"));
67
68         this.data = data;
69
70         data.registerDataLookup("Location.source",
71             new DataLookup() {
72                 public Object JavaDoc lookupData() {
73                     return sourceFile;
74                 }
75             });
76
77         setCanGoNext(false);
78     }
79
80     /* (non-Javadoc)
81  * @see net.javaprog.ui.wizard.AbstractStep#createComponent()
82  */

83     protected JComponent JavaDoc createComponent() {
84         JPanel JavaDoc panel = new JPanel JavaDoc(new BorderLayout JavaDoc());
85
86         AbstractExternalToolsPlugin plugin = (AbstractExternalToolsPlugin) data.getData(
87                 "Plugin");
88
89         sourceFile = plugin.locate();
90
91         if (sourceFile == null) {
92             MultiLineLabel label = new MultiLineLabel(GlobalResourceLoader.getString(
93                         RESOURCE_PATH, "externaltools", "LocationStep.noauto"));
94             panel.add(label, BorderLayout.NORTH);
95
96             WizardTextField middlePanel = new WizardTextField();
97             LabelWithMnemonic sourceLabel = new LabelWithMnemonic(GlobalResourceLoader.getString(
98                         RESOURCE_PATH, "externaltools", "LocationStep.location"));
99             middlePanel.add(sourceLabel);
100
101             sourceButton = new ButtonWithMnemonic(GlobalResourceLoader.getString(
102                         RESOURCE_PATH, "externaltools", "LocationStep.browse"));
103             sourceLabel.setLabelFor(sourceButton);
104             sourceButton.addActionListener(this);
105             middlePanel.add(sourceButton);
106
107             panel.add(middlePanel, BorderLayout.CENTER);
108         } else {
109             JPanel JavaDoc northPanel = new JPanel JavaDoc(new GridLayout JavaDoc(2, 1, 0, 15));
110             MultiLineLabel label = new MultiLineLabel(GlobalResourceLoader.getString(
111                         RESOURCE_PATH, "externaltools", "LocationStep.auto"));
112             northPanel.add(label);
113
114             JPanel JavaDoc sourceFilePanel = new JPanel JavaDoc(new FlowLayout JavaDoc(
115                         FlowLayout.LEFT, 20, 0));
116             JLabel JavaDoc label2 = new JLabel JavaDoc(sourceFile.getPath());
117             Font JavaDoc font = (Font JavaDoc) UIManager.getFont("Label.font");
118             font = font.deriveFont(Font.BOLD);
119             label2.setFont(font);
120             sourceFilePanel.add(label2);
121
122             sourceButton = new ButtonWithMnemonic(GlobalResourceLoader.getString(
123                         RESOURCE_PATH, "externaltools", "LocationStep.change"));
124             sourceButton.addActionListener(this);
125             sourceFilePanel.add(sourceButton);
126
127             northPanel.add(sourceFilePanel);
128             panel.add(northPanel, BorderLayout.NORTH);
129         }
130
131         return panel;
132     }
133
134     /* (non-Javadoc)
135  * @see net.javaprog.ui.wizard.Step#prepareRendering()
136  */

137     public void prepareRendering() {
138         // init component before querying for sourceFile
139
getComponent();
140         updateCanFinish();
141     }
142
143     protected void updateCanFinish() {
144         setCanFinish(sourceFile != null);
145     }
146
147     public void actionPerformed(ActionEvent JavaDoc e) {
148         Object JavaDoc source = e.getSource();
149
150         if (source == sourceButton) {
151             JFileChooser JavaDoc fc = new JFileChooser JavaDoc();
152             fc.setMultiSelectionEnabled(true);
153             fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
154             fc.setFileHidingEnabled(false);
155
156             if (fc.showOpenDialog(getComponent()) == JFileChooser.APPROVE_OPTION) {
157                 sourceFile = fc.getSelectedFile();
158
159                 sourceButton.setText(sourceFile.getPath());
160             }
161
162             updateCanFinish();
163         }
164     }
165 }
166
Popular Tags