1 17 18 package org.objectweb.jac.aspects.gui.swing; 19 20 import javax.swing.JLabel; 21 import org.apache.log4j.Logger; 22 import org.objectweb.jac.aspects.gui.FieldUpdate; 23 import org.objectweb.jac.aspects.gui.FieldView; 24 import org.objectweb.jac.aspects.gui.GuiAC; 25 import org.objectweb.jac.core.rtti.FieldItem; 26 import org.objectweb.jac.util.Enum; 27 import org.objectweb.jac.util.InvalidIndexException; 28 29 public class EnumViewer extends AbstractFieldView 30 implements FieldView, FieldUpdate 31 { 32 static Logger logger = Logger.getLogger("gui"); 33 34 Object value; 35 Enum enum; 36 JLabel label = new JLabel (); 37 38 public EnumViewer(Object value, 39 Object substance, FieldItem field) { 40 super(substance,field); 41 if (field!=null) 42 this.enum = (Enum)field.getAttribute(GuiAC.FIELD_ENUM); 43 else 44 logger.warn("EnumViewer: Cannot determine enum because field is null"); 45 setValue(value); 46 add(label); 47 } 48 49 public EnumViewer() { 50 label.setFont(null); 51 add(label); 52 } 53 54 public void setField(FieldItem field) { 55 super.setField(field); 56 if (field!=null) 57 this.enum = (Enum)field.getAttribute(GuiAC.FIELD_ENUM); 58 else 59 logger.warn("EnumViewer: Cannot determine enum because field is null"); 60 } 61 62 public void setValue(Object value) { 63 this.value = value; 64 try { 65 label.setText(value!=null?enum.int2string(((Integer)value).intValue()):"null"); 66 } catch (InvalidIndexException e) { 67 label.setText(value.toString()); 68 } 69 } 70 } 71 | Popular Tags |