001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library 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 GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.properties.editors;
020:
021: import java.awt.Component;
022: import java.awt.event.ItemEvent;
023: import java.awt.event.ItemListener;
024:
025: import javax.swing.BoxLayout;
026: import javax.swing.JCheckBox;
027: import javax.swing.JPanel;
028:
029: import com.jeta.swingbuilder.gui.properties.JETAPropertyEditor;
030:
031: public class BooleanEditor extends JETAPropertyEditor {
032: private JPanel m_panel;
033: private JCheckBox m_cbox = new JCheckBox();
034:
035: public BooleanEditor() {
036: m_panel = new JPanel() {
037: public void updateUI() {
038: super .updateUI();
039: if (m_panel != null) {
040: m_panel.setBackground(javax.swing.UIManager
041: .getColor("TextField.background"));
042: m_cbox.setBorder(javax.swing.BorderFactory
043: .createEmptyBorder(2, 4, 2, 2));
044: m_cbox.setOpaque(false);
045: }
046: }
047: };
048: m_panel.setLayout(new BoxLayout(m_panel, BoxLayout.Y_AXIS));
049: m_panel.add(m_cbox);
050: m_panel.setOpaque(true);
051: m_panel.setBackground(javax.swing.UIManager
052: .getColor("TextField.background"));
053: m_cbox.setOpaque(false);
054: m_cbox.setBorder(javax.swing.BorderFactory.createEmptyBorder(2,
055: 4, 4, 2));
056:
057: m_cbox.addItemListener(new ItemListener() {
058: public void itemStateChanged(ItemEvent evt) {
059: if (evt.getStateChange() == ItemEvent.SELECTED) {
060: setValue(Boolean.TRUE);
061: } else {
062: setValue(Boolean.FALSE);
063:
064: }
065: }
066: });
067:
068: }
069:
070: public Component getCustomEditor() {
071: return m_panel;
072: }
073:
074: /**
075: *
076: */
077: public boolean isPaintable() {
078: return false;
079: }
080:
081: /**
082: * @return true if this editor supports custom editing inline in the
083: * property table. Property types such as the Java primitives and
084: * Strings support inline editing.
085: */
086: public boolean supportsInlineEditing() {
087: return true;
088: }
089:
090: public boolean supportsCustomEditor() {
091: return true;
092: }
093:
094: public void setValue(Object value) {
095: super .setValue(value);
096: if (value != null) {
097: try {
098: m_cbox.setText(value.toString());
099: if (m_cbox.isSelected() != ((Boolean) value)
100: .booleanValue()) {
101: // Don't call setSelected unless the state actually changes
102: // to avoid a loop.
103: m_cbox
104: .setSelected(((Boolean) value)
105: .booleanValue());
106: }
107: } catch (Exception ex) {
108: ex.printStackTrace();
109: }
110: }
111:
112: }
113:
114: public Object getValue() {
115: return Boolean.valueOf(m_cbox.isSelected());
116: }
117:
118: }
|