KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > multiview > ItemCheckBoxHelper


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.multiview;
21
22 import javax.swing.*;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25
26 /**
27  * The class simplifies use of a combo box to show/set value of an item
28  *
29  * @author pfiala
30  */

31 public abstract class ItemCheckBoxHelper implements ActionListener JavaDoc, Refreshable {
32     private JCheckBox checkBox;
33     private XmlMultiViewDataSynchronizer synchronizer;
34
35     /**
36      * Constructor initializes object by combo box and data object which will be handled
37      *
38      * @param synchronizer
39      * @param checkBox handled JComboBox.
40      */

41     public ItemCheckBoxHelper(XmlMultiViewDataSynchronizer synchronizer, JCheckBox checkBox) {
42         this.synchronizer = synchronizer;
43         this.checkBox = checkBox;
44         checkBox.addActionListener(this);
45         setValue(getItemValue());
46     }
47
48     /**
49      * Invoked when an action occurs on a combo box.
50      */

51     public final void actionPerformed(ActionEvent JavaDoc e) {
52         final boolean value = getValue();
53         if (value != getItemValue()) {
54             setItemValue(value);
55             synchronizer.requestUpdateData();
56         }
57     }
58
59     /**
60      * Selects the item value in check box.
61      *
62      * @param itemValue value of item to be selected in check box
63      */

64     public void setValue(boolean itemValue) {
65         checkBox.setSelected(itemValue);
66     }
67
68     /**
69      * Check box getter
70      *
71      * @return handled check box
72      */

73     public JCheckBox getCheckBox() {
74         return checkBox;
75     }
76
77     /**
78      * Retrieves the text value selected in the check box.
79      *
80      * @return selected item of the check box
81      */

82     public boolean getValue() {
83         return checkBox.isSelected();
84     }
85
86     /**
87      * Called by the helper in order to retrieve the value of the item.
88      *
89      * @return value of the handled item.
90      */

91     public abstract boolean getItemValue();
92
93     /**
94      * Called by the helper in order to set the value of the item
95      *
96      * @param value new value of the hanlded item
97      */

98     public abstract void setItemValue(boolean value);
99
100     public void refresh() {
101         setValue(getItemValue());
102     }
103 }
104
Popular Tags