View on GitHub

main

Must Do List ( Task Scheduler Application )

A0140007B

\java\seedu\taskscheduler\commons\events\ui\CommandBoxTextChangeRequestEvent.java

/**
 * Indicates a request to change command box text
 */
public class CommandBoxTextChangeRequestEvent extends BaseEvent {

    public final String text;

    public CommandBoxTextChangeRequestEvent(String text) {
        this.text = text;
    }
    
    @Override
    public String toString() {
        return this.getClass().getSimpleName();
    }

}
\java\seedu\taskscheduler\commons\util\TaskUtil.java

/**
 * Utility methods for Task
 */

public final class TaskUtil {

	public static String convertToTaskString(ReadOnlyTask task) {
		if (task.getType() == TaskType.FLOATING) {
			return getFloatingTaskString(task);
		} else if (task.getType() == TaskType.DEADLINE) {
			return getDeadlineTaskString(task);
		} else {
			return getEventTaskString(task);
		}
		
	}
	
	private static String getFloatingTaskString(ReadOnlyTask task) {
		return "add " + task.getName();
	}
	
	private static String getDeadlineTaskString(ReadOnlyTask task) {
		return "add " + task.getName() + " by " + task.getEndDate();
	}
	
	private static String getEventTaskString(ReadOnlyTask task) {
		return "add " + task.getName() + " from " + task.getStartDate()
			+ " to " + task.getEndDate() + " at " + task.getLocation();
	}
}
\java\seedu\taskscheduler\logic\commands\CommandHistory.java
/**
 * Keep track of commands and modifications to task scheduler.
 */
public class CommandHistory {
    
	private static final int EMPTY_VALUE = 0;
	private static final int FIRST_VALUE = 1;
	
	private static Stack<String> prevCommand = new Stack<String>();
	private static Stack<String> nextCommand = new Stack<String>();
	private static Stack<Command> executedCommands = new Stack<Command>();
    private static Stack<Command> revertedCommands = new Stack<Command>();
	private static ReadOnlyTask lastModifiedTask = null;
    private static Set<String> filteredKeywords = null;
    private static Stack<String> previousStorageFilePath = new Stack<String>();
    private static String initStoragePath;
	
	public static void addPrevCommand(String commandText) {
		while (!nextCommand.isEmpty()) {
			prevCommand.push(nextCommand.pop());
		}
		prevCommand.push(commandText);
	}
	
	public static void addNextCommand(String commandText) {
		nextCommand.push(commandText);
	}
	
	
	public static String getPrevCommand() {
		String result = "";
		if (prevCommand.size() > EMPTY_VALUE) {
			if (prevCommand.size() == FIRST_VALUE) {
				result = prevCommand.peek();
			} else {
				result = prevCommand.pop();
				nextCommand.push(result);
			}
		}
		return result;
	}

	public static String getNextCommand() {
		String result = "";
		if (!nextCommand.isEmpty()) {
			result = nextCommand.pop();
			prevCommand.push(result);
		}
		return result;
	}

	public static void addExecutedCommand(Command command) {
		executedCommands.push(command);
	}
	
    public static void addRevertedCommand(Command command) {
        revertedCommands.push(command);
    }
	
	public static Command getExecutedCommand() throws EmptyStackException{
		if (executedCommands.size() > EMPTY_VALUE) {
			return executedCommands.pop();
		} else {
			throw new EmptyStackException();
		}
	}

    public static Command getRevertedCommand() throws EmptyStackException{
        if (revertedCommands.size() > EMPTY_VALUE) {
            return revertedCommands.pop();
        } else {
            throw new EmptyStackException();
        }
    }
	
	public static void flushExecutedCommands() {
		executedCommands.clear();
	}
	
    public static void flushRevertedCommands() {
        revertedCommands.clear();
    }
	
    public static void flushPrevCommands() {
        prevCommand.clear();
    }
    
    public static void flushNextCommands() {
        nextCommand.clear();
    }
	
