package de.javasoft.synthetica.democenter.examples.jyswitchbutton;

import java.awt.Container;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridBagLayoutInfo;
import java.awt.Insets;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;

import de.javasoft.swing.JYSwitchButton;

/**
 * Demonstrates simple switch button usage.  
 */
@SuppressWarnings("serial")
public class SimpleSwitchButton extends JFrame
{
  public SimpleSwitchButton()
  {
    super("Simple JYSwitchButton Demo");
    JPanel p = new JPanel();
    //respect preferred size to avoid collapsing when window will be resized 
    p.setLayout(new GridBagLayout()
    {
      @Override
      protected GridBagLayoutInfo getLayoutInfo(Container parent, int sizeflag)
      {
        return super.getLayoutInfo(parent, PREFERREDSIZE);
      }
    });
    
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,0,0,0), 0, 0);
    
//@highlight
    JYSwitchButton switchButton = new JYSwitchButton("JYSwitchButton selected", true);
//@/highlight
    p.add(switchButton, gbc);

//@highlight
    JYSwitchButton switchButton2 = new JYSwitchButton("JYSwitchButton deselected", false);
    switchButton2.setOnText("1");
    switchButton2.setOffText("0");
    switchButton2.setTextGap(12);
//@/highlight
    gbc.gridy++;
    p.add(switchButton2, gbc);

//@highlight
    JYSwitchButton switchButton3 = new JYSwitchButton("JYSwitchButton selected", true);
    switchButton3.setOnText("Yes");
    switchButton3.setOffText("No");
//@/highlight
    gbc.gridy++;
    p.add(switchButton3, gbc);
    
    add(p);
    
    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setSize(400, 250);
    setLocationRelativeTo(null);        //center
    setVisible(true);
  }

  /**
   * Static main method for application startup. 
   */
  public static void main(String[] args)
  {
    EventQueue.invokeLater(new Runnable()
    {
      public void run()
      {
        try
        {
          UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaStandardLookAndFeel");
          new SimpleSwitchButton();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }  
}
