Skip to content

Commit

Permalink
Merge pull request #131 from talesrune/master
Browse files Browse the repository at this point in the history
Local changes: Changed some of the magic numbers into constants
  • Loading branch information
talesrune authored Oct 16, 2019
2 parents 435b193 + d822306 commit 315a82a
Show file tree
Hide file tree
Showing 18 changed files with 313 additions and 230 deletions.
4 changes: 3 additions & 1 deletion src/main/java/duke/AddWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
public class AddWindow extends AnchorPane {
private Duke duke;
private static final int ZERO = 0;

private MainWindow mainWindow;

@FXML
Expand Down Expand Up @@ -62,7 +64,7 @@ public void setAddWindow(Duke d, MainWindow mainWindow) {
"Do After"
);
TaskList items = d.getTaskList();
for (int i = 0; i < items.size(); i++) {
for (int i = ZERO; i < items.size(); i++) {
cbExistingTask.getItems().add(items.get(i).getDescription());
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class Duke {

private BudgetStorage budgetStorage;
private BudgetList budgetList;
private static final int ZERO = 0;

/**
* Creates a duke to initialize storage, task list, and ui.
Expand Down Expand Up @@ -82,7 +83,7 @@ public Duke(String filePath1, String filePath2, String filePathForBudget, String
} catch (IOException e) {
ui.showLoadingError();
budgetList = new BudgetList();
budgetList.addToBudget(0);
budgetList.addToBudget(ZERO);
}
}

Expand Down
23 changes: 14 additions & 9 deletions src/main/java/duke/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public class MainWindow extends AnchorPane {

private Duke duke;

private static final int ZERO = 0;
private static final int ONE = 1;
private static final int TIMER_DELAY = 500;
private static final int VBOX_WIDTH = 200;

private Image userImage = new Image(this.getClass().getResourceAsStream("/images/myUser.png"));
private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/myBot.png"));

Expand All @@ -90,7 +95,7 @@ public void setDuke(Duke d) {
Timer timer = new Timer();
TimerTask exitDuke = new TimerTask() {
public void run() {
System.exit(0);
System.exit(ZERO);
}
};

Expand All @@ -113,7 +118,7 @@ private void handleUserInput() {
dialogContainer.getChildren().add(
DialogBox.getDukeDialog(response, dukeImage)
);
timer.schedule(exitDuke, new Date(System.currentTimeMillis() + 500));
timer.schedule(exitDuke, new Date(System.currentTimeMillis() + TIMER_DELAY));
} else {
response = duke.executeCommand(cmd);
dialogContainer.getChildren().add(
Expand Down Expand Up @@ -186,7 +191,7 @@ private void onMouseClickDone() {
//System.out.println("CURRENTLY on " + listT.getSelectionModel().getSelectedItem());
Task taskObj = listT.getSelectionModel().getSelectedItem();
TaskList items = duke.getTaskList();
int itemNumber = items.getIndex(taskObj) + 1;
int itemNumber = items.getIndex(taskObj) + ONE;
handleUserEvent("done " + itemNumber);
updateGui();
}
Expand All @@ -195,7 +200,7 @@ private void onMouseClickDone() {
private void onMouseClickDelete() {
Task taskObj = listT.getSelectionModel().getSelectedItem();
TaskList items = duke.getTaskList();
int itemNumber = items.getIndex(taskObj) + 1;
int itemNumber = items.getIndex(taskObj) + ONE;
handleUserEvent("delete " + itemNumber);
updateGui();
}
Expand Down Expand Up @@ -225,7 +230,7 @@ private void onMouseClickUpdate() {
private void onMouseClickOK() {
Task taskObj = listT.getSelectionModel().getSelectedItem();
TaskList items = duke.getTaskList();
int itemNumber = items.getIndex(taskObj) + 1;
int itemNumber = items.getIndex(taskObj) + ONE;
if (cbupdateType.getSelectionModel().getSelectedItem().equals("Description")) {
handleUserEvent("update " + itemNumber + " /desc " + tfnewDesc.getText().trim());
} else if (cbupdateType.getSelectionModel().getSelectedItem().equals("Date/Time")) {
Expand Down Expand Up @@ -269,10 +274,10 @@ private void cleanUp() {
@FXML
private void setVboxWidth(boolean isEnabled) {
if (isEnabled) {
vboxUpdate.setPrefWidth(200);
vboxUpdate.setPrefWidth(VBOX_WIDTH);
vboxUpdate.setVisible(true);
} else {
vboxUpdate.setPrefWidth(0);
vboxUpdate.setPrefWidth(ZERO);
vboxUpdate.setVisible(false);
}
}
Expand Down Expand Up @@ -306,7 +311,7 @@ private void updateGui() {
protected void listViewRefresh() {
listT.getItems().clear();
TaskList items = duke.getTaskList();
for (int i = 0; i < items.size(); i++) {
for (int i = ZERO; i < items.size(); i++) {
listT.getItems().add(items.get(i));
}
}
Expand All @@ -332,7 +337,7 @@ private void exitProgram() {
dialogContainer.getChildren().add(
DialogBox.getDukeDialog(response, dukeImage)
);
timer.schedule(exitDuke, new Date(System.currentTimeMillis() + 500));
timer.schedule(exitDuke, new Date(System.currentTimeMillis() + TIMER_DELAY));
} catch (DukeException e) {
response = Ui.showErrorMsgGui(e.getMessage());
dialogContainer.getChildren().add(
Expand Down
Loading

0 comments on commit 315a82a

Please sign in to comment.