1 14 package org.compiere.swing; 15 16 import java.awt.Color ; 17 18 import javax.swing.Icon ; 19 import javax.swing.JLabel ; 20 21 import org.compiere.plaf.CompierePLAF; 22 23 29 public class CLabel extends JLabel 30 { 31 public static int DEFAULT_ALIGNMENT = JLabel.TRAILING; 32 33 49 public CLabel (String text, Icon icon, int horizontalAlignment) 50 { 51 super (text, icon, horizontalAlignment); 52 init(); 53 } 54 55 69 public CLabel (String text, int horizontalAlignment) 70 { 71 super(text, horizontalAlignment); 72 init(); 73 } 74 75 82 public CLabel (String text) 83 { 84 super(text, DEFAULT_ALIGNMENT); 85 init(); 86 } 87 88 102 public CLabel (Icon image, int horizontalAlignment) 103 { 104 super (image, horizontalAlignment); 105 init(); 106 } 107 108 115 public CLabel (Icon image) 116 { 117 super (image, DEFAULT_ALIGNMENT); 118 init(); 119 } 120 121 129 public CLabel () 130 { 131 super("", DEFAULT_ALIGNMENT); 132 init(); 133 } 134 135 143 public CLabel (String label, String toolTip) 144 { 145 super (label, DEFAULT_ALIGNMENT); 146 if (toolTip != null && toolTip.length() > 0) 147 super.setToolTipText(toolTip); 148 init(); 149 } 151 154 private void init() 155 { 156 setFocusable (false); 157 setOpaque(false); 158 setForeground(CompierePLAF.getTextColor_Label()); 160 setFont(CompierePLAF.getFont_Label()); 161 } 163 164 168 public void setBackground (Color bg) 169 { 170 if (bg.equals(getBackground())) 171 return; 172 super.setBackground(bg); 173 } 175 176 177 181 public void setText (String mnemonicLabel) 182 { 183 super.setText (createMnemonic (mnemonicLabel)); 184 } 186 190 public void setTextDirect (String label) 191 { 192 super.setText (label); 193 } 195 202 private String createMnemonic(String text) 203 { 204 if (text == null) 205 return text; 206 int pos = text.indexOf("&"); 207 if (pos != -1) { 209 char ch = text.charAt(pos+1); 210 if (ch != ' ') { 212 setDisplayedMnemonic(ch); 213 return text.substring(0, pos) + text.substring(pos+1); 214 } 215 } 216 return text; 217 } 219 223 public void setReadWrite (boolean rw) 224 { 225 this.setEnabled(rw); 226 } 228 } | Popular Tags |