1 package org.oddjob.jobs.swing; 2 3 import java.io.File ; 4 5 import javax.swing.JFileChooser ; 6 import javax.swing.JFrame ; 7 import javax.swing.UIManager ; 8 9 import org.oddjob.framework.SimpleJob; 10 11 16 17 public class ChooseFile extends SimpleJob { 18 19 private File chosen; 20 21 private transient File dir; 22 23 public File getChosen() { 24 return chosen; 25 } 26 27 public void setDir(File dir) { 28 this.dir = dir; 29 } 30 31 public int execute() throws Exception { 32 33 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 34 35 JFrame f = new JFrame (); 36 37 JFileChooser chooser = new JFileChooser (); 38 if (dir != null) { 39 chooser.setCurrentDirectory(dir); 40 } 41 42 int option = chooser.showOpenDialog(f); 43 f.dispose(); 44 45 if (option == JFileChooser.APPROVE_OPTION) { 46 chosen = chooser.getSelectedFile(); 47 logger().debug("chosen file " + chosen.getAbsolutePath()); 48 return 0; 49 } else { 50 chosen = null; 51 return 1; 52 } 53 } 54 55 } 56 | Popular Tags |