package jfdi.ui;

import com.google.common.eventbus.EventBus;

import jfdi.logic.ControlCenter;



public class UI implements IUserInterface {

    private static final String UI_MESSAGE_INIT = "Initializing UI...";
    private static final String UI_MESSAGE_INITED = "Initialization Completed!";
    private static final String UI_MESSAGE_WELCOME = "J.F.D.I.: Hello! :) What can I do for you?";
    private static final String UI_MESSAGE_USERCMD = "You said: %1$s";
    private static final String UI_MESSAGE_RESPONSE = "J.F.D.I.: %1$s";
    private static final String UI_MESSAGE_WARNING = "Warning: %1$s";
    private static final String UI_MESSAGE_QUIT = "Bye Bye! See you next time! :)";

    private static EventBus eventBus = new EventBus();

    ControlCenter logic;
    private MainController controller;

    public UI() {
        // what to do for constructor?
    }

    @Override
    public void init() {

        showToUser(UI_MESSAGE_INIT);

        // Initialize Logic
        logic = ControlCenter.getInstance();

        // Error: if fail to get data (logic issue, cannot find storage), query user for filename

        showToUser(UI_MESSAGE_INITED);
    }

    @Override
    public void displayWelcome() {
        // Create and display a default view
        //controller.clearFb();
        showToUser(UI_MESSAGE_WELCOME);

        // display default list
    }

    @Override
    public void processInput(String input) {

        // Clear controller first
        controller.clearCmdArea();
        controller.clearFb();

        // Show user what the command recognized in the feedback area
        controller.displayFb(String.format(UI_MESSAGE_USERCMD, input));

        // Relay user input to logic and wait for reply
        logic.handleInput(input);

        /*// Update UI according to reply from logic
        switch (feedback) {
            case "QUIT":
                doQuit();
                break;
            default:
                doUserCmd();
                break;
        }*/
    }

    @Override
    public void setController(MainController controller) {
        this.controller = controller;
    }

    /***************************
     *** LEVEL 1 Abstraction ***
     ***************************/

    private void showToUser(String string) {
        System.out.println(string);
    }

    private void doQuit() {
        showToUser(UI_MESSAGE_QUIT);
        System.exit(0);
    }

    private void doUserCmd() {
        CommandHandler cmdHandler = new CommandHandler();
        eventBus.register(cmdHandler);
    }

    public static EventBus getEventBus() {
        return eventBus;
    }
}

@@ -11,16 +11,50 @@
 di.ui;%0A%0A
+import jfdi.logic.ControlCenter;%0A%0A
 import c
@@ -94,44 +94,8 @@
 s;%0A%0A
-import jfdi.logic.ControlCenter;%0A%0A%0A%0A
 publ
@@ -743,34 +743,8 @@
 s();
-%0A%0A    ControlCenter logic;
 %0A   
@@ -780,16 +780,50 @@
 oller;%0A%0A
+    private ControlCenter logic;%0A%0A
     publ
@@ -1109,16 +1109,27 @@
 ), query
+%0A        //
  user fo
@@ -1290,16 +1290,17 @@
       //
+ 
 controll
@@ -1797,16 +1797,28 @@
       /*
+%0A         * 
 // Updat
@@ -1851,24 +1851,16 @@
 om logic
-%0A       
  switch 
@@ -1871,16 +1871,21 @@
 dback) %7B
+ case
 %0A       
@@ -1890,23 +1890,17 @@
     
-   case
+*
  %22QUIT%22:
 %0A   
@@ -1899,130 +1899,56 @@
 IT%22:
-%0A                doQuit();%0A                break;%0A            default:%0A                doUserCmd();%0A               
+ doQuit(); break; default: doUserCmd();
  break;
+ %7D
 %0A   
@@ -1952,17 +1952,17 @@
         
-%7D
+ 
 */%0A    %7D

Refactor UI.java