1 50 package com.lowagie.tools.arguments; 51 52 import java.awt.event.ActionEvent; 53 import java.io.File; 54 55 import javax.swing.JFileChooser; 56 import javax.swing.filechooser.FileFilter; 57 58 import com.lowagie.tools.plugins.AbstractTool; 59 60 63 public class FileArgument extends ToolArgument { 64 65 private FileFilter filter; 66 67 private boolean newFile; 68 69 77 public FileArgument(AbstractTool tool, String name, String description, boolean newFile, FileFilter filter) { 78 super(tool, name, description, File.class.getName()); 79 this.newFile = newFile; 80 this.filter = filter; 81 } 82 89 public FileArgument(AbstractTool tool, String name, String description, boolean newFile) { 90 this(tool, name, description, newFile, null); 91 } 92 93 98 public Object getArgument() throws InstantiationException { 99 if (value == null) return null; 100 try { 101 return new File(value); 102 } catch (Exception e) { 103 throw new InstantiationException(e.getMessage()); 104 } 105 } 106 107 110 public void actionPerformed(ActionEvent e) { 111 JFileChooser fc = new JFileChooser(); 112 if (filter != null) fc.setFileFilter(filter); 113 if (newFile) { 114 fc.showSaveDialog(tool.getInternalFrame()); 115 } 116 else { 117 fc.showOpenDialog(tool.getInternalFrame()); 118 } 119 try { 120 setValue(fc.getSelectedFile().getAbsolutePath()); 121 } 122 catch(NullPointerException npe) { 123 } 124 } 125 126 } | Popular Tags |