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

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

import org.jdesktop.swingx.JXMonthView;

import de.javasoft.swing.DateComboBox;

/**
 * A DateComboBox application used to demonstrate and explain  
 * essential functionality.
 */
@SuppressWarnings("serial")
public class CustomDateComboBox extends JFrame
{
  public CustomDateComboBox()
  {
    super("CustomDateComboBox");
    
    //create and add the combobox panel and its components
    JPanel panel = new JPanel();
    createAndAddComponents(panel);
    add(panel);

    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    pack();
    setLocationRelativeTo(null);        //center
    setVisible(true);
  }

  /**
   * Adds labels and comboboxes to the panel - using GridBagLayout.
   */
  private void createAndAddComponents(JPanel panel)
  {
    panel.setLayout(new GridBagLayout());    
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.gridheight = 1;
    gbc.weightx = 1.0;
    gbc.insets = new Insets(5,5,5,5);
    gbc.fill = GridBagConstraints.HORIZONTAL;

    gbc.gridx = 0;
    gbc.gridy = 0;
    panel.add(new JLabel("Customized DateComboBox"), gbc);
    gbc.gridx = 1;
//@highlight
    DateComboBox dateCombo = new DateComboBox();
    dateCombo.setDateFormat(new SimpleDateFormat("MM/dd/yyyy"));
    JXMonthView mv = dateCombo.getPopup().getMonthView();
    mv.setShowingLeadingDays(true);
    mv.setShowingTrailingDays(true);
    mv.setShowingWeekNumber(true);
    mv.setDayForeground(Calendar.SATURDAY, new Color(0xE04020));
    mv.setDayForeground(Calendar.SUNDAY, new Color(0xE04020));
    // display year within header
    mv.setZoomable(true);
    panel.add(dateCombo, gbc);
//@/highlight

    panel.setBorder(new EmptyBorder(10,10,200,10));    
  }

  /**
   * 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 CustomDateComboBox();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
      }
    });
  }  
}
