1 /* -------------------------------------------------------------------
2 * Java source file for the class BooleanEditor
3 *
4 * Copyright (c), 2002, Masahiro Takatsuka.
5 * All Rights Researved.
6 *
7 * Original Author: Masahiro Takatsuka (masa@jbeans.net)
8 * $Author: takatsukam $
9 *
10 * $Date: 2003/07/25 04:51:44 $
11 *
12 * $Id: BooleanEditor.java,v 1.1.1.1 2003/07/25 04:51:44 takatsukam Exp $
13 *
14 * Reference: Document no:
15 * ___ ___
16 *
17 * To Do:
18 * ___
19 *
20 ------------------------------------------------------------------- */
21
22 /* --------------------------- Package ---------------------------- */
23 package net.jbeans.bean.property.editor;
24
25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">color="#329900"> ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900"> ------------------ Import classes (packages) ------------------- */
26 import java.awt.event.*;
27 import javax.swing.*;
28
29 /*====================================================================
30 Implementation of class BooleanEditor
31 ====================================================================*/
32 /***
33 * An editor which represents a boolean value. This editor is implemented
34 * as a checkbox with the text of the check box reflecting the state of the
35 * checkbox.
36 *
37 * @version $Revision: 1.1.1.1 $
38 * @author Masahiro Takatsuka (masa@jbeans.net)
39 * @see EditorSupport
40 */
41
42 public final class BooleanEditor extends EditorSupport {
43 private JCheckBox checkbox;
44
45 public BooleanEditor() {
46 this.checkbox = new JCheckBox();
47 this.checkbox.addItemListener(new ItemListener() {
48 public final void itemStateChanged(ItemEvent evt) {
49 if (evt.getStateChange() == ItemEvent.SELECTED) {
50 setValue(Boolean.TRUE);
51 } else {
52 setValue(Boolean.FALSE);
53 }
54 }
55 });
56 JPanel panel = new JPanel();
57 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
58 panel.add(this.checkbox);
59 setPanel(panel);
60 }
61
62 public final void setValue(Object value ) {
63 super.setValue(value);
64 if (value != null) {
65 try {
66 this.checkbox.setText(value.toString());
67 if (this.checkbox.isSelected() != ((Boolean)value).booleanValue()) {
68 /* Don't call setSelected unless the state
69 actually changes to avoid a loop.
70 */
71 this.checkbox.setSelected(((Boolean)value).booleanValue());
72 }
73 } catch (Exception ex) {
74 ex.printStackTrace();
75 }
76 }
77 }
78
79 public final Object getValue() {
80 return new Boolean(this.checkbox.isSelected());
81 }
82
83 public final String getJavaInitializationString() {
84 if (((Boolean)getValue()).booleanValue()) {
85 return "true";
86 } else {
87 return "false";
88 }
89 }
90 }
This page was automatically generated by Maven