Skip to content

Commit

Permalink
Merge pull request #13 from TheItachiUchiha/master
Browse files Browse the repository at this point in the history
Comments and Logging along with code clean up
  • Loading branch information
Vogel612 committed Jan 24, 2015
2 parents ea6b3d4 + be8bb63 commit a8c9d24
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/main/java/de/vogel612/testclient_javabot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import javafx.application.Application;
import javafx.stage.Stage;

/**
* Entry point of Application. Class responsible for creating an JavaFX Application thread
* This class extends {@link Application}.
*/
public final class Main extends Application {

public static final void main(final String[] args) {
Expand Down Expand Up @@ -62,7 +66,6 @@ public boolean isLoggable(final LogRecord record) {
public void start(Stage primaryStage) throws Exception {
TestProgram p = new TestProgram(primaryStage);
AppContext.INSTANCE.add(p);

p.startup();
}
}
24 changes: 13 additions & 11 deletions src/main/java/de/vogel612/testclient_javabot/TestProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

import com.gmail.inverseconduit.AppContext;
import com.gmail.inverseconduit.bot.DefaultBot;
import com.gmail.inverseconduit.chat.ChatInterface;
import com.gmail.inverseconduit.commands.CommandHandle;
import com.gmail.inverseconduit.commands.sets.CoreBotCommands;

import de.vogel612.testclient_javabot.client.ClientGui;
import de.vogel612.testclient_javabot.core.TestingChatInterface;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

/**
* Class responsible for making things know each other. This class is the core
Expand Down Expand Up @@ -46,36 +47,34 @@ public TestProgram(Stage stage) {
LOGGER.info("instantiating TestProgram class");
AppContext.INSTANCE.add(chatInterface);
bot = new DefaultBot(chatInterface);

gui = new ClientGui();
try {
gui.start(stage);
gui.init(stage);
} catch (IOException e) {
throw new RuntimeException(e);
}
LOGGER.info("awaiting latch");

chatInterface.subscribe(bot);
chatInterface.subscribe(gui);
LOGGER.info("Basic component setup completed, beginning command glueing.");
new CoreBotCommands(chatInterface, bot).allCommands().forEach(bot::subscribe);
LOGGER.info("Glued Core Commands");

// Used to shut down the executor when the window is closed
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
dispose();
LOGGER.info("Junior Client - Bye Bye!");
}
});

}

public void startup() {
// fake the login??
scheduleQueryingThread();
bot.start();
gui.start();

LOGGER.info("Startup successfully completed");
}

Expand All @@ -90,9 +89,12 @@ private void scheduleQueryingThread() {
}, 3, 1, TimeUnit.SECONDS);
Logger.getAnonymousLogger().info("querying thread started");
}


/**
* Shuts down the executor
*/
public void dispose() {
LOGGER.info("Shutting down Executor");
executor.shutdownNow();
}

}
32 changes: 20 additions & 12 deletions src/main/java/de/vogel612/testclient_javabot/client/ClientGui.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package de.vogel612.testclient_javabot.client;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
Expand All @@ -17,18 +15,29 @@

import de.vogel612.testclient_javabot.client.controller.ChatRenderController;

public class ClientGui extends Application implements ChatWorker {
/**
* Class responsible for loading the FXML and creating an JavaFX test client scene
* for the JavaBot.
*
* @author itachi<<a href="mailto:abhinay_agarwal@live.com"
* >abhinay_agarwal@live.com</a>>
*
*/
public class ClientGui implements ChatWorker {

private static final Logger LOGGER = Logger.getLogger(ClientGui.class.getName());

private ChatRenderController controller;
private Stage stage;

public ClientGui() {
}

@Override
public void start(Stage stage) throws IOException {
/**
* Loads FXML and css, creates a scene and plugs it into the stage
* <br/>
*
* @throws IOException
*/
public void init(Stage stage) throws IOException {
LOGGER.info("Loading fxml and css");
this.stage = stage;
//Loading the FXML
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/ChatRender.fxml"));
Expand All @@ -39,17 +48,16 @@ public void start(Stage stage) throws IOException {
// Remove this to disable the dark theme
scene.getStylesheets().add(getClass().getResource("/style/darkTheme.css").toExternalForm());
stage.setScene(scene);
LOGGER.info("ClientGui loaded successfully");
}

/**
* {@see ChatWorker#start()}
*/
@Override
public void start() {
Platform.runLater(() -> {
stage.show();
controller.bindVvalue();
});
stage.show();
controller.bindVvalue();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
import de.vogel612.testclient_javabot.core.ChatMessageUtils;
import de.vogel612.testclient_javabot.core.MessageTracker;

/**
* Controller class for ChatRender FXML file
*
* @author itachi<<a href="mailto:abhinay_agarwal@live.com"
* >abhinay_agarwal@live.com</a>>
*
*/
public class ChatRenderController implements Initializable {

@FXML
Expand Down

0 comments on commit a8c9d24

Please sign in to comment.