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.JTextField ; 34 import javax.swing.JLabel ; 35 import javax.swing.Box ; 36 import javax.swing.SwingConstants ; 37 38 import java.awt.Component ; 39 import java.awt.Dimension ; 40 41 47 public class LabelBox 48 extends AbstractElementBox{ 49 50 51 protected String label_; 52 53 54 protected JTextField name_; 55 56 60 public LabelBox(String label) { 61 this(label,true); 62 } 63 64 69 public LabelBox(String label, boolean isMandatory) { 70 super(isMandatory); 71 label_ = label; 72 add(Box.createHorizontalGlue()); 73 JLabel fieldLabel = new JLabel (label_ + ": ", SwingConstants.RIGHT); 74 fieldLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); 75 fieldLabel.setAlignmentY(Component.CENTER_ALIGNMENT); 76 add(fieldLabel); 77 add(Box.createHorizontalStrut(5)); 78 name_ = new JTextField (); 79 name_.setPreferredSize(new Dimension (225, 20)); 80 name_.setMaximumSize(new Dimension (225, 20)); 81 add(name_); 82 } 83 84 89 public LabelBox(String label, String defaultValue){ 90 this(label, defaultValue, true); 91 } 92 93 99 public LabelBox(String label, String defaultValue, boolean isMandatory){ 100 this(label, isMandatory); 101 name_.setText(defaultValue); 102 } 103 104 110 114 public ValidateReport validateBox(){ 115 if(isMandatory_){ 116 if(name_.getText()==null||name_.getText().equals("")) 117 return new DefaultValidateReport(false,"The \"" + label_ + "\" value is mandatory"); 118 } 119 return new DefaultValidateReport(); 120 } 121 122 126 public Box getBox(){ 127 return this; 128 } 129 130 136 137 public String getLabel() { 138 return name_.getText(); 139 } 140 141 } 142 | Popular Tags |