001    /*
002      Copyright (C) 2001 Renaud Pawlak, Laurent Martelli
003      
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful,
010      but WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012      GNU Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser General Public License
015      along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
017    
018    package org.objectweb.jac.aspects.gui.swing;
019    
020    
021    import org.objectweb.jac.aspects.gui.FieldEditor;
022    import org.objectweb.jac.core.rtti.FieldItem;
023    import java.net.URL;
024    import javax.swing.BoxLayout;
025    import javax.swing.ImageIcon;
026    import javax.swing.JComponent;
027    import javax.swing.JLabel;
028    
029    /**
030     * This is a special value editor that allows the user to nicely edit
031     * an URL. */
032    
033    public class ImageURLEditor extends AbstractFieldEditor
034       implements FieldEditor 
035    {
036    
037       protected JLabel image;
038       protected URLEditor urlEditor;
039    
040       /**
041        * Constructs a new URL editor.
042        */
043    
044       public ImageURLEditor(Object substance, FieldItem field) {
045          super(substance,field);
046          setLayout( new BoxLayout( this, BoxLayout.Y_AXIS ) );
047          image = new JLabel();
048          urlEditor = new URLEditor(substance,field);
049          add(image);
050          add(urlEditor);
051       }
052    
053       public void setValue(Object value) {
054          urlEditor.setValue(value);
055          image.setIcon(value != null ? new ImageIcon((URL)value) : null);
056       }
057    
058       public Object getValue() {
059          return urlEditor.getValue();
060       }
061    
062       public void setWidth(int width) {
063          urlEditor.setWidth(width);
064       }
065    
066       public void setHeight(int height) {
067          urlEditor.setHeight(height);
068       }
069    
070       public void onSetFocus(Object extra) {
071          urlEditor.onSetFocus(extra);
072       }
073    
074       protected JComponent getComponent() {
075          return urlEditor;
076       }
077    }