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 ServletResultUI extends JPanel implements ActionListener
{
	JTextArea classField;
	JScrollPane classFieldPane;
	
	JButton okBtn;
	JButton compileBtn;
	JPanel btnPane;
	
	JDialog jd;
	
	
	public ServletResultUI(JDialog jd)
	{
		this.jd = jd;
		setLayout(new BorderLayout());
		setBorder(BorderFactory.createTitledBorder("변환된 자바 클래스 : "));			
		
		classField = new JTextArea();		
		classFieldPane = new JScrollPane(classField);
		
		btnPane = new JPanel();
		okBtn = new JButton("Next Servlet");		
		okBtn.addActionListener(this);
		compileBtn = new JButton("Compile");
		compileBtn.addActionListener(this);
		//btnPane.add(okBtn);
		btnPane.add(compileBtn);
		
		add(classFieldPane, BorderLayout.CENTER);		
		add(btnPane, BorderLayout.SOUTH);
		
		setSize(100, 50);
	}

	public void actionPerformed(ActionEvent e) 
	{
		Object obj = e.getSource();
		if(obj == compileBtn)
		{
			System.out.println("I'm a compile button.");
		}
	}


/*	public void compile(String sFileName) throws Exception{

		System.out.println(sFileName);

        Runtime rt = Runtime.getRuntime();
        Process ps = null;

        try{

			outputMessage.setText(" ");
			System.out.println("===> " + sFileName.substring(0, sFileName.lastIndexOf("\\")));
			System.out.println("===> sFileName = " + sFileName);
            //String cmd = "javac  -sourcepath " + sFileName.substring(0, sFileName.lastIndexOf("\\")) + " "; 
            //            cmd =   cmd +  sFileName;

			String sPath = System.getProperty("user.dir");
			sPath = sPath + "\\Destination_source";
            		
            		String cmd = "javac -classpath \"%classpath%;.;c:\\j2sdkee1.3.1\\lib\\j2ee.jar;" + sPath + "\"  " + sFileName; 
            		System.out.println(cmd);
			ps = rt.exec(cmd);

        }

        catch (Exception e) {
			outputMessage.append("Error occurred!"+ e.toString() + "\n");
        }

        try {

            //BufferedReader br=new BufferedReader(new InputStreamReader(new SequenceInputStream(ps.getInputStream(),
            //    ps.getErrorStream())));


			BufferedReader br = new BufferedReader(new InputStreamReader(ps.getErrorStream()));

            PrintWriter pr = new PrintWriter(ps.getOutputStream());
            String str=null;

			if (br.readLine() == null)
			{
				outputMessage.setText("");
				outputMessage.append("Normal Termination" + "\n");
				outputMessage.append(sFileName + " is compiled"  + "\n");

			}else{
				outputMessage.setText("");
	            while ((str=br.readLine())!=null) {
					outputMessage.append("Error : "+str + "\n");
			    }
			}
        }
        catch (IOException ie) {
			outputMessage.setText("");
			outputMessage.append("Error occurred!"+ ie.toString()+ "\n");
			outputMessage.append("Total "+ps.exitValue() +"errors" +  "\n");
        }

        try {
			ps.waitFor();

        }
        catch (InterruptedException ire) {
			outputMessage.append("Error occurred!"+ ire.toString()+ "\n");
        }
    }*/
	
	/*public static void main(String[] arg)
	{
		JFrame f = new JFrame();
		ServletResultUI sName = new ServletResultUI();
		f.getContentPane().add(sName);
		f.setVisible(true);
		f.pack();
	}*/
	
}