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.JButton ; 21 22 import org.compiere.plaf.CompiereColor; 23 import org.compiere.plaf.CompierePLAF; 24 import org.compiere.util.Trace; 25 26 32 public class CButton extends JButton implements CEditor 33 { 34 37 public CButton() 38 { 39 this (null, null); 40 } 41 42 47 public CButton(Icon icon) 48 { 49 this (null, icon); 50 } 51 52 57 public CButton(String text) 58 { 59 this (text, null); 60 } 61 62 70 public CButton (Action a) 71 { 72 super (a); 73 setContentAreaFilled(false); 74 setOpaque(false); 75 } 76 77 83 public CButton(String text, Icon icon) 84 { 85 super (text, icon); 86 setContentAreaFilled(false); 87 setOpaque(false); 88 setFont(CompierePLAF.getFont_Label()); 90 setForeground(CompierePLAF.getTextColor_Label()); 91 } 93 94 95 100 public void setBackground (Color bg) 101 { 102 if (bg.equals(getBackground())) 103 return; 104 super.setBackground (bg); 105 if (!Trace.getCallerClass(1).startsWith("javax")) 107 { 108 setOpaque(true); 109 setContentAreaFilled(true); 110 } 111 this.repaint(); 112 } 114 118 public void setBackground (boolean error) 119 { 120 } 122 125 public void setBackgroundColor () 126 { 127 setBackgroundColor (null); 128 } 130 134 public void setBackgroundColor (CompiereColor bg) 135 { 136 if (bg == null) 137 bg = CompiereColor.getDefaultBackground(); 138 setOpaque(true); 139 putClientProperty(CompierePLAF.BACKGROUND, bg); 140 super.setBackground (bg.getFlatColor()); 141 this.repaint(); 142 } 144 148 public CompiereColor getBackgroundColor () 149 { 150 try 151 { 152 return (CompiereColor)getClientProperty(CompierePLAF.BACKGROUND); 153 } 154 catch (Exception e) 155 { 156 System.err.println("CButton - ClientProperty: " + e.getMessage()); 157 } 158 return null; 159 } 161 162 private boolean m_mandatory = false; 163 164 private boolean m_readWrite = true; 165 166 170 public void setMandatory (boolean mandatory) 171 { 172 m_mandatory = mandatory; 173 setBackground(false); 174 } 176 180 public boolean isMandatory() 181 { 182 return m_mandatory; 183 } 185 189 public void setReadWrite (boolean rw) 190 { 191 if (super.isEnabled() != rw) 192 super.setEnabled(rw); 193 m_readWrite = rw; 194 } 196 200 public boolean isReadWrite() 201 { 202 return m_readWrite; 203 } 205 209 public void setValue (Object value) 210 { 211 if (value == null) 212 setText(""); 213 else 214 setText(value.toString()); 215 } 217 221 public Object getValue() 222 { 223 return getText(); 224 } 226 230 public String getDisplay() 231 { 232 return getText(); 233 } 235 236 } | Popular Tags |