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

[T6A1][F11-B1]Christopher Hendra #510

Open
wants to merge 1 commit 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
7 changes: 4 additions & 3 deletions src/seedu/addressbook/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import seedu.addressbook.data.AddressBook;
import seedu.addressbook.data.person.ReadOnlyPerson;
import seedu.addressbook.parser.Parser;
import seedu.addressbook.storage.Storage;
import seedu.addressbook.storage.StorageFile;

import java.util.Collections;
Expand All @@ -17,7 +18,7 @@
public class Logic {


private StorageFile storage;
private Storage storage;
private AddressBook addressBook;

/** The list of person shown to the user most recently. */
Expand All @@ -33,7 +34,7 @@ public Logic() throws Exception{
setAddressBook(addressBook);
}

void setStorage(StorageFile storage){
void setStorage(Storage storage){
this.storage = storage;
}

Expand All @@ -45,7 +46,7 @@ void setAddressBook(AddressBook addressBook){
* Creates the StorageFile object based on the user specified path (if any) or the default storage path.
* @throws StorageFile.InvalidStorageFilePathException if the target file path is incorrect.
*/
private StorageFile initializeStorage() throws StorageFile.InvalidStorageFilePathException {
private Storage initializeStorage() throws Storage.InvalidStorageFilePathException {
return new StorageFile();
}

Expand Down
36 changes: 36 additions & 0 deletions src/seedu/addressbook/storage/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.addressbook.storage;

import java.nio.file.Path;

import seedu.addressbook.data.AddressBook;
import seedu.addressbook.data.exception.IllegalValueException;

public abstract class Storage {


/**
* Signals that the given file path does not fulfill the storage filepath constraints.
*/
public static class InvalidStorageFilePathException extends IllegalValueException {
public InvalidStorageFilePathException(String message) {
super(message);
}
}

/**
* Signals that some error has occured while trying to convert and read/write data between the application
* and the storage file.
*/
public static class StorageOperationException extends Exception {
public StorageOperationException(String message) {
super(message);
}
}

public abstract void save(AddressBook addressBook)throws StorageOperationException;

public abstract AddressBook load() throws Exception;

public abstract String getPath();

}
24 changes: 2 additions & 22 deletions src/seedu/addressbook/storage/StorageFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Represents the file used to store address book data.
*/
public class StorageFile {
public class StorageFile extends Storage {

/** Default file path used if the user doesn't provide the file name. */
public static final String DEFAULT_STORAGE_FILEPATH = "addressbook.txt";
Expand All @@ -24,25 +24,6 @@ public class StorageFile {
* More info https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
*/

/**
* Signals that the given file path does not fulfill the storage filepath constraints.
*/
public static class InvalidStorageFilePathException extends IllegalValueException {
public InvalidStorageFilePathException(String message) {
super(message);
}
}

/**
* Signals that some error has occured while trying to convert and read/write data between the application
* and the storage file.
*/
public static class StorageOperationException extends Exception {
public StorageOperationException(String message) {
super(message);
}
}

private final JAXBContext jaxbContext;

public final Path path;
Expand Down Expand Up @@ -74,7 +55,7 @@ public StorageFile(String filePath) throws InvalidStorageFilePathException {
* Returns true if the given path is acceptable as a storage file.
* The file path is considered acceptable if it ends with '.txt'
*/
private static boolean isValidPath(Path filePath) {
private boolean isValidPath(Path filePath) {
return filePath.toString().endsWith(".txt");
}

Expand Down Expand Up @@ -144,5 +125,4 @@ public AddressBook load() throws StorageOperationException {
public String getPath() {
return path.toString();
}

}
17 changes: 17 additions & 0 deletions test/bin/seedu/addressbook/ui/DarkTheme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


.text-field {
-fx-font-size: 12pt;
-fx-font-family: "Consolas";
-fx-font-weight: bold;
-fx-text-fill: yellow;
-fx-control-inner-background: derive(#1d1d1d,20%);
}

.text-area {
-fx-background-color: black;
-fx-control-inner-background: black;
-fx-font-family: "Segoe UI Semibold";
-fx-font-size: 10pt;
-fx-padding: 5 5 5 5;
}
20 changes: 20 additions & 0 deletions test/bin/seedu/addressbook/ui/mainwindow.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<?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">

<children>

<TextField fx:id="commandInput" onAction="#onCommand" VBox.vgrow="NEVER">
</TextField>

<TextArea fx:id="outputConsole" editable="false" wrapText="true" VBox.vgrow="ALWAYS">
</TextArea>

</children>

</VBox>
2 changes: 1 addition & 1 deletion test/java/seedu/addressbook/storage/StorageFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import seedu.addressbook.data.person.Phone;
import seedu.addressbook.data.tag.Tag;
import seedu.addressbook.data.tag.UniqueTagList;
import seedu.addressbook.storage.StorageFile.StorageOperationException;
import seedu.addressbook.storage.Storage.StorageOperationException;
import static seedu.addressbook.util.TestUtil.assertTextFilesEqual;

public class StorageFileTest {
Expand Down
6 changes: 6 additions & 0 deletions test/test/data/StorageFileTest/InvalidData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AddressBook>
<persons>
<invalid>data</invalid>
</persons>
</AddressBook>
19 changes: 19 additions & 0 deletions test/test/data/StorageFileTest/ValidData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AddressBook>
<persons>
<name>John Doe</name>
<phone isPrivate="false">98765432</phone>
<email isPrivate="false">[email protected]</email>
<address isPrivate="false">John street, block 123, #01-01</address>
</persons>
<persons>
<name>Betsy Crowe</name>
<phone isPrivate="true">1234567</phone>
<email isPrivate="false">[email protected]</email>
<address isPrivate="true">Newgate Prison</address>
<tagged>friend</tagged>
<tagged>criminal</tagged>
</persons>
<tags>friend</tags>
<tags>criminal</tags>
</AddressBook>