KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > config > mailboximport > 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.mail.gui.config.mailboximport;
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 import javax.swing.SwingUtilities JavaDoc;
30
31 import net.javaprog.ui.wizard.AbstractStep;
32 import net.javaprog.ui.wizard.DataLookup;
33 import net.javaprog.ui.wizard.DataModel;
34
35 import org.columba.api.gui.frame.IFrameMediator;
36 import org.columba.core.gui.base.LabelWithMnemonic;
37 import org.columba.core.gui.base.MultiLineLabel;
38 import org.columba.core.gui.base.WizardTextField;
39 import org.columba.mail.folder.IMailFolder;
40 import org.columba.mail.gui.tree.util.SelectFolderDialog;
41 import org.columba.mail.util.MailResourceLoader;
42
43
44 class LocationStep extends AbstractStep implements ActionListener JavaDoc {
45     protected File JavaDoc[] sourceFiles;
46     protected IMailFolder destinationFolder;
47     protected JButton JavaDoc sourceButton;
48     protected JButton JavaDoc destinationButton;
49     protected IFrameMediator mediator;
50     
51     public LocationStep(IFrameMediator mediator, DataModel data) {
52         super(MailResourceLoader.getString("dialog", "mailboximport", "location"),
53             MailResourceLoader.getString("dialog", "mailboximport",
54                 "location_description"));
55         this.mediator = mediator;
56         
57         data.registerDataLookup("Location.source",
58             new DataLookup() {
59                 public Object JavaDoc lookupData() {
60                     return sourceFiles;
61                 }
62             });
63         data.registerDataLookup("Location.destination",
64             new DataLookup() {
65                 public Object JavaDoc lookupData() {
66                     return destinationFolder;
67                 }
68             });
69         setCanGoNext(false);
70     }
71
72     protected JComponent JavaDoc createComponent() {
73         JComponent JavaDoc component = new JPanel JavaDoc();
74         component.setLayout(new BoxLayout JavaDoc(component, BoxLayout.Y_AXIS));
75         component.add(new MultiLineLabel(MailResourceLoader.getString(
76                     "dialog", "mailboximport", "location_text")));
77         component.add(Box.createVerticalStrut(40));
78
79         WizardTextField middlePanel = new WizardTextField();
80
81         LabelWithMnemonic sourceLabel = new LabelWithMnemonic(MailResourceLoader.getString(
82                     "dialog", "mailboximport", "source"));
83         middlePanel.addLabel(sourceLabel);
84         sourceButton = new JButton JavaDoc("...");
85         sourceLabel.setLabelFor(sourceButton);
86         sourceButton.addActionListener(this);
87         middlePanel.addTextField(sourceButton);
88         middlePanel.addExample(new JLabel JavaDoc());
89
90         LabelWithMnemonic destinationLabel = new LabelWithMnemonic(MailResourceLoader.getString(
91                     "dialog", "mailboximport", "destination"));
92         middlePanel.addLabel(destinationLabel);
93         destinationButton = new JButton JavaDoc("...");
94         destinationLabel.setLabelFor(destinationButton);
95         destinationButton.addActionListener(this);
96         middlePanel.addTextField(destinationButton);
97         middlePanel.addExample(new JLabel JavaDoc(MailResourceLoader.getString(
98                     "dialog", "mailboximport", "explanation")));
99         component.add(middlePanel);
100
101         return component;
102     }
103
104     public void actionPerformed(ActionEvent JavaDoc e) {
105         Object JavaDoc source = e.getSource();
106
107         if (source == sourceButton) {
108             JFileChooser JavaDoc fc = new JFileChooser JavaDoc();
109             fc.setMultiSelectionEnabled(true);
110             fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
111             fc.setFileHidingEnabled(false);
112
113             if (fc.showOpenDialog(getComponent()) == JFileChooser.APPROVE_OPTION) {
114                 sourceFiles = fc.getSelectedFiles();
115
116                 if (sourceFiles.length > 1) {
117                     sourceButton.setText(sourceFiles.length + " " +
118                         MailResourceLoader.getString("dialog", "mailboximport",
119                             "files"));
120
121                     StringBuffer JavaDoc toolTip = new StringBuffer JavaDoc();
122                     toolTip.append("<html><body>");
123
124                     int i = 0;
125
126                     for (; i < (sourceFiles.length - 1); i++) {
127                         toolTip.append(sourceFiles[i].getPath());
128                         toolTip.append("<br>");
129                     }
130
131                     toolTip.append(sourceFiles[i].getPath());
132                     toolTip.append("</body></html>");
133                     sourceButton.setToolTipText(toolTip.toString());
134                 } else {
135                     sourceButton.setText(sourceFiles[0].getPath());
136                     sourceButton.setToolTipText(null);
137                 }
138
139                 updateCanFinish();
140             }
141         } else if (source == destinationButton) {
142             SelectFolderDialog dialog = new SelectFolderDialog(mediator);
143
144             if (dialog.success()) {
145                 destinationFolder = (IMailFolder) dialog.getSelectedFolder();
146                 destinationButton.setText(destinationFolder.getTreePath());
147                 updateCanFinish();
148             }
149         }
150     }
151
152     protected void updateCanFinish() {
153         setCanFinish((sourceFiles != null) && (destinationFolder != null));
154     }
155
156     public void prepareRendering() {
157         SwingUtilities.invokeLater(new Runnable JavaDoc() {
158                 public void run() {
159                     sourceButton.requestFocus();
160                 }
161             });
162     }
163 }
164
Popular Tags