1 26 27 package org.objectweb.util.explorer.swing.gui.lib; 28 29 import javax.swing.JTextField ; 30 import javax.swing.JLabel ; 31 import javax.swing.Box ; 32 import javax.swing.SwingConstants ; 33 34 import org.objectweb.util.explorer.swing.gui.api.ValidateReport; 35 36 import java.awt.Component ; 37 import java.awt.Dimension ; 38 39 45 public class LabelBox 46 extends AbstractElementBox{ 47 48 49 protected String label_; 50 51 52 protected JTextField name_; 53 54 58 public LabelBox(String label) { 59 this(label,true); 60 } 61 62 67 public LabelBox(String label, boolean isMandatory) { 68 super(isMandatory); 69 label_ = label; 70 add(Box.createHorizontalGlue()); 71 JLabel fieldLabel = new JLabel (label_ + ": ", SwingConstants.RIGHT); 72 fieldLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); 73 fieldLabel.setAlignmentY(Component.CENTER_ALIGNMENT); 74 add(fieldLabel); 75 add(Box.createHorizontalStrut(5)); 76 name_ = new JTextField (); 77 name_.setPreferredSize(new Dimension (225, 20)); 78 name_.setMaximumSize(new Dimension (225, 20)); 79 add(name_); 80 } 81 82 87 public LabelBox(String label, String defaultValue){ 88 this(label, defaultValue, true); 89 } 90 91 97 public LabelBox(String label, String defaultValue, boolean isMandatory){ 98 this(label, isMandatory); 99 name_.setText(defaultValue); 100 } 101 102 108 112 public ValidateReport validateBox(){ 113 if(isMandatory_){ 114 if(name_.getText()==null||name_.getText().equals("")) 115 return new DefaultValidateReport(false,"The \"" + label_ + "\" value is mandatory"); 116 } 117 return new DefaultValidateReport(); 118 } 119 120 124 public Box getBox(){ 125 return this; 126 } 127 128 134 135 public String getLabel() { 136 return name_.getText(); 137 } 138 139 } 140 | Popular Tags |