1 50 package com.lowagie.tools.arguments; 51 52 import java.awt.event.ActionEvent; 53 54 import javax.swing.JFileChooser; 55 import javax.swing.filechooser.FileFilter; 56 57 import com.lowagie.text.Image; 58 import com.lowagie.tools.plugins.AbstractTool; 59 60 63 public class ImageArgument extends ToolArgument { 64 65 private FileFilter filter; 66 67 74 public ImageArgument(AbstractTool tool, String name, String description, FileFilter filter) { 75 super(tool, name, description, Image.class.getName()); 76 this.filter = filter; 77 } 78 79 85 public ImageArgument(AbstractTool tool, String name, String description) { 86 this(tool, name, description, new ImageFilter()); 87 } 88 89 94 public Object getArgument() throws InstantiationException { 95 if (value == null) return null; 96 try { 97 return Image.getInstance(value); 98 } catch (Exception e) { 99 throw new InstantiationException(e.getMessage()); 100 } 101 } 102 103 106 public void actionPerformed(ActionEvent e) { 107 JFileChooser fc = new JFileChooser(); 108 if (filter != null) fc.setFileFilter(filter); 109 fc.showOpenDialog(tool.getInternalFrame()); 110 try { 111 setValue(fc.getSelectedFile().getAbsolutePath()); 112 } 113 catch(NullPointerException npe) { 114 } 115 } 116 117 } 118 | Popular Tags |