package view;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import model.Receiver;

public class Feed {
	private Receiver myReceiver;
	private HBox myObjects;
	private VBox myButtons;
	private Button add;
	private Button enter;
	private TextArea prompter;
	private static final String PROMPT_TEXT = "Input command here";
	private static final String ADD_TEXT = "Add";
	private static final String ENTER_TEXT = "Return";
	private static final double PROMPT_WIDTH = Double.MAX_VALUE;

	protected Feed(Receiver receiver) {
		myReceiver = receiver;
		myObjects = new HBox();
		myButtons = new VBox();
		setupPrompter();
		setupAdd();
		setupEnter();
		myButtons.getChildren().addAll(enter, add);
		myObjects.getChildren().addAll(prompter, myButtons);
	}

	/**
	 * 
	 */
	public void setupEnter() {
		enter = new Button(ENTER_TEXT);
		enter.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent e) {
				if (prompter.getText() != null)
					// CommandSender.send(prompter.getText());
					try {
						myReceiver.giveText(prompter.getText());
						} catch (Exception ex) {
							ErrorDisplay.getInstance().displayError(ex);
						}
					myReceiver.giveText(prompter.getText());
				System.out.println(prompter.getText().toString());
				prompter.clear();
			}
		});
	}

	/**
	 * 
	 */
	public void setupAdd() {
		add = new Button(ADD_TEXT);
	}

	/**
	 * 
	 */
	public void setupPrompter() {
		prompter = new TextArea();
		prompter.setPromptText(PROMPT_TEXT);
		HBox.setHgrow(prompter, Priority.ALWAYS);
	}

	protected HBox getFeed() {
		return myObjects;
	}

}

@@ -355,33 +355,8 @@
 ts;%0A
-%09private VBox myButtons;%0A
 %09pri
@@ -372,16 +372,16 @@
 on add;%0A
+
 %09private
@@ -742,34 +742,8 @@
 ();%0A
-%09%09myButtons = new VBox();%0A
 %09%09se
@@ -791,54 +791,8 @@
 ();%0A
-%09%09myButtons.getChildren().addAll(enter, add);%0A
 %09%09my
@@ -820,16 +820,21 @@
 .addAll(
+add, 
 prompter
@@ -839,17 +839,13 @@
 er, 
-myButtons
+enter
 );%0A%09
@@ -1177,17 +1177,16 @@
 );%0A%09%09%09%09%09
-%09
 %7D catch 
@@ -1202,17 +1202,16 @@
 n ex) %7B%0A
-%09
 %09%09%09%09%09%09Er
@@ -1258,20 +1258,18 @@
 );%0A%09%09%09%09%09
-%09
 %7D%0A
-%09
 %09%09%09%09myRe
@@ -1438,16 +1438,16 @@
 Add() %7B%0A
-
 %09%09add = 
@@ -1468,16 +1468,17 @@
 _TEXT);%0A
+%0A
 %09%7D%0A%0A%09/**

reset feed