/*
 * ParamsPanel.java
 *
 * Created on November 5, 2002, 7:54 AM
 */

package net.sf.hibernate.tool.ddl2hbm;
import javax.swing.DefaultListModel;
/**
 *
 * @author  Administrator
 */
public class ParamsPanel extends javax.swing.JPanel {
	
	/** Creates new form ParamsPanel */
	public ParamsPanel() {
		initComponents();
		paramList.setModel(new DefaultListModel());
	}
	
	/** 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;
		
		jPanel1 = new javax.swing.JPanel();
		jPanel2 = new javax.swing.JPanel();
		paramValue = new javax.swing.JTextField();
		jLabel2 = new javax.swing.JLabel();
		jScrollPane1 = new javax.swing.JScrollPane();
		paramList = new javax.swing.JList();
		jLabel1 = new javax.swing.JLabel();
		jPanel3 = new javax.swing.JPanel();
		cmdAdd = new javax.swing.JButton();
		cmdEdit = new javax.swing.JButton();
		cmdRemove = new javax.swing.JButton();
		
		setLayout(new java.awt.BorderLayout());
		
		jPanel1.setLayout(new java.awt.BorderLayout());
		
		jPanel1.setMinimumSize(new java.awt.Dimension(200, 200));
		jPanel1.setPreferredSize(new java.awt.Dimension(250, 120));
		jPanel2.setLayout(new java.awt.GridBagLayout());
		
		jPanel2.setMinimumSize(new java.awt.Dimension(250, 200));
		jPanel2.setPreferredSize(new java.awt.Dimension(300, 200));
		paramValue.setPreferredSize(new java.awt.Dimension(200, 16));
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridy = 1;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
		jPanel2.add(paramValue, gridBagConstraints);
		
		jLabel2.setFont(new java.awt.Font("Dialog", 0, 10));
		jLabel2.setText("Parameter List");
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 0);
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
		jPanel2.add(jLabel2, gridBagConstraints);
		
		jScrollPane1.setMinimumSize(new java.awt.Dimension(150, 60));
		jScrollPane1.setPreferredSize(new java.awt.Dimension(120, 200));
		paramList.setFont(new java.awt.Font("Dialog", 0, 12));
		paramList.setPreferredSize(null);
		paramList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
		paramList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
			public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
				paramListValueChanged(evt);
			}
		});
		
		jScrollPane1.setViewportView(paramList);
		
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
		gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
		jPanel2.add(jScrollPane1, gridBagConstraints);
		
		jLabel1.setFont(new java.awt.Font("Dialog", 0, 10));
		jLabel1.setText("Parameter Value");
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
		gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
		jPanel2.add(jLabel1, gridBagConstraints);
		
		jPanel1.add(jPanel2, java.awt.BorderLayout.CENTER);
		
		jPanel3.setLayout(new java.awt.GridBagLayout());
		
		jPanel3.setPreferredSize(new java.awt.Dimension(90, 200));
		cmdAdd.setText("Add");
		cmdAdd.setPreferredSize(new java.awt.Dimension(81, 20));
		cmdAdd.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cmdAddActionPerformed(evt);
			}
		});
		
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		jPanel3.add(cmdAdd, gridBagConstraints);
		
		cmdEdit.setText("Edit");
		cmdEdit.setPreferredSize(new java.awt.Dimension(81, 20));
		cmdEdit.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cmdEditActionPerformed(evt);
			}
		});
		
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		jPanel3.add(cmdEdit, gridBagConstraints);
		
		cmdRemove.setText("Remove");
		cmdRemove.setPreferredSize(new java.awt.Dimension(81, 20));
		cmdRemove.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cmdRemoveActionPerformed(evt);
			}
		});
		
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.insets = new java.awt.Insets(0, 0, 25, 0);
		jPanel3.add(cmdRemove, gridBagConstraints);
		
		jPanel1.add(jPanel3, java.awt.BorderLayout.EAST);
		
		add(jPanel1, java.awt.BorderLayout.CENTER);
		
	}//GEN-END:initComponents
	
	private void paramListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_paramListValueChanged
		// Add your handling code here:
		if (paramList.getSelectedIndex() != -1) {
			paramValue.setText((String)paramList.getSelectedValue());
		}
	}//GEN-LAST:event_paramListValueChanged
	
	private void cmdRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdRemoveActionPerformed
		int selectedIndex = paramList.getSelectedIndex();
		if (selectedIndex != -1) {
			javax.swing.DefaultListModel dlm = (DefaultListModel)paramList.getModel();
			dlm.removeElementAt(selectedIndex);
			paramList.setSelectedIndex(selectedIndex-1);
		}
	}//GEN-LAST:event_cmdRemoveActionPerformed
	
	private void cmdEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdEditActionPerformed
		// Add your handling code here:
		int selectedIndex = paramList.getSelectedIndex();
		if (selectedIndex != -1) {
			javax.swing.DefaultListModel dlm = (DefaultListModel)paramList.getModel();
			dlm.setElementAt(paramValue.getText(), selectedIndex);
		}
	}//GEN-LAST:event_cmdEditActionPerformed
	
	private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdAddActionPerformed
		javax.swing.DefaultListModel dlm = (DefaultListModel)paramList.getModel();
		dlm.addElement(paramValue.getText());
	}//GEN-LAST:event_cmdAddActionPerformed
	
	
	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JPanel jPanel3;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JButton cmdEdit;
	private javax.swing.JTextField paramValue;
	private javax.swing.JButton cmdRemove;
	private javax.swing.JList paramList;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JButton cmdAdd;
	private javax.swing.JLabel jLabel1;
	// End of variables declaration//GEN-END:variables
	public String[] getParameters() {
		javax.swing.DefaultListModel dlm = (DefaultListModel)paramList.getModel();
		String[] rv = new String[dlm.getSize()];
		for (int i=0; i < dlm.getSize(); i++) {
			rv[i] = (String)dlm.get(i);
		}
		return rv;
	}
	public void setParameters(String[] parameters) {
		javax.swing.DefaultListModel dlm = (DefaultListModel)paramList.getModel();
		for (int i=0; parameters != null && i < parameters.length; i++) {
			dlm.addElement(parameters[i]);
		}
	}
}






