1 19 package org.openharmonise.him.metadata.range.swing.booleanhandling; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 24 import javax.swing.*; 25 26 import org.openharmonise.him.metadata.range.swing.*; 27 import org.openharmonise.vfs.gui.*; 28 import org.openharmonise.vfs.metadata.*; 29 import org.openharmonise.vfs.metadata.range.*; 30 31 32 39 public class BooleanValuePanel 40 extends AbstractRangeDisplay 41 implements RangeDisplay, LayoutManager, ActionListener { 42 43 46 protected int m_nHeight = 10; 47 48 51 private JComboBox m_comboBox = null; 52 53 56 protected WarningsLabel m_warnings = null; 57 58 61 protected JLabel m_errorLabel = null; 62 63 66 private String m_sValue = ""; 67 68 71 private String m_sPreviousValue = ""; 72 73 76 private BooleanRangeDisplay m_display = null; 77 78 private String m_sTrueText = "Yes"; 79 private String m_sFalseText = "No"; 80 81 88 public BooleanValuePanel(BooleanRangeDisplay display, PropertyInstance propInstance, String sValue) { 89 super(propInstance); 90 this.m_display = display; 91 this.m_sValue = sValue; 92 if(sValue.equals("true")) { 93 this.m_sPreviousValue = "Yes"; 94 } else if(sValue.equals("false")) { 95 this.m_sPreviousValue = "No"; 96 } else { 97 this.m_sPreviousValue = ""; 98 } 99 this.setup(); 100 } 101 102 105 public void setup() { 106 this.setLayout(this); 107 BooleanRange range = 108 (BooleanRange) this 109 .getPropertyInstance() 110 .getDefinition() 111 .getRange(); 112 113 this.m_sTrueText = range.getTrueText(); 114 this.m_sFalseText = range.getFalseText(); 115 116 if(this.m_sValue.equals("true")) { 117 this.m_sPreviousValue = this.m_sTrueText; 118 } else if(this.m_sValue.equals("false")) { 119 this.m_sPreviousValue = this.m_sFalseText; 120 } else { 121 this.m_sPreviousValue = ""; 122 } 123 124 this.m_errorLabel = new JLabel(); 125 this.m_errorLabel.setIcon( 126 IconManager.getInstance().getIcon("16-message-confirm.gif")); 127 this.add(this.m_errorLabel); 128 129 String sWarning = "Please select a value."; 130 131 m_warnings = new WarningsLabel(sWarning); 132 this.add(m_warnings); 133 134 m_comboBox = new JComboBox( new String []{"", this.m_sTrueText, this.m_sFalseText} ); 135 if(this.m_sValue!=null && this.m_sValue.equals("true")) { 136 m_comboBox.setSelectedItem(this.m_sTrueText); 137 } else if(this.m_sValue!=null && this.m_sValue.equals("false")) { 138 m_comboBox.setSelectedItem(this.m_sFalseText); 139 } 140 m_comboBox.setActionCommand("COMBO"); 141 m_comboBox.addActionListener(this); 142 int nHeight = 30; 143 m_nHeight = nHeight + 20; 144 m_comboBox.setPreferredSize(new Dimension(200, 20)); 145 this.add(m_comboBox); 146 147 } 148 149 152 public void actionPerformed(ActionEvent ae) { 153 if(ae.getActionCommand().equals("COMBO")) { 154 String sCurrentValue =(String ) this.m_comboBox.getSelectedItem(); 155 if(sCurrentValue.equals("")) { 156 this.m_display.valueChanged(""); 157 } else if(sCurrentValue.equals( this.m_sTrueText )) { 158 this.m_display.valueChanged("true"); 159 this.m_sPreviousValue = sCurrentValue; 160 } else if(sCurrentValue.equals( this.m_sFalseText )) { 161 this.m_display.valueChanged("false"); 162 this.m_sPreviousValue = sCurrentValue; 163 } 164 } 165 } 166 167 170 public Dimension getPreferredSize() { 171 this.layoutContainer(null); 172 int nWidth = this.getParent().getWidth(); 173 int nHeight = 10; 174 nHeight = nHeight + this.m_comboBox.getSize().height; 175 return new Dimension(nWidth, nHeight); 176 } 177 178 181 public void removeLayoutComponent(Component arg0) { 182 } 184 185 188 public void layoutContainer(Container arg0) { 189 int nWidth = this.getParent().getWidth() - 50; 190 191 Dimension dim = m_comboBox.getPreferredSize(); 192 m_comboBox.setPreferredSize(new Dimension(nWidth - 85, dim.height)); 193 m_comboBox.setSize(m_comboBox.getPreferredSize()); 194 m_comboBox.setLocation(20, 0); 195 196 this.m_errorLabel.setLocation(0,0); 197 this.m_errorLabel.setSize(15, 15); 198 this.repaint(); 199 } 200 201 204 public void addLayoutComponent(String arg0, Component arg1) { 205 } 207 208 211 public Dimension minimumLayoutSize(Container arg0) { 212 return this.getPreferredSize(); 213 } 214 215 218 public Dimension preferredLayoutSize(Container arg0) { 219 return this.getPreferredSize(); 220 } 221 222 225 public JPanel getPanel() { 226 return null; 227 } 228 229 234 protected String getValue() { 235 if(this.m_comboBox.getSelectedItem().equals( this.m_sTrueText )) { 236 return "true"; 237 } else if(this.m_comboBox.getSelectedItem().equals( this.m_sFalseText )) { 238 return "false"; 239 } else { 240 return ""; 241 } 242 } 243 244 247 public boolean isMetadataValid() { 248 return !this.m_errorLabel.getIcon().toString().equals(IconManager.getInstance().getIcon("16-message-error.gif").toString()); 249 } 250 251 256 public void setValid(boolean bValid) { 257 if(!bValid) { 258 this.m_comboBox.setBorder(BorderFactory.createLineBorder(Color.RED)); 259 this.m_errorLabel.setIcon(IconManager.getInstance().getIcon("16-message-error.gif")); 260 } else { 261 this.m_comboBox.setBorder(BorderFactory.createLineBorder(Color.BLACK)); 262 this.m_errorLabel.setIcon(IconManager.getInstance().getIcon("16-message-confirm.gif")); 263 } 264 this.revalidate(); 265 this.repaint(); 266 } 267 268 } 269 | Popular Tags |