1 18 19 package org.objectweb.jac.aspects.gui.swing; 20 21 import javax.swing.ImageIcon ; 22 import javax.swing.JComponent ; 23 import javax.swing.JLabel ; 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 32 public class ImageViewer extends AbstractFieldView 33 implements FieldView 34 { 35 JLabel label = new JLabel (); 36 37 39 40 public ImageViewer(byte[] value, Object substance, FieldItem field) { 41 super(substance,field); 42 setValue(value); 43 add(label); 44 } 45 46 public ImageViewer() { 47 add(label); 48 } 49 50 55 public void setValue(Object 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 e) { 65 logger.error("Failed to create thumbnail for "+ 66 substance+"."+field.getName(),e); 67 } 68 label.setIcon(new ImageIcon (data)); 69 setPreferredSize(label.getPreferredSize()); 70 } else { 71 label.setIcon(new ImageIcon (data)); 72 } 73 } else { 74 label.setIcon(null); 75 } 76 } 77 78 protected JComponent getComponent() { 79 return label; 80 } 81 } 82 | Popular Tags |