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

Morph UI and Integrate Anakin components #77

Merged
merged 35 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
48ab62b
Shift command box and result display to bottom
yujiatay Oct 11, 2018
d9ec178
Update app icon to Anakin
yujiatay Oct 11, 2018
e53b69d
Update app title to Anakin
yujiatay Oct 11, 2018
c4f8374
Fix unit test for config
yujiatay Oct 11, 2018
036efd3
Add Anakin Card UI components
yujiatay Oct 14, 2018
d00e301
Add Anakin Card Change Event
yujiatay Oct 14, 2018
4a574a4
Add Anakin Deck UI components
yujiatay Oct 15, 2018
05893fc
Update docs for Anakin Card UI
yujiatay Oct 15, 2018
f749a94
Add FXMLs for Anakin Deck and Cards
yujiatay Oct 15, 2018
2c3349b
Add ability to getFilteredCardList to AnakinLogic
yujiatay Oct 15, 2018
5a4ea5d
Add SwitchPanelRequestEvent
yujiatay Oct 15, 2018
16e8ba3
Merge branch 'master' into adapt-ui
yujiatay Oct 16, 2018
47a0092
Add sample data for Anakin
yujiatay Oct 16, 2018
4d4f9ad
Update user preferences
yujiatay Oct 16, 2018
01e83d6
Update sample data
yujiatay Oct 16, 2018
b4383f6
Stack card and deck list onto list panel
yujiatay Oct 16, 2018
e4d42f0
Add ability to switch panel
yujiatay Oct 16, 2018
cb0da51
Fix New Deck Command
yujiatay Oct 16, 2018
3c9897d
Add concept of displayedCards
yujiatay Oct 16, 2018
5e14293
Change logging for card and deck list
yujiatay Oct 16, 2018
3aaf9c5
Merge branch 'master' into adapt-ui
yujiatay Oct 16, 2018
a5c7794
Merge branch 'master' into adapt-ui
yujiatay Oct 16, 2018
46cb1f8
Update Anakin sample data
yujiatay Oct 16, 2018
a81c583
Integrate Anakin components into MainApp
yujiatay Oct 16, 2018
611aba0
Remove SwitchPanelRequest Event
yujiatay Oct 16, 2018
3be1fb3
Update styles
yujiatay Oct 16, 2018
c0031af
Merge branch 'master' into adapt-ui
yujiatay Oct 16, 2018
1b3aa27
Clean up code
yujiatay Oct 16, 2018
11e8322
Fix checkstyle errors
yujiatay Oct 16, 2018
0855d5a
Update Anakin sample data
yujiatay Oct 16, 2018
42ea698
Update css
yujiatay Oct 16, 2018
51027ac
Fix style issue with card panel
yujiatay Oct 16, 2018
76d801d
Add javadoc comment
yujiatay Oct 16, 2018
0c7fa85
Do not display answer in Anakin card UI
yujiatay Oct 16, 2018
d43239e
Fix test errors in travis
yujiatay Oct 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 37 additions & 36 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
import seedu.address.commons.exceptions.DataConversionException;
import seedu.address.commons.util.ConfigUtil;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.logic.AnakinLogic;
import seedu.address.logic.AnakinLogicManager;
import seedu.address.model.Anakin;
import seedu.address.model.AnakinModel;
import seedu.address.model.AnakinModelManager;
import seedu.address.model.AnakinReadOnlyAnakin;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.AddressBookStorage;
import seedu.address.model.util.AnakinSampleDataUtil;
import seedu.address.storage.AnakinAnakinStorage;
import seedu.address.storage.AnakinStorage;
import seedu.address.storage.AnakinStorageManager;
import seedu.address.storage.AnakinXmlAnakinStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.Storage;
import seedu.address.storage.StorageManager;
import seedu.address.storage.UserPrefsStorage;
import seedu.address.storage.XmlAddressBookStorage;
import seedu.address.ui.Ui;
import seedu.address.ui.UiManager;

