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.addressbook.gui.dialog.importfilter;
017:
018: import java.awt.event.ActionEvent;
019: import java.awt.event.ActionListener;
020: import java.io.File;
021:
022: import javax.swing.Box;
023: import javax.swing.BoxLayout;
024: import javax.swing.JButton;
025: import javax.swing.JComponent;
026: import javax.swing.JFileChooser;
027: import javax.swing.JLabel;
028: import javax.swing.JPanel;
029:
030: import net.javaprog.ui.wizard.AbstractStep;
031: import net.javaprog.ui.wizard.DataLookup;
032: import net.javaprog.ui.wizard.DataModel;
033:
034: import org.columba.addressbook.folder.IFolder;
035: import org.columba.addressbook.gui.tree.AddressbookTreeModel;
036: import org.columba.addressbook.gui.tree.util.ISelectFolderDialog;
037: import org.columba.addressbook.util.AddressbookResourceLoader;
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:
042: class LocationStep extends AbstractStep implements ActionListener {
043: protected File sourceFile;
044: protected IFolder destinationFolder;
045: protected JButton sourceButton;
046: protected JButton destinationButton;
047:
048: public LocationStep(DataModel data) {
049: super (AddressbookResourceLoader.getString("dialog",
050: "addressbookimport", "location"),
051: AddressbookResourceLoader.getString("dialog",
052: "addressbookimport", "location_description"));
053: data.registerDataLookup("Location.source", new DataLookup() {
054: public Object lookupData() {
055: return sourceFile;
056: }
057: });
058: data.registerDataLookup("Location.destination",
059: new DataLookup() {
060: public Object lookupData() {
061: return destinationFolder;
062: }
063: });
064: setCanGoNext(false);
065: }
066:
067: protected JComponent createComponent() {
068: JComponent component = new JPanel();
069: component.setLayout(new BoxLayout(component, BoxLayout.Y_AXIS));
070: component.add(new MultiLineLabel(AddressbookResourceLoader
071: .getString("dialog", "addressbookimport",
072: "location_text")));
073: component.add(Box.createVerticalStrut(40));
074:
075: WizardTextField middlePanel = new WizardTextField();
076: LabelWithMnemonic sourceLabel = new LabelWithMnemonic(
077: AddressbookResourceLoader.getString("dialog",
078: "addressbookimport", "source"));
079: middlePanel.addLabel(sourceLabel);
080: sourceButton = new JButton("...");
081: sourceButton.addActionListener(this );
082: sourceLabel.setLabelFor(sourceButton);
083: middlePanel.addTextField(sourceButton);
084: middlePanel.addExample(new JLabel());
085:
086: LabelWithMnemonic destinationLabel = new LabelWithMnemonic(
087: AddressbookResourceLoader.getString("dialog",
088: "addressbookimport", "destination"));
089: middlePanel.addLabel(destinationLabel);
090: destinationButton = new JButton("...");
091: destinationButton.addActionListener(this );
092: destinationLabel.setLabelFor(destinationButton);
093: middlePanel.addTextField(destinationButton);
094: middlePanel.addExample(new JLabel(
095: AddressbookResourceLoader.getString("dialog",
096: "addressbookimport", "explanation")));
097: component.add(middlePanel);
098:
099: return component;
100: }
101:
102: public void actionPerformed(ActionEvent e) {
103: Object source = e.getSource();
104:
105: if (source == sourceButton) {
106: JFileChooser fc = new JFileChooser();
107: fc.setFileHidingEnabled(false);
108:
109: if (fc.showOpenDialog(getComponent()) == JFileChooser.APPROVE_OPTION) {
110: sourceFile = fc.getSelectedFile();
111: sourceButton.setText(sourceFile.getPath());
112: updateCanFinish();
113: }
114: } else if (source == destinationButton) {
115: ISelectFolderDialog dialog = AddressbookTreeModel
116: .getInstance().getSelectAddressbookFolderDialog();
117:
118: if (dialog.success()) {
119: destinationFolder = dialog.getSelectedFolder();
120: //destinationButton.setText(destinationFolder.getTreePath());
121: destinationButton.setText(destinationFolder.getName());
122: updateCanFinish();
123: }
124: }
125: }
126:
127: protected void updateCanFinish() {
128: setCanFinish((sourceFile != null)
129: && (destinationFolder != null));
130: }
131:
132: public void prepareRendering() {
133: }
134: }
|