1 36 package org.ungoverned.oscar.installer.editor; 37 38 import java.awt.event.ActionEvent ; 39 import java.awt.event.ActionListener ; 40 41 import javax.swing.ButtonGroup ; 42 import javax.swing.JPanel ; 43 import javax.swing.JRadioButton ; 44 45 import org.ungoverned.oscar.installer.BooleanProperty; 46 import org.ungoverned.oscar.installer.Property; 47 48 public class BooleanEditor extends JPanel 49 { 50 private BooleanProperty m_prop = null; 51 private JRadioButton m_trueButton = null; 52 private JRadioButton m_falseButton = null; 53 private String m_trueString = null; 54 private String m_falseString = null; 55 56 public BooleanEditor(BooleanProperty prop) 57 { 58 this(prop, "true", "false"); 59 } 60 61 public BooleanEditor(BooleanProperty prop, String trueString, String falseString) 62 { 63 m_prop = prop; 64 m_trueString = trueString; 65 m_falseString = falseString; 66 init(); 67 } 68 69 public Property getProperty() 70 { 71 return m_prop; 72 } 73 74 public void setEnabled(boolean b) 75 { 76 m_trueButton.setEnabled(b); 77 m_falseButton.setEnabled(b); 78 } 79 80 protected void init() 81 { 82 add(m_trueButton = new JRadioButton (m_trueString)); 83 add(m_falseButton = new JRadioButton (m_falseString)); 84 ButtonGroup group = new ButtonGroup (); 85 group.add(m_trueButton); 86 group.add(m_falseButton); 87 if (m_prop.getBooleanValue()) 88 { 89 m_trueButton.setSelected(true); 90 } 91 else 92 { 93 m_falseButton.setSelected(true); 94 } 95 96 m_trueButton.addActionListener(new ActionListener () { 98 public void actionPerformed(ActionEvent event) 99 { 100 m_prop.setBooleanValue(true); 101 } 102 }); 103 m_falseButton.addActionListener(new ActionListener () { 104 public void actionPerformed(ActionEvent event) 105 { 106 m_prop.setBooleanValue(false); 107 } 108 }); 109 } 110 } | Popular Tags |