1 package org.columba.addressbook.gui.dialog.importfilter; 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 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 { 44 protected File sourceFile; 45 protected IFolder destinationFolder; 46 protected JButton sourceButton; 47 protected JButton 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 lookupData() { 57 return sourceFile; 58 } 59 }); 60 data.registerDataLookup("Location.destination", 61 new DataLookup() { 62 public Object lookupData() { 63 return destinationFolder; 64 } 65 }); 66 setCanGoNext(false); 67 } 68 69 protected JComponent createComponent() { 70 JComponent component = new JPanel (); 71 component.setLayout(new BoxLayout (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 ("..."); 81 sourceButton.addActionListener(this); 82 sourceLabel.setLabelFor(sourceButton); 83 middlePanel.addTextField(sourceButton); 84 middlePanel.addExample(new JLabel ()); 85 86 LabelWithMnemonic destinationLabel = new LabelWithMnemonic(AddressbookResourceLoader.getString( 87 "dialog", "addressbookimport", "destination")); 88 middlePanel.addLabel(destinationLabel); 89 destinationButton = new JButton ("..."); 90 destinationButton.addActionListener(this); 91 destinationLabel.setLabelFor(destinationButton); 92 middlePanel.addTextField(destinationButton); 93 middlePanel.addExample(new JLabel (AddressbookResourceLoader.getString( 94 "dialog", "addressbookimport", "explanation"))); 95 component.add(middlePanel); 96 97 return component; 98 } 99 100 public void actionPerformed(ActionEvent e) { 101 Object source = e.getSource(); 102 103 if (source == sourceButton) { 104 JFileChooser fc = new JFileChooser (); 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.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 |