KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   Copyright (C) 2001-2003 Renaud Pawlak <renaud@aopsys.com>,
3                           Laurent Martelli <laurent@aopsys.com>
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU Lesser General Public License as
7   published by the Free Software Foundation; either version 2 of the
8   License, or (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful, but
11   WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18   USA */

19
20 package org.objectweb.jac.aspects.gui.swing;
21
22 import java.awt.event.ItemEvent JavaDoc;
23 import java.awt.event.ItemListener JavaDoc;
24 import javax.swing.JCheckBox JavaDoc;
25 import org.objectweb.jac.aspects.gui.FieldEditor;
26 import org.objectweb.jac.core.rtti.FieldItem;
27 import org.objectweb.jac.util.ExtBoolean;
28
29 /**
30  * A Swing editor component for boolean values.
31  */

32
33 public class BooleanEditor extends AbstractFieldEditor
34    implements FieldEditor, ItemListener JavaDoc
35 {
36     JCheckBox JavaDoc checkBox = new JCheckBox JavaDoc();
37
38     /**
39      * Constructs a new primitive checkbox editor for booleans.
40      */

41     public BooleanEditor(Object JavaDoc substance, FieldItem field) {
42         super(substance,field);
43         checkBox.addFocusListener(this);
44         checkBox.addItemListener(this);
45         add(checkBox);
46     }
47
48     public Object JavaDoc getValue() {
49         return ExtBoolean.valueOf(checkBox.isSelected());
50     }
51
52     public void setValue(Object JavaDoc value) {
53         super.setValue(value);
54         checkBox.setSelected(((Boolean JavaDoc)value).booleanValue());
55     }
56
57     /**
58      * Set the focus on the checkBox
59      */

60     public void requestFocus() {
61         checkBox.requestFocus();
62         loggerFocus.debug("focusing "+checkBox.getClass().getName());
63     }
64    
65     // ItemListener interface
66

67     public void itemStateChanged(ItemEvent JavaDoc event) {
68         loggerEvents.debug("itemStateChanged on "+this);
69         if (field!=null && isEmbedded) {
70             invokeInContext(this,"commit", new Object JavaDoc[]{});
71         } else {
72             loggerEvents.debug("ignoring item event");
73         }
74     }
75 }
76
77
Popular Tags