Expand All @@ -45,60 +45,61 @@ public class MainApp extends Application {
private static final Logger logger = LogsCenter.getLogger(MainApp.class);

protected Ui ui;
protected Logic logic;
protected Storage storage;
protected Model model;
protected Config config;
protected UserPrefs userPrefs;
protected AnakinLogic logic;
protected AnakinModel model;
protected AnakinStorage storage;


@Override
public void init() throws Exception {
logger.info("=============================[ Initializing AddressBook ]===========================");
logger.info("=============================[ Initializing Anakin ]===========================");
super.init();

AppParameters appParameters = AppParameters.parse(getParameters());
config = initConfig(appParameters.getConfigPath());

UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
userPrefs = initPrefs(userPrefsStorage);
AddressBookStorage addressBookStorage = new XmlAddressBookStorage(userPrefs.getAddressBookFilePath());
storage = new StorageManager(addressBookStorage, userPrefsStorage);

AnakinAnakinStorage anakinStorage = new AnakinXmlAnakinStorage(userPrefs.getAnakinFilePath());
storage = new AnakinStorageManager(anakinStorage, userPrefsStorage);

initLogging(config);

model = initModelManager(storage, userPrefs);

logic = new LogicManager(model);
logic = new AnakinLogicManager(model);

ui = new UiManager(logic, config, userPrefs);

initEventsCenter();
}

/**
* Returns a {@code ModelManager} with the data from {@code storage}'s address book and {@code userPrefs}. <br>
* The data from the sample address book will be used instead if {@code storage}'s address book is not found,
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
* Returns a {@code ModelManager} with the data from {@code storage}'s anakin and {@code userPrefs}. <br>
* The data from the sample anakin will be used instead if {@code storage}'s anakin is not found,
* or an empty anakin will be used instead if errors occur when reading {@code storage}'s anakin.
*/
private Model initModelManager(Storage storage, UserPrefs userPrefs) {
Optional<ReadOnlyAddressBook> addressBookOptional;
ReadOnlyAddressBook initialData;
private AnakinModel initModelManager(AnakinStorage storage, UserPrefs userPrefs) {
Optional<AnakinReadOnlyAnakin> anakinOptional;
AnakinReadOnlyAnakin initialData;
try {
addressBookOptional = storage.readAddressBook();
if (!addressBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample AddressBook");
anakinOptional = storage.readAnakin();
if (!anakinOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample Anakin");
}
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
initialData = anakinOptional.orElseGet(AnakinSampleDataUtil::getSampleAnakin);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
initialData = new AddressBook();
logger.warning("Data file not in the correct format. Will be starting with an empty Anakin");
initialData = new Anakin();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
initialData = new AddressBook();
logger.warning("Problem while reading from the file. Will be starting with an empty Anakin");
initialData = new Anakin();
}

return new ModelManager(initialData, userPrefs);
return new AnakinModelManager(initialData, userPrefs);
}

private void initLogging(Config config) {
Expand Down Expand Up @@ -159,7 +160,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
+ "Using default user prefs");
initializedPrefs = new UserPrefs();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
logger.warning("Problem while reading from the file. Will be starting with an empty Anakin");
initializedPrefs = new UserPrefs();
}

Expand All @@ -179,13 +180,13 @@ private void initEventsCenter() {

@Override
public void start(Stage primaryStage) {
logger.info("Starting AddressBook " + MainApp.VERSION);
logger.info("Starting Anakin " + MainApp.VERSION);
ui.start(primaryStage);
}

@Override
public void stop() {
logger.info("============================ [ Stopping Address Book ] =============================");
logger.info("============================ [ Stopping Anakin ] =============================");
ui.stop();
try {
storage.saveUserPrefs(userPrefs);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Config {
public static final Path DEFAULT_CONFIG_FILE = Paths.get("config.json");

// Config values customizable through config file
private String appTitle = "Address App";
private String appTitle = "Anakin";
private Level logLevel = Level.INFO;
private Path userPrefsFilePath = Paths.get("preferences.json");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package seedu.address.commons.events.ui;

import seedu.address.commons.events.BaseEvent;
import seedu.address.model.anakindeck.AnakinCard;

/**
* Represents a selection change in the Card List Panel
*/
public class CardPanelSelectionChangedEvent extends BaseEvent {


private final AnakinCard newSelection;

public CardPanelSelectionChangedEvent(AnakinCard newSelection) {
this.newSelection = newSelection;
}

@Override
public String toString() {
return getClass().getSimpleName();
}

public AnakinCard getNewSelection() {
return newSelection;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package seedu.address.commons.events.ui;

import seedu.address.commons.events.BaseEvent;
import seedu.address.model.anakindeck.AnakinDeck;

/**
* Represents a selection change in the Deck List Panel
*/
public class DeckPanelSelectionChangedEvent extends BaseEvent {


private final AnakinDeck newSelection;

public DeckPanelSelectionChangedEvent(AnakinDeck newSelection) {
this.newSelection = newSelection;
}

@Override
public String toString() {
return getClass().getSimpleName();
}

public AnakinDeck getNewSelection() {
return newSelection;
}
}
6 changes: 5 additions & 1 deletion src/main/java/seedu/address/logic/AnakinLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.anakindeck.AnakinCard;
import seedu.address.model.anakindeck.AnakinDeck;

/**
Expand All @@ -19,9 +20,12 @@ public interface AnakinLogic {
*/
CommandResult execute(String commandText) throws CommandException, ParseException;

/** Returns an unmodifiable view of the filtered list of persons */
/** Returns an unmodifiable view of the filtered list of decks */
ObservableList<AnakinDeck> getFilteredDeckList();

/** Returns an unmodifiable view of the filtered list of cards */
ObservableList<AnakinCard> getFilteredCardList();

/** Returns the list of input entered by the user, encapsulated in a {@code ListElementPointer} object */
ListElementPointer getHistorySnapshot();
}
7 changes: 6 additions & 1 deletion src/main/java/seedu/address/logic/AnakinLogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.logging.Logger;

import javafx.collections.ObservableList;

import seedu.address.commons.core.ComponentManager;
import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.anakincommands.AnakinCommand;
Expand All @@ -12,6 +11,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.AnakinModel;
import seedu.address.model.anakindeck.AnakinCard;
import seedu.address.model.anakindeck.AnakinDeck;

/**
Expand Down Expand Up @@ -46,6 +46,11 @@ public ObservableList<AnakinDeck> getFilteredDeckList() {
return model.getFilteredDeckList();
}

@Override
public ObservableList<AnakinCard> getFilteredCardList() {
return model.getFilteredCardList();
}

@Override
public ListElementPointer getHistorySnapshot() {
return new ListElementPointer(history.getHistory());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package seedu.address.logic.anakinparser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ANSWER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DECK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_FILEPATH;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION;

import java.util.stream.Stream;

import seedu.address.logic.anakincommands.AnakinNewDeckCommand;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.ArgumentMultimap;
import seedu.address.logic.parser.ArgumentTokenizer;
import seedu.address.logic.parser.Prefix;
Expand All @@ -31,25 +26,16 @@ public class AnakinNewDeckCommandParser implements AnakinParserInterface<AnakinN
*/
public AnakinNewDeckCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DECK,
PREFIX_ANSWER, PREFIX_QUESTION, PREFIX_FILEPATH);
ArgumentTokenizer.tokenize(args, PREFIX_NAME);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_DECK,
PREFIX_ANSWER, PREFIX_QUESTION, PREFIX_FILEPATH)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
AddCommand.MESSAGE_USAGE));
AnakinNewDeckCommand.MESSAGE_USAGE));
}

