Skip to content

Commit

Permalink
Merge pull request #70 from QX-CHEN/display
Browse files Browse the repository at this point in the history
Display
  • Loading branch information
mhchan163 authored Oct 27, 2020
2 parents 3c7b801 + af1bde9 commit e0d32ed
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 61 deletions.
26 changes: 20 additions & 6 deletions src/main/java/seedu/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import seedu.data.TaskMap;
import seedu.ui.DisplayMode;

import java.time.LocalDate;

public class CommandResult {
private final String message;

private TaskMap tasks = null;
private DisplayMode displayMode = DisplayMode.ALL;
private boolean isExit = false;
private LocalDate date;

public CommandResult(String message) {
this.message = message;
Expand All @@ -18,12 +22,6 @@ public CommandResult(String message, TaskMap tasks) {
this.tasks = tasks;
}

public CommandResult(String message, TaskMap tasks, DisplayMode displayMode) {
this.message = message;
this.tasks = tasks;
this.displayMode = displayMode;
}

public String getMessage() {
return message;
}
Expand All @@ -43,4 +41,20 @@ public boolean isExit() {
public void setExit(boolean exit) {
isExit = exit;
}

public LocalDate getDate() {
return date;
}

public void setDate(LocalDate date) {
this.date = date;
}

public void setTasks(TaskMap tasks) {
this.tasks = tasks;
}

public void setDisplayMode(DisplayMode displayMode) {
this.displayMode = displayMode;
}
}
29 changes: 13 additions & 16 deletions src/main/java/seedu/commands/List.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.util.Locale;
import java.util.regex.Pattern;
import java.util.zip.CheckedOutputStream;

import static seedu.messages.Messages.LIST_MESSAGE;
import static seedu.messages.Messages.LS;

public class List extends ReadOnlyCommand {
public static final String COMMAND_WORD = "list";
Expand Down Expand Up @@ -41,26 +39,25 @@ public CommandResult execute(TaskMap tasks) {
assert !(dateFlag && priorityFlag);

// TODO Check flag condition

if (dateFlag) {
return new CommandResult(LIST_MESSAGE, tasks.sortListByDate());
} else if (priorityFlag) {
return new CommandResult(LIST_MESSAGE, tasks.sortListByPriority());
}
if (displayByWeek || displayByMonth) {
DisplayMode displayMode;
if (displayByWeek) {
displayMode = DisplayMode.WEEK;
} else {
displayMode = DisplayMode.MONTH;
}
return new CommandResult(LIST_MESSAGE, tasks, displayMode);
}

CommandResult result = new CommandResult(LIST_MESSAGE, tasks);

if (date != null) {
LocalDate tempDate = LocalDate.parse(date, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
String dateString = LS + tempDate.format(DateTimeFormatter.ofPattern("dd-MMM-yyyy"))
+ " " + tempDate.getDayOfWeek().getDisplayName(TextStyle.SHORT, Locale.ENGLISH) + ":" + LS;
return new CommandResult(LIST_MESSAGE + dateString, tasks.searchByDate(tempDate));
result.setDate(tempDate);
result.setDisplayMode(DisplayMode.DAY);
} else if (displayByWeek) {
result.setDisplayMode(DisplayMode.WEEK);
} else if (displayByMonth) {
result.setDisplayMode(DisplayMode.MONTH);
}
return new CommandResult(LIST_MESSAGE, tasks);

return result;
}
}
57 changes: 56 additions & 1 deletion src/main/java/seedu/ui/DayStructure.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,71 @@
package seedu.ui;

import seedu.commons.Util;
import seedu.data.TaskMap;
import seedu.task.Task;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.util.Locale;

import static seedu.messages.Messages.LS;

public class DayStructure extends DisplayDateStructure {

public DayStructure(LocalDate date) {
super(date);
}

@Override
protected void generateScreen(TaskMap tasks) {
protected void generateContent(TaskMap tasks) {
StringBuilder stringBuilder = new StringBuilder();

String headerFormat = " | %-10s | %-20s | %-15s | %-10s | %-10s | %-11s |" + LS;
String contentFormat = " | %-10s | %-20s | %-15s | %-10s | %-10s | %-20s |" + LS;

stringBuilder.append(LS)
.append(currentDate.format(DateTimeFormatter.ofPattern("dd-MMM-yyyy")))
.append(" ")
.append(currentDate.getDayOfWeek().getDisplayName(TextStyle.SHORT, Locale.ENGLISH))
.append(":")
.append(LS)
.append(" ")
.append(Util.generatePadStringWithCharAndLength('_', 93))
.append(LS)
.append(String.format(headerFormat, "Index", "Description", "Date", "Start", "End", "Priority"))
.append(" ").append(Util.generatePadStringWithCharAndLength('-', 93))
.append(LS);

TaskMap filteredTasks = tasks.searchByDate(currentDate);
if (filteredTasks.size() == 0) {
stringBuilder.append(" |")
.append(Util.generatePadStringWithCharAndLength(' ', 93))
.append("|")
.append(LS);
} else {
for (Task task : filteredTasks.getValues()) {
stringBuilder.append(String.format(contentFormat,
"#" + task.getTaskID(),
Util.limitStringWithDots(task.getDescription(), 20),
task.getDate(),
task.getStartTime() == null ? "" : task.getStartTime(),
task.getEndTime() == null ? "" : task.getEndTime(),
task.getPriority()));
}
}
stringBuilder.append(" ")
.append(Util.generatePadStringWithCharAndLength('-', 93))
.append(LS);

content = stringBuilder.toString();
}

public void increment() {
setCurrentDate(currentDate.plusDays(1));
}

public void decrement() {
setCurrentDate(currentDate.minusDays(1));
}
}
54 changes: 50 additions & 4 deletions src/main/java/seedu/ui/DisplayDateStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.time.format.TextStyle;
import java.util.Locale;

public abstract class DisplayDateStructure {
public class DisplayDateStructure {
protected static final TextStyle MONTH_TEXT_STYLE = TextStyle.FULL;
protected static final TextStyle WEEKDAY_TEXT_STYLE = TextStyle.SHORT;
protected static final Locale LOCALE = Locale.ENGLISH;
Expand All @@ -24,11 +24,57 @@ public abstract class DisplayDateStructure {
protected DayOfWeek currentDateDayOfWeek = currentDate.getDayOfWeek();

protected char[][] screen;
protected String content = null;

public char[][] getScreen() {
return screen;

public DisplayDateStructure() {
this(LocalDate.now());
}

protected abstract void generateScreen(TaskMap tasks);
public DisplayDateStructure(LocalDate date) {
init(date);
}

private void init(LocalDate date) {
currentDate = date;
currentMonth = currentDate.getMonth();
currentDateDayOfMonth = currentDate.getDayOfMonth();
currentDateDayOfWeek = currentDate.getDayOfWeek();
}

public String getContent() {
if (screen != null) {
StringBuilder stringBuilder = new StringBuilder();
for (char[] arr : screen) {
stringBuilder.append(arr);
stringBuilder.append(System.lineSeparator());
}
content = stringBuilder.toString();
}
return content;
}

protected void generateContent(TaskMap tasks) {
}

public void setCurrentDate(LocalDate currentDate) {
this.currentDate = currentDate;
updateFields();
}

public void setCurrentMonth(Month currentMonth) {
this.currentMonth = currentMonth;
}

public void increment() {
}

public void decrement() {
}

public void updateFields() {
currentMonth = currentDate.getMonth();
currentDateDayOfMonth = currentDate.getDayOfMonth();
currentDateDayOfWeek = currentDate.getDayOfWeek();
}
}
3 changes: 2 additions & 1 deletion src/main/java/seedu/ui/DisplayMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum DisplayMode {
ALL,
WEEK,
MONTH;
MONTH,
DAY;
}
43 changes: 37 additions & 6 deletions src/main/java/seedu/ui/MonthStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
import static seedu.commons.Util.putsIntoArrayWithCentralise;

public class MonthStructure extends DisplayDateStructure {
private static final int DISPLAY_HEIGHT = 51;
private static int displayHeight = 53;
private static final int ROW_NUM_OFFSET = 2; // Month name and Day of week

@Override
protected void generateScreen(TaskMap tasks) {

protected void generateContent(TaskMap tasks) {
setHeight();
String monthString = currentMonth.getDisplayName(MONTH_TEXT_STYLE, LOCALE);

int currentCol = 1;
int currentRow = 1;

// Set empty screen
screen = new char[DISPLAY_HEIGHT][DISPLAY_LENGTH];
screen = new char[displayHeight][DISPLAY_LENGTH];
generateScreenWithBorder();

// Display month name
Expand Down Expand Up @@ -79,12 +79,43 @@ protected void generateScreen(TaskMap tasks) {
}

private void generateScreenWithBorder() {
for (int i = 0; i < DISPLAY_HEIGHT; i++) {
for (int i = 0; i < displayHeight; i++) {
for (int j = 0; j < DISPLAY_LENGTH; j++) {
screen[i][j] = (i == 0 || i == (DISPLAY_HEIGHT - 1)
screen[i][j] = (i == 0 || i == (displayHeight - 1)
|| ((i - ROW_NUM_OFFSET) % WEEK_ROW_WIDTH == 0 && i != ROW_NUM_OFFSET)
|| j % DAY_COLUMN_WIDTH == 0) ? '*' : ' ';
}
}
}

public void increment() {
setCurrentMonth(currentMonth.plus(1));
if (currentMonth.getValue() == 1) {
setCurrentDate(LocalDate.of(currentDate.getYear() + 1, currentMonth, 1));
} else {
setCurrentDate(LocalDate.of(currentDate.getYear(), currentMonth, 1));
}
}

public void decrement() {
setCurrentMonth(currentMonth.minus(1));
if (currentMonth.getValue() == 12) {
setCurrentDate(LocalDate.of(currentDate.getYear() - 1, currentMonth, 1));
} else {
setCurrentDate(LocalDate.of(currentDate.getYear(), currentMonth, 1));
}
}

private void setHeight() {
LocalDate firstDay = LocalDate.of(currentDate.getYear(), currentMonth, 1);
int count = 0;
int lengthOfCurrentMonth = currentDate.lengthOfMonth();
LocalDate tempDay = firstDay;
while (tempDay.isBefore(firstDay.plusDays(lengthOfCurrentMonth + firstDay.getDayOfWeek().getValue() - 1))) {
tempDay = tempDay.plusDays(DAYS_PER_WEEK);
count++;
}
displayHeight = 10 * count + 3;
}

}
Loading

0 comments on commit e0d32ed

Please sign in to comment.