/*
 * AlgorithmPanel.java
 *
 * Created on Ketvirtadienis, 2007, Sausio 25, 17.15
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Main.panels;

import java.awt.event.*;
import Main.parser.*;
import java.awt.*;
import javax.swing.*;


public class AlgorithmPanel extends JPanel
{
	JTextArea mUEquation;
	JTextArea mVEquation;
	final String U= "U=";
	final String V= "V=";
	final String PARSE_EQUATIONS= "PARSE";

	
	public AlgorithmPanel()
	{
		setLayout(new GridBagLayout());
		GridBagConstraints gbc;
		gbc= new GridBagConstraints();
		
		JLabel mULabel= new JLabel(U);
		gbc.fill= GridBagConstraints.NONE;
		gbc.anchor= GridBagConstraints.WEST;
		gbc.gridwidth= GridBagConstraints.REMAINDER;
		((GridBagLayout)getLayout()).setConstraints(mULabel, gbc);
		add(mULabel);
		
		mUEquation= new JTextArea();
		gbc.fill= GridBagConstraints.BOTH;
		gbc.anchor= GridBagConstraints.CENTER;
		gbc.gridwidth= GridBagConstraints.REMAINDER;
		gbc.weighty= 1;
		gbc.weightx=1;
		
		JScrollPane scrol= new JScrollPane(mUEquation);
		
		((GridBagLayout)getLayout()).setConstraints(scrol,gbc);
		add(scrol);
		
		JLabel mVLabel= new JLabel(V);
		gbc.fill= GridBagConstraints.NONE;
		gbc.anchor= GridBagConstraints.WEST;
		gbc.gridwidth= GridBagConstraints.REMAINDER;
		gbc.weighty= 0;
		gbc.weightx=0;
		((GridBagLayout)getLayout()).setConstraints(mVLabel, gbc);
		add(mVLabel);
		
		mVEquation= new JTextArea();
		gbc.weighty= 1;
		gbc.weightx=1;
		gbc.fill= GridBagConstraints.BOTH;
		gbc.anchor= GridBagConstraints.CENTER;
		
		scrol= new JScrollPane(mVEquation);
		
		((GridBagLayout)getLayout()).setConstraints(scrol,gbc);
		add(scrol);
		
		JButton parseButton= new JButton(PARSE_EQUATIONS);
		gbc.fill= GridBagConstraints.NONE;
		gbc.anchor= GridBagConstraints.WEST;
		gbc.gridwidth= GridBagConstraints.REMAINDER;
		gbc.weighty= 0;
		gbc.weightx=0;
		
		((GridBagLayout)getLayout()).setConstraints(parseButton,gbc);
		add(parseButton);
		
		parseButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				EquationsManager.getInstance().parseText(mUEquation.getText(), EquationsManager.U_EQUATION);
				EquationsManager.getInstance().parseText(mVEquation.getText(), EquationsManager.V_EQUATION);
			}
		}
		);
		
		mUEquation.setFont(new Font(mUEquation.getFont().getName(), Font.PLAIN, 14 ));
		mVEquation.setFont(new Font(mVEquation.getFont().getName(), Font.PLAIN, 14 ));
		
	}
	
	public String getUEquation()
	{
		return mUEquation.getText();
	}
	
	public void setUEquation(String u)
	{
		mUEquation.setText(u);
	}
	
	public String getVEquation()
	{
		return mVEquation.getText();
	}
	
	public void setVEquation(String u)
	{
		mVEquation.setText(u);
	}

}

