001 /* 002 Copyright (C) 2001-2003 Renaud Pawlak <renaud@aopsys.com>, 003 Laurent Martelli <laurent@aopsys.com> 004 005 This program is free software; you can redistribute it and/or modify 006 it under the terms of the GNU Lesser General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This program is distributed in the hope that it will be useful, but 011 WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 Lesser General Public License for more details. 014 015 You should have received a copy of the GNU Lesser General Public 016 License along with this program; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 018 USA */ 019 020 package org.objectweb.jac.aspects.gui.swing; 021 022 import java.awt.event.ItemEvent; 023 import java.awt.event.ItemListener; 024 import javax.swing.JCheckBox; 025 import org.objectweb.jac.aspects.gui.FieldEditor; 026 import org.objectweb.jac.core.rtti.FieldItem; 027 import org.objectweb.jac.util.ExtBoolean; 028 029 /** 030 * A Swing editor component for boolean values. 031 */ 032 033 public class BooleanEditor extends AbstractFieldEditor 034 implements FieldEditor, ItemListener 035 { 036 JCheckBox checkBox = new JCheckBox(); 037 038 /** 039 * Constructs a new primitive checkbox editor for booleans. 040 */ 041 public BooleanEditor(Object substance, FieldItem field) { 042 super(substance,field); 043 checkBox.addFocusListener(this); 044 checkBox.addItemListener(this); 045 add(checkBox); 046 } 047 048 public Object getValue() { 049 return ExtBoolean.valueOf(checkBox.isSelected()); 050 } 051 052 public void setValue(Object value) { 053 super.setValue(value); 054 checkBox.setSelected(((Boolean)value).booleanValue()); 055 } 056 057 /** 058 * Set the focus on the checkBox 059 */ 060 public void requestFocus() { 061 checkBox.requestFocus(); 062 loggerFocus.debug("focusing "+checkBox.getClass().getName()); 063 } 064 065 // ItemListener interface 066 067 public void itemStateChanged(ItemEvent event) { 068 loggerEvents.debug("itemStateChanged on "+this); 069 if (field!=null && isEmbedded) { 070 invokeInContext(this,"commit", new Object[]{}); 071 } else { 072 loggerEvents.debug("ignoring item event"); 073 } 074 } 075 } 076