1 14 package org.compiere.swing; 15 16 import java.awt.Color ; 17 import java.awt.event.MouseListener ; 18 import java.util.Vector ; 19 20 import javax.swing.ComboBoxModel ; 21 import javax.swing.Icon ; 22 import javax.swing.JButton ; 23 import javax.swing.JComboBox ; 24 import javax.swing.plaf.ComboBoxUI ; 25 26 import org.compiere.plaf.CompiereComboBoxUI; 27 import org.compiere.plaf.CompierePLAF; 28 import org.compiere.util.Trace; 29 30 36 public class CComboBox extends JComboBox 37 implements CEditor 38 { 39 50 public CComboBox(ComboBoxModel aModel) 51 { 52 super(aModel); 53 init(); 54 } 56 64 public CComboBox(final Object items[]) 65 { 66 super(items); 67 init(); 68 } 70 78 public CComboBox(Vector items) 79 { 80 super(items); 81 init(); 82 } 84 92 public CComboBox() 93 { 94 super(); 95 init(); 96 } 98 101 private void init() 102 { 103 setFont(CompierePLAF.getFont_Field()); 105 setForeground(CompierePLAF.getTextColor_Normal()); 106 setBackground(false); 107 } 109 110 111 112 113 private Icon m_icon = null; 114 115 119 public void setIcon (Icon defaultIcon) 120 { 121 if (getUI() instanceof CompiereComboBoxUI) 122 ((CompiereComboBoxUI)getUI()).setIcon(defaultIcon); 123 m_icon = defaultIcon; 124 } 126 130 public void setUI (ComboBoxUI ui) 131 { 132 super.setUI(ui); 133 if (m_icon != null && ui instanceof CompiereComboBoxUI) 134 ((CompiereComboBoxUI)getUI()).setIcon(m_icon); 135 } 137 143 public boolean displayPopup() 144 { 145 return true; 146 } 148 149 150 151 private boolean m_mandatory = false; 152 153 157 public void setMandatory (boolean mandatory) 158 { 159 m_mandatory = mandatory; 160 setBackground(false); 161 } 163 167 public boolean isMandatory() 168 { 169 return m_mandatory; 170 } 172 176 public void setReadWrite (boolean rw) 177 { 178 if (super.isEnabled() != rw) 179 super.setEnabled (rw); 180 setBackground(false); 181 } 183 187 public boolean isReadWrite() 188 { 189 return super.isEnabled(); 190 } 192 196 public void setBackground (boolean error) 197 { 198 if (error) 199 setBackground(CompierePLAF.getFieldBackground_Error()); 200 else if (!isReadWrite()) 201 setBackground(CompierePLAF.getFieldBackground_Inactive()); 202 else if (m_mandatory) 203 setBackground(CompierePLAF.getFieldBackground_Mandatory()); 204 else 205 setBackground(CompierePLAF.getFieldBackground_Normal()); 206 } 208 212 public void setBackground (Color bg) 213 { 214 if (bg.equals(getBackground())) 215 return; 216 super.setBackground(bg); 217 } 219 223 public void setValue (Object value) 224 { 225 super.setSelectedItem(value); 226 } 228 232 public Object getValue() 233 { 234 return super.getSelectedItem(); 235 } 237 241 public String getDisplay() 242 { 243 Object o = super.getSelectedItem(); 244 if (o == null) 245 return ""; 246 return o.toString(); 247 } 249 256 public void addMouseListener (MouseListener ml) 257 { 258 super.addMouseListener(ml); 259 if (getUI() instanceof CompiereComboBoxUI && !Trace.getCallerClass(1).startsWith("javax")) 261 { 262 JButton b = ((CompiereComboBoxUI)getUI()).getArrowButton(); 263 if (b != null) 264 b.addMouseListener(ml); 265 } 266 } 268 272 public void removeMouseListener (MouseListener ml) 273 { 274 super.removeMouseListener(ml); 275 if (getUI() instanceof CompiereComboBoxUI) 276 { 277 JButton b = ((CompiereComboBoxUI)getUI()).getArrowButton(); 278 if (b != null) 279 b.removeMouseListener(ml); 280 } 281 } 283 } | Popular Tags |