KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   Copyright (C) 2001-2002 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, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.aspects.gui.swing;
20
21 import javax.swing.ImageIcon JavaDoc;
22 import javax.swing.JComponent JavaDoc;
23 import javax.swing.JLabel JavaDoc;
24 import org.objectweb.jac.aspects.gui.FieldView;
25 import org.objectweb.jac.aspects.gui.GuiAC;
26 import org.objectweb.jac.core.rtti.FieldItem;
27 import org.objectweb.jac.util.Thumbnail;
28
29 /**
30  * A Swing viewer component for image values.
31  */

32 public class ImageViewer extends AbstractFieldView
33     implements FieldView
34 {
35     JLabel JavaDoc label = new JLabel JavaDoc();
36    
37     /**
38      * Constructs a new date editor. */

39
40     public ImageViewer(byte[] value, Object JavaDoc substance, FieldItem field) {
41         super(substance,field);
42         setValue(value);
43         add(label);
44     }
45
46     public ImageViewer() {
47         add(label);
48     }
49
50     /**
51      * Sets the value of the edited image
52      *
53      * @param value an array of byte
54      */

55     public void setValue(Object JavaDoc value) {
56         if (value!=null) {
57             byte[] data = (byte[])value;
58             if (isCellViewer) {
59                 try {
60                     data = Thumbnail.createThumbArray(
61                         data,
62                         GuiAC.THUMB_MAX_WIDTH,GuiAC.THUMB_MAX_HEIGHT,
63                         GuiAC.THUMB_QUALITY);
64                 } catch(Exception JavaDoc e) {
65                     logger.error("Failed to create thumbnail for "+
66                                  substance+"."+field.getName(),e);
67                 }
68                 label.setIcon(new ImageIcon JavaDoc(data));
69                 setPreferredSize(label.getPreferredSize());
70             } else {
71                 label.setIcon(new ImageIcon JavaDoc(data));
72             }
73         } else {
74             label.setIcon(null);
75         }
76     }
77
78     protected JComponent JavaDoc getComponent() {
79         return label;
80     }
81 }
82
Popular Tags