1 package org.columba.core.gui.externaltools; 17 18 import java.awt.BorderLayout ; 19 import java.awt.FlowLayout ; 20 import java.awt.Font ; 21 import java.awt.GridLayout ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.io.File ; 25 26 import javax.swing.JButton ; 27 import javax.swing.JComponent ; 28 import javax.swing.JFileChooser ; 29 import javax.swing.JLabel ; 30 import javax.swing.JPanel ; 31 import javax.swing.UIManager ; 32 33 import net.javaprog.ui.wizard.AbstractStep; 34 import net.javaprog.ui.wizard.DataLookup; 35 import net.javaprog.ui.wizard.DataModel; 36 37 import org.columba.core.gui.base.ButtonWithMnemonic; 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 import org.columba.core.resourceloader.GlobalResourceLoader; 42 43 44 52 class LocationStep extends AbstractStep implements ActionListener { 53 private static final String RESOURCE_PATH = "org.columba.core.i18n.dialog"; 54 protected DataModel data; 55 protected JButton sourceButton; 56 protected File sourceFile; 57 58 62 public LocationStep(DataModel data) { 63 super(GlobalResourceLoader.getString(RESOURCE_PATH, "externaltools", 64 "LocationStep.title"), 65 GlobalResourceLoader.getString(RESOURCE_PATH, "externaltools", 66 "LocationStep.description")); 67 68 this.data = data; 69 70 data.registerDataLookup("Location.source", 71 new DataLookup() { 72 public Object lookupData() { 73 return sourceFile; 74 } 75 }); 76 77 setCanGoNext(false); 78 } 79 80 83 protected JComponent createComponent() { 84 JPanel panel = new JPanel (new BorderLayout ()); 85 86 AbstractExternalToolsPlugin plugin = (AbstractExternalToolsPlugin) data.getData( 87 "Plugin"); 88 89 sourceFile = plugin.locate(); 90 91 if (sourceFile == null) { 92 MultiLineLabel label = new MultiLineLabel(GlobalResourceLoader.getString( 93 RESOURCE_PATH, "externaltools", "LocationStep.noauto")); 94 panel.add(label, BorderLayout.NORTH); 95 96 WizardTextField middlePanel = new WizardTextField(); 97 LabelWithMnemonic sourceLabel = new LabelWithMnemonic(GlobalResourceLoader.getString( 98 RESOURCE_PATH, "externaltools", "LocationStep.location")); 99 middlePanel.add(sourceLabel); 100 101 sourceButton = new ButtonWithMnemonic(GlobalResourceLoader.getString( 102 RESOURCE_PATH, "externaltools", "LocationStep.browse")); 103 sourceLabel.setLabelFor(sourceButton); 104 sourceButton.addActionListener(this); 105 middlePanel.add(sourceButton); 106 107 panel.add(middlePanel, BorderLayout.CENTER); 108 } else { 109 JPanel northPanel = new JPanel (new GridLayout (2, 1, 0, 15)); 110 MultiLineLabel label = new MultiLineLabel(GlobalResourceLoader.getString( 111 RESOURCE_PATH, "externaltools", "LocationStep.auto")); 112 northPanel.add(label); 113 114 JPanel sourceFilePanel = new JPanel (new FlowLayout ( 115 FlowLayout.LEFT, 20, 0)); 116 JLabel label2 = new JLabel (sourceFile.getPath()); 117 Font font = (Font ) UIManager.getFont("Label.font"); 118 font = font.deriveFont(Font.BOLD); 119 label2.setFont(font); 120 sourceFilePanel.add(label2); 121 122 sourceButton = new ButtonWithMnemonic(GlobalResourceLoader.getString( 123 RESOURCE_PATH, "externaltools", "LocationStep.change")); 124 sourceButton.addActionListener(this); 125 sourceFilePanel.add(sourceButton); 126 127 northPanel.add(sourceFilePanel); 128 panel.add(northPanel, BorderLayout.NORTH); 129 } 130 131 return panel; 132 } 133 134 137 public void prepareRendering() { 138 getComponent(); 140 updateCanFinish(); 141 } 142 143 protected void updateCanFinish() { 144 setCanFinish(sourceFile != null); 145 } 146 147 public void actionPerformed(ActionEvent e) { 148 Object source = e.getSource(); 149 150 if (source == sourceButton) { 151 JFileChooser fc = new JFileChooser (); 152 fc.setMultiSelectionEnabled(true); 153 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 154 fc.setFileHidingEnabled(false); 155 156 if (fc.showOpenDialog(getComponent()) == JFileChooser.APPROVE_OPTION) { 157 sourceFile = fc.getSelectedFile(); 158 159 sourceButton.setText(sourceFile.getPath()); 160 } 161 162 updateCanFinish(); 163 } 164 } 165 } 166 | Popular Tags |