	public static void setModifiedTask(ReadOnlyTask task) {
	    lastModifiedTask = task;
	}
	
    public static void resetModifiedTask() {
        lastModifiedTask = null;
    }
	
    public static ReadOnlyTask getModifiedTask() throws TaskNotFoundException {
        if (lastModifiedTask == null) {
            throw new TaskNotFoundException(Messages.MESSAGE_PREV_TASK_NOT_FOUND);
        } else {
            return lastModifiedTask;
        }
    }
    
    public static Set<String> getFilteredKeyWords() {
        return filteredKeywords;
    }
    
    public static void setFilteredKeyWords(Set<String> keywords) {
        filteredKeywords = keywords;
    }

    public static void resetFilteredKeyWords() {
        filteredKeywords = null;
    }
    
    public static void resetAll() {
        resetFilteredKeyWords();
        resetModifiedTask();
        flushExecutedCommands();
        flushNextCommands();
        flushPrevCommands();
        flushRevertedCommands();
    }
    
\java\seedu\taskscheduler\logic\commands\SelectCommand.java
/**
 * Selects a task display the index's command.
 */
public class SelectCommand extends Command {

    public final int targetIndex;

    public static final String COMMAND_WORD = "select";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Selects the task display the index's command.\n"
            + "Parameters: INDEX (must be a positive integer)\n"
            + "Example: " + COMMAND_WORD + " 1";

    public static final String MESSAGE_SELECT_TASK_SUCCESS = "Selected Task: %1$s";

    public SelectCommand(int targetIndex) {
        this.targetIndex = targetIndex;
    }

\java\seedu\taskscheduler\logic\commands\SelectCommand.java
    @Override
    public CommandResult execute() {

        UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

        if (lastShownList.size() < targetIndex) {
            indicateAttemptToExecuteIncorrectCommand();
            return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }
        EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex - 1));
        EventsCenter.getInstance().post(new CommandBoxTextChangeRequestEvent(
        		TaskUtil.convertToTaskString(lastShownList.get(targetIndex - 1))));
        CommandHistory.setModifiedTask(lastShownList.get(targetIndex - 1));
        return new CommandResult(String.format(MESSAGE_SELECT_TASK_SUCCESS, targetIndex));

    }
\java\seedu\taskscheduler\logic\commands\UndoCommand.java

/**
 * Undo a previous command in the task scheduler.
 */

public class UndoCommand extends Command{
	
	public static final String COMMAND_WORD = "undo";

	public static final String MESSAGE_FAILURE = "There is no previous command to undo!";
	
    @Override
	public CommandResult execute() {
    	assert model != null;
    	try {
            return CommandHistory.getExecutedCommand().revert();
    	} catch (EmptyStackException e) {
    	    return new CommandResult(MESSAGE_FAILURE);
    	}
	}

    @Override
    public CommandResult revert() {
        // This command not available for revert
        assert false : Messages.MESSAGE_PROGRAM_ERROR;
        return null;
    }
}
\java\seedu\taskscheduler\logic\parser\UndoCommandParser.java

/**
* Parses setpath command user input.
*/
public class UndoCommandParser extends CommandParser {

    @Override
    public Command prepareCommand(String args) {
        return new UndoCommand();
    }

}
\java\seedu\taskscheduler\model\Model.java
	/** Inserts the newTask into the given position */
	void insertTask(int index, Task newTask) throws TaskNotFoundException;

\java\seedu\taskscheduler\model\ModelManager.java
    @Override
    public void insertTask(int index, Task newTask) 
            throws TaskNotFoundException {
        taskScheduler.insertTask(index, newTask);
        updateFilteredListToShowAll();
        indicateTaskSchedulerChanged();
    }
\java\seedu\taskscheduler\model\task\UniqueTaskList.java
    /**
     * Inserts a task into another task's position in the list.
     *
     * @throws TaskNotFoundException
     */
    public void insert(int index, Task newTask) throws TaskNotFoundException {
        assert newTask != null;
        assert index > FIRST_INDEX;
        internalList.add(index-1, newTask);
    }
