package net.hexid.hexbot.bot.gui;

import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.TextArea;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import net.hexid.hexbot.bot.Bots;

public abstract class BotTab extends javafx.scene.control.Tab implements net.hexid.hexbot.bot.Bot {
	protected BotTabProcess process;
	protected TextArea output;
	protected String botID;

	public BotTab(String botID) {
		super();
		this.botID = botID;
		setText(Bots.getBotName(botID));
		setContent(defaultContent());
	}

	public abstract void processExitCode(int exitCode);
	protected abstract Node defaultContent(); // what is shown when the tab is created
	protected abstract Node[] createBottomOutputContent();

	public String getBotID() {
		return botID;
	}

	protected void createProcess() {
		setContent(createOutputContent()); // change to output mode
		try { // create a new bot process and start it
			process = new BotTabProcess(this);
			process.start();
		} catch (java.io.IOException e) {
			appendOutput(e.getMessage());
		}
	}

	protected VBox createOutputContent() { // create an output pane
		VBox outputContent = new VBox();

		output = new TextArea();
		output.setEditable(false);
		VBox.setVgrow(output, Priority.ALWAYS);
		outputContent.getChildren().add(output);

		Node[] bottomNodes = createBottomOutputContent();
		if(bottomNodes != null) {
			HBox bottom = new HBox(7.5d);
			VBox.setMargin(bottom, new Insets(5.0d, 15.0d, 5.0d, 15.0d));
			VBox.setVgrow(bottom, Priority.NEVER);
			HBox.setHgrow(bottom, Priority.ALWAYS);
			bottom.getChildren().addAll(bottomNodes);
			outputContent.getChildren().add(bottom);
		}

		return outputContent;
	}

	public void killProcess() { // stop the process, if one exists
		if(process != null)
			process.killProcess();
	}

	/**
	 * Append a string to the output and move the cursor to the end of that string
	 * @param str
	 */
	public void appendOutput(String str) {
		if(output != null) {
			output.appendText((output.getText().equals("") ? "" : '\n') + str);
			output.positionCaret(output.getLength() - str.length() + 2);
		}
	}
}
@@ -28,16 +28,44 @@
 t.gui;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -113,16 +113,49 @@
 e.Node;%0A
+import javafx.scene.control.Tab;%0A
 import j
@@ -283,24 +283,57 @@
 ayout.VBox;%0A
+import net.hexid.hexbot.bot.Bot;%0A
 import net.h
@@ -396,65 +396,8 @@
 nds 
-javafx.scene.control.Tab implements net.hexid.hexbot.bot.
 Bot 
@@ -471,28 +471,23 @@
 otected 
-String botID
+Tab tab
 ;%0A%0A%09publ
@@ -524,42 +524,31 @@
 per(
+botID
 );%0A%09%09t
-his.botID = botID;%0A%09%09setText
+ab = new Tab
 (Bot
@@ -601,24 +601,132 @@
 ent());%0A%09%7D%0A%0A
+%09public Tab getTab() %7B%0A%09%09return tab;%0A%09%7D%0A%09protected void setContent(Node node) %7B%0A%09%09tab.setContent(node);%0A%09%7D%0A%0A
 %09public abst
@@ -911,56 +911,8 @@
 );%0A%0A
-%09public String getBotID() %7B%0A%09%09return botID;%0A%09%7D%0A%0A
 %09pro
@@ -943,16 +943,20 @@
 s() %7B%0A%09%09
+tab.
 setConte
@@ -1125,24 +1125,16 @@
  catch (
-java.io.
 IOExcept

Switch BotTab to extend the Bot abstract class and use a Tab variable