1 26 27 package org.objectweb.util.browser.gui.lib; 28 29 30 import org.objectweb.util.browser.gui.api.ValidateReport; 31 32 33 import javax.swing.JRadioButton ; 34 import javax.swing.ButtonGroup ; 35 import javax.swing.JLabel ; 36 import javax.swing.Box ; 37 import javax.swing.SwingConstants ; 38 import java.awt.Component ; 39 import java.awt.Dimension ; 40 41 47 public class BooleanBox 48 extends AbstractElementBox{ 49 50 56 protected ButtonGroup group_ = null; 57 58 64 67 public BooleanBox(String label) { 68 this(label, "True","False", true); 69 } 70 71 74 public BooleanBox(String label, String trueLabel, String falseLabel, boolean defaultValue) { 75 JRadioButton trueButton, falseButton; 76 add(Box.createHorizontalGlue()); 77 JLabel fieldLabel = new JLabel (label + ": ", SwingConstants.RIGHT); 78 fieldLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); 79 fieldLabel.setAlignmentY(Component.CENTER_ALIGNMENT); 80 add(fieldLabel); 81 add(Box.createHorizontalStrut(5)); 82 trueButton = new JRadioButton (trueLabel); 83 trueButton.setActionCommand("true"); 84 if(defaultValue) 85 trueButton.setSelected(true); 86 trueButton.setPreferredSize(new Dimension (110, 20)); 87 trueButton.setMaximumSize(new Dimension (110, 20)); 88 add(trueButton); 89 add(Box.createHorizontalStrut(5)); 90 falseButton = new JRadioButton (falseLabel); 91 falseButton.setActionCommand("false"); 92 if(!defaultValue) 93 falseButton.setSelected(true); 94 falseButton.setPreferredSize(new Dimension (110, 20)); 95 falseButton.setMaximumSize(new Dimension (110, 20)); 96 add(falseButton); 97 98 group_ = new ButtonGroup (); 99 group_.add(trueButton); 100 group_.add(falseButton); 101 102 } 103 104 110 114 public ValidateReport validateBox(){ 115 return new DefaultValidateReport(); 116 } 117 118 122 public Box getBox(){ 123 return this; 124 } 125 126 132 133 public boolean getValue() { 134 return group_.getSelection().getActionCommand().equals("true"); 135 } 136 137 } 138 | Popular Tags |