1 package org.columba.mail.gui.config.mailboximport; 17 18 import java.awt.event.ActionEvent ; 19 import java.awt.event.ActionListener ; 20 import java.io.File ; 21 22 import javax.swing.Box ; 23 import javax.swing.BoxLayout ; 24 import javax.swing.JButton ; 25 import javax.swing.JComponent ; 26 import javax.swing.JFileChooser ; 27 import javax.swing.JLabel ; 28 import javax.swing.JPanel ; 29 import javax.swing.SwingUtilities ; 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 { 45 protected File [] sourceFiles; 46 protected IMailFolder destinationFolder; 47 protected JButton sourceButton; 48 protected JButton 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 lookupData() { 60 return sourceFiles; 61 } 62 }); 63 data.registerDataLookup("Location.destination", 64 new DataLookup() { 65 public Object lookupData() { 66 return destinationFolder; 67 } 68 }); 69 setCanGoNext(false); 70 } 71 72 protected JComponent createComponent() { 73 JComponent component = new JPanel (); 74 component.setLayout(new BoxLayout (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 ("..."); 85 sourceLabel.setLabelFor(sourceButton); 86 sourceButton.addActionListener(this); 87 middlePanel.addTextField(sourceButton); 88 middlePanel.addExample(new JLabel ()); 89 90 LabelWithMnemonic destinationLabel = new LabelWithMnemonic(MailResourceLoader.getString( 91 "dialog", "mailboximport", "destination")); 92 middlePanel.addLabel(destinationLabel); 93 destinationButton = new JButton ("..."); 94 destinationLabel.setLabelFor(destinationButton); 95 destinationButton.addActionListener(this); 96 middlePanel.addTextField(destinationButton); 97 middlePanel.addExample(new JLabel (MailResourceLoader.getString( 98 "dialog", "mailboximport", "explanation"))); 99 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 MailResourceLoader.getString("dialog", "mailboximport", 119 "files")); 120 121 StringBuffer toolTip = new StringBuffer (); 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 () { 158 public void run() { 159 sourceButton.requestFocus(); 160 } 161 }); 162 } 163 } 164 | Popular Tags |