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

[T5A2][T16-A3] Edward Tan Wei Chong #529

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Binary file added Resources/Pictures/book.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions doc/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* [Setting Up](#setting-up)
* [Design](#design)
* [Testing](#testing)
* [Appendix A: User Stories](#appendix-a--user-stories)
* [Appendix B: Use Cases](#appendix-b--use-cases)
* [Appendix C: Non Functional Requirements](#appendix-c--non-functional-requirements)
* [Appendix D: Gloassary](#appendix-d--glossary)
* [Appendix A: User Stories](#appendix-a-user-stories)
* [Appendix B: Use Cases](#appendix-b-use-cases)
* [Appendix C: Non Functional Requirements](#appendix-c-non-functional-requirements)
* [Appendix D: Gloassary](#appendix-d-glossary)

## Setting up

Expand Down
Binary file added doc/images/edited.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ReadOnlyPerson getPerson() {
}

@Override
public CommandResult execute() {
public CommandResult execute() throws Exception{
try {
addressBook.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
Expand All @@ -67,4 +67,9 @@ public CommandResult execute() {
}
}

@Override
public boolean isMutating() {
return true;
}

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public CommandResult execute() {
addressBook.clear();
return new CommandResult(MESSAGE_SUCCESS);
}

@Override
public boolean isMutating() {
return true;
}
}
8 changes: 7 additions & 1 deletion src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ public static String getMessageForPersonListShownSummary(List<? extends ReadOnly

/**
* Executes the command and returns the result.
* @throws Exception
*/
public abstract CommandResult execute();
public abstract CommandResult execute() throws Exception;

/**
* Returns true if command mutates the data in addressbook
*/
public abstract boolean isMutating();

/**
* Supplies the data the command will operate on.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/seedu/addressbook/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ public CommandResult execute() {
}
}


@Override
public boolean isMutating() {
return true;
}

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public CommandResult execute() {
return new CommandResult(MESSAGE_EXIT_ACKNOWEDGEMENT);
}

@Override
public boolean isMutating() {
return false;
}

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ private List<ReadOnlyPerson> getPersonsWithNameContainingAnyKeyword(Set<String>
return matchedPersons;
}

@Override
public boolean isMutating() {
return false;
}

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public class HelpCommand extends Command {
public CommandResult execute() {
return new CommandResult(MESSAGE_ALL_USAGES);
}

@Override
public boolean isMutating() {
return false;
}
}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/IncorrectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public CommandResult execute() {
return new CommandResult(feedbackToUser);
}

@Override
public boolean isMutating() {
return false;
}

}
6 changes: 6 additions & 0 deletions src/seedu/addressbook/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ public CommandResult execute() {
List<ReadOnlyPerson> allPersons = addressBook.getAllPersons().immutableListView();
return new CommandResult(getMessageForPersonListShownSummary(allPersons), allPersons);
}


@Override
public boolean isMutating() {
return false;
}
}
6 changes: 6 additions & 0 deletions src/seedu/addressbook/commands/ViewAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ public CommandResult execute() {
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
}


@Override
public boolean isMutating() {
return false;
}
}
6 changes: 6 additions & 0 deletions src/seedu/addressbook/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ public CommandResult execute() {
}
}


@Override
public boolean isMutating() {
return false;
}

}
4 changes: 3 additions & 1 deletion src/seedu/addressbook/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public CommandResult execute(String userCommandText) throws Exception {
private CommandResult execute(Command command) throws Exception {
command.setData(addressBook, lastShownList);
CommandResult result = command.execute();
storage.save(addressBook);
if(command.isMutating()) {
storage.save(addressBook);
}
return result;
}

Expand Down
15 changes: 15 additions & 0 deletions src/seedu/addressbook/ui/BrightTheme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.text-field {
-fx-font-size: 12pt;
-fx-font-family: "Consolas";
-fx-font-weight: bold;
-fx-text-fill: black;
-fx-control-inner-background: derive(#ffffff,20%);
}

.text-area {
-fx-background-color: white;
-fx-control-inner-background: white;
-fx-font-family: "Segoe UI Semibold";
-fx-font-size: 10pt;
-fx-padding: 5 5 5 5;
}
40 changes: 38 additions & 2 deletions src/seedu/addressbook/ui/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.image.Image;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import seedu.addressbook.logic.Logic;
import seedu.addressbook.Main;
Expand Down Expand Up @@ -41,14 +46,45 @@ private MainWindow createMainWindow(Stage stage, Stoppable mainApp) throws IOExc
* More info: http://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html#res_name_context
*/
loader.setLocation(Main.class.getResource("ui/mainwindow.fxml"));

VBox vBox = addMenuToVBox(loader);
stage.getIcons().add(new Image("file:Resources/Pictures/book.png"));
stage.setTitle(version);
stage.setScene(new Scene(loader.load(), INITIAL_WINDOW_WIDTH, INITIAL_WINDOW_HEIGHT));
stage.setScene(new Scene(vBox, INITIAL_WINDOW_WIDTH, INITIAL_WINDOW_HEIGHT));
stage.show();
MainWindow mainWindow = loader.getController();
mainWindow.setLogic(logic);
mainWindow.setMainApp(mainApp);
return mainWindow;
}

private VBox addMenuToVBox(FXMLLoader loader) throws IOException {
String darkTheme = Main.class.getResource("ui/DarkTheme.css").toExternalForm();
String brightTheme = Main.class.getResource("ui/BrightTheme.css").toExternalForm();

VBox vBox = loader.load();
MenuBar menuBar = (MenuBar) vBox.getChildren().get(0);
Menu menu = menuBar.getMenus().get(0);
CheckMenuItem dark = (CheckMenuItem) menu.getItems().get(0);
CheckMenuItem bright = (CheckMenuItem) menu.getItems().get(1);

dark.setOnAction((event) -> {
dark.setSelected(true);
bright.setSelected(false);
vBox.getStylesheets().remove(brightTheme);
if(!vBox.getStylesheets().contains(darkTheme)) {
vBox.getStylesheets().add(darkTheme);
}
});

bright.setOnAction((event) -> {
dark.setSelected(false);
bright.setSelected(true);
if(!vBox.getStylesheets().contains(brightTheme)) {
vBox.getStylesheets().add(brightTheme);
}
});

return vBox;
}

}
16 changes: 14 additions & 2 deletions src/seedu/addressbook/ui/mainwindow.fxml
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.CheckMenuItem?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.VBox?>

<VBox stylesheets="@/seedu/addressbook/ui/DarkTheme.css" alignment="center" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="seedu.addressbook.ui.MainWindow">
<VBox alignment="center" stylesheets="@/seedu/addressbook/ui/DarkTheme.css" xmlns="http://javafx.com/javafx/8.0.102" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seedu.addressbook.ui.MainWindow">

<children>
<MenuBar>
<menus>
<Menu mnemonicParsing="false" text="Theme">
<items>
<CheckMenuItem mnemonicParsing="false" selected="true" text="Dark" />
<CheckMenuItem mnemonicParsing="false" text="Bright" />
</items>
</Menu>
</menus>
</MenuBar>

<TextField fx:id="commandInput" onAction="#onCommand" VBox.vgrow="NEVER">
</TextField>
Expand Down
6 changes: 5 additions & 1 deletion test/java/seedu/addressbook/logic/LogicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.addressbook.data.person.*;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;
import seedu.addressbook.parser.Parser;
import seedu.addressbook.storage.StorageFile;

import java.util.*;
Expand Down Expand Up @@ -78,6 +79,7 @@ private void assertCommandBehavior(String inputCommand,
List<? extends ReadOnlyPerson> lastShownList) throws Exception {

//Execute the command
Command command = new Parser().parseCommand(inputCommand);
CommandResult r = logic.execute(inputCommand);

//Confirm the result contains the right data
Expand All @@ -90,7 +92,9 @@ private void assertCommandBehavior(String inputCommand,
//Confirm the state of data is as expected
assertEquals(expectedAddressBook, addressBook);
assertEquals(lastShownList, logic.getLastShownList());
assertEquals(addressBook, saveFile.load());
if(command.isMutating()){
assertEquals(addressBook, saveFile.load());
}
}


Expand Down