/*
 * SGUpgradeDialog.java
 *
 * Created on 2004/10/28, 10:20
 */

package jp.riken.brain.ni.samuraigraph.application;

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import jp.riken.brain.ni.samuraigraph.base.*;
import jp.riken.brain.ni.samuraigraph.data.*;
import jp.riken.brain.ni.samuraigraph.figure.*;
import jp.riken.brain.ni.samuraigraph.figure.java2d.*;


/**
 *
 * @author  kuromaru
 */
public class SGUpgradeDialog extends SGDialog
{

	public static final String TITLE = "Upgrade";


	/**
	 * 
	 */
	public SGUpgradeDialog()
	{
		super();
		this.initComponents();
		this.initProperty();
	}

    
    /** Creates new form SGUpgradeDialog */
    public SGUpgradeDialog(java.awt.Frame parent, boolean modal)
    {
        super(parent, modal);
        initComponents();
		this.initProperty();
    }

    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        mPanel = new javax.swing.JPanel();
        mButtonPanel = new javax.swing.JPanel();
        mOKButton = new javax.swing.JButton();
        mCancelButton = new javax.swing.JButton();
        mUpgradeCyclePanel = new javax.swing.JPanel();
        mUpgradeCycleComboBox = new javax.swing.JComboBox();
        mUpdateButtonPanel = new javax.swing.JPanel();
        mUpgradeButton = new javax.swing.JButton();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        mPanel.setLayout(new java.awt.GridBagLayout());

        mButtonPanel.setBorder(new javax.swing.border.EtchedBorder());
        mOKButton.setFont(new java.awt.Font("MS Sans Serif", 1, 12));
        mOKButton.setText("OK");
        mButtonPanel.add(mOKButton);

        mCancelButton.setFont(new java.awt.Font("MS Sans Serif", 1, 12));
        mCancelButton.setText("Cancel");
        mButtonPanel.add(mCancelButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(9, 6, 4, 6);
        mPanel.add(mButtonPanel, gridBagConstraints);

        mUpgradeCyclePanel.setLayout(new java.awt.GridBagLayout());

        mUpgradeCyclePanel.setBorder(new javax.swing.border.TitledBorder(null, "Upgrade Cycle", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 3, 12)));
        mUpgradeCycleComboBox.setFont(new java.awt.Font("Dialog", 0, 12));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(6, 6, 6, 6);
        mUpgradeCyclePanel.add(mUpgradeCycleComboBox, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
        mPanel.add(mUpgradeCyclePanel, gridBagConstraints);

        mUpdateButtonPanel.setLayout(new java.awt.GridBagLayout());

        mUpdateButtonPanel.setBorder(new javax.swing.border.TitledBorder(null, "Get the Latest Version", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 3, 12)));
        mUpgradeButton.setFont(new java.awt.Font("Dialog", 0, 12));
        mUpgradeButton.setText("Upgrade Now");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(6, 14, 6, 14);
        mUpdateButtonPanel.add(mUpgradeButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        mPanel.add(mUpdateButtonPanel, gridBagConstraints);

        getContentPane().add(mPanel, new java.awt.GridBagConstraints());

        pack();
    }//GEN-END:initComponents


    // 変数宣言 - 編集不可//GEN-BEGIN:variables
    private javax.swing.JPanel mButtonPanel;
    private javax.swing.JButton mCancelButton;
    private javax.swing.JButton mOKButton;
    private javax.swing.JPanel mPanel;
    private javax.swing.JPanel mUpdateButtonPanel;
    private javax.swing.JButton mUpgradeButton;
    private javax.swing.JComboBox mUpgradeCycleComboBox;
    private javax.swing.JPanel mUpgradeCyclePanel;
    // 変数宣言の終わり//GEN-END:variables



	//
	public static final String NO_UPGRADE = "No Upgrade";
	public static final String EVERY_TIME = "Every Time";
	public static final String EVERY_DAY = "Every Day";
	public static final String EVERY_WEEK = "Every Week";
	public static final String EVERY_MONTH = "Every Month";

	public static final String UPGRADE_NOW = "Upgrade Now";


	private String mUpgrade = null;



	/**
	 * 
	 */
	private boolean initProperty()
	{
		//
		this.setTitle( TITLE );

		//
		final String[] styleNameArray = {
			NO_UPGRADE,
			EVERY_TIME,
			EVERY_DAY,
			EVERY_WEEK,
			EVERY_MONTH
		};
		for( int ii=0; ii<styleNameArray.length; ii++ )
		{
			this.mUpgradeCycleComboBox.addItem( styleNameArray[ii] );
		}

		this.pack();


{
	this.mOKButton.addActionListener(this);
	this.mCancelButton.addActionListener(this);
}

		this.mUpgradeButton.addActionListener(this);

		return true;
	}



	/**
	 * 
	 */
	public void actionPerformed( final ActionEvent e )
	{
		Object source = e.getSource();
		String command = e.getActionCommand();
		
		if( command.equals( SGDialog.OK_BUTTON_TEXT ) )
		{
			this.onOK();
		}
		else if( command.equals( SGDialog.CANCEL_BUTTON_TEXT ) )
		{
			this.onCanceled();
		}
		else if( command.equals( SGUpgradeDialog.UPGRADE_NOW ) )
		{
			this.notifyToListener( command );
		}

	}


	/**
	 * 
	 * @return
	 */
	public String getUpgradeCycle()
	{
		return this.mUpgrade;
	}


	/**
	 * 
	 * @param cycle
	 */
	public void setUpgradeCycle( final String cycle )
	{
		this.mUpgrade = cycle;
	}


	/**
	 * 
	 */
	public void setVisible( final boolean b )
	{
		this.mUpgradeCycleComboBox.setSelectedItem( this.mUpgrade );
		super.setVisible(b);
	}


	/**
	 * 
	 */
	protected boolean onOK()
	{
		this.mUpgrade = (String)this.mUpgradeCycleComboBox.getSelectedItem();

		this.setVisible(false);
		this.notifyToListener( OK_BUTTON_TEXT );
		return true;
	}


	/**
	 * 
	 */
	protected boolean onCanceled()
	{
		this.setVisible(false);
		this.notifyToListener( CANCEL_BUTTON_TEXT );
		return true;
	}


}

