* Create a new toggleField that maps the java events to the forte events
*
* @return a new instance of a checkbox
*/
public static JCheckBox newToggleField() {
final JCheckBox result = new ToggleField();
// CraigM:29/04/2008 - If the check box is not enabled but is focusable, don't let the
// toggle field disabled text be hard to read.
result.setUI(new WindowsCheckBoxUI() {
@Override
protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
if (UIManager.getLookAndFeel() instanceof Win32LookAndFeel && result.isEnabled() == false && result.isFocusable()) {
String version = System.getProperty("java.version", ".");
// CraigM:30/04/2008 - Java1.6 uses the Button.shadow as the foreground colour on disabled check boxes.
if (version.startsWith("1.6")) {
Color foreground = UIManager.getColor("Button.shadow");
Color shadow = UIManager.getColor("Button.disabledShadow");
UIManager.getDefaults().put("Button.shadow", SystemColor.controlText);
UIManager.getDefaults().put("Button.disabledShadow", result.getBackground());
super.paintText(g, b, textRect, text);
UIManager.getDefaults().put("Button.shadow", foreground);
UIManager.getDefaults().put("Button.disabledShadow", shadow);
}
else {
Color foreground = UIManager.getColor("Button.disabledForeground");
Color shadow = UIManager.getColor("Button.disabledShadow");
UIManager.getDefaults().put("Button.disabledForeground", SystemColor.controlText);
UIManager.getDefaults().put("Button.disabledShadow", result.getBackground());
super.paintText(g, b, textRect, text);
UIManager.getDefaults().put("Button.disabledForeground", foreground);
UIManager.getDefaults().put("Button.disabledShadow", shadow);
}
}
else {
super.paintText(g, b, textRect, text);
}
}
});
// added to fix ARD-32
// The data changed flag is now set when a Chack Box is changed
result.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
UIutils.setDataChangedFlag((JComponent) e.getSource());
}
});
result.setBackground(null);
return result;
}