KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > swing > ImageURLEditor


1 /*
2   Copyright (C) 2001 Renaud Pawlak, Laurent Martelli
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.gui.swing;
19
20
21 import java.net.URL JavaDoc;
22 import javax.swing.BoxLayout JavaDoc;
23 import javax.swing.ImageIcon JavaDoc;
24 import javax.swing.JComponent JavaDoc;
25 import javax.swing.JLabel JavaDoc;
26 import org.objectweb.jac.aspects.gui.FieldEditor;
27 import org.objectweb.jac.aspects.gui.Length;
28 import org.objectweb.jac.core.rtti.FieldItem;
29
30 /**
31  * This is a special value editor that allows the user to nicely edit
32  * an URL. */

33
34 public class ImageURLEditor extends AbstractFieldEditor
35     implements FieldEditor
36 {
37
38     protected JLabel JavaDoc image;
39     protected URLEditor urlEditor;
40
41     /**
42      * Constructs a new URL editor.
43      */

44     public ImageURLEditor(Object JavaDoc substance, FieldItem field) {
45         super(substance,field);
46         setLayout( new BoxLayout JavaDoc( this, BoxLayout.Y_AXIS ) );
47         image = new JLabel JavaDoc();
48         urlEditor = new URLEditor(substance,field);
49         add(image);
50         add(urlEditor);
51     }
52
53     public void setValue(Object JavaDoc value) {
54         urlEditor.setValue(value);
55         image.setIcon(value != null ? new ImageIcon JavaDoc((URL JavaDoc)value) : null);
56     }
57
58     public Object JavaDoc getValue() {
59         return urlEditor.getValue();
60     }
61
62     public void setSize(Length width, Length height) {
63         super.setSize(width,height);
64         urlEditor.setSize(width,height);
65     }
66
67     public void onSetFocus(Object JavaDoc extra) {
68         urlEditor.onSetFocus(extra);
69     }
70
71     protected JComponent JavaDoc getComponent() {
72         return urlEditor;
73     }
74 }
75
Popular Tags