1 14 package org.compiere.swing; 15 16 import java.awt.Color ; 17 18 import javax.swing.Action ; 19 import javax.swing.Icon ; 20 import javax.swing.JToggleButton ; 21 22 import org.compiere.plaf.CompiereColor; 23 import org.compiere.plaf.CompierePLAF; 24 import org.compiere.util.Trace; 25 26 32 public class CToggleButton extends JToggleButton implements CEditor 33 { 34 38 public CToggleButton () { 39 this(null, null, false); 40 } 41 42 48 public CToggleButton(Icon icon) { 49 this(null, icon, false); 50 } 51 52 60 public CToggleButton(Icon icon, boolean selected) { 61 this(null, icon, selected); 62 } 63 64 69 public CToggleButton (String text) { 70 this(text, null, false); 71 } 72 73 81 public CToggleButton (String text, boolean selected) { 82 this(text, null, selected); 83 } 84 85 91 public CToggleButton(Action a) { 92 this(); 93 setAction(a); 94 } 95 96 103 public CToggleButton(String text, Icon icon) { 104 this(text, icon, false); 105 } 106 107 116 public CToggleButton (String text, Icon icon, boolean selected) 117 { 118 super(text, icon, selected); 119 setContentAreaFilled(false); 120 setOpaque(false); 121 setFont(CompierePLAF.getFont_Label()); 123 setForeground(CompierePLAF.getTextColor_Label()); 124 } 125 126 127 128 133 public void setBackground(Color bg) 134 { 135 if (bg.equals(getBackground())) 136 return; 137 super.setBackground( bg); 138 if (!Trace.getCallerClass(1).startsWith("javax")) 140 { 141 setOpaque(true); 142 setContentAreaFilled(true); 143 } 144 } 146 150 public void setBackground (boolean error) 151 { 152 } 154 157 public void setBackgroundColor () 158 { 159 setBackgroundColor (null); 160 } 162 166 public void setBackgroundColor (CompiereColor bg) 167 { 168 if (bg == null) 169 bg = CompiereColor.getDefaultBackground(); 170 setOpaque(true); 171 putClientProperty(CompierePLAF.BACKGROUND, bg); 172 super.setBackground (bg.getFlatColor()); 173 } 175 179 public CompiereColor getBackgroundColor () 180 { 181 try 182 { 183 return (CompiereColor)getClientProperty(CompierePLAF.BACKGROUND); 184 } 185 catch (Exception e) 186 { 187 System.err.println("CButton - ClientProperty: " + e.getMessage()); 188 } 189 return null; 190 } 192 193 private boolean m_mandatory = false; 194 195 199 public void setMandatory (boolean mandatory) 200 { 201 m_mandatory = mandatory; 202 setBackground(false); 203 } 205 209 public boolean isMandatory() 210 { 211 return m_mandatory; 212 } 214 218 public void setReadWrite (boolean rw) 219 { 220 if (super.isEnabled() != rw) 221 super.setEnabled(rw); 222 } 224 228 public boolean isReadWrite() 229 { 230 return super.isEnabled(); 231 } 233 237 public void setValue (Object value) 238 { 239 if (value == null) 240 setText(""); 241 else 242 setText(value.toString()); 243 } 245 249 public Object getValue() 250 { 251 return getText(); 252 } 254 258 public String getDisplay() 259 { 260 return getText(); 261 } 263 }
| Popular Tags
|