1 17 18 package org.objectweb.jac.aspects.gui.swing; 19 20 import java.awt.Dimension ; 21 import java.awt.Insets ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.io.File ; 25 import javax.swing.JButton ; 26 import javax.swing.JFileChooser ; 27 import org.objectweb.jac.aspects.gui.FieldEditor; 28 import org.objectweb.jac.aspects.gui.Length; 29 import org.objectweb.jac.aspects.gui.ResourceManager; 30 import org.objectweb.jac.core.rtti.FieldItem; 31 32 36 public abstract class AbstractFileEditor extends TextFieldEditor 37 implements FieldEditor, ActionListener 38 { 39 42 public AbstractFileEditor(Object substance, FieldItem field) { 43 super(substance,field); 44 textField = new JTextField(20); 45 textField.addFocusListener(this); 46 add(textField); 47 48 JButton button = new JButton (ResourceManager.getIconResource("open_icon")); 49 button.setToolTipText("Edit"); 50 button.setActionCommand("choose"); 51 button.addActionListener(this); 52 button.setMargin(new Insets (1,1,1,1)); 53 add(button); 54 } 55 56 65 public void actionPerformed(ActionEvent evt) { 66 if (evt.getActionCommand().equals("choose")) { 67 JFileChooser chooser = createFileChooser(); 68 int returnVal = chooser.showOpenDialog(this); 69 70 if (returnVal==JFileChooser.APPROVE_OPTION) { 71 textField.setText(chooser.getSelectedFile().toString()); 72 } 73 } 74 } 75 76 79 JFileChooser createFileChooser() { 80 return new JFileChooser (); 81 } 82 83 public void setValue(Object value) { 84 super.setValue(value); 85 if (value==null) 86 textField.setText(""); 87 else 88 textField.setText(value.toString()); 89 } 90 } 91 | Popular Tags |