1 17 18 package org.objectweb.jac.aspects.gui.swing; 19 20 import java.awt.Dimension ; 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.ActionListener ; 23 import java.io.File ; 24 import javax.swing.JButton ; 25 import javax.swing.JFileChooser ; 26 import org.objectweb.jac.aspects.gui.FieldEditor; 27 import org.objectweb.jac.aspects.gui.ResourceManager; 28 import org.objectweb.jac.core.rtti.FieldItem; 29 import org.objectweb.jac.util.Files; 30 31 35 public class FileEditor extends AbstractFileEditor 36 implements FieldEditor, ActionListener 37 { 38 41 public FileEditor(Object substance, FieldItem field) { 42 super(substance,field); 43 } 44 45 48 JFileChooser createFileChooser() { 49 return new JFileChooser ((File )getValue()); 50 } 51 52 public Object getValue() { 53 String file = textField.getText(); 54 if (file.equals("")) { 55 return null; 56 } 57 58 return createFileInstance(Files.expandFileName(file)); 59 } 60 61 66 protected File createFileInstance(String path) { 67 if (type!=null) 68 try { 69 return (File )type.newInstance(new Object [] {path}); 70 } catch(Exception e) { 71 logger.error("FileEditor.createFileInstance: failed to instanciate "+type+ 72 ", falling back on java.io.File"); 73 return new File (path); 74 } 75 else 76 return new File (path); 77 } 78 79 public void setValue(Object value) { 80 super.setValue(value); 81 if (value==null) 82 textField.setText(""); 83 else 84 textField.setText(value.toString()); 85 } 86 } 87 | Popular Tags |