001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.core.gui.externaltools;
017:
018: import java.awt.BorderLayout;
019: import java.awt.FlowLayout;
020: import java.awt.Font;
021: import java.awt.GridLayout;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.io.File;
025:
026: import javax.swing.JButton;
027: import javax.swing.JComponent;
028: import javax.swing.JFileChooser;
029: import javax.swing.JLabel;
030: import javax.swing.JPanel;
031: import javax.swing.UIManager;
032:
033: import net.javaprog.ui.wizard.AbstractStep;
034: import net.javaprog.ui.wizard.DataLookup;
035: import net.javaprog.ui.wizard.DataModel;
036:
037: import org.columba.core.gui.base.ButtonWithMnemonic;
038: import org.columba.core.gui.base.LabelWithMnemonic;
039: import org.columba.core.gui.base.MultiLineLabel;
040: import org.columba.core.gui.base.WizardTextField;
041: import org.columba.core.resourceloader.GlobalResourceLoader;
042:
043: /**
044: * Asks the user about the location of an executable file.
045: * <p>
046: * Usually this should should include a short explanation about
047: * what the tool does, where to download, etc.
048: *
049: * @author fdietz
050: */
051: class LocationStep extends AbstractStep implements ActionListener {
052: private static final String RESOURCE_PATH = "org.columba.core.i18n.dialog";
053: protected DataModel data;
054: protected JButton sourceButton;
055: protected File sourceFile;
056:
057: /**
058: * @param arg0
059: * @param arg1
060: */
061: public LocationStep(DataModel data) {
062: super (GlobalResourceLoader.getString(RESOURCE_PATH,
063: "externaltools", "LocationStep.title"),
064: GlobalResourceLoader.getString(RESOURCE_PATH,
065: "externaltools", "LocationStep.description"));
066:
067: this .data = data;
068:
069: data.registerDataLookup("Location.source", new DataLookup() {
070: public Object lookupData() {
071: return sourceFile;
072: }
073: });
074:
075: setCanGoNext(false);
076: }
077:
078: /* (non-Javadoc)
079: * @see net.javaprog.ui.wizard.AbstractStep#createComponent()
080: */
081: protected JComponent createComponent() {
082: JPanel panel = new JPanel(new BorderLayout());
083:
084: AbstractExternalToolsPlugin plugin = (AbstractExternalToolsPlugin) data
085: .getData("Plugin");
086:
087: sourceFile = plugin.locate();
088:
089: if (sourceFile == null) {
090: MultiLineLabel label = new MultiLineLabel(
091: GlobalResourceLoader.getString(RESOURCE_PATH,
092: "externaltools", "LocationStep.noauto"));
093: panel.add(label, BorderLayout.NORTH);
094:
095: WizardTextField middlePanel = new WizardTextField();
096: LabelWithMnemonic sourceLabel = new LabelWithMnemonic(
097: GlobalResourceLoader.getString(RESOURCE_PATH,
098: "externaltools", "LocationStep.location"));
099: middlePanel.add(sourceLabel);
100:
101: sourceButton = new ButtonWithMnemonic(GlobalResourceLoader
102: .getString(RESOURCE_PATH, "externaltools",
103: "LocationStep.browse"));
104: sourceLabel.setLabelFor(sourceButton);
105: sourceButton.addActionListener(this );
106: middlePanel.add(sourceButton);
107:
108: panel.add(middlePanel, BorderLayout.CENTER);
109: } else {
110: JPanel northPanel = new JPanel(new GridLayout(2, 1, 0, 15));
111: MultiLineLabel label = new MultiLineLabel(
112: GlobalResourceLoader.getString(RESOURCE_PATH,
113: "externaltools", "LocationStep.auto"));
114: northPanel.add(label);
115:
116: JPanel sourceFilePanel = new JPanel(new FlowLayout(
117: FlowLayout.LEFT, 20, 0));
118: JLabel label2 = new JLabel(sourceFile.getPath());
119: Font font = (Font) UIManager.getFont("Label.font");
120: font = font.deriveFont(Font.BOLD);
121: label2.setFont(font);
122: sourceFilePanel.add(label2);
123:
124: sourceButton = new ButtonWithMnemonic(GlobalResourceLoader
125: .getString(RESOURCE_PATH, "externaltools",
126: "LocationStep.change"));
127: sourceButton.addActionListener(this );
128: sourceFilePanel.add(sourceButton);
129:
130: northPanel.add(sourceFilePanel);
131: panel.add(northPanel, BorderLayout.NORTH);
132: }
133:
134: return panel;
135: }
136:
137: /* (non-Javadoc)
138: * @see net.javaprog.ui.wizard.Step#prepareRendering()
139: */
140: public void prepareRendering() {
141: // init component before querying for sourceFile
142: getComponent();
143: updateCanFinish();
144: }
145:
146: protected void updateCanFinish() {
147: setCanFinish(sourceFile != null);
148: }
149:
150: public void actionPerformed(ActionEvent e) {
151: Object source = e.getSource();
152:
153: if (source == sourceButton) {
154: JFileChooser fc = new JFileChooser();
155: fc.setMultiSelectionEnabled(true);
156: fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
157: fc.setFileHidingEnabled(false);
158:
159: if (fc.showOpenDialog(getComponent()) == JFileChooser.APPROVE_OPTION) {
160: sourceFile = fc.getSelectedFile();
161:
162: sourceButton.setText(sourceFile.getPath());
163: }
164:
165: updateCanFinish();
166: }
167: }
168: }
|