001    /*
002      Copyright (C) 2002-2003 Laurent Martelli <laurent@aopsys.com>
003      
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful,
010      but WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012      GNU Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser General Public License
015      along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
017    
018    package org.objectweb.jac.aspects.gui.web;
019    
020    import java.io.PrintWriter;
021    import org.apache.log4j.Logger;
022    import org.objectweb.jac.aspects.gui.GuiAC;
023    import org.objectweb.jac.core.rtti.FieldItem;
024    import org.objectweb.jac.util.Enum;
025    import org.objectweb.jac.util.InvalidIndexException;
026    
027    public class EnumViewer extends AbstractFieldView 
028        implements HTMLViewer
029    {
030        static Logger loggerContext = Logger.getLogger("gui");
031    
032        Object value;
033        Enum enum;
034    
035        public EnumViewer(Object value, 
036                          Object substance, FieldItem field) {
037            super(substance,field);
038            if (field!=null)
039                this.enum = (Enum)field.getAttribute(GuiAC.FIELD_ENUM);
040            else
041                logger.warn("EnumViewer: Cannot determine enum because field is null");
042            setValue(value);
043        }
044    
045        public EnumViewer() {
046        }
047    
048        public void setField(FieldItem field) {
049            super.setField(field);
050            if (field!=null)
051                this.enum = (Enum)field.getAttribute(GuiAC.FIELD_ENUM);
052            else
053                logger.warn("EnumViewer: Cannot determine enum because field is null");        
054        }
055    
056        public void setValue(Object value) {
057            this.value = value;
058        }
059    
060        public void genHTML(PrintWriter out) {
061            if (value!=null) {
062                try {
063                    out.print(enum.int2string(((Integer)value).intValue()));
064                } catch(InvalidIndexException e) {
065                    out.print(((Integer)value).intValue());
066                }
067            }
068        }
069    }
070