package seedu.ezdo.ui;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Logger;

import org.controlsfx.control.StatusBar;

import com.google.common.eventbus.Subscribe;

import javafx.fxml.FXML;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Region;
import seedu.ezdo.commons.core.LogsCenter;
import seedu.ezdo.commons.events.model.EzDoChangedEvent;
import seedu.ezdo.commons.events.storage.EzDoDirectoryChangedEvent;
import seedu.ezdo.commons.util.FxViewUtil;

/**
 * A ui for the status bar that is displayed at the footer of the application.
 */
public class StatusBarFooter extends UiPart<Region> {

    private static final String MESSAGE_SAVE_LOCATION_TOOLTIP =
            "ezDo Directory Box\nDisplays the directory of ezDo data file.";
    private static final String MESSAGE_STATUS_BAR_TOOLTIP =
            "Status Box\nDisplays when ezDo data file is last updated.";

    private static final Logger logger = LogsCenter.getLogger(StatusBarFooter.class);

    @FXML
    private StatusBar syncStatus;
    @FXML
    private StatusBar saveLocationStatus;

    private static final String FXML = "StatusBarFooter.fxml";

    public StatusBarFooter(AnchorPane placeHolder, String saveLocation) {
        super(FXML);
        syncStatus.setTooltip(new Tooltip(MESSAGE_STATUS_BAR_TOOLTIP));
        saveLocationStatus.setTooltip(new Tooltip(MESSAGE_SAVE_LOCATION_TOOLTIP));
        addToPlaceholder(placeHolder);
        setSyncStatus("Not updated yet in this session");
        setSaveLocation(saveLocation);
        registerAsAnEventHandler(this);
    }

    private void addToPlaceholder(AnchorPane placeHolder) {
        FxViewUtil.applyAnchorBoundaryParameters(getRoot(), 0.0, 0.0, 0.0, 0.0);
        placeHolder.getChildren().add(getRoot());
    }

    private void setSaveLocation(String location) {
        this.saveLocationStatus.setText(location);
    }

    private void setSyncStatus(String status) {
        this.syncStatus.setText(status);
    }

    @Subscribe
    public void handleEzDoChangedEvent(EzDoChangedEvent ezce) {
        String lastUpdated = (new SimpleDateFormat("dd/MM/YYYY H:mm:ss")).format(new Date());
        logger.info(LogsCenter.getEventHandlingLogMessage(ezce, "Setting last updated status to " + lastUpdated));
        setSyncStatus("Last Updated: " + lastUpdated);
    }
  //@@author A0139248X
    /**
     * Updates the status bar footer to show the new ezdo storage file path and the last updated time
     */
    @Subscribe
    public void handleEzDoDirectoryChangedEvent(EzDoDirectoryChangedEvent ezce) {
        String lastUpdated = (new Date()).toString();
        logger.info(LogsCenter.getEventHandlingLogMessage(ezce, "Setting last updated status to " + lastUpdated));
        logger.info(LogsCenter.getEventHandlingLogMessage(ezce, "Setting save location to " + ezce.getPath()));
        setSyncStatus("Last Updated: " + lastUpdated);
        setSaveLocation(ezce.getPath());
    }
}

@@ -687,16 +687,497 @@
 ion%3E %7B%0A%0A
+    private static final Date CURRENT_DATE = new Date();%0A    private static final String MESSAGE_SET_SAVE_LOCATION = %22Setting save location to %22;%0A    private static final String MESSAGE_LAST_UPDATED = %22Last Updated: %22;%0A    private static final String MESSAGE_SET_LAST_UPDATED = %22Setting last updated status to %22;%0A    private static final String STATUS_BAR_DATE_FORMAT = %22dd/MM/YYYY H:mm:ss%22;%0A    private static final String MESSAGE_NOT_UPDATED = %22Not updated yet in this session%22;%0A
     priv
@@ -2007,41 +2007,27 @@
 tus(
-%22Not updated yet in this session%22
+MESSAGE_NOT_UPDATED
 );%0A 
@@ -2603,37 +2603,37 @@
        S
-tring lastUpdated
+impleDateFormat df
  = 
-(
 new Simp
@@ -2649,48 +2649,84 @@
 mat(
-%22dd/MM/YYYY H:mm:ss%22)).format(new Date()
+STATUS_BAR_DATE_FORMAT);%0A        String lastUpdated = df.format(CURRENT_DATE
 );%0A 
@@ -2792,41 +2792,32 @@
 ce, 
-%22Setting last updated status to %22
+MESSAGE_SET_LAST_UPDATED
  + l
@@ -2852,32 +2852,36 @@
 cStatus(
-%22Last Updated: %22
+MESSAGE_LAST_UPDATED
  + lastU
@@ -3166,20 +3166,20 @@
 d = 
-(new Date())
+CURRENT_DATE
 .toS
@@ -3255,41 +3255,32 @@
 ce, 
-%22Setting last updated status to %22
+MESSAGE_SET_LAST_UPDATED
  + l
@@ -3361,35 +3361,33 @@
 ce, 
-%22Setting save location to %22
+MESSAGE_SET_SAVE_LOCATION
  + e
@@ -3425,32 +3425,36 @@
 cStatus(
-%22Last Updated: %22
+MESSAGE_LAST_UPDATED
  + lastU

Extract magic strings in lines 25 to 30