\java\seedu\taskscheduler\model\TaskScheduler.java
    /**
     * Inserts a task into another task's position in the task scheduler
     * Also checks the new task's tags and updates {@link #tags} with any new tags found,
     * and updates the Tag objects in the task to point to those in {@link #tags}.
     *
     * @throws UniqueTaskList.DuplicateTaskException if an equivalent task already exists.
     */
    public void insertTask(int index, Task newTask) 
            throws UniqueTaskList.TaskNotFoundException {
        syncTagsWithMasterList(newTask);
        tasks.insert(index, newTask);
    }
\java\seedu\taskscheduler\ui\CommandBox.java
    @FXML
    private void handleKeyPressedEvent(KeyEvent keyEvent) {
    	if (keyEvent.getCode() == KeyCode.DOWN) {
    		commandTextField.setText(CommandHistory.getNextCommand());
    	} else if (keyEvent.getCode() == KeyCode.UP) {
    		commandTextField.setText(CommandHistory.getPrevCommand());
    	} 
    }
\java\seedu\taskscheduler\ui\CommandBox.java
    /**
     * Sets the command box text 
     */
    public void setCommandText(String text) {
        commandTextField.setText(text);
    }
\java\seedu\taskscheduler\ui\MainWindow.java
    public CommandBox getCommandBox() {
        return commandBox;
    }
\java\seedu\taskscheduler\ui\UiManager.java
    @Subscribe
    private void handleCommandBoxTextChangeRequestEvent(CommandBoxTextChangeRequestEvent event) {
        logger.info(LogsCenter.getEventHandlingLogMessage(event));
        mainWindow.getCommandBox().setCommandText(event.text);
    }
\resources\view\MainWindow.fxml

