KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   Copyright (C) 2002 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.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