1 18 19 package org.objectweb.jac.aspects.gui.swing; 20 21 import org.objectweb.jac.aspects.gui.FieldView; 22 import org.objectweb.jac.aspects.gui.GuiAC; 23 import org.objectweb.jac.core.rtti.FieldItem; 24 import org.objectweb.jac.lib.Attachment; 25 import org.objectweb.jac.util.Thumbnail; 26 import javax.swing.BoxLayout ; 27 import javax.swing.ImageIcon ; 28 import javax.swing.JComponent ; 29 import javax.swing.JLabel ; 30 31 34 35 public class AttachmentViewer extends AbstractFieldView 36 implements FieldView 37 { 38 JLabel label = new JLabel (); 39 Attachment value; 40 41 44 45 public AttachmentViewer(Object value, Object substance, FieldItem field) { 46 super(substance,field); 47 setValue(value); 48 add(label); 49 } 50 51 public AttachmentViewer() { 52 isCellViewer = true; 53 setLayout(new BoxLayout (this,BoxLayout.Y_AXIS)); 54 label.setAlignmentX((float)0.5); 55 add(label); 56 } 57 58 63 public void setValue(Object newValue) { 64 if (newValue!=null) { 66 if (value==newValue) 67 return; 68 Attachment value = (Attachment)newValue; 69 70 72 if (value.getMimeType()==null) { 73 label.setIcon(null); 74 label.setText(value.getName()); 75 } else if (value.getMimeType().startsWith("image/")) { 76 if (isCellViewer) { 77 byte[] thumb = null; 78 try { 79 thumb = Thumbnail.createThumbArray( 80 value.getData(), 81 GuiAC.THUMB_MAX_WIDTH,GuiAC.THUMB_MAX_HEIGHT, 82 GuiAC.THUMB_QUALITY); 83 } catch(Exception e) { 84 logger.error("Failed to create thumbnail for "+ 85 substance+"."+field.getName(),e); 86 } 87 label.setIcon(new ImageIcon (thumb)); 88 setPreferredSize(label.getPreferredSize()); 89 } else { 90 label.setIcon(new ImageIcon (value.getData())); 91 } 92 } else { 93 label.setIcon(null); 94 label.setText(value.getName()); 95 } 96 } else { 97 value = (Attachment)newValue; 98 label.setIcon(null); 99 setPreferredSize(label.getPreferredSize()); 100 } 101 } 102 103 protected JComponent getComponent() { 104 return label; 105 } 106 } 107 | Popular Tags |