Skip to content

Commit

Permalink
Merge 0171710 into a6d0001
Browse files Browse the repository at this point in the history
  • Loading branch information
linnnruoo committed Nov 11, 2018
2 parents a6d0001 + 0171710 commit 485c441
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package seedu.address.ui.calendar;
package seedu.address.ui;

import java.time.LocalDate;
import java.time.YearMonth;
Expand All @@ -7,20 +7,20 @@
import javafx.fxml.FXML;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Node;

import javafx.scene.layout.GridPane;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import seedu.address.ui.UiPart;

//@@author linnnruoo
//Inspired by the original @@author guekling
/**
* Supports the display of the month view of the calendar.
* Display the layout of calendar view
*/
public class MonthView extends UiPart<Region> {
public class CalendarLayout extends UiPart<Region> {

private static final String FXML = "MonthView.fxml";
private static final String FXML = "CalendarLayout.fxml";

private static final int SUNDAY = 7;
private static final int MAX_COLUMN = 6;
Expand All @@ -36,42 +36,41 @@ public class MonthView extends UiPart<Region> {
@FXML
private GridPane gridCalendar;

public MonthView() {
public CalendarLayout() {
super(FXML);

currentYearMonth = YearMonth.now();
viewYearMonth = currentYearMonth;

}

/**
* Displays the month view.
*
* @param yearMonth Year and month in the YearMonth format.
*/
public void getMonthView(YearMonth yearMonth) {
public void getCalendarLayout(YearMonth yearMonth) {
viewYearMonth = yearMonth;
YearMonth y = YearMonth.now();
int year = y.getYear();

setMonthCalendarTitle(year, yearMonth.getMonth().toString());
setMonthCalendarDatesAndEntries(year, yearMonth.getMonthValue());
setCalendarTitle(year, yearMonth.getMonth().toString());
setCalendarDates(year, yearMonth.getMonthValue());
}

/**
* Sets the title of the calendar according to a specific month and year.
*/
public void setMonthCalendarTitle(int year, String month) {
public void setCalendarTitle(int year, String month) {
calendarTitle.setText(month + " " + year);
}

/**
* Sets the dates and entries of a month-view calendar according to the specific month and year.
* Sets the dates of the calendar according to the specific month and year.
*
* @param year Year represented as a 4-digit integer.
* @param month Month represented by numbers from 1 to 12.
*/
private void setMonthCalendarDatesAndEntries(int year, int month) {
private void setCalendarDates(int year, int month) {
LocalDate startDate = LocalDate.of(year, month, 1);
int lengthOfMonth = startDate.lengthOfMonth();
int startDay = getMonthStartDay(startDate);
Expand All @@ -80,11 +79,11 @@ private void setMonthCalendarDatesAndEntries(int year, int month) {
datesToBePrinted = new String[36];
storeMonthDatesToBePrinted(lengthOfMonth);

setFiveWeeksMonthCalendar(startDay);
setFiveWeeksCalendar(startDay);

// If month has more than 5 weeks
if (dateCount != lengthOfMonth) {
setSixWeeksMonthCalendar(lengthOfMonth);
setSixWeeksCalendar(lengthOfMonth);
}
}

Expand All @@ -94,7 +93,7 @@ private void setMonthCalendarDatesAndEntries(int year, int month) {
* @param startDay Integer value of the day of week of the start day of the month. Values ranges from 1 - 7,
* representing the different days of the week.
*/
private void setFiveWeeksMonthCalendar(int startDay) {
private void setFiveWeeksCalendar(int startDay) {
dateCount = 1;
for (int row = 0; row <= MAX_ROW; row++) {
if (row == 0) {
Expand All @@ -118,7 +117,7 @@ private void setFiveWeeksMonthCalendar(int startDay) {
*
* @param lengthOfMonth Integer value of the number of days in a month.
*/
private void setSixWeeksMonthCalendar(int lengthOfMonth) {
private void setSixWeeksCalendar(int lengthOfMonth) {
int remainingDays = lengthOfMonth - dateCount;

for (int column = 0; column <= remainingDays; column++) {
Expand Down Expand Up @@ -181,25 +180,4 @@ private void storeMonthDatesToBePrinted(int lengthOfMonth) {
}
}
}

/**
* Checks if the dates are printed in the same row and column.
*/
public boolean dateIsEqual(Object other) {
MonthView monthView = (MonthView) other;

for (int date = 1; date <= viewYearMonth.lengthOfMonth(); date++) {
Node expectedText = gridCalendar.lookup("#date" + String.valueOf(date));
int expectedRow = gridCalendar.getRowIndex(expectedText);
int expectedColumn = gridCalendar.getColumnIndex(expectedText);

Node actualText = monthView.gridCalendar.lookup("#date" + String.valueOf(date));
int actualRow = monthView.gridCalendar.getRowIndex(actualText);
int actualColumn = monthView.gridCalendar.getColumnIndex(actualText);

return (expectedRow == actualRow) && (expectedColumn == actualColumn);
}

return false;
}
}
14 changes: 7 additions & 7 deletions src/main/java/seedu/address/ui/CalendarPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import javafx.fxml.FXML;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import seedu.address.ui.calendar.MonthView;

//@@author linnnruo
/**
* The Calendar Panel of the App.
*/
public class CalendarPanel extends UiPart<Region> {

private static final String FXML = "CalendarPanel.fxml";

private MonthView monthView;
private CalendarLayout CalendarLayout;
private YearMonth currentYearMonth;

@FXML
Expand All @@ -23,7 +23,7 @@ public class CalendarPanel extends UiPart<Region> {
public CalendarPanel() {
super(FXML);

monthView = new MonthView();
CalendarLayout = new CalendarLayout();
currentYearMonth = YearMonth.now();
createMainView();
}
Expand All @@ -32,11 +32,11 @@ public CalendarPanel() {
* Creates the view of the calendar
*/
private void createMainView() {
monthView.getMonthView(currentYearMonth);
calendar.getChildren().add(monthView.getRoot());
CalendarLayout.getCalendarLayout(currentYearMonth);
calendar.getChildren().add(CalendarLayout.getRoot());
}

public MonthView getMonthView() {
return monthView;
public CalendarLayout getCalendarLayout() {
return CalendarLayout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>

<!--@@author guekling-->
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox alignment="BASELINE_CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
<StackPane fx:id="personListPanelPlaceholder" VBox.vgrow="ALWAYS"/>
</VBox>

<StackPane fx:id="browserPlaceholder" minWidth="230" prefWidth="230" >
<StackPane fx:id="browserPlaceholder" prefWidth="230" >
<padding>
<Insets top="3" right="3" bottom="3" left="3" />
</padding>
</StackPane>

<StackPane fx:id="calendarPlaceholder" minWidth="480" prefWidth="480" >
<StackPane fx:id="calendarPlaceholder" minWidth="340" prefWidth="340" >
</StackPane>

<VBox fx:id="todoList" minWidth="230" prefWidth="230" maxWidth="240" SplitPane.resizableWithParent="false">
Expand Down

0 comments on commit 485c441

Please sign in to comment.