blob: e11a654c699fec0835b74608a116bf721a3e271c [file] [log] [blame]
Richard S. Hall930fecc2005-08-16 18:33:34 +00001/*
2 * Copyright 2005 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.osgi.framework.installer.editor;
18
19import java.awt.event.ActionEvent;
20import java.awt.event.ActionListener;
21
22import javax.swing.*;
23
24import org.apache.osgi.framework.installer.BooleanProperty;
25import org.apache.osgi.framework.installer.Property;
26
27public class BooleanEditor extends JPanel
28{
29 private BooleanProperty m_prop = null;
30 private JRadioButton m_trueButton = null;
31 private JRadioButton m_falseButton = null;
32 private String m_trueString = null;
33 private String m_falseString = null;
34
35 public BooleanEditor(BooleanProperty prop)
36 {
37 this(prop, "true", "false");
38 }
39
40 public BooleanEditor(BooleanProperty prop, String trueString, String falseString)
41 {
42 m_prop = prop;
43 m_trueString = trueString;
44 m_falseString = falseString;
45 init();
46 }
47
48 public Property getProperty()
49 {
50 return m_prop;
51 }
52
53 public void setEnabled(boolean b)
54 {
55 m_trueButton.setEnabled(b);
56 m_falseButton.setEnabled(b);
57 }
58
59 protected void init()
60 {
61 add(m_trueButton = new JRadioButton(m_trueString));
62 add(m_falseButton = new JRadioButton(m_falseString));
63 ButtonGroup group = new ButtonGroup();
64 group.add(m_trueButton);
65 group.add(m_falseButton);
66 if (m_prop.getBooleanValue())
67 {
68 m_trueButton.setSelected(true);
69 }
70 else
71 {
72 m_falseButton.setSelected(true);
73 }
74
75 // Add action listeners.
76 m_trueButton.addActionListener(new ActionListener() {
77 public void actionPerformed(ActionEvent event)
78 {
79 m_prop.setBooleanValue(true);
80 }
81 });
82 m_falseButton.addActionListener(new ActionListener() {
83 public void actionPerformed(ActionEvent event)
84 {
85 m_prop.setBooleanValue(false);
86 }
87 });
88 }
89}