KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > dialog > importfilter > 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.addressbook.gui.dialog.importfilter;
17
18 import java.awt.event.ActionEvent JavaDoc;
19 import java.awt.event.ActionListener JavaDoc;
20 import java.io.File JavaDoc;
21
22 import javax.swing.Box JavaDoc;
23 import javax.swing.BoxLayout JavaDoc;
24 import javax.swing.JButton JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import javax.swing.JFileChooser JavaDoc;
27 import javax.swing.JLabel JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29
30 import net.javaprog.ui.wizard.AbstractStep;
31 import net.javaprog.ui.wizard.DataLookup;
32 import net.javaprog.ui.wizard.DataModel;
33
34 import org.columba.addressbook.folder.IFolder;
35 import org.columba.addressbook.gui.tree.AddressbookTreeModel;
36 import org.columba.addressbook.gui.tree.util.ISelectFolderDialog;
37 import org.columba.addressbook.util.AddressbookResourceLoader;
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
42
43 class LocationStep extends AbstractStep implements ActionListener JavaDoc {
44     protected File JavaDoc sourceFile;
45     protected IFolder destinationFolder;
46     protected JButton JavaDoc sourceButton;
47     protected JButton JavaDoc destinationButton;
48
49     public LocationStep(DataModel data) {
50         super(AddressbookResourceLoader.getString("dialog",
51                 "addressbookimport", "location"),
52             AddressbookResourceLoader.getString("dialog", "addressbookimport",
53                 "location_description"));
54         data.registerDataLookup("Location.source",
55             new DataLookup() {
56                 public Object JavaDoc lookupData() {
57                     return sourceFile;
58                 }
59             });
60         data.registerDataLookup("Location.destination",
61             new DataLookup() {
62                 public Object JavaDoc lookupData() {
63                     return destinationFolder;
64                 }
65             });
66         setCanGoNext(false);
67     }
68
69     protected JComponent JavaDoc createComponent() {
70         JComponent JavaDoc component = new JPanel JavaDoc();
71         component.setLayout(new BoxLayout JavaDoc(component, BoxLayout.Y_AXIS));
72         component.add(new MultiLineLabel(AddressbookResourceLoader.getString(
73                     "dialog", "addressbookimport", "location_text")));
74         component.add(Box.createVerticalStrut(40));
75
76         WizardTextField middlePanel = new WizardTextField();
77         LabelWithMnemonic sourceLabel = new LabelWithMnemonic(AddressbookResourceLoader.getString(
78                     "dialog", "addressbookimport", "source"));
79         middlePanel.addLabel(sourceLabel);
80         sourceButton = new JButton JavaDoc("...");
81         sourceButton.addActionListener(this);
82         sourceLabel.setLabelFor(sourceButton);
83         middlePanel.addTextField(sourceButton);
84         middlePanel.addExample(new JLabel JavaDoc());
85
86         LabelWithMnemonic destinationLabel = new LabelWithMnemonic(AddressbookResourceLoader.getString(
87                     "dialog", "addressbookimport", "destination"));
88         middlePanel.addLabel(destinationLabel);
89         destinationButton = new JButton JavaDoc("...");
90         destinationButton.addActionListener(this);
91         destinationLabel.setLabelFor(destinationButton);
92         middlePanel.addTextField(destinationButton);
93         middlePanel.addExample(new JLabel JavaDoc(AddressbookResourceLoader.getString(
94                     "dialog", "addressbookimport", "explanation")));
95         component.add(middlePanel);
96
97         return component;
98     }
99
100     public void actionPerformed(ActionEvent JavaDoc e) {
101         Object JavaDoc source = e.getSource();
102
103         if (source == sourceButton) {
104             JFileChooser JavaDoc fc = new JFileChooser JavaDoc();
105             fc.setFileHidingEnabled(false);
106
107             if (fc.showOpenDialog(getComponent()) == JFileChooser.APPROVE_OPTION) {
108                 sourceFile = fc.getSelectedFile();
109                 sourceButton.setText(sourceFile.getPath());
110                 updateCanFinish();
111             }
112         } else if (source == destinationButton) {
113             ISelectFolderDialog dialog = AddressbookTreeModel.getInstance().getSelectAddressbookFolderDialog();
114
115             if (dialog.success()) {
116                 destinationFolder = dialog.getSelectedFolder();
117                 //destinationButton.setText(destinationFolder.getTreePath());
118
destinationButton.setText(destinationFolder.getName());
119                 updateCanFinish();
120             }
121         }
122     }
123
124     protected void updateCanFinish() {
125         setCanFinish((sourceFile != null) && (destinationFolder != null));
126     }
127
128     public void prepareRendering() {
129     }
130 }
131
Popular Tags