package net.hexid.hexbot.bot.gui;

import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuBuilder;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import net.hexid.hexbot.bot.Bots;

public class BotGUI extends javafx.application.Application {
	protected AnchorPane root;
	protected BotTabPane tabPane;

	public static void init(String[] args) {
		launch(args);
	}

	@Override public void start(Stage stage) {
		root = new AnchorPane();
		tabPane = createTabPane();
		root.getChildren().addAll(tabPane, createMenuBar());

		// if there are arguments
		if(getParameters().getRaw().size() > 0) {
			// iterate over each argument (names of bots)
			for(String arg : getParameters().getRaw()) {
				// add a new tab if the argument is the name of a bot
				if(Bots.hasBot(arg)) addTab(arg);
			}
		}
		if(tabPane.getTabs().size() == 0) { // if no arguments were passed to the gui
			System.out.println("args: 'gui' [BotName...]");
			System.out.println("Available bots: " + Bots.botIDsString());
		}

		stage.getIcons().add(new Image(BotGUI.class.getResourceAsStream("/HexBot.png")));
		stage.setTitle("HexBot by Hexid");
		stage.setScene(new javafx.scene.Scene(root, 630, 300));
		stage.show();
	}

	protected void addTab(String botID) {
		try { // create a new tab based on the bot's guiClassPath
			tabPane.addBotTab((BotTab)Class.forName(Bots.getBotGuiClassPath(botID))
					.getConstructor(String.class).newInstance(botID));
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	protected MenuBar createMenuBar() {
		MenuBar menuBar = new MenuBar();
		ObservableList<Menu> menus = menuBar.getMenus();
		MenuBuilder<? extends MenuBuilder> mb = MenuBuilder.create();

		for(final String botID : Bots.botIDs()) { // iterate over botNames
			// create a menu item with the bot's long name
			menus.add(mb.text(Bots.getBotName(botID))
					.onShown(new EventHandler<Event>() {
						@Override public void handle(Event e) {
							((Menu)e.getSource()).hide();
							addTab(botID); // create a new tab
						}
					}).items(new MenuItem()).build());
		}

		if(menus.size() == 0) // if no bot tabs were created
			menus.add(mb.text("No bots found").build());

		AnchorPane.setTopAnchor(menuBar, 0.0d);
		AnchorPane.setLeftAnchor(menuBar, 0.0d);
		AnchorPane.setRightAnchor(menuBar, 0.0d);
		return menuBar;
	}

	protected BotTabPane createTabPane() {
		tabPane = new BotTabPane();
		AnchorPane.setTopAnchor(tabPane, 24.0d); // fit to the top menu bar
		AnchorPane.setBottomAnchor(tabPane, 0.0d);
		AnchorPane.setLeftAnchor(tabPane, 0.0d);
		AnchorPane.setRightAnchor(tabPane, 0.0d);
		return tabPane;
	}
}
@@ -758,36 +758,8 @@
 );%0A%0A
-%09%09// if there are arguments%0A
 %09%09if
@@ -800,164 +800,105 @@
  0) 
-%7B%0A%09%09%09// iterate over each argument (names of bots)%0A%09%09%09for(String arg : getParameters().getRaw()) %7B%0A%09%09%09%09// add a new tab if the argument is the name of a bot
+// if there are arguments%0A%09%09%09for(String arg : getParameters().getRaw()) // iterate over bot names
 %0A%09%09%09
@@ -935,17 +935,39 @@
 rg);
-%0A%09%09%09%7D%0A%09%09%7D
+ // add bot if the name exists%0A
 %0A%09%09i
@@ -998,18 +998,16 @@
 () == 0)
- %7B
  // if n
@@ -1092,35 +1092,10 @@
 ...%5D
-%22);%0A%09%09%09System.out.println(%22
+%5Cn
 Avai
@@ -1127,28 +1127,24 @@
 DsString());
-%0A%09%09%7D
 %0A%0A%09%09stage.ge
@@ -1848,18 +1848,16 @@
 otIDs())
- %7B
  // iter
@@ -2144,16 +2144,16 @@
 %09%09%09%09%09%09%7D%0A
+
 %09%09%09%09%09%7D).
@@ -2183,20 +2183,16 @@
 uild());
-%0A%09%09%7D
 %0A%0A%09%09if(m

Remove unnecessary brackets