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.mail.gui.config.mailboximport;
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: import javax.swing.SwingUtilities;
030:
031: import net.javaprog.ui.wizard.AbstractStep;
032: import net.javaprog.ui.wizard.DataLookup;
033: import net.javaprog.ui.wizard.DataModel;
034:
035: import org.columba.api.gui.frame.IFrameMediator;
036: import org.columba.core.gui.base.LabelWithMnemonic;
037: import org.columba.core.gui.base.MultiLineLabel;
038: import org.columba.core.gui.base.WizardTextField;
039: import org.columba.mail.folder.IMailFolder;
040: import org.columba.mail.gui.tree.util.SelectFolderDialog;
041: import org.columba.mail.util.MailResourceLoader;
042:
043: class LocationStep extends AbstractStep implements ActionListener {
044: protected File[] sourceFiles;
045: protected IMailFolder destinationFolder;
046: protected JButton sourceButton;
047: protected JButton destinationButton;
048: protected IFrameMediator mediator;
049:
050: public LocationStep(IFrameMediator mediator, DataModel data) {
051: super (MailResourceLoader.getString("dialog", "mailboximport",
052: "location"), MailResourceLoader.getString("dialog",
053: "mailboximport", "location_description"));
054: this .mediator = mediator;
055:
056: data.registerDataLookup("Location.source", new DataLookup() {
057: public Object lookupData() {
058: return sourceFiles;
059: }
060: });
061: data.registerDataLookup("Location.destination",
062: new DataLookup() {
063: public Object lookupData() {
064: return destinationFolder;
065: }
066: });
067: setCanGoNext(false);
068: }
069:
070: protected JComponent createComponent() {
071: JComponent component = new JPanel();
072: component.setLayout(new BoxLayout(component, BoxLayout.Y_AXIS));
073: component.add(new MultiLineLabel(MailResourceLoader.getString(
074: "dialog", "mailboximport", "location_text")));
075: component.add(Box.createVerticalStrut(40));
076:
077: WizardTextField middlePanel = new WizardTextField();
078:
079: LabelWithMnemonic sourceLabel = new LabelWithMnemonic(
080: MailResourceLoader.getString("dialog", "mailboximport",
081: "source"));
082: middlePanel.addLabel(sourceLabel);
083: sourceButton = new JButton("...");
084: sourceLabel.setLabelFor(sourceButton);
085: sourceButton.addActionListener(this );
086: middlePanel.addTextField(sourceButton);
087: middlePanel.addExample(new JLabel());
088:
089: LabelWithMnemonic destinationLabel = new LabelWithMnemonic(
090: MailResourceLoader.getString("dialog", "mailboximport",
091: "destination"));
092: middlePanel.addLabel(destinationLabel);
093: destinationButton = new JButton("...");
094: destinationLabel.setLabelFor(destinationButton);
095: destinationButton.addActionListener(this );
096: middlePanel.addTextField(destinationButton);
097: middlePanel.addExample(new JLabel(MailResourceLoader.getString(
098: "dialog", "mailboximport", "explanation")));
099: component.add(middlePanel);
100:
101: return component;
102: }
103:
104: public void actionPerformed(ActionEvent e) {
105: Object source = e.getSource();
106:
107: if (source == sourceButton) {
108: JFileChooser fc = new JFileChooser();
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: + " "
119: + MailResourceLoader.getString("dialog",
120: "mailboximport", "files"));
121:
122: StringBuffer toolTip = new StringBuffer();
123: toolTip.append("<html><body>");
124:
125: int i = 0;
126:
127: for (; i < (sourceFiles.length - 1); i++) {
128: toolTip.append(sourceFiles[i].getPath());
129: toolTip.append("<br>");
130: }
131:
132: toolTip.append(sourceFiles[i].getPath());
133: toolTip.append("</body></html>");
134: sourceButton.setToolTipText(toolTip.toString());
135: } else {
136: sourceButton.setText(sourceFiles[0].getPath());
137: sourceButton.setToolTipText(null);
138: }
139:
140: updateCanFinish();
141: }
142: } else if (source == destinationButton) {
143: SelectFolderDialog dialog = new SelectFolderDialog(mediator);
144:
145: if (dialog.success()) {
146: destinationFolder = (IMailFolder) dialog
147: .getSelectedFolder();
148: destinationButton.setText(destinationFolder
149: .getTreePath());
150: updateCanFinish();
151: }
152: }
153: }
154:
155: protected void updateCanFinish() {
156: setCanFinish((sourceFiles != null)
157: && (destinationFolder != null));
158: }
159:
160: public void prepareRendering() {
161: SwingUtilities.invokeLater(new Runnable() {
162: public void run() {
163: sourceButton.requestFocus();
164: }
165: });
166: }
167: }
|