KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > EnumViewer


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

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