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.net.MalformedURLException ; 24 import java.net.URL ; 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 35 36 public class URLEditor extends TextFieldEditor 37 implements FieldEditor, ActionListener 38 { 39 42 public URLEditor(Object substance, FieldItem field) { 43 super(substance,field); 44 textField = new JTextField(10); 45 textField.addFocusListener(this); 46 add(textField); 47 48 JButton button = new JButton (ResourceManager.getIconResource("edit_icon")); 49 button.setToolTipText("Edit"); 50 button.setActionCommand("choose"); 51 button.addActionListener(this); 52 add(button); 53 } 54 55 64 public void actionPerformed(ActionEvent evt) { 65 if (evt.getActionCommand().equals("choose")) { 66 JFileChooser chooser = new JFileChooser (); 67 85 int returnVal = chooser.showOpenDialog( this ); 86 87 if ( returnVal == JFileChooser.APPROVE_OPTION ) { 88 textField.setText( "file:" + chooser.getSelectedFile().toString() ); 89 } 90 } 91 } 92 93 public Object getValue() { 94 String urlString = textField.getText(); 95 if (urlString.equals("")) { 96 return null; 97 } 98 if (urlString.indexOf(":")==-1) { 99 urlString = "file:/"+urlString; 100 } 101 102 try { 103 return new URL (urlString); 104 } catch (MalformedURLException e) { 105 logger.warn("Malfromed URL: "+urlString); 106 return null; 107 } 108 } 109 110 public void setValue(Object value) { 111 super.setValue(value); 112 if( value == null ) 113 textField.setText(""); 114 else 115 textField.setText(((URL )value).toString()); 116 } 117 118 } 119 | Popular Tags |