001    /*
002    
003      Copyright (C) 2001 Renaud Pawlak, Laurent Martelli
004      
005      This program is free software; you can redistribute it and/or modify
006      it under the terms of the GNU Lesser General Public License as
007      published by the Free Software Foundation; either version 2 of the
008      License, or (at your option) any later version.
009    
010      This program is distributed in the hope that it will be useful,
011      but WITHOUT ANY WARRANTY; without even the implied warranty of
012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013      GNU Lesser General Public License for more details.
014    
015      You should have received a copy of the GNU Lesser General Public License
016      along with this program; if not, write to the Free Software
017      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
018    
019    package org.objectweb.jac.aspects.gui.swing;
020    
021    import org.objectweb.jac.core.rtti.FieldItem;
022    import java.awt.event.ActionEvent;
023    import javax.swing.JFileChooser;
024    
025    /**
026     * This is a special value editor that allows the user to nicely edit
027     * an URL. */
028    
029    public class DirectoryURLEditor extends URLEditor {
030       
031       public DirectoryURLEditor(Object substance, FieldItem field) {
032          super(substance,field);
033       }
034    
035       public void actionPerformed(ActionEvent evt) {
036          if (evt.getActionCommand().equals("choose")) {
037             JFileChooser chooser = new JFileChooser(); 
038             chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
039             int returnVal = chooser.showOpenDialog( this );         
040             if ( returnVal == JFileChooser.APPROVE_OPTION ) {
041                textField.setText( "file:" + chooser.getSelectedFile().toString() );
042             }
043          }
044       }
045    }