1 23 package org.enhydra.kelp.common.importer; 24 25 import org.enhydra.tool.common.PathHandle; 27 import org.enhydra.tool.common.SwingUtil; 28 29 import org.enhydra.kelp.common.PathUtil; 31 import org.enhydra.kelp.common.ValidationException; 32 import org.enhydra.kelp.common.ValidationUtil; 33 34 import javax.swing.*; 36 import javax.swing.border.*; 37 import java.awt.*; 38 import java.awt.event.ActionEvent ; 39 import java.awt.event.ActionListener ; 40 import java.beans.*; 41 import java.io.File ; 42 import java.util.ResourceBundle ; 43 44 50 public class PathPanel extends ImporterPanel { 51 static ResourceBundle res = 52 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); transient private JPanel panelSource; 54 transient private JTextField textSource; 55 transient private JButton buttonSource; 56 transient private JPanel panelResource; 57 transient private JTextField textResource; 58 transient private JButton buttonResource; 59 60 transient private JPanel panelFiller; 62 transient private GridBagLayout layoutMain; 63 transient private GridBagLayout layoutSource; 64 transient private GridBagLayout layoutResource; 65 transient private LocalButtonListener buttonListener; 66 transient private TitledBorder borderSource; 67 transient private TitledBorder borderResource; 68 69 74 public PathPanel() { 75 try { 76 jbInit(); 77 pmInit(); 78 } catch (Exception ex) { 79 ex.printStackTrace(); 80 } 81 } 82 83 90 public void readOptions() { 91 92 } 94 95 102 public void writeOptions() throws ValidationException { 103 String value = new String (); 104 105 if (getPaths() == null) { 106 throw new ValidationException(res.getString("Import_paths_not_set")); 107 } 108 109 value = textSource.getText().trim(); 111 getPaths().setSourcePath(value); 112 113 value = textResource.getText().trim(); 115 getPaths().setResourcePath(value); 116 } 117 118 126 public void validateOptions() throws ValidationException { 127 String value = new String (); 128 129 value = textSource.getText().trim(); 131 if (!ValidationUtil.isDirectory(value)) { 132 throw new ValidationException(res.getString("SourcePathInvalid") 133 + res.getString("DirectoryNotFound")); 134 } 135 136 value = textResource.getText().trim(); 138 if (!ValidationUtil.isDirectory(value)) { 139 throw new ValidationException(res.getString("ResourcePathInvalid") 140 + res.getString("DirectoryNotFound")); 141 } 142 } 143 144 150 public String getPageTitle() { 151 return res.getString("Path_details"); 152 } 153 154 161 public String getInstructions() { 162 StringBuffer buf = new StringBuffer (); 163 164 buf.append(res.getString("PathInstruct1")); 165 buf.append(res.getString("PathInstruct2")); 166 buf.append(res.getString("PathInstruct3")); 167 buf.append(res.getString("PathInstruct4")); 168 buf.append(res.getString("PathInstruct5")); 169 buf.append(res.getString("PathInstruct6")); 170 buf.append(res.getString("PathInstruct7")); 171 buf.append(res.getString("PathInstruct8")); 172 buf.append(res.getString("PathInstruct9")); 173 return buf.toString(); 174 } 175 176 public void activated() { 177 initPaths(); 178 } 179 180 private void initPaths() { 181 String path = null; 182 183 path = getPaths().getSourcePath(); 185 if (path == null) { 186 textSource.setText(getPaths().getDefaultSourcePath()); 187 } else { 188 textSource.setText(path); 189 } 190 191 path = getPaths().getResourcePath(); 193 if (path == null) { 194 textResource.setText(getPaths().getDefaultResourcePath()); 195 } else { 196 textResource.setText(path); 197 } 198 } 199 200 203 211 private void jbInit() throws Exception { 212 textSource = 213 (JTextField) Beans.instantiate(getClass().getClassLoader(), 214 JTextField.class.getName()); 215 panelSource = (JPanel) Beans.instantiate(getClass().getClassLoader(), 216 JPanel.class.getName()); 217 panelResource = 218 (JPanel) Beans.instantiate(getClass().getClassLoader(), 219 JPanel.class.getName()); 220 layoutSource = 221 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 222 GridBagLayout.class.getName()); 223 layoutResource = 224 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 225 GridBagLayout.class.getName()); 226 buttonSource = 227 (JButton) Beans.instantiate(getClass().getClassLoader(), 228 JButton.class.getName()); 229 buttonResource = 230 (JButton) Beans.instantiate(getClass().getClassLoader(), 231 JButton.class.getName()); 232 textResource = 233 (JTextField) Beans.instantiate(getClass().getClassLoader(), 234 JTextField.class.getName()); 235 layoutMain = 236 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 237 GridBagLayout.class.getName()); 238 panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(), 239 JPanel.class.getName()); 240 buttonSource.setText("..."); buttonResource.setText("..."); panelSource.setLayout(layoutSource); 243 panelSource.add(textSource, 244 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1, 245 GridBagConstraints.WEST, 246 GridBagConstraints.HORIZONTAL, 247 new Insets(5, 5, 5, 5), 0, 0)); 248 panelSource.add(buttonSource, 249 new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, 250 GridBagConstraints.CENTER, 251 GridBagConstraints.NONE, 252 new Insets(5, 5, 5, 20), 0, 253 0)); 254 panelResource.setLayout(layoutResource); 255 panelResource.add(textResource, 256 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1, 257 GridBagConstraints.WEST, 258 GridBagConstraints.HORIZONTAL, 259 new Insets(5, 5, 5, 5), 0, 260 0)); 261 panelResource.add(buttonResource, 262 new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, 263 GridBagConstraints.CENTER, 264 GridBagConstraints.NONE, 265 new Insets(5, 5, 5, 20), 0, 266 0)); 267 this.setLayout(layoutMain); 268 this.add(panelSource, 269 new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1, 270 GridBagConstraints.CENTER, 271 GridBagConstraints.BOTH, 272 new Insets(5, 5, 5, 5), 0, 0)); 273 this.add(panelResource, 274 new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1, 275 GridBagConstraints.CENTER, 276 GridBagConstraints.BOTH, 277 new Insets(5, 5, 5, 5), 0, 0)); 278 } 279 280 286 private void pmInit() { 287 Border border = BorderFactory.createEtchedBorder(); 288 289 borderSource = BorderFactory.createTitledBorder(border); 290 borderSource.setTitle(res.getString("borderSource_Title")); 291 borderResource = BorderFactory.createTitledBorder(border); 292 borderResource.setTitle(res.getString("borderResource_Title")); 293 panelSource.setBorder(borderSource); 294 panelResource.setBorder(borderResource); 295 buttonListener = new LocalButtonListener(); 296 buttonResource.addActionListener(buttonListener); 297 buttonSource.addActionListener(buttonListener); 298 textResource.setText(new String ()); 299 textSource.setText(new String ()); 300 } 301 302 308 private void browseForFile(JTextField field, String title) { 309 File destDir = null; 310 311 destDir = SwingUtil.getDirectoryChoice(this, field.getText(), title); 312 if (destDir != null) { 313 field.setText(PathHandle.createPathString(destDir)); 314 } 315 } 316 317 323 private class LocalButtonListener implements ActionListener { 324 325 public void actionPerformed(ActionEvent event) { 326 Object source = event.getSource(); 327 328 if (source == buttonSource) { 329 browseForFile(textSource, 330 res.getString("Select_source_path")); 331 } else { 332 browseForFile(textResource, 333 res.getString("Select_resource_path")); 334 } 335 } 336 337 } 338 } 339 | Popular Tags |