/*
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
*/

AnakinDeck deck = new AnakinDeck(new Name("Deck1")); //TO DO
Name name = AnakinParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
AnakinDeck deck = new AnakinDeck(name);

return new AnakinNewDeckCommand(deck);
}
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/seedu/address/model/Anakin.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class Anakin implements AnakinReadOnlyAnakin {
// Represent the current list of cards (when user get into a deck)
private AnakinUniqueCardList cards;

// Represents the list of cards displayed on the UI
private AnakinUniqueCardList displayedCards;

/*
* The 'unusual' code block below is an non-static initialization block, sometimes used to avoid duplication
* between constructors. See https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html
Expand All @@ -32,6 +35,8 @@ public class Anakin implements AnakinReadOnlyAnakin {
*/
{
decks = new AnakinUniqueDeckList();
cards = new AnakinUniqueCardList();
displayedCards = new AnakinUniqueCardList();
}

public Anakin() { }
Expand All @@ -54,13 +59,22 @@ public void setDecks(List<AnakinDeck> decks) {
this.decks.setDecks(decks);
}

/**
* Replaces the contents of the card list with {@code cards}.
* {@code cards} must not contain duplicate cards.
*/
public void setCards(List<AnakinCard> cards) {
this.cards.setCards(cards);
}

/**
* Resets the existing data of this {@code Anakin} with {@code newData}.
*/
public void resetData(AnakinReadOnlyAnakin newData) {
requireNonNull(newData);

setDecks(newData.getDeckList());
setCards(newData.getCardList());
}

//// navigating operations
Expand All @@ -72,6 +86,7 @@ public void getIntoDeck(AnakinDeck deck) {
requireNonNull(deck);
isInsideDeck = true;
cards = deck.getCards();
displayedCards.setCards(deck.getCards());
}

/**
Expand All @@ -82,7 +97,8 @@ public void getOutOfDeck() {
throw new DeckNotFoundException();
}
isInsideDeck = false;
cards = null;
cards = new AnakinUniqueCardList();
displayedCards.clear();
}

/**
Expand Down Expand Up @@ -151,6 +167,7 @@ public void addCard(AnakinCard c) {
throw new DeckNotFoundException();
}
cards.add(c);
displayedCards.setCards(cards);
}

/**
Expand All @@ -164,6 +181,7 @@ public void updateCard(AnakinCard target, AnakinCard editedCard) {
throw new DeckNotFoundException();
}
cards.setCard(target, editedCard);
displayedCards.setCards(cards);
}

/**
Expand All @@ -175,6 +193,7 @@ public void removeCard(AnakinCard key) {
throw new DeckNotFoundException();
}
cards.remove(key);
displayedCards.setCards(cards);
}

//// util methods
Expand All @@ -192,10 +211,7 @@ public ObservableList<AnakinDeck> getDeckList() {

@Override
public ObservableList<AnakinCard> getCardList() {
if (!isInsideDeck()) {
throw new DeckNotFoundException();
}
return cards.asUnmodifiableObservableList();
return displayedCards.asUnmodifiableObservableList();
}

@Override
Expand Down