1 17 18 package org.objectweb.jac.aspects.gui.swing; 19 20 21 22 import org.objectweb.jac.core.rtti.FieldItem; 23 import org.objectweb.jac.lib.Attachment; 24 import org.objectweb.jac.util.Streams; 25 import org.objectweb.jac.util.WrappedThrowableException; 26 import java.io.File ; 27 import java.io.FileInputStream ; 28 import java.io.IOException ; 29 import javax.swing.JFileChooser ; 30 31 35 36 public class AttachmentEditor extends FileEditor 37 { 38 public AttachmentEditor(Object substance, FieldItem field) { 39 super(substance,field); 40 } 41 42 public Object getValue() { 43 String file = textField.getText(); 44 if (file.equals("")) { 45 return null; 46 } 47 try { 48 return new Attachment(Streams.readStream(new FileInputStream (file)), 49 null,file); 50 } catch (IOException e) { 51 throw new WrappedThrowableException(e); 52 } 53 } 54 55 public void setValue(Object value) { 56 super.setValue(value); 57 if (value==null) 58 textField.setText(""); 59 else 60 textField.setText(((Attachment)value).getName()); 61 } 62 63 64 67 JFileChooser createFileChooser() { 68 return new JFileChooser (new File (textField.getText())); 69 } 70 71 } 72 | Popular Tags |