package extractor.ui.servletUI;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;

import java.util.*;

public class ServletVariableTFUI extends JPanel implements ActionListener
{
	JPanel textGroupPane;
	JPanel deletePane;
	JComboBox deleteCombo;
	JList deleteList;
	JScrollPane deleteFieldPane;
	JTextArea addField;
	JScrollPane addFieldPane;
	JTextArea resultField;
	JScrollPane resultFieldPane;
	
	JButton okBtn;
	JPanel btnPane;
	
	DefaultListModel listModel;
	
	
	
	public ServletVariableTFUI()
	{
		setLayout(new BorderLayout());
		
		textGroupPane = new JPanel();
		textGroupPane.setLayout(new BoxLayout(textGroupPane, BoxLayout.Y_AXIS));
		textGroupPane.setBorder(BorderFactory.createTitledBorder("서블릿 변수를 바꿉니다"));		
		
		deletePane = new JPanel(new BorderLayout(0, 10));
		
	//for test		
		Vector listValues = new Vector();
		listValues.add("variable 1");
		listValues.add("variable 2");
		listValues.add("variable 3");
		listValues.add("variable 4");
		listValues.add("variable 5"); 
		
		deleteCombo = new JComboBox(listValues);
		deleteCombo.addActionListener(this);		
		listModel = new DefaultListModel();
		deleteList = new JList(listModel);
		deleteFieldPane = new JScrollPane(deleteList);
		deleteFieldPane.setPreferredSize(new Dimension(200, 250));
		deleteFieldPane.setBorder(BorderFactory.createTitledBorder("삭제할 변수 : "));				
		deletePane.add(deleteCombo, BorderLayout.NORTH);
		deletePane.add(deleteFieldPane, BorderLayout.CENTER);
				
		addField = new JTextArea();
		addFieldPane = new JScrollPane(addField);
		addFieldPane.setBorder(BorderFactory.createTitledBorder("추가할 변수 : "));			
		addFieldPane.setPreferredSize(new Dimension(200, 250));
				
		resultField = new JTextArea();		
		resultFieldPane = new JScrollPane(resultField);
		resultFieldPane.setBorder(BorderFactory.createTitledBorder("변환 결과 : "));			
		
		textGroupPane.add(deletePane);
		textGroupPane.add(Box.createRigidArea(new Dimension(0,5)));
		textGroupPane.add(addFieldPane);
		//textGroupPane.add(resultFieldPane);
		
		btnPane = new JPanel();
		okBtn = new JButton("OK");
		okBtn.addActionListener(this);
		btnPane.add(okBtn);
		
		add(textGroupPane, BorderLayout.CENTER);		
		//add(btnPane, BorderLayout.SOUTH);
		
		setSize(100, 50);
	}

	public void actionPerformed(ActionEvent e) 
	{
		if(e.getSource() == deleteCombo)
		{
			System.out.println("Hi, deleteCombo");
       		String listValue = (String)deleteCombo.getSelectedItem();
        	if(!listModel.contains(listValue))
        	{
	        	listModel.addElement(listValue);
				deleteList.setSelectedIndex(listModel.size()-1);
			}
	   	}
	}
	
	public static void main(String[] arg)
	{
		JFrame f = new JFrame();
		ServletVariableTFUI sName = new ServletVariableTFUI();
		f.getContentPane().add(sName);
		f.setVisible(true);
		f.pack();
	}
	
}