package at.vector.jide;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.TristateCheckBox;

public class TristateCheckBoxMain
{

    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable()
        {
            @Override
            public void run()
            {
                LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
                TristateCheckBoxMain main = new TristateCheckBoxMain();
                main.start();
            }
        });
    }

    TristateCheckBox tristate = null;

    private void start()
    {
        JFrame frame = new JFrame();
        tristate = new TristateCheckBox("Tristate");
        tristate.addActionListener(new ActionListener()
        {

            @Override
            public void actionPerformed(ActionEvent e)
            {
                int state = tristate.getState();
//              Comment setState out and it will not work
                tristate.setState(state);
            }
        });
//      If the intial state is not mixed, the ActionListener is required
        tristate.setState(TristateCheckBox.STATE_UNSELECTED);

        frame.getContentPane().setLayout(new FlowLayout());
        frame.getContentPane().add(tristate);
        frame.pack();
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
