KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > ui > config > BooleanOptionComponent


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.ui.config;
35
36 import javax.swing.*;
37 import edu.rice.cs.drjava.config.*;
38 import edu.rice.cs.drjava.*;
39 import java.awt.*;
40 import java.awt.event.*;
41
42
43 /**
44  * Graphical form of a BooleanOption.
45  * @version $Id: BooleanOptionComponent.java 3900 2006-06-29 13:16:38Z rcartwright $
46  */

47 public class BooleanOptionComponent extends OptionComponent<Boolean JavaDoc> {
48   protected JCheckBox _jcb;
49
50   /**
51    * Constructs a new BooleanOptionComponent.
52    * @param opt the BooleanOption this component represents
53    * @param text the text to display with the option
54    * @param parent the parent frame
55    */

56   public BooleanOptionComponent(BooleanOption opt, String JavaDoc text, Frame parent) {
57     super(opt, "", parent);
58     _jcb = new JCheckBox();
59     _jcb.setText(text);
60     _jcb.addActionListener(new ActionListener() {
61       public void actionPerformed(ActionEvent e) { notifyChangeListeners(); }
62     });
63     
64     _jcb.setSelected(DrJava.getConfig().getSetting(_option).booleanValue());
65   }
66
67   /** Constructs a new BooleanOptionComponent with a tooltip description.
68    * @param opt the BooleanOption this component represents
69    * @param text the text to display with the option
70    * @param parent the parent frame
71    * @param description text to show in a tooltip over
72    */

73   public BooleanOptionComponent(BooleanOption opt, String JavaDoc text,
74                                 Frame parent, String JavaDoc description) {
75     this(opt, text, parent);
76     setDescription(description);
77   }
78
79   /** Sets the tooltip description text for this option.
80    * @param description the tooltip text
81    */

82   public void setDescription(String JavaDoc description) {
83     _jcb.setToolTipText(description);
84     _label.setToolTipText(description);
85   }
86
87   /** Updates the config object with the new setting.
88    * @return true if the new value is set successfully
89    */

90   public boolean updateConfig() {
91     Boolean JavaDoc oldValue = DrJava.getConfig().getSetting(_option);
92     Boolean JavaDoc newValue = Boolean.valueOf(_jcb.isSelected());
93     
94     if (!oldValue.equals(newValue)) DrJava.getConfig().setSetting(_option, newValue);
95
96     return true;
97   }
98   
99   /** Displays the given value. */
100   public void setValue(Boolean JavaDoc value) {
101     _jcb.setSelected(value.booleanValue());
102   }
103   
104   /**
105    * Return's this OptionComponent's configurable component.
106    */

107   public JComponent getComponent() { return _jcb; }
108 }
109
Popular Tags