package juum.naach;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import juum.Juum;
import juum.wiinkil.SerialListener;

public class Plurifocal extends JFrame implements SerialListener, ActionListener{

	private static final long serialVersionUID = 842636290099602689L;

	private JLabel outputLabel;
	private JTextField outputText;
	private JTextArea inputData;
	private JButton outputButton;
	
	public Plurifocal(){

		this.setUndecorated(true);
		this.setVisible(true);
		this.setBounds(0, 525, 600, 200);
		this.setResizable(false);
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		this.setIconImage(Toolkit.getDefaultToolkit().getImage("materials/logos/logoJuumSmall.png"));
	
		setLayout(new FlowLayout());
		
		inputData = new JTextArea(7,50);
		inputData.setTabSize(1);
		inputData.setFont(new Font("Arial", Font.PLAIN, 13));
		JScrollPane areaScrollPane = new JScrollPane(inputData);
		areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		areaScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		this.add(areaScrollPane);
		
		outputLabel = new JLabel("raw input");
		outputText = new JTextField(15);
		outputButton = new JButton("Send");
		
		this.add(outputLabel);
		this.add(outputText);
		this.add(outputButton);		
		this.add(areaScrollPane);
		
		outputButton.addActionListener(this);	
		Juum.serial.addSerialListener(this);
		validate();
	
	}
	
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == outputButton)
		{
			String text = outputText.getText();
			Juum.serial.serialOut(text + "\n\r");
		}
	}
	
	public void dataReceived(String data) {
		inputData.setCaretPosition(inputData.getText().length());
		inputData.append(data);
	}

}
