diff --git a/.project b/.project index 18f57e9ae6ac..9a3c79b5d72f 100644 --- a/.project +++ b/.project @@ -1,7 +1,7 @@ - addressbook-level4 - Project addressbook-level4 created by Buildship. + main + Project main created by Buildship. @@ -26,24 +26,4 @@ org.eclipse.jdt.core.javanature net.sf.eclipsecs.core.CheckstyleNature - - - 1476898072165 - - 26 - - org.eclipse.ui.ide.multiFilter - 1.0-projectRelativePath-matches-false-false-build - - - - 1476898072188 - - 26 - - org.eclipse.ui.ide.multiFilter - 1.0-projectRelativePath-matches-false-false-.gradle - - - diff --git a/.simplecov b/.simplecov new file mode 100644 index 000000000000..f01404882382 --- /dev/null +++ b/.simplecov @@ -0,0 +1,7 @@ +require 'simplecov' +require 'coveralls' + +SimpleCov.formatter = Coveralls::SimpleCov::Formatter +SimpleCov.start do + add_filter 'collated/' +end diff --git a/Collate-TUI.jar b/Collate-TUI.jar new file mode 100644 index 000000000000..2b9e032106dd Binary files /dev/null and b/Collate-TUI.jar differ diff --git a/README.md b/README.md index b20684a1eac0..e492ced55ae9 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,14 @@ -# Address Book (Level 4) +# Task Manager + +[![Build Status](https://travis-ci.org/CS2103JAN2017-T11-B3/main.svg?branch=master)](https://travis-ci.org/CS2103JAN2017-T11-B3/main) +[![Build status](https://ci.appveyor.com/api/projects/status/7sjb96y2061vwddh/branch/master?svg=true)](https://ci.appveyor.com/project/tylerrocha/main/branch/master) +[![Coverage Status](https://coveralls.io/repos/github/CS2103JAN2017-T11-B3/main/badge.svg?branch=master)](https://coveralls.io/github/CS2103JAN2017-T11-B3/main?branch=master) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/0e7b2134ae32403ea022773f59c76332)](https://www.codacy.com/app/tylerrocha/main?utm_source=github.com&utm_medium=referral&utm_content=CS2103JAN2017-T11-B3/main&utm_campaign=Badge_Grade) -[![Build Status](https://travis-ci.org/se-edu/addressbook-level4.svg?branch=master)](https://travis-ci.org/se-edu/addressbook-level4) -[![Build status](https://ci.appveyor.com/api/projects/status/3boko2x2vr5cc3w2?svg=true)](https://ci.appveyor.com/project/damithc/addressbook-level4) -[![Coverage Status](https://coveralls.io/repos/github/se-edu/addressbook-level4/badge.svg?branch=master)](https://coveralls.io/github/se-edu/addressbook-level4?branch=master) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/fc0b7775cf7f4fdeaf08776f3d8e364a)](https://www.codacy.com/app/damith/addressbook-level4?utm_source=github.com&utm_medium=referral&utm_content=se-edu/addressbook-level4&utm_campaign=Badge_Grade)
-* This is a desktop Address Book application. It has a GUI but most of the user interactions happen using - a CLI (Command Line Interface). -* It is a Java sample application intended for students learning Software Engineering while using Java as - the main programming language. -* It is **written in OOP fashion**. It provides a **reasonably well-written** code example that is - **significantly bigger** (around 6 KLoC)than what students usually write in beginner-level SE modules. -* What's different from [level 3](https://github.com/se-edu/addressbook-level3): - * A more sophisticated GUI that includes a list panel and an in-built Browser. - * More test cases, including automated GUI testing. - * Support for *Build Automation* using Gradle and for *Continuous Integration* using Travis CI. +* This is a desktop Task Manager application created for CS2103 Software Engineering at the National University of Singapore. It has a GUI but most of the user interactions happen using a CLI (Command Line Interface). #### Site Map @@ -29,8 +21,9 @@ #### Acknowledgements -* Some parts of this sample application were inspired by the excellent +* Some parts of this sample application were inspired by this [Java FX tutorial](http://code.makery.ch/library/javafx-8-tutorial/) by *Marco Jakob*. +* This project was built off an address book application by SE-EDU and can be found at https://github.com/se-edu/ #### Licence : [MIT](LICENSE) diff --git a/_config.yml b/_config.yml index 277f1f2c510d..72d781d70d10 100644 --- a/_config.yml +++ b/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-cayman +theme: jekyll-theme-tactile diff --git a/blooper b/blooper new file mode 100644 index 000000000000..93f65208e5e4 --- /dev/null +++ b/blooper @@ -0,0 +1,24 @@ + + + + Say so long to Fiona Kunz + 1 + false + 0 + owesMoney + friends + + false + + 02/03/2100 + 2100-03-02T00:00:00+08:00 + + + 01/02/2017 + 2017-02-01T00:00:00+08:00 + + + + owesMoney + friends + diff --git a/build.gradle b/build.gradle index d5a0c00943ee..298d1d3a0622 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ plugins { } // Specifies the entry point of the application -mainClassName = 'seedu.address.MainApp' +mainClassName = 'seedu.task.MainApp' allprojects { apply plugin: 'idea' @@ -39,7 +39,7 @@ allprojects { jacksonVersion = '2.7.0' jacksonDataTypeVersion = '2.7.4' junitVersion = '4.12' - testFxVersion = '4.0.+' + testFxVersion = '4.0.5-alpha' monocleVersion = '1.8.0_20' checkstyleVersion = '7.1.2' diff --git a/collate b/collate new file mode 100755 index 000000000000..9c4bf6f0e1d0 --- /dev/null +++ b/collate @@ -0,0 +1,5 @@ +java -jar Collate-TUI.jar collate from src/main to collated/main include java, fxml, css + +java -jar Collate-TUI.jar collate from src/test to collated/test include java + +java -jar Collate-TUI.jar collate from unused to collated/unused include java, fxml, css diff --git a/collated/main/A0113795Y.md b/collated/main/A0113795Y.md new file mode 100644 index 000000000000..ffab2a27c8bf --- /dev/null +++ b/collated/main/A0113795Y.md @@ -0,0 +1,446 @@ +# A0113795Y +###### /java/seedu/task/logic/commands/CompleteCommand.java +``` java +package seedu.task.logic.commands; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.logging.Logger; + +import seedu.task.commons.core.LogsCenter; +import seedu.task.commons.core.Messages; +import seedu.task.commons.core.UnmodifiableObservableList; +import seedu.task.commons.exceptions.IllegalValueException; +import seedu.task.logic.commands.exceptions.CommandException; +import seedu.task.logic.parser.ParserUtil; +import seedu.task.model.tag.UniqueTagList; +import seedu.task.model.task.Description; +import seedu.task.model.task.EditTaskDescriptor; +import seedu.task.model.task.Priority; +import seedu.task.model.task.ReadOnlyTask; +import seedu.task.model.task.RecurringFrequency; +import seedu.task.model.task.Task; +import seedu.task.model.task.Timing; +import seedu.task.model.task.UniqueTaskList; + +/** + * Change the task status to completed + */ + +public class CompleteCommand extends Command { + private static final Logger logger = LogsCenter.getLogger(CompleteCommand.class); + public static final String COMMAND_WORD = "complete"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Mark the task identified by the index number." + + "used in the last task lisitng as completed.\n" + + "Parameter: INDEX (must be a positive integer)\n" + + "Example: " + COMMAND_WORD + " 2"; + + public static final String MESSAGE_COMPLETE_TASK_SUCCESS = "Completed task: %1$s"; + public static final String MESSAGE_DUPLICATE_TAG = "This tag already exists in the tag list"; + public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task manager."; + public static final String MESSAGE_TAG_CONSTRAINTS = "Tags names should be alphanumeric"; + public static final String MESSAGE_NULL_TIMING = + "Both the start and end timings must be specified for a recurring task"; + + public final int targetIndex; + public final EditTaskDescriptor completeTaskDescriptor; + + public CompleteCommand(int targetIndex) { + assert targetIndex > 0; + + this.targetIndex = targetIndex - 1; + this.completeTaskDescriptor = new EditTaskDescriptor(); + + List list = new ArrayList<>(); + list.add("complete"); + try { + this.completeTaskDescriptor.setTags(parseTagsForComplete(ParserUtil.toSet(Optional.of(list)))); + } catch (IllegalValueException e) { + e.printStackTrace(); + } + } +``` +###### /java/seedu/task/logic/commands/CompleteCommand.java +``` java + /** + * Creates and returns a {@code Task} with the details of {@code taskToComplete} + * edited with {@code editTaskDescriptor}. + */ + private static Task createCompletedTask(ReadOnlyTask taskToComplete, + EditTaskDescriptor editTaskDescriptor) throws CommandException { + assert taskToComplete != null; + + Description updatedDescription = editTaskDescriptor.getDescription().orElseGet(taskToComplete::getDescription); + Priority updatedPriority = editTaskDescriptor.getPriority().orElseGet(taskToComplete::getPriority); + Timing updatedStartDate = editTaskDescriptor.getStartTiming().orElseGet(taskToComplete::getStartTiming); + Timing updatedEndDate = editTaskDescriptor.getEndTiming().orElseGet(taskToComplete::getEndTiming); + UniqueTagList updatedTags = editTaskDescriptor.getTags().orElseGet(taskToComplete::getTags); + boolean updatedRecurring = editTaskDescriptor.isRecurring().orElseGet(taskToComplete::isRecurring); + RecurringFrequency updatedFrequency = editTaskDescriptor.getFrequency().orElseGet(taskToComplete::getFrequency); + + updatedStartDate.setTiming(updatedStartDate.toString()); + updatedEndDate.setTiming(updatedEndDate.toString()); + + Task ret; + try { + ret = new Task(updatedDescription, updatedPriority, updatedStartDate, + updatedEndDate, updatedTags, updatedRecurring, updatedFrequency); + } catch (IllegalValueException e) { + throw new CommandException(MESSAGE_NULL_TIMING); + } + ret.setComplete(); + return ret; + } + + /** + * Parses {@code Collection tags} into an {@code Optional} if {@code tags} is non-empty. + * If {@code tags} contain only one element which is an empty string, it will be parsed into a + * {@code Optional} containing zero tags. + */ + private Optional parseTagsForComplete(Collection tags) throws IllegalValueException { + Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; + return Optional.of(ParserUtil.parseTags(tagSet)); + } +} +``` +###### /java/seedu/task/logic/commands/PrioritizeCommand.java +``` java +package seedu.task.logic.commands; + +import java.util.Optional; +import java.util.logging.Logger; + +import seedu.task.commons.core.LogsCenter; +import seedu.task.commons.core.Messages; +import seedu.task.commons.core.UnmodifiableObservableList; +import seedu.task.commons.exceptions.IllegalValueException; +import seedu.task.logic.commands.exceptions.CommandException; +import seedu.task.model.tag.UniqueTagList; +import seedu.task.model.task.Description; +import seedu.task.model.task.EditTaskDescriptor; +import seedu.task.model.task.Priority; +import seedu.task.model.task.ReadOnlyTask; +import seedu.task.model.task.RecurringFrequency; +import seedu.task.model.task.Task; +import seedu.task.model.task.Timing; +import seedu.task.model.task.UniqueTaskList; + +public class PrioritizeCommand extends Command { + private static final Logger logger = LogsCenter.getLogger(PrioritizeCommand.class); + public static final String COMMAND_WORD = "prioritize"; + public static final String MESSAGE_PRIORITY_CONSTRAINTS = "Task priority should be between 1-3"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Change the priority of the task identified " + + "by the index number used in the last task lisitng as completed.\n" + + "Parameter: INDEX (must be a positive integer) NEW_PRIORITY_LEVEL (integer from 1 to 3)\n" + + "Example: " + COMMAND_WORD + " 2" + " 1"; + + public static final String MESSAGE_PRIORITIZE_TASK_SUCCESS = "Prioritized task: %1$s"; + public static final String MESSAGE_DUPLICATE_TAG = "This tag already exists in the tag list"; + public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task manager."; + public static final String MESSAGE_TAG_CONSTRAINTS = "Tags names should be alphanumeric"; + public static final String MESSAGE_NULL_TIMING = + "Both the start and end timings must be specified for a recurring task"; + + public final int targetIndex; + public final EditTaskDescriptor prioritizeTaskDescriptor; + + public PrioritizeCommand(int targetIndex, Priority newPriority) { + assert targetIndex > 0; + + this.targetIndex = targetIndex - 1; + this.prioritizeTaskDescriptor = new EditTaskDescriptor(); + this.prioritizeTaskDescriptor.setPriority(Optional.of(newPriority)); + } + + @Override + public CommandResult execute() throws CommandException { + + UnmodifiableObservableList lastShownList = model.getFilteredTaskList(); + if (lastShownList.size() <= targetIndex) { + logger.info(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + } + + ReadOnlyTask taskToComplete = lastShownList.get(targetIndex); + Task completedTask = createPrioritizedTask(taskToComplete, prioritizeTaskDescriptor); + + try { + model.updateTask(targetIndex, completedTask); + } catch (UniqueTaskList.DuplicateTaskException dpe) { + logger.info(MESSAGE_DUPLICATE_TASK); + throw new CommandException(MESSAGE_DUPLICATE_TASK); + } + + model.updateFilteredListToShowAll(); + logger.info(String.format(MESSAGE_PRIORITIZE_TASK_SUCCESS, taskToComplete)); + return new CommandResult(String.format(MESSAGE_PRIORITIZE_TASK_SUCCESS, taskToComplete)); + } + + /** + * Creates and returns a {@code Task} with the details of {@code taskToComplete} + * edited with {@code editTaskDescriptor}. + */ + private static Task createPrioritizedTask(ReadOnlyTask taskToPrioritize, + EditTaskDescriptor editTaskDescriptor) throws CommandException { + assert taskToPrioritize != null; + + Description updatedDescription = editTaskDescriptor.getDescription() + .orElseGet(taskToPrioritize::getDescription); + Priority updatedPriority = editTaskDescriptor.getPriority().orElseGet(taskToPrioritize::getPriority); + Timing updatedStartDate = editTaskDescriptor.getStartTiming().orElseGet(taskToPrioritize::getStartTiming); + Timing updatedEndDate = editTaskDescriptor.getEndTiming().orElseGet(taskToPrioritize::getEndTiming); + UniqueTagList updatedTags = editTaskDescriptor.getTags().orElseGet(taskToPrioritize::getTags); + boolean updatedRecurring = editTaskDescriptor.isRecurring().orElseGet(taskToPrioritize::isRecurring); + RecurringFrequency updatedFrequency = editTaskDescriptor.getFrequency() + .orElseGet(taskToPrioritize::getFrequency); + + try { + return new Task(updatedDescription, updatedPriority, updatedStartDate, + updatedEndDate, updatedTags, updatedRecurring, updatedFrequency); + } catch (IllegalValueException e) { + throw new CommandException(MESSAGE_NULL_TIMING); + } + } +} +``` +###### /java/seedu/task/logic/commands/RedoCommand.java +``` java +package seedu.task.logic.commands; + +import java.util.EmptyStackException; +import java.util.logging.Logger; + +import seedu.task.commons.core.LogsCenter; +import seedu.task.logic.commands.exceptions.CommandException; + +/** + * Redo the previous change undone to the Task Manager + */ +public class RedoCommand extends Command { + private static final Logger logger = LogsCenter.getLogger(RedoCommand.class); + public static final String COMMAND_WORD = "redo"; + public static final String MESSAGE_SUCCESS = "Preivous undo restored."; + public static final String MESSAGE_INVALID_REDO_COMMAND = "Nothing to redo!"; + + @Override + public CommandResult execute() throws CommandException { + assert model != null; + try { + model.redo(); + } catch (EmptyStackException ese) { + logger.info(MESSAGE_INVALID_REDO_COMMAND); + throw new CommandException(MESSAGE_INVALID_REDO_COMMAND); + } + logger.info(MESSAGE_SUCCESS); + return new CommandResult(MESSAGE_SUCCESS); + } +} +``` +###### /java/seedu/task/logic/commands/UndoCommand.java +``` java +package seedu.task.logic.commands; + +import java.util.EmptyStackException; +import java.util.logging.Logger; + +import seedu.task.commons.core.LogsCenter; +import seedu.task.logic.commands.exceptions.CommandException; + +/** + * Undo the previous change to the Task Manager + */ +public class UndoCommand extends Command { + private static final Logger logger = LogsCenter.getLogger(UndoCommand.class); + public static final String COMMAND_WORD = "undo"; + public static final String MESSAGE_SUCCESS = "Previous change is undone"; + public static final String MESSAGE_INVALID_UNDO_COMMAND = "Nothing to undo!"; + + @Override + public CommandResult execute() throws CommandException { + assert model != null; + try { + model.undo(); + } catch (EmptyStackException ese) { + logger.info(MESSAGE_INVALID_UNDO_COMMAND); + throw new CommandException(MESSAGE_INVALID_UNDO_COMMAND); + } + logger.info(MESSAGE_SUCCESS); + return new CommandResult(MESSAGE_SUCCESS); + } +} +``` +###### /java/seedu/task/logic/parser/CompleteCommandParser.java +``` java +package seedu.task.logic.parser; + +import static seedu.task.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import java.util.Optional; + +import seedu.task.logic.commands.Command; +import seedu.task.logic.commands.CompleteCommand; +import seedu.task.logic.commands.IncorrectCommand; + +/** + * Parses input arguments and creates a new DeleteCommand object + */ +public class CompleteCommandParser { + + /** + * Parses the given {@code String} of arguments in the context of the DeleteCommand + * and returns an DeleteCommand object for execution. + */ + public Command parse(String args) { + + Optional index = ParserUtil.parseIndex(args); + if (!index.isPresent()) { + return new IncorrectCommand( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, CompleteCommand.MESSAGE_USAGE)); + } + return new CompleteCommand(index.get()); + } +} +``` +###### /java/seedu/task/logic/parser/PrioritizeCommandParser.java +``` java +package seedu.task.logic.parser; + +import static seedu.task.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.task.model.task.Priority.MESSAGE_PRIORITY_CONSTRAINTS; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; + +import seedu.task.commons.exceptions.IllegalValueException; +import seedu.task.logic.commands.Command; +import seedu.task.logic.commands.IncorrectCommand; +import seedu.task.logic.commands.PrioritizeCommand; +import seedu.task.model.task.Priority; + +public class PrioritizeCommandParser { + + /** + * Parses the given {@code String} of arguments in the context of the PrioritizeCommand + * and returns an EditCommand object for execution. + */ + public Command parse(String args) throws NoSuchElementException { + assert args != null; + ArgumentTokenizer argsTokenizer = + new ArgumentTokenizer(); + argsTokenizer.tokenize(args); + List> preambleFields = ParserUtil.splitPreamble(argsTokenizer.getPreamble().orElse(""), 2); + Optional newValue = preambleFields.get(1); + + Optional index = preambleFields.get(0).flatMap(ParserUtil::parseIndex); + if (!index.isPresent()) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, PrioritizeCommand.MESSAGE_USAGE)); + } + + try { + return new PrioritizeCommand(index.get(), new Priority(newValue.get())); + } catch (NoSuchElementException nsee) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, PrioritizeCommand.MESSAGE_USAGE)); + } catch (IllegalValueException ive) { + return new IncorrectCommand(String.format(MESSAGE_PRIORITY_CONSTRAINTS)); + } + } +} +``` +###### /java/seedu/task/model/ModelManager.java +``` java + @Override + public synchronized void deleteTask(ReadOnlyTask target) throws TaskNotFoundException { + TaskList update = new TaskList(this.taskList); + undoStack.push(update); + while (!redoStack.empty()) { + redoStack.pop(); + } + this.taskList.removeTask(target); + indicateTaskListChanged(); + } + + @Override + public synchronized void deleteThisTask(ReadOnlyTask targetToDelete, + Task targetToAdd) throws TaskNotFoundException, DuplicateTaskException { + this.taskList.removeTask(targetToDelete); + this.taskList.addTask(targetToAdd); + TaskList update = new TaskList(this.taskList); + undoStack.push(update); + while (!redoStack.empty()) { + redoStack.pop(); + } + this.taskList.removeTask(targetToAdd); + this.taskList.addTask((Task) targetToDelete); + updateFilteredListToShowAll(); + indicateTaskListChanged(); + } + + @Override + public synchronized void addTask(Task task) throws UniqueTaskList.DuplicateTaskException { + TaskList update = new TaskList(this.taskList); + undoStack.push(update); + while (!redoStack.empty()) { + redoStack.pop(); + } + this.taskList.addTask(task); + updateFilteredListToShowAll(); + indicateTaskListChanged(); + } + + @Override + public void updateTask(int filteredPersonListIndex, ReadOnlyTask editedTask) + throws UniqueTaskList.DuplicateTaskException { + assert editedTask != null; + + int addressBookIndex = filteredTasks.getSourceIndex(filteredPersonListIndex); + TaskList update = new TaskList(this.taskList); + undoStack.push(update); + while (!redoStack.empty()) { + redoStack.pop(); + } + this.taskList.updateTask(addressBookIndex, editedTask); + indicateTaskListChanged(); + } + + @Override + public void updateThisTask(int filteredPersonListIndex, ReadOnlyTask editedTask, + Task newTaskToAdd) throws UniqueTaskList.DuplicateTaskException { + assert editedTask != null; + + int addressBookIndex = filteredTasks.getSourceIndex(filteredPersonListIndex); + TaskList update = new TaskList(this.taskList); + undoStack.push(update); + while (!redoStack.empty()) { + redoStack.pop(); + } + this.taskList.updateTask(addressBookIndex, editedTask); + this.taskList.addTask(newTaskToAdd); + } + + @Override + public void undo() { + TaskList temp = undoStack.peek(); + redoStack.push(new TaskList(this.taskList)); + this.taskList.resetData(temp); + undoStack.pop(); + } + + @Override + public void redo() { + TaskList temp = redoStack.peek(); + undoStack.push(new TaskList(this.taskList)); + this.taskList.resetData(temp); + redoStack.pop(); + } + + @Override + public Stack getUndoStack() { + return this.undoStack; + } +``` diff --git a/collated/main/A0163559U.md b/collated/main/A0163559U.md new file mode 100644 index 000000000000..2678405f7fb6 --- /dev/null +++ b/collated/main/A0163559U.md @@ -0,0 +1,495 @@ +# A0163559U +###### /java/seedu/task/commons/util/FileUtil.java +``` java + /** + * Compares the contents of two files. + * @param f1 file 1 + * @param f2 file 2 + * @return true if file contents are identical + * @throws IOException + */ + public static boolean isFileContentSame(File f1, File f2) throws IOException { + String fileAsString1 = readFromFile(f1); + String fileAsString2 = readFromFile(f2); + System.out.println(fileAsString1); + System.out.println(fileAsString2); + return fileAsString1.equals(fileAsString2); + } +``` +###### /java/seedu/task/logic/commands/Command.java +``` java + public void setConfig(Config config) { + this.config = config; + } + + public void setStorage(Storage storage) { + this.storage = storage; + } +``` +###### /java/seedu/task/logic/commands/LoadCommand.java +``` java +package seedu.task.logic.commands; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Optional; +import java.util.logging.Logger; + +import seedu.task.commons.core.Config; +import seedu.task.commons.core.LogsCenter; +import seedu.task.commons.exceptions.DataConversionException; +import seedu.task.commons.exceptions.IllegalValueException; +import seedu.task.commons.util.ConfigUtil; +import seedu.task.logic.commands.exceptions.CommandException; +import seedu.task.model.ReadOnlyTaskList; + +/** + * Loads task data from the specified directory and file. + */ +public class LoadCommand extends Command { + private static final Logger logger = LogsCenter.getLogger(LoadCommand.class); + + public static final String COMMAND_WORD = "load"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Loads all tasks from specified directory and file name. " + + "Parameters: LOAD_LOCATION\n" + + "Example: " + COMMAND_WORD + + " /Users/username/Documents/TaskManager/taskmanager.xml"; + + public static final String MESSAGE_SUCCESS = "Tasks loaded from location: %1$s"; + public static final String MESSAGE_INVALID_LOAD_LOCATION = "This load location is invalid: %1$s"; + public static final String MESSAGE_NULL_LOAD_LOCATION = "A load location must be specified."; + public static final String MESSAGE_DIRECTORY_LOAD_LOCATION = "A load location must also include the file name."; + public static final String MESSAGE_LOAD_IO_EXCEPTION = "Failed to load file in location: %1$s"; + + private final File toLoad; + /** + * Creates a LoadCommand using raw values. + * + * @throws IllegalValueException if the load location is invalid + * @throws IOException + */ + public LoadCommand(String fileAsString) throws IllegalValueException { + if (fileAsString == null || fileAsString.equals("")) { + throw new IllegalValueException(MESSAGE_NULL_LOAD_LOCATION); + } + + this.toLoad = new File(fileAsString.trim()); + + if (!toLoad.exists()) { + throw new IllegalValueException(String.format(MESSAGE_INVALID_LOAD_LOCATION, fileAsString)); + } + + if (toLoad.isDirectory()) { + throw new IllegalValueException(MESSAGE_DIRECTORY_LOAD_LOCATION); + } + + assert toLoad.exists(); + + } + + @Override + public CommandResult execute() throws CommandException { + assert model != null; + assert config != null; + logger.info("Executing load command with " + toLoad.toString()); + + try { + Optional newTaskList = storage.loadTaskListFromNewLocation(toLoad); + if (newTaskList.isPresent()) { + model.resetData(newTaskList.get()); + } + } catch (FileNotFoundException | DataConversionException e1) { + logger.warning("Failed to execute load."); + throw new CommandException(MESSAGE_LOAD_IO_EXCEPTION); + } + + config.setTaskManagerFilePath(toLoad.toString()); + + try { + ConfigUtil.saveConfig(config, Config.DEFAULT_CONFIG_FILE); + } catch (IOException e) { + logger.warning("Failed to execute load."); + throw new CommandException(String.format(MESSAGE_LOAD_IO_EXCEPTION, toLoad.toString())); + } + logger.info("Execute load succeeded"); + return new CommandResult(String.format(MESSAGE_SUCCESS, toLoad.toString())); + + } + +} +``` +###### /java/seedu/task/logic/commands/SaveCommand.java +``` java +package seedu.task.logic.commands; + +import java.io.File; +import java.io.IOException; +import java.util.logging.Logger; + +import seedu.task.commons.core.Config; +import seedu.task.commons.core.LogsCenter; +import seedu.task.commons.exceptions.IllegalValueException; +import seedu.task.commons.util.ConfigUtil; +import seedu.task.commons.util.FileUtil; +import seedu.task.logic.commands.exceptions.CommandException; + +/** + * Saves task data in the specified directory and updates the default save directory. + */ +public class SaveCommand extends Command { + private static final Logger logger = LogsCenter.getLogger(SaveCommand.class); + + public static final String COMMAND_WORD = "save"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Saves all tasks in specified directory with specified file name. " + + "Parameters: SAVE_LOCATION\n" + + "Example: " + COMMAND_WORD + + " /Users/username/Documents/TaskManager/taskmanager.xml"; + + public static final String MESSAGE_SUCCESS = "Tasks saved in location: %1$s"; + public static final String MESSAGE_INVALID_SAVE_LOCATION = "This save location is invalid: %1$s"; + public static final String MESSAGE_NULL_SAVE_LOCATION = "A save location must be specified.\n" + + "Otherwise, saving occurs automatically in the current save location."; + public static final String MESSAGE_DIRECTORY_SAVE_LOCATION = "A save location must also include the file name."; + public static final String MESSAGE_SAVE_IO_EXCEPTION = "Failed to save file in location: %1$s"; + + private final File toSave; + /** + * Creates an SaveCommand using raw values. + * + * @throws IllegalValueException if the save location is invalid + * @throws IOException + */ + public SaveCommand(String fileAsString) throws IllegalValueException { + if (fileAsString == null || fileAsString.equals("")) { + throw new IllegalValueException(MESSAGE_NULL_SAVE_LOCATION); + } + this.toSave = new File(fileAsString.trim()); + if (toSave.isDirectory()) { + throw new IllegalValueException(MESSAGE_DIRECTORY_SAVE_LOCATION); + } + try { + createSaveFile(); + } catch (IOException ioe) { + throw new IllegalValueException(String.format(MESSAGE_INVALID_SAVE_LOCATION, fileAsString)); + } + assert toSave.exists(); + + } + + private boolean createSaveFile() throws IOException { + boolean created = FileUtil.createFile(toSave); + if (!FileUtil.isFileExists(toSave) && !created) { + throw new IOException(); + } + return created; + } + + @Override + public CommandResult execute() throws CommandException { + assert model != null; + assert config != null; + logger.info("Executing load command with " + toSave.toString()); + + try { + + storage.saveTaskListInNewLocation(model.getTaskList(), toSave); + + //update configuration to reflect new save location + config.setTaskManagerFilePath(toSave.toString()); + + ConfigUtil.saveConfig(config, Config.DEFAULT_CONFIG_FILE); + + } catch (IOException e) { + logger.warning("Failed to execute save."); + + throw new CommandException(String.format(MESSAGE_SAVE_IO_EXCEPTION, toSave.toString())); + } + logger.info("Execute save succeeded"); + return new CommandResult(String.format(MESSAGE_SUCCESS, toSave.toString())); + + } + +} +``` +###### /java/seedu/task/logic/parser/LoadCommandParser.java +``` java +package seedu.task.logic.parser; + +import static seedu.task.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import java.util.NoSuchElementException; + +import seedu.task.commons.exceptions.IllegalValueException; +import seedu.task.logic.commands.Command; +import seedu.task.logic.commands.IncorrectCommand; +import seedu.task.logic.commands.LoadCommand; + +/** + * Parses input arguments and creates a new LoadCommand object + */ +public class LoadCommandParser { + + /** + * Parses the given {@code String} of arguments in the context of the LoadCommand + * and returns a LoadCommand object for execution. + */ + public Command parse(String args) { + if (args == null || args.trim().equals("")) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, LoadCommand.MESSAGE_USAGE)); + } + String trimmedArgs = args.trim(); + try { + //System.out.println("@@@Parsing load command: " + args); + return new LoadCommand(trimmedArgs); + } catch (NoSuchElementException nsee) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, LoadCommand.MESSAGE_USAGE)); + } catch (IllegalValueException ive) { + return new IncorrectCommand(ive.getMessage()); + } + } + +} +``` +###### /java/seedu/task/logic/parser/SaveCommandParser.java +``` java +package seedu.task.logic.parser; + +import static seedu.task.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import java.util.NoSuchElementException; + +import seedu.task.commons.exceptions.IllegalValueException; +import seedu.task.logic.commands.Command; +import seedu.task.logic.commands.IncorrectCommand; +import seedu.task.logic.commands.SaveCommand; + +/** + * Parses input arguments and creates a new SaveCommand object + */ +public class SaveCommandParser { + + /** + * Parses the given {@code String} of arguments in the context of the SaveCommand + * and returns a SaveCommand object for execution. + */ + public Command parse(String args) { + if (args == null || args.trim().equals("")) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SaveCommand.MESSAGE_USAGE)); + } + String trimmedArgs = args.trim(); + try { + return new SaveCommand(trimmedArgs); + } catch (NoSuchElementException nsee) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SaveCommand.MESSAGE_USAGE)); + } catch (IllegalValueException ive) { + return new IncorrectCommand(ive.getMessage()); + } + } + +} +``` +###### /java/seedu/task/model/task/Priority.java +``` java + /** + * Results in Priority sorted in ascending order. + */ + @Override + public int compareTo(Priority comparePriority) { + int thisValue = Integer.parseInt(this.value); + int otherValue = Integer.parseInt(comparePriority.value); + return thisValue - otherValue; + } +``` +###### /java/seedu/task/model/task/Task.java +``` java + /** + * Results in Tasks sorted by completed state, followed by priority, endTiming, startTiming + * and lastly by frequency. + * Note: If a and b are tasks and a.compareTo(b) == 0, that does not imply + * a.equals(b). + */ + @Override + public int compareTo(Task compareTask) { + int compareToResult = 0; + + if (this.isComplete() && compareTask.isComplete()) { + compareToResult = 0; + } else if (this.isComplete()) { + compareToResult = 1; + } else if (compareTask.isComplete()) { + compareToResult = -1; + } + + if (compareToResult == 0) { + compareToResult = this.priority.compareTo(compareTask.priority); + } + + if (compareToResult == 0) { + compareToResult = this.getEndTiming().compareTo(compareTask.getEndTiming()); + } + + if (compareToResult == 0) { + compareToResult = this.getStartTiming().compareTo(compareTask.getStartTiming()); + } + + if (compareToResult == 0) { + compareToResult = this.getDescription().compareTo(compareTask.getDescription()); + } + + return compareToResult; + } + + public static Comparator taskComparator = new Comparator() { + + @Override + public int compare(Task task1, Task task2) { + task1.getStartTiming().setTiming(task1.getStartTiming().toString()); + task1.getEndTiming().setTiming(task1.getEndTiming().toString()); + return task1.compareTo(task2); + } + + }; +``` +###### /java/seedu/task/model/task/Timing.java +``` java + @Override + public int compareTo(Timing compareTiming) { + int compareToResult = 0; + + boolean thisTimingSpecified = this.value.equals(TIMING_NOT_SPECIFIED); + boolean otherTimingSpecified = compareTiming.value.equals(TIMING_NOT_SPECIFIED); + + if (thisTimingSpecified && otherTimingSpecified) { + return compareToResult; + } else if (thisTimingSpecified) { + compareToResult = 1; + } else if (otherTimingSpecified) { + compareToResult = -1; + } + + if (compareToResult == 0) { + Calendar thisCal = Calendar.getInstance(); + Calendar otherCal = Calendar.getInstance(); + thisCal.setTime(this.getTiming()); + compareTiming.setTiming(compareTiming.toString()); + otherCal.setTime(compareTiming.getTiming()); + compareToResult = thisCal.compareTo(otherCal); + } + + return compareToResult; + } +``` +###### /java/seedu/task/storage/Storage.java +``` java + /** + * Attempts to save current version of the Task Manager to new file location + * @param taskList is the Task Manager data to be saved + * @param saveFile is the save location + * @throws IOException if file operation fails + */ + @Override + void saveTaskListInNewLocation(ReadOnlyTaskList taskList, File saveFile) throws IOException; + + /** + * Attempts to load Task Manager data from specified file location + * @param loadFile is the file to load Task Manager data from + * @return + * @throws DataConversionException if data conversion fails + * @throws FileNotFoundException if the file is not found + */ + @Override + Optional loadTaskListFromNewLocation(File loadFile) + throws FileNotFoundException, DataConversionException; + +``` +###### /java/seedu/task/storage/StorageManager.java +``` java + @Override + /** + * Saves current state of task list in new location. + */ + public void saveTaskListInNewLocation(ReadOnlyTaskList taskList, File newFile) throws IOException { + logger.fine("Attempting to copy task manager data to file: " + newFile.toString()); + taskListStorage.saveTaskListInNewLocation(taskList, newFile); + } + + @Override + /** + * Attempts to load a stored task list into the task manager. + */ + public Optional loadTaskListFromNewLocation(File loadFile) + throws FileNotFoundException, DataConversionException { + logger.fine("Attempting to load task manager data from file: " + loadFile.toString()); + return taskListStorage.loadTaskListFromNewLocation(loadFile); + } + + /** + * Updates internal state data as storage support. + * @param file File to update state + */ + public void updateXmlTaskListStorage(File file) { + XmlTaskListStorage xmlTaskListStorage = (XmlTaskListStorage) taskListStorage; + xmlTaskListStorage.updateState(file);; + } +``` +###### /java/seedu/task/storage/TaskListStorage.java +``` java + /** + * Copies the current save state of the Task Manager into a new location + * @param taskList is the state to be copied + * @param newFile is the new save location + * @throws IOException if file operations fail + */ + void saveTaskListInNewLocation(ReadOnlyTaskList taskList, File newFile) throws IOException; + + /** + * Loads saved state of Task Manager from specified location + * @param loadFile is the file to load state from + * @return new loaded task list, if successful + * @throws DataConversionException if data conversion fails + * @throws FileNotFoundException if file operation fails + */ + Optional loadTaskListFromNewLocation(File loadFile) + throws FileNotFoundException, DataConversionException; +``` +###### /java/seedu/task/storage/XmlTaskListStorage.java +``` java + @Override + public void saveTaskListInNewLocation(ReadOnlyTaskList taskList, File newFile) throws IOException { + logger.info("Attempting to save taskList in file" + newFile); + saveTaskList(taskList, filePath); + try { + String taskData = FileUtil.readFromFile(savedFile); + System.out.println(taskData); + FileUtil.writeToFile(newFile, taskData); + + } catch (FileAlreadyExistsException faee) { + logger.warning("FileAlreadyExistsException in saveTaskListInNewLocation"); + return; //abort updating state + } catch (IOException ioe) { + logger.warning("IO Exception in saveTaskListInNewLocation"); + return; //abort updating state + } + updateState(newFile); + } + + public void updateState(File file) { + this.savedFile = file; + this.filePath = file.toString(); + } + + @Override + public Optional loadTaskListFromNewLocation(File loadFile) + throws FileNotFoundException, DataConversionException { + Optional newTaskList = readTaskList(loadFile.toString()); + if (newTaskList.isPresent()) { + updateState(loadFile); + } + return newTaskList; + } +``` diff --git a/collated/main/A0163935X.md b/collated/main/A0163935X.md new file mode 100644 index 000000000000..5e0b4a9c3ade --- /dev/null +++ b/collated/main/A0163935X.md @@ -0,0 +1,491 @@ +# A0163935X +###### /java/seedu/task/ui/CalenderPanel.java +``` java + +package seedu.task.ui; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.logging.Logger; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.ListView; +import javafx.scene.control.TextField; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Region; +import seedu.task.commons.core.LogsCenter; +import seedu.task.commons.util.FxViewUtil; +import seedu.task.model.task.ReadOnlyTask; + +/** + * The Calender Panel of the App. + */ +// tutorial +// https://www.youtube.com/watch?v=HiZ-glk9_LE&t=568s +public class CalenderPanel extends UiPart { + private static final String FXML = "CalenderPanel.fxml"; + private static final DateFormat YEAR = new SimpleDateFormat("yyyy"); + private static final DateFormat MONTH = new SimpleDateFormat("MM"); + private static final DateFormat DATE = new SimpleDateFormat("dd"); + private static final DateFormat DAY = new SimpleDateFormat("EEEE"); + private static final SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); + private HashMap dayHashMap = new HashMap(); + private HashMap> taskListHashMap = new HashMap>(); + // private static final DateTimeFormatter dtf = + // DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); + // private HashMap dayHashMap; + // tutorial + // https://www.mkyong.com/java/java-how-to-get-current-date-time-date-and-calender/ + @FXML + private TextField textfield; + @FXML + private Button button; + @FXML + private ListView listview1; + @FXML + private ListView listview2; + @FXML + private ListView listview3; + @FXML + private ListView listview4; + @FXML + private ListView listview5; + @FXML + private ListView listview6; + @FXML + private ListView listview7; + @FXML + private ListView listview8; + @FXML + private ListView listview9; + @FXML + private ListView listview10; + @FXML + private ListView listview11; + @FXML + private ListView listview12; + @FXML + private ListView listview13; + @FXML + private ListView listview14; + @FXML + private ListView listview15; + @FXML + private ListView listview16; + @FXML + private ListView listview17; + @FXML + private ListView listview18; + @FXML + private ListView listview19; + @FXML + private ListView listview20; + @FXML + private ListView listview21; + @FXML + private ListView listview22; + @FXML + private ListView listview23; + @FXML + private ListView listview24; + @FXML + private ListView listview25; + @FXML + private ListView listview26; + @FXML + private ListView listview27; + @FXML + private ListView listview28; + @FXML + private Label label1; + + @FXML + private Label day1; + @FXML + private Label day2; + @FXML + private Label day3; + @FXML + private Label day4; + @FXML + private Label day5; + @FXML + private Label day6; + @FXML + private Label day7; + @FXML + private Label day8; + @FXML + private Label day9; + @FXML + private Label day10; + @FXML + private Label day11; + @FXML + private Label day12; + @FXML + private Label day13; + @FXML + private Label day14; + @FXML + private Label day15; + @FXML + private Label day16; + @FXML + private Label day17; + @FXML + private Label day18; + @FXML + private Label day19; + @FXML + private Label day20; + @FXML + private Label day21; + @FXML + private Label day22; + @FXML + private Label day23; + @FXML + private Label day24; + @FXML + private Label day25; + @FXML + private Label day26; + @FXML + private Label day27; + @FXML + private Label day28; + private static final Logger logger = LogsCenter.getLogger(CalenderPanel.class); + public CalenderPanel(AnchorPane calendertPlaceholder, ObservableList taskList, int dDate, int dMonth, + int dYear) { + super(FXML); + logger.info(" Initializing Calendar "); + FxViewUtil.applyAnchorBoundaryParameters(getRoot(), 0.0, 0.0, 0.0, 0.0); + /* ObservableList data = */ FXCollections.observableArrayList("hey", "you"); + // label1.setText("v0.1"); + setDate(dDate, dMonth, dYear); + setTasks(taskList); + // listview1.getItems().addAll("eat pizza", "go to gym"); + calendertPlaceholder.getChildren().add(getRoot()); + button.setOnAction(event -> { + String str = textfield.getText(); + if (str != null) { + str = str.replaceAll("[^0-9]+", " "); + List monthAndDate = Arrays.asList(str.trim().split(" ")); + int day = Integer.valueOf(monthAndDate.get(0)); + int month = Integer.valueOf(monthAndDate.get(1)); + int year = Integer.valueOf(monthAndDate.get(2)); + cleanAllListView(); + setDate(day, month, year); + setTasks(taskList); + } + }); + } + private void cleanAllListView() { + listview1.getItems().clear(); + listview2.getItems().clear(); + listview3.getItems().clear(); + listview4.getItems().clear(); + listview5.getItems().clear(); + listview6.getItems().clear(); + listview7.getItems().clear(); + listview8.getItems().clear(); + listview9.getItems().clear(); + listview10.getItems().clear(); + listview11.getItems().clear(); + listview12.getItems().clear(); + listview13.getItems().clear(); + listview14.getItems().clear(); + listview15.getItems().clear(); + listview16.getItems().clear(); + listview17.getItems().clear(); + listview18.getItems().clear(); + listview19.getItems().clear(); + listview20.getItems().clear(); + listview21.getItems().clear(); + listview22.getItems().clear(); + listview23.getItems().clear(); + listview24.getItems().clear(); + listview25.getItems().clear(); + listview26.getItems().clear(); + listview27.getItems().clear(); + listview28.getItems().clear(); + + + } + private void initTaskListHashMap(HashMap> mytaskListHashMap) { + mytaskListHashMap.put("day1TaskList", listview1); + mytaskListHashMap.put("day2TaskList", listview2); + mytaskListHashMap.put("day3TaskList", listview3); + mytaskListHashMap.put("day4TaskList", listview4); + mytaskListHashMap.put("day5TaskList", listview5); + mytaskListHashMap.put("day6TaskList", listview6); + mytaskListHashMap.put("day7TaskList", listview7); + mytaskListHashMap.put("day8TaskList", listview8); + mytaskListHashMap.put("day9TaskList", listview9); + mytaskListHashMap.put("day10TaskList", listview10); + mytaskListHashMap.put("day11TaskList", listview11); + mytaskListHashMap.put("day12TaskList", listview12); + mytaskListHashMap.put("day13TaskList", listview13); + mytaskListHashMap.put("day14TaskList", listview14); + mytaskListHashMap.put("day15TaskList", listview15); + mytaskListHashMap.put("day16TaskList", listview16); + mytaskListHashMap.put("day17TaskList", listview17); + mytaskListHashMap.put("day18TaskList", listview18); + mytaskListHashMap.put("day19TaskList", listview19); + mytaskListHashMap.put("day20TaskList", listview20); + mytaskListHashMap.put("day21TaskList", listview21); + mytaskListHashMap.put("day22TaskList", listview22); + mytaskListHashMap.put("day23TaskList", listview23); + mytaskListHashMap.put("day24TaskList", listview24); + mytaskListHashMap.put("day25TaskList", listview25); + mytaskListHashMap.put("day26TaskList", listview26); + mytaskListHashMap.put("day27TaskList", listview27); + mytaskListHashMap.put("day28TaskList", listview28); + } + + private void setTasks(ObservableList taskList) { + logger.info(" set tasks "); + initTaskListHashMap(taskListHashMap); + for (int i = 0; i < taskList.size(); i++) { + if (!taskList.get(i).getEndTiming().isFloating()) { + if (taskList.get(i).isRecurring()) { + for (int k = 0; k < taskList.get(i).getOccurrences().size(); k++) { + for (int j = 0; j < 28; j++) { + ListView currentTaskList = taskListHashMap.get("day" + (j + 1) + "TaskList"); + String labelDate = dayHashMap.get("day" + (j + 1)).getText().toString(); + String taskDate = taskList.get(i).getOccurrences().get(k).getEndTiming().toString(); + String[] taskListDateData = taskDate.toString().split("/"); + + String test = String.valueOf( + taskList.get(i).getOccurrences().get(k).getEndTiming().getTiming().getMonth() + 1 + ); + String taskDateMonth = String.valueOf( + taskList.get(i).getOccurrences().get(k).getEndTiming().getTiming().getMonth() + 1 + ); + String taskDateDate = String.valueOf( + taskList.get(i).getOccurrences().get(k).getEndTiming().getTiming().getDate() + ); + + + if ((taskDateMonth + "/" + taskDateDate).equals(labelDate)) { + currentTaskList.getItems().addAll(taskList.get(i).getDescription().toString()); + + } + } + } + } else { + for (int j = 0; j < 28; j++) { + ListView currentTaskList = taskListHashMap.get("day" + (j + 1) + "TaskList"); + String labelDate = dayHashMap.get("day" + (j + 1)).getText().toString(); + Date taskDate = taskList.get(i).getEndTiming().getTiming(); + String[] taskListDateData = taskDate.toString().split("/"); + String taskDateMonth = String.valueOf(taskDate.getMonth() + 1); + String taskDateDate = String.valueOf(taskDate.getDate()); + if ((taskDateMonth + "/" + taskDateDate).equals(labelDate)) { + currentTaskList.getItems().addAll(taskList.get(i).getDescription().toString()); + + } + } + } + } + } + } + + + + private void initDayHashMap(HashMap dayHash) { + dayHash.put("day1", day1); + dayHash.put("day2", day2); + dayHash.put("day3", day3); + dayHash.put("day4", day4); + dayHash.put("day5", day5); + dayHash.put("day6", day6); + dayHash.put("day7", day7); + dayHash.put("day8", day8); + dayHash.put("day9", day9); + dayHash.put("day10", day10); + dayHash.put("day11", day11); + dayHash.put("day12", day12); + dayHash.put("day13", day13); + dayHash.put("day14", day14); + dayHash.put("day15", day15); + dayHash.put("day16", day16); + dayHash.put("day17", day17); + dayHash.put("day18", day18); + dayHash.put("day19", day19); + dayHash.put("day20", day20); + dayHash.put("day21", day21); + dayHash.put("day22", day22); + dayHash.put("day23", day23); + dayHash.put("day24", day24); + dayHash.put("day25", day25); + dayHash.put("day26", day26); + dayHash.put("day27", day27); + dayHash.put("day28", day28); + } + + private void setDate(int dDate, int dMonth, int dYear) { + logger.info(" set Date "); + SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); + Date date = new Date(); + if (dDate != 0) { + try { + // date = + // fmt.parse(Integer.toString(Year)+"-"+Integer.toString(Month)+"-"+Integer.toString(Date)); + date = fmt.parse(String.valueOf(dYear) + + "-" + String.valueOf(dMonth) + "-" + String.valueOf(dDate)); + } catch (java.text.ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + initDayHashMap(dayHashMap); + String dayOfTheWeek = DAY.format(date); + + Calendar firstDay = Calendar.getInstance(); + if (dDate != 0) { + firstDay.set(Calendar.YEAR, dYear); + + // We will have to increment the month field by 1 + + firstDay.set(Calendar.MONTH, dMonth - 1); + + // As the month indexing starts with 0 + + firstDay.set(Calendar.DAY_OF_MONTH, dDate); + } + Date firstDate; + firstDate = firstDay.getTime(); + + if ("星期一".equals(dayOfTheWeek) || "Monday".equals(dayOfTheWeek)) { + firstDay.add(Calendar.DATE, -1); + } else if ("星期二".equals(dayOfTheWeek) || "Tuesday".equals(dayOfTheWeek)) { + firstDay.add(Calendar.DATE, -2); + } else if ("星期三".equals(dayOfTheWeek) || "Wednesday".equals(dayOfTheWeek)) { + firstDay.add(Calendar.DATE, -3); + } else if ("星期四".equals(dayOfTheWeek) || "Thursday".equals(dayOfTheWeek)) { + firstDay.add(Calendar.DATE, -4); + } else if ("星期五".equals(dayOfTheWeek) || "Friday".equals(dayOfTheWeek)) { + firstDay.add(Calendar.DATE, -5); + } else if ("星期六".equals(dayOfTheWeek) || "Saturday".equals(dayOfTheWeek)) { + firstDay.add(Calendar.DATE, -6); + } + + firstDate = firstDay.getTime(); + int firstDateYear = Integer.valueOf(YEAR.format(firstDate)); + int firstDateMonth = Integer.valueOf(MONTH.format(firstDate)); + int firstDateDate = Integer.valueOf(DATE.format(firstDate)); + + for (int count = 1; count <= 28; count++) { + dayHashMap.get("day" + count).setText(Integer.toString(firstDateMonth) + + "/" + Integer.toString(firstDateDate)); + firstDateDate++; + if (firstDateMonth == 2 && firstDateDate > 29 && firstDateYear % 4 == 0) { + firstDateMonth += 1; + firstDateDate = 1; + } else if (firstDateMonth == 2 && firstDateDate > 28 && firstDateYear % 4 != 0) { + firstDateMonth += 1; + firstDateDate = 1; + } else if ((firstDateMonth == 1 || firstDateMonth == 3 || firstDateMonth == 5 || + firstDateMonth == 7 || firstDateMonth == 8 || firstDateMonth == 10 || + firstDateMonth == 12) && firstDateDate > 31) { + if (firstDateMonth == 12)firstDateMonth = 1; + else firstDateMonth += 1; + firstDateDate = 1; + } else if ((firstDateMonth == 2 || firstDateMonth == 4 || firstDateMonth == 6 || + firstDateMonth == 9 || firstDateMonth == 11) && firstDateDate > 30) { + firstDateMonth += 1; + firstDateDate = 1; + } + + } + } +} +``` +###### /java/seedu/task/ui/CommandBox.java +``` java + updateCalender(this.mainwindow , logic.getFilteredTaskList() , 0 , 0 , 0); +``` +###### /resources/view/CalenderPanel.fxml +``` fxml + + + +