Package DisplayProject.factory

Source Code of DisplayProject.factory.ToggleFieldFactory

/*
Copyright (c) 2003-2008 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package DisplayProject.factory;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.AbstractButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.UIManager;

import DisplayProject.UIutils;
import DisplayProject.controls.ToggleField;
import DisplayProject.plaf.Win32LookAndFeel;

import com.sun.java.swing.plaf.windows.WindowsCheckBoxUI;

/**
* @author Tim
*
*/
public class ToggleFieldFactory {

    private ToggleFieldFactory() {
        super();
    }

    /**
     * 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;
    }

    /**
     * Create a new toggleField that maps the java events to the forte events
     * with the passed label
     *
     * @return a new instance of a checkbox
     */
    public static JCheckBox newToggleField(String pLabel) {
        JCheckBox result = newToggleField();
        result.setText(pLabel);
        return result;
    }

    /**
     * Create a new toggleField that maps the java events to the forte events
     * with the passed label and the passed name
     *
     * @return a new instance of a checkbox
     */
    public static JCheckBox newToggleField(String pLabel, String pName) {
        JCheckBox result = newToggleField(pLabel);
        result.setName(pName);
        return result;
    }
}
TOP

Related Classes of DisplayProject.factory.ToggleFieldFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.