forked from nus-cs2103-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 5
/
StatusBarFooter.java
83 lines (66 loc) · 2.5 KB
/
StatusBarFooter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package seedu.address.ui;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Clock;
import java.util.Date;
import java.util.logging.Logger;
import org.controlsfx.control.StatusBar;
import com.google.common.eventbus.Subscribe;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.events.model.AddressBookChangedEvent;
/**
* A ui for the status bar that is displayed at the footer of the application.
*/
public class StatusBarFooter extends UiPart<Region> {
public static final String SYNC_STATUS_INITIAL = "Not updated yet in this session";
public static final String SYNC_STATUS_UPDATED = "Last Updated: %s";
/**
* Used to generate time stamps.
*
* TODO: change clock to an instance variable.
* We leave it as a static variable because manual dependency injection
* will require passing down the clock reference all the way from MainApp,
* but it should be easier once we have factories/DI frameworks.
*/
private static Clock clock = Clock.systemDefaultZone();
private static final Logger logger = LogsCenter.getLogger(StatusBarFooter.class);
private static final String FXML = "StatusBarFooter.fxml";
@FXML
private StatusBar syncStatus;
@FXML
private StatusBar saveLocationStatus;
public StatusBarFooter(Path saveLocation) {
super(FXML);
setSyncStatus(SYNC_STATUS_INITIAL);
setSaveLocation(Paths.get(".").resolve(saveLocation).toString());
registerAsAnEventHandler(this);
}
/**
* Sets the clock used to determine the current time.
*/
public static void setClock(Clock clock) {
StatusBarFooter.clock = clock;
}
/**
* Returns the clock currently in use.
*/
public static Clock getClock() {
return clock;
}
private void setSaveLocation(String location) {
Platform.runLater(() -> saveLocationStatus.setText(location));
}
private void setSyncStatus(String status) {
Platform.runLater(() -> syncStatus.setText(status));
}
@Subscribe
public void handleAddressBookChangedEvent(AddressBookChangedEvent abce) {
long now = clock.millis();
String lastUpdated = new Date(now).toString();
logger.info(LogsCenter.getEventHandlingLogMessage(abce, "Setting last updated status to " + lastUpdated));
setSyncStatus(String.format(SYNC_STATUS_UPDATED, lastUpdated));
}
}