1 26 27 package org.objectweb.util.explorer.swing.gui.lib; 28 29 import java.awt.Component ; 30 import java.awt.Dimension ; 31 32 import javax.swing.Box ; 33 import javax.swing.ButtonGroup ; 34 import javax.swing.JLabel ; 35 import javax.swing.JRadioButton ; 36 import javax.swing.SwingConstants ; 37 38 import org.objectweb.util.explorer.swing.gui.api.ValidateReport; 39 40 41 47 public class BooleanBox 48 extends AbstractElementBox{ 49 50 56 protected ButtonGroup group_ = null; 57 58 64 68 public BooleanBox(String label) { 69 this(label, "True","False", true); 70 } 71 72 79 public BooleanBox(String label, String trueLabel, String falseLabel, boolean defaultValue) { 80 JRadioButton trueButton, falseButton; 81 add(Box.createHorizontalGlue()); 82 JLabel fieldLabel = new JLabel (label + ": ", SwingConstants.RIGHT); 83 fieldLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); 84 fieldLabel.setAlignmentY(Component.CENTER_ALIGNMENT); 85 add(fieldLabel); 86 add(Box.createHorizontalStrut(5)); 87 trueButton = new JRadioButton (trueLabel); 88 trueButton.setActionCommand("true"); 89 if(defaultValue) 90 trueButton.setSelected(true); 91 trueButton.setPreferredSize(new Dimension (110, 20)); 92 trueButton.setMaximumSize(new Dimension (110, 20)); 93 add(trueButton); 94 add(Box.createHorizontalStrut(5)); 95 falseButton = new JRadioButton (falseLabel); 96 falseButton.setActionCommand("false"); 97 if(!defaultValue) 98 falseButton.setSelected(true); 99 falseButton.setPreferredSize(new Dimension (110, 20)); 100 falseButton.setMaximumSize(new Dimension (110, 20)); 101 add(falseButton); 102 103 group_ = new ButtonGroup (); 104 group_.add(trueButton); 105 group_.add(falseButton); 106 107 } 108 109 115 119 public ValidateReport validateBox(){ 120 return new DefaultValidateReport(); 121 } 122 123 127 public Box getBox(){ 128 return this; 129 } 130 131 137 141 public boolean getValue() { 142 return group_.getSelection().getActionCommand().equals("true"); 143 } 144 145 } 146 | Popular Tags |