Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some refactoring for the ui code #215

Merged
merged 8 commits into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/main/java/seedu/agendum/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class CommandBox extends UiPart {

@FXML
private TextField commandTextField;
private CommandResult mostRecentResult;

public static CommandBox load(Stage primaryStage, AnchorPane commandBoxPlaceholder, StackPane messagePlaceHolder,
ResultPopUp resultPopUp, Logic logic) {
Expand All @@ -58,7 +57,7 @@ public static CommandBox load(Stage primaryStage, AnchorPane commandBoxPlacehold
return commandBox;
}

public void configure(ResultPopUp resultPopUp, StackPane messagePlaceHolder, Logic logic) {
private void configure(ResultPopUp resultPopUp, StackPane messagePlaceHolder, Logic logic) {
this.resultPopUp = resultPopUp;
this.messagePlaceHolder = messagePlaceHolder;
this.logic = logic;
Expand Down Expand Up @@ -90,7 +89,7 @@ public void setPlaceholder(AnchorPane pane) {
}

/**
* Executes the command and saves this command to history if comamnd input
* Executes the command and saves this command to history if command input
* is changed
*/
@FXML
Expand All @@ -110,7 +109,7 @@ private void handleCommandInputChanged() {
*/

setStyleToIndicateCorrectCommand();
mostRecentResult = logic.execute(previousCommandTest);
CommandResult mostRecentResult = logic.execute(previousCommandTest);
if(!previousCommandTest.toLowerCase().equals(HELP_COMMAND)) {
resultPopUp.postMessage(mostRecentResult.feedbackToUser);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/agendum/ui/CommandBoxHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public class CommandBoxHistory {
private static final String NEXT_QUERY = "next";
private static final String EMPTY_QUERY = "";
private static final String EMPTY_COMMAND = "";
private LinkedList<String> pastCommands;
private final LinkedList<String> pastCommands;
private ListIterator<String> iterator;
private String lastCommand = "";
private String lastQuery = EMPTY_QUERY;

private static CommandBoxHistory instance = null;

protected CommandBoxHistory() {
private CommandBoxHistory() {
pastCommands = new LinkedList<>();
iterator = pastCommands.listIterator();
}
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/seedu/agendum/ui/CompletedTasksPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javafx.animation.PauseTransition;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.scene.control.Control;
import javafx.scene.control.ListCell;
Expand Down Expand Up @@ -35,20 +35,15 @@ public String getFxmlPath() {
@Override
protected void setConnections(ObservableList<ReadOnlyTask> taskList) {
mainTaskList = taskList;
completedTasksListView.setItems(taskList.filtered(task -> task.isCompleted()));
completedTasksListView.setItems(taskList.filtered(ReadOnlyTask::isCompleted));
completedTasksListView.setCellFactory(listView -> new CompletedTasksListViewCell());
configure();
}

private void configure() {
selectionModel = completedTasksListView.getSelectionModel();
completedTasksListView.setSelectionModel(null);
completedTasksListView.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
event.consume();
}
});
completedTasksListView.addEventFilter(MouseEvent.MOUSE_PRESSED, Event::consume);
}

public void scrollTo(Task task, boolean hasMultipleTasks) {
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/seedu/agendum/ui/FloatingTasksPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javafx.animation.PauseTransition;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.scene.control.Control;
import javafx.scene.control.ListCell;
Expand Down Expand Up @@ -43,12 +43,7 @@ protected void setConnections(ObservableList<ReadOnlyTask> taskList) {
private void configure() {
selectionModel = floatingTasksListView.getSelectionModel();
floatingTasksListView.setSelectionModel(null);
floatingTasksListView.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
event.consume();
}
});
floatingTasksListView.addEventFilter(MouseEvent.MOUSE_PRESSED, Event::consume);
}

public void scrollTo(Task task, boolean hasMultipleTasks) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/agendum/ui/HelpWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class HelpWindow extends UiPart {
private static final double COMMAND_COLUMN_WIDTH = 0.2;
private static final double DESCRIPTION_COLUMN_WIDTH = 0.4;
private static final double FORMAT_COLUMN_WIDTH = 0.4;
private ObservableList<Map<CommandColumns, String>> commandList = FXCollections.observableArrayList();
private final ObservableList<Map<CommandColumns, String>> commandList = FXCollections.observableArrayList();

private enum CommandColumns {
COMMAND, DESCRIPTION, FORMAT
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/seedu/agendum/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public String getFxmlPath() {

public static MainWindow load(Stage primaryStage, Config config, UserPrefs prefs, Logic logic) {
MainWindow mainWindow = UiPartLoader.loadUiPart(primaryStage, new MainWindow());
mainWindow.configure(config.getAppTitle(), config.getToDoListName(), config, prefs, logic);
mainWindow.configure(config.getAppTitle(), config, prefs, logic);
return mainWindow;
}

private void configure(String appTitle, String toDoListName, Config config, UserPrefs prefs, Logic logic) {
private void configure(String appTitle, Config config, UserPrefs prefs, Logic logic) {

this.logic = logic;
this.config = config;
Expand Down Expand Up @@ -143,16 +143,13 @@ public void handle(KeyEvent evt) {
* command or showing help page
*/
private void configureEscape() {
scene.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent evt) {
if (evt.getCode().equals(KeyCode.ESCAPE) && messagePlaceHolder.getChildren().contains(helpWindow)) {
closeHelpWindow();
} else if(evt.getCode().equals(KeyCode.ESCAPE) && messagePlaceHolder.getChildren().size() > 0) {
messagePlaceHolder.getChildren().clear();
messagePlaceHolder.setMaxHeight(0);
logic.execute(LIST_COMMAND);
}
scene.addEventFilter(KeyEvent.KEY_PRESSED, evt -> {
if (evt.getCode().equals(KeyCode.ESCAPE) && messagePlaceHolder.getChildren().contains(helpWindow)) {
closeHelpWindow();
} else if(evt.getCode().equals(KeyCode.ESCAPE) && messagePlaceHolder.getChildren().size() > 0) {
messagePlaceHolder.getChildren().clear();
messagePlaceHolder.setMaxHeight(0);
logic.execute(LIST_COMMAND);
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/agendum/ui/ResultPopUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class ResultPopUp extends UiPart {
private static Stage root;
private AnchorPane mainPane;
private Stage dialogStage;
private PauseTransition delay = new PauseTransition(Duration.seconds(5));

private final PauseTransition delay = new PauseTransition(Duration.seconds(5));

@FXML
private Label resultDisplay;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void postMessage(String message) {
show();
}

public void show() {
private void show() {
dialogStage.setOpacity(1.0);
dialogStage.sizeToScene();
dialogStage.show();
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/seedu/agendum/ui/StatusBarFooter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public class StatusBarFooter extends UiPart {
private static final String NOT_UPDATED_STATUS = "Not updated yet in this session";
private StatusBar syncStatus;
private StatusBar saveLocationStatus;
private Label timeStatus;


private GridPane mainPane;

Expand All @@ -58,7 +56,7 @@ public static StatusBarFooter load(Stage stage, AnchorPane placeHolder, String s
return statusBarFooter;
}

public void configure(String saveLocation) {
private void configure(String saveLocation) {
addMainPane();
addSyncStatus();
setSyncStatus(NOT_UPDATED_STATUS);
Expand Down Expand Up @@ -95,7 +93,7 @@ private void addSyncStatus() {

//@@author A0148031R
private void addTimeStatus() {
this.timeStatus = new DigitalClock();
Label timeStatus = new DigitalClock();
FxViewUtil.applyAnchorBoundaryParameters(timeStatus, 0.0, 0.0, 0.0, 0.0);
timeStatus.setAlignment(Pos.CENTER);
timeStatusBarPane.getChildren().add(timeStatus);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/agendum/ui/TaskCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void initialize() {
}
}

public String formatTime(String dateTimePattern, String prefix, Optional<LocalDateTime> dateTime) {
private String formatTime(String dateTimePattern, String prefix, Optional<LocalDateTime> dateTime) {

StringBuilder sb = new StringBuilder();
DateTimeFormatter format = DateTimeFormatter.ofPattern(dateTimePattern);
Expand All @@ -106,7 +106,7 @@ public String formatTime(String dateTimePattern, String prefix, Optional<LocalDa
return sb.toString();
}

public String formatTaskTime(ReadOnlyTask task) {
private String formatTaskTime(ReadOnlyTask task) {

StringBuilder timeStringBuilder = new StringBuilder();

Expand All @@ -127,7 +127,7 @@ public String formatTaskTime(ReadOnlyTask task) {
return timeStringBuilder.toString();
}

public String formatUpdatedTime(ReadOnlyTask task) {
private String formatUpdatedTime(ReadOnlyTask task) {
StringBuilder timeStringBuilder = new StringBuilder();
if (task.hasTime()) {
timeStringBuilder.append("\n");
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/seedu/agendum/ui/UpcomingTasksPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import javafx.animation.PauseTransition;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.scene.control.Control;
import javafx.scene.control.ListCell;
Expand Down Expand Up @@ -44,12 +44,7 @@ protected void setConnections(ObservableList<ReadOnlyTask> taskList) {
private void configure() {
selectionModel = upcomingTasksListView.getSelectionModel();
upcomingTasksListView.setSelectionModel(null);
upcomingTasksListView.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
event.consume();
}
});
upcomingTasksListView.addEventFilter(MouseEvent.MOUSE_PRESSED, Event::consume);
}

public void scrollTo(Task task, boolean hasMultipleTasks) {
Expand Down