diff --git a/src/planmysem/commands/ViewCommand.java b/src/planmysem/commands/ViewCommand.java new file mode 100644 index 000000000..e5796f1e0 --- /dev/null +++ b/src/planmysem/commands/ViewCommand.java @@ -0,0 +1,137 @@ +package planmysem.commands; + +import java.time.LocalDate; +import java.util.HashMap; + +import planmysem.data.semester.Day; +import planmysem.data.semester.Semester; + +/** + * Adds a person to the address book. + */ +public class ViewCommand extends Command { + + public static final String COMMAND_WORD = "view"; + public static final String COMMAND_WORD_SHORT = "v"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": View month/week/day view or all details of planner." + + "\n\tParameters: " + + "\n\t\tMandatory: [viewType] [specifier]" + + "\n\tExample 1: " + COMMAND_WORD + + " month" + + "\n\tExample 2: " + COMMAND_WORD + + " week 7" + + "\n\tExample 3: " + COMMAND_WORD + + " week recess" + + "\n\tExample 4: " + COMMAND_WORD + + " day 01/03/2019" + + "\n\tExample 5: " + COMMAND_WORD + + " all"; + + private final String viewArgs; + + public ViewCommand(String viewArgs) { + this.viewArgs = viewArgs; + } + + @Override + public CommandResult execute() { + String viewType; + //String viewSpecifier; + final Semester currentSemester = planner.getSemester(); + String output = null; + + if ("all".equals(viewArgs)) { + //TODO: print all planner details + output = "all"; + } else if ("month".equals(viewArgs)) { + output = displayMonthView(currentSemester); + } else { + viewType = viewArgs.split(" ")[0]; + //viewSpecifier = viewArgs.split(" ")[1]; + + switch (viewType) { + case "month": + //TODO: month view + break; + case "week": + //TODO: week view + break; + case "day": + //TODO: day view + break; + default: + break; + } + } + + return new CommandResult(output); + } + + /** + * Display all months for the semester. + */ + private String displayMonthView(Semester currentSemester) { + HashMap allDays = currentSemester.getDays(); + LocalDate semesterStartDate = currentSemester.getStartDate(); + LocalDate semesterEndDate = currentSemester.getEndDate(); + int year = semesterStartDate.getYear(); + LocalDate firstDayOfMonth = semesterStartDate.withDayOfMonth(1); + int spaces = firstDayOfMonth.getDayOfWeek().getValue(); + int lastMonthOfSem = semesterEndDate.getMonthValue(); + StringBuilder sb = new StringBuilder(); + + String[] months = {"", "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December"}; + + int[] days = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + for (int m = 1; m <= lastMonthOfSem; m++) { + // Set number of days in February to 29 if it is a leap year. + if ((((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) && m == 2) { + days[m] = 29; + } + + // Print calendar header. + sb.append(" " + months[m] + " " + year + "\n"); + sb.append("_____________________________________\n"); + sb.append(" Sun Mon Tue Wed Thu Fri Sat\n"); + + // Print spaces required for the start of a month. + spaces = (days[m - 1] + spaces) % 7; + for (int i = 0; i < spaces; i++) { + sb.append(" "); + } + // Print the days in the month. + for (int i = 1; i <= days[m]; i++) { + sb.append(String.format(" %3d", i)); + if (((i + spaces) % 7 == 0)) { + Day tempDay = allDays.get(LocalDate.of(year, m, i)); + String weekType = ""; + if (tempDay != null) { + weekType = tempDay.getType(); + } + sb.append(" | " + weekType + "\n"); + } + if (i == days[m]) { + LocalDate tempDate = LocalDate.of(year, m, i); + Day tempDay = allDays.get(tempDate); + String weekType = ""; + int extraSpaces = 6 - (tempDate.getDayOfWeek().getValue() % 7); + for (int j = 0; j < extraSpaces; j++) { + sb.append(" "); + } + if (tempDay != null) { + weekType = tempDay.getType(); + } + sb.append(" | " + weekType + "\n"); + } + } + + sb.append("\n"); + } + + return sb.toString(); + } + +} diff --git a/src/planmysem/parser/Parser.java b/src/planmysem/parser/Parser.java index 6475cca4f..70f65b4d9 100644 --- a/src/planmysem/parser/Parser.java +++ b/src/planmysem/parser/Parser.java @@ -23,6 +23,7 @@ import planmysem.commands.HelpCommand; import planmysem.commands.IncorrectCommand; import planmysem.commands.ListCommand; +import planmysem.commands.ViewCommand; import planmysem.common.Utils; import planmysem.data.exception.IllegalValueException; @@ -95,6 +96,10 @@ public Command parseCommand(String userInput) { case ListCommand.COMMAND_WORD_SHORT: return prepareList(arguments); + case ViewCommand.COMMAND_WORD: + case ViewCommand.COMMAND_WORD_SHORT: + return prepareView(arguments); + case ClearCommand.COMMAND_WORD: return new ClearCommand(); @@ -344,31 +349,28 @@ private Command prepareList(String args) { * @param args full command args string * @return the prepared command */ - // private Command prepareView(String args) { - // - // try { - // final int targetIndex = parseArgsAsDisplayedIndex(args); - // return new ViewCommand(targetIndex); - // } catch (ParseException | NumberFormatException e) { - // return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, - // ViewCommand.MESSAGE_USAGE)); - // } - // } + private Command prepareView(String args) { + if (args == null || args.trim().isEmpty()) { + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE)); + } - /** - * Parses the given arguments string as a single index number. - * - * @param args arguments string to parse as index number - * @return the parsed index number - * @throws ParseException if no region of the args string could be found for the index - * @throws NumberFormatException the args string region is not a valid number - */ - private int parseArgsAsDisplayedIndex(String args) throws ParseException, NumberFormatException { - final Matcher matcher = PERSON_INDEX_ARGS_FORMAT.matcher(args.trim()); - if (!matcher.matches()) { - throw new ParseException("Could not find index number to parse"); + String[] viewArgs = args.split(" "); + if ("all".equals(viewArgs[1]) && viewArgs.length == 2) { + return new ViewCommand(viewArgs[1]); + } else if ("month".equals(viewArgs[1]) && viewArgs.length == 2) { + return new ViewCommand(viewArgs[1]); + } else if ("month".equals(viewArgs[1]) && viewArgs.length == 3) { + //TODO: ensure month arguments + return new ViewCommand(viewArgs[1] + " " + viewArgs[2]); + } else if ("week".equals(viewArgs[1]) && viewArgs.length == 3) { + //TODO: ensure week arguments + return new ViewCommand(viewArgs[1] + " " + viewArgs[2]); + } else if ("day".equals(viewArgs[1]) && viewArgs.length == 3) { + //TODO: ensure day arguments + return new ViewCommand(viewArgs[1] + " " + viewArgs[2]); } - return Integer.parseInt(matcher.group("targetIndex")); + + return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE)); } /** diff --git a/src/planmysem/ui/DarkTheme.css b/src/planmysem/ui/DarkTheme.css index 5b2b70656..1c619d1de 100644 --- a/src/planmysem/ui/DarkTheme.css +++ b/src/planmysem/ui/DarkTheme.css @@ -10,7 +10,7 @@ .text-area { -fx-background-color: black; -fx-control-inner-background: black; - -fx-font-family: "Segoe UI Semibold"; + -fx-font-family: "Lucida Console"; -fx-font-size: 10pt; -fx-padding: 5 5 5 5; }