package seedu.address.ui;

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.layout.AnchorPane;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.events.model.AddressBookChangedEvent;
import seedu.address.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 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);
        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 handleAddressBookChangedEvent(AddressBookChangedEvent abce) {
        String lastUpdated = (new Date()).toString();
        logger.info(LogsCenter.getEventHandlingLogMessage(abce, "Setting last updated status to " + lastUpdated));
        setSyncStatus("Last Updated: " + lastUpdated);
    }
}

@@ -20,16 +20,40 @@
 ss.ui;%0A%0A
+import java.time.Clock;%0A
 import j
@@ -593,254 +593,943 @@
 %3E %7B%0A
-    private static final Logger logger = LogsCenter.getLogger(StatusBarFooter.class);%0A%0A    @FXML%0A    private StatusBar syncStatus;%0A    @FXML%0A    private StatusBar saveLocationStatus;%0A%0A    private static final String FXML = %22StatusBarFooter.fxml%22;
+%0A    /**%0A     * Used to generate time stamps.%0A     *%0A     * TODO: change clock to an instance variable.%0A     * We leave it as a static variable because manual dependency injection%0A     * will require passing down the clock reference all the way from MainApp,%0A     * but it should be easier once we have factories/DI frameworks.%0A     */%0A    private static Clock clock = Clock.systemDefaultZone();%0A%0A    private static final Logger logger = LogsCenter.getLogger(StatusBarFooter.class);%0A%0A    @FXML%0A    private StatusBar syncStatus;%0A    @FXML%0A    private StatusBar saveLocationStatus;%0A%0A    private static final String FXML = %22StatusBarFooter.fxml%22;%0A%0A    /**%0A     * Sets the clock used to determine the current time.%0A     */%0A    public static void setClock(Clock clock) %7B%0A        StatusBarFooter.clock = clock;%0A    %7D%0A%0A    /**%0A     * Returns the clock currently in use.%0A     */%0A    public static Clock getClock() %7B%0A        return clock;%0A    %7D
 %0A%0A  
@@ -2304,24 +2304,59 @@
 ent abce) %7B%0A
+        long now = clock.millis();%0A
         Stri
@@ -2372,17 +2372,16 @@
 dated = 
-(
 new Date
@@ -2381,17 +2381,19 @@
 ew Date(
-)
+now
 ).toStri

enable dependency injection of a Clock