/*
 *  Draco Econometrics
 *  Copyright (C) 2006-2007 Approximatrix, LLC
 *  http://www.approximatrix.com
 *  
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.approximatrix.draco.main.ui;
import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import com.approximatrix.draco.datamodel.StatTableModel;

/**
 * @author armstrongj
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class RenameColumnDialog extends JDialog {

	private javax.swing.JPanel jContentPane = null;

	private JPanel jPanel = null;
	private JButton cancel_rename_button = null;
	private JPanel jPanel1 = null;
	private JLabel jLabel = null;
	private JTextField name_textfield = null;
	private JButton set_name_button = null;
	
	private StatTableModel current_model;
	private String the_name;
	
	/**
	 * This is the default constructor
	 */
	public RenameColumnDialog(StatTableModel information, String current_column) {
		super();
		
		current_model = information;
		the_name = current_column;
		
		initialize();
	}
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setResizable(false);
		this.setModal(true);
		this.setTitle("Rename Column");
		this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		this.setSize(220, 123);
		this.setContentPane(getJContentPane());
		
		name_textfield.setText(the_name);
		
	}
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private javax.swing.JPanel getJContentPane() {
		if(jContentPane == null) {
			jContentPane = new javax.swing.JPanel();
			jContentPane.setLayout(new java.awt.BorderLayout());
			jContentPane.add(getJPanel(), java.awt.BorderLayout.SOUTH);
			jContentPane.add(getJPanel1(), java.awt.BorderLayout.CENTER);
		}
		return jContentPane;
	}
	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanel() {
		if (jPanel == null) {
			java.awt.FlowLayout flowLayout6 = new FlowLayout();
			jPanel = new JPanel();
			jPanel.setLayout(flowLayout6);
			flowLayout6.setAlignment(java.awt.FlowLayout.RIGHT);
			jPanel.add(getSet_name_button(), null);
			jPanel.add(getCancel_rename_button(), null);
		}
		return jPanel;
	}
	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */    
	private JButton getCancel_rename_button() {
		if (cancel_rename_button == null) {
			cancel_rename_button = new JButton();
			cancel_rename_button.setText("Cancel");
			cancel_rename_button.addMouseListener(new java.awt.event.MouseAdapter() { 
				public void mouseClicked(java.awt.event.MouseEvent e) {    
					dispose();
				}
			});
		}
		return cancel_rename_button;
	}
	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jLabel = new JLabel();
			java.awt.FlowLayout flowLayout7 = new FlowLayout();
			jPanel1 = new JPanel();
			jPanel1.setLayout(flowLayout7);
			jLabel.setText("Column name:");
			flowLayout7.setAlignment(java.awt.FlowLayout.LEFT);
			jPanel1.add(jLabel, null);
			jPanel1.add(getName_textfield(), null);
		}
		return jPanel1;
	}
	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */    
	private JTextField getName_textfield() {
		if (name_textfield == null) {
			name_textfield = new JTextField();
			name_textfield.setPreferredSize(new java.awt.Dimension(200,21));
		}
		return name_textfield;
	}
	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */    
	private JButton getSet_name_button() {
		if (set_name_button == null) {
			set_name_button = new JButton();
			set_name_button.setText("Set Name");
			set_name_button.addMouseListener(new java.awt.event.MouseAdapter() { 
				public void mouseClicked(java.awt.event.MouseEvent e) {    
					current_model.renameColumn(the_name,name_textfield.getText());
					dispose();
				}
			});
		}
		return set_name_button;
	}
     }  //  @jve:decl-index=0:visual-constraint="10,10"