<VBox maxHeight="Infinity" maxWidth="Infinity" minHeight="600.0" minWidth="900.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seedu.taskscheduler.ui.MainWindow">
	<stylesheets>
		<URL value="@DarkTheme.css" />
		<URL value="@Extensions.css" />
	</stylesheets>
	<children>
		<MenuBar focusTraversable="false" VBox.vgrow="NEVER">
			<menus>
				<Menu mnemonicParsing="false" text="File">
					<items>
						<MenuItem mnemonicParsing="false" onAction="#handleExit" text="Exit">
                     <accelerator>
                        <KeyCodeCombination alt="DOWN" code="F4" control="UP" meta="UP" shift="UP" shortcut="UP" />
                     </accelerator></MenuItem>
					</items>
				</Menu>
				<Menu mnemonicParsing="false" text="Help">
					<items>
						<MenuItem fx:id="helpMenuItem" mnemonicParsing="false" onAction="#handleHelp" text="Help">
                     <accelerator>
                        <KeyCodeCombination alt="UP" code="F1" control="UP" meta="UP" shift="UP" shortcut="ANY" />
                     </accelerator></MenuItem>
					</items>
				</Menu>
				<Menu mnemonicParsing="false" text="Controls">
					<items>
						<MenuItem fx:id="tagsPaneMenuItem" mnemonicParsing="false" onAction="#handleFocusTagPane" text="Tags List">
                     <accelerator>
                        <KeyCodeCombination alt="UP" code="DIGIT1" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
                     </accelerator></MenuItem>
						<MenuItem fx:id="priorityPaneMenuItem" mnemonicParsing="false" onAction="#handleFocusPriorityPane" text="Priority List">
                     <accelerator>
                        <KeyCodeCombination alt="UP" code="DIGIT2" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
                     </accelerator></MenuItem>
						<MenuItem fx:id="taskPaneMenuItem" mnemonicParsing="false" onAction="#handleFocusTaskPane" text="Task List">
                     <accelerator>
                        <KeyCodeCombination alt="UP" code="DIGIT3" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
                     </accelerator></MenuItem>
						<MenuItem fx:id="commandBoxPaneMenuItem" mnemonicParsing="false" onAction="#handleFocusCommandBox" text="Command Box">
                     <accelerator>
                        <KeyCodeCombination alt="UP" code="DIGIT4" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
                     </accelerator></MenuItem>
					</items>
				</Menu>
			</menus>
		</MenuBar>
		<SplitPane id="splitPane" fx:id="splitPane" dividerPositions="0.3333" focusTraversable="false" pickOnBounds="false" VBox.vgrow="ALWAYS">
			<items>
				<VBox fx:id="priorityList" minHeight="600.0" minWidth="300.0" pickOnBounds="false">
					<padding>
						<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
					</padding>
					<children>
						<AnchorPane fx:id="tagListPanelPlaceholder" minHeight="240.0" styleClass="anchor-pane-with-border" VBox.vgrow="NEVER">
							<padding>
								<Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />
							</padding>
						</AnchorPane>
						<AnchorPane fx:id="priorityListPanelPlaceholder" styleClass="anchor-pane-with-border" VBox.vgrow="NEVER">
							<padding>
								<Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />
							</padding>
						</AnchorPane>
					</children>
				</VBox>
				<VBox fx:id="taskList" minHeight="600.0" minWidth="600.0" pickOnBounds="false">
					<padding>
						<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
					</padding>
					<children>
                  <GridPane alignment="TOP_CENTER" pickOnBounds="false">
                    <columnConstraints>
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                        <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                        <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                    </columnConstraints>
                    <rowConstraints>
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                    </rowConstraints>
                     <children>
                        <Label fx:id="lblCompleted" contentDisplay="CENTER" focusTraversable="false" text="1000">
                           <padding>
                              <Insets left="100.0" />
                           </padding>
                        </Label>
                        <Label alignment="CENTER_RIGHT" contentDisplay="CENTER" focusTraversable="false" text="Completed" GridPane.vgrow="ALWAYS">
                           <padding>
                              <Insets left="10.0" />
                           </padding>
                        </Label>
                        <Label alignment="CENTER_RIGHT" contentDisplay="CENTER" focusTraversable="false" text="Pending" GridPane.columnIndex="1">
                           <padding>
                              <Insets left="10.0" />
                           </padding>
                        </Label>
                        <Label fx:id="lblPending" contentDisplay="CENTER" focusTraversable="false" text="1000" GridPane.columnIndex="1">
                           <padding>
                              <Insets left="100.0" />
                           </padding>
                        </Label>
                        <Label fx:id="lblOverdue" contentDisplay="CENTER" focusTraversable="false" text="1000" GridPane.columnIndex="2">
                           <padding>
                              <Insets left="100.0" />
                           </padding>
                        </Label>
                        <Label alignment="CENTER_RIGHT" contentDisplay="CENTER" focusTraversable="false" text="Overdue" GridPane.columnIndex="2">
                           <padding>
                              <Insets left="10.0" />
                           </padding>
                        </Label>
                     </children>
                  </GridPane>
						<AnchorPane fx:id="taskListPanelPlaceholder" styleClass="anchor-pane-with-border" VBox.vgrow="ALWAYS">
							<padding>
								<Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />
							</padding>
						</AnchorPane>
						<AnchorPane fx:id="commandBoxPlaceholder" minHeight="40.0" styleClass="anchor-pane-with-border" VBox.vgrow="NEVER">
							<padding>
								<Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />
							</padding>
						</AnchorPane>
						<AnchorPane fx:id="resultDisplayPlaceholder" maxHeight="100" minHeight="100" prefHeight="100" styleClass="anchor-pane-with-border" VBox.vgrow="NEVER">
							<padding>
								<Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />
							</padding>
						</AnchorPane>
					</children>
				</VBox>
			</items>
			<effect>
				<Glow />
			</effect>
		</SplitPane>
		<AnchorPane fx:id="statusbarPlaceholder" pickOnBounds="false" VBox.vgrow="NEVER" />
	</children>
</VBox>