Skip to content

Commit

Permalink
feat: add description window and touch up ui
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuhanming committed Apr 3, 2020
1 parent 210f2e8 commit 22550fd
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 46 deletions.
5 changes: 5 additions & 0 deletions src/main/java/modulo/model/Title.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.time.format.DateTimeFormatter;

import modulo.model.displayable.Displayable;
import modulo.model.module.AcademicYear;

/**
* Class to section events out by date.
Expand Down Expand Up @@ -51,6 +52,10 @@ public Title(LocalDateTime localDateTime) {
}
}

public Title(AcademicYear academicYear) {
this.title = academicYear.toModuleCardFormat();
}

public String getTitle() {
return title;
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/modulo/model/module/AcademicYear.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,15 @@ public String toModuleCardFormat() {
public String toString() {
return getStartYear() + "/" + getEndYear() + "+" + getSemester();
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AcademicYear // instanceof handles nulls
&& startYear == (((AcademicYear) other).startYear)
&& endYear == (((AcademicYear) other).endYear)
&& semester == (((AcademicYear) other).semester)
&& startDate.equals(((AcademicYear) other).startDate)
&& endDate.equals(((AcademicYear) other).endDate)); // state check
}
}
99 changes: 99 additions & 0 deletions src/main/java/modulo/ui/DescriptionWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package modulo.ui;

import java.util.logging.Logger;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import modulo.commons.core.LogsCenter;

/**
* Controller for a description page
*/
public class DescriptionWindow extends UiPart<Stage> {

private static final Logger logger = LogsCenter.getLogger(DescriptionWindow.class);
private static final String FXML = "DescriptionWindow.fxml";

@FXML
private Label description;

@FXML
private Label moduleName;

/**
* Creates a new DescriptionWindow.
*
* @param root Stage to use as the root of the DescriptionWindow.
* @param description Description to display.
*/
public DescriptionWindow(Stage root, String description, String moduleName) {
super(FXML, root);
this.moduleName.setText(moduleName);
this.moduleName.setWrapText(true);
this.moduleName.setMaxWidth(600.0);
this.description.setText(description);
this.description.setWrapText(true);
this.description.setMaxWidth(600.0);
}

/**
* Creates a new empty DescriptionWindow.
*/
public DescriptionWindow() {
this(new Stage(), "", "");
}

/**
* Creates a new DescriptionWindow with a description.
*/
public DescriptionWindow(String description, String moduleName) {
this(new Stage(), description, moduleName);
}

/**
* Shows the help window.
*
* @throws IllegalStateException <ul>
* <li>
* if this method is called on a thread other than the JavaFX
* Application Thread.
* </li>
* <li>
* if this method is called during animation or layout processing.
* </li>
* <li>
* if this method is called on the primary stage.
* </li>
* <li>
* if {@code dialogStage} is already showing.
* </li>
* </ul>
*/
public void show() {
logger.fine("Showing help page about the application.");
getRoot().show();
getRoot().centerOnScreen();
}

/**
* Returns true if the help window is currently being shown.
*/
public boolean isShowing() {
return getRoot().isShowing();
}

/**
* Hides the help window.
*/
public void hide() {
getRoot().hide();
}

/**
* Focuses on the help window.
*/
public void focus() {
getRoot().requestFocus();
}
}
59 changes: 43 additions & 16 deletions src/main/java/modulo/ui/ListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import modulo.model.displayable.Displayable;
import modulo.model.displayable.DisplayablePair;
import modulo.model.event.Event;
import modulo.model.module.AcademicYear;
import modulo.model.module.Module;

/**
Expand All @@ -33,9 +34,9 @@ public ListPanel(ObservableList<? extends Displayable> displayableList, MainWind
super(FXML);
ObservableList<Displayable> listViewList;
if (!displayableList.isEmpty() && displayableList.get(0) instanceof Event) {
listViewList = processDisplayableList((ObservableList<Displayable>) displayableList);
listViewList = processEventDisplayableList((ObservableList<Displayable>) displayableList);
} else {
listViewList = (ObservableList<Displayable>) displayableList;
listViewList = processModuleDisplayableList((ObservableList<Displayable>) displayableList);
}
listView.setItems(listViewList);
listView.setCellFactory(listView -> new ListViewCell(mainWindow));
Expand All @@ -44,19 +45,19 @@ public ListPanel(ObservableList<? extends Displayable> displayableList, MainWind
/**
* Returns a processed Event list with Titles inserted.
*
* @param displaybleList List of {@code Event} to process.
* @param displayableList List of {@code Event} to process.
* @return List with Titles inserted.
*/
private ObservableList<Displayable> processDisplayableList(ObservableList<Displayable> displaybleList) {
private ObservableList<Displayable> processEventDisplayableList(ObservableList<Displayable> displayableList) {
final ObservableList<Displayable> result = FXCollections.observableArrayList();
if (displaybleList.size() == 0) {
if (displayableList.size() == 0) {
return result;
}
LocalDateTime currentDateTime = ((Event) displaybleList.get(0)).getEventStart();
LocalDateTime currentDateTime = ((Event) displayableList.get(0)).getEventStart();
LocalDate currentDate = currentDateTime.toLocalDate();
result.add(0, new Title(currentDateTime));
for (int i = 0; i < displaybleList.size(); i++) {
Event event = (Event) displaybleList.get(i);
for (int i = 0; i < displayableList.size(); i++) {
Event event = (Event) displayableList.get(i);
LocalDateTime localDateTime = event.getEventStart();
LocalDate localDate = localDateTime.toLocalDate();
if (!localDate.isEqual(currentDate)) {
Expand All @@ -68,6 +69,31 @@ private ObservableList<Displayable> processDisplayableList(ObservableList<Displa
return result;
}

/**
* Returns a processed Module list with Titles inserted.
*
* @param displayableList List of {@code Module} to process.
* @return List with Titles inserted.
*/
private ObservableList<Displayable> processModuleDisplayableList(ObservableList<Displayable> displayableList) {
final ObservableList<Displayable> result = FXCollections.observableArrayList();
if (displayableList.size() == 0) {
return result;
}
AcademicYear currentAcademicYear = ((Module) displayableList.get(0)).getAcademicYear();
result.add(0, new Title(currentAcademicYear));
for (int i = 0; i < displayableList.size(); i++) {
Module module = (Module) displayableList.get(i);
AcademicYear academicYear = module.getAcademicYear();
if (!academicYear.equals(currentAcademicYear)) {
result.add(new Title(academicYear));
currentAcademicYear = academicYear;
}
result.add(new DisplayablePair<>(module, i));
}
return result;
}

/**
* Selects displayable at given index.
*
Expand Down Expand Up @@ -125,14 +151,15 @@ protected void updateItem(Displayable listItem, boolean empty) {
setGraphic(null);
setText(null);
} else if (listItem instanceof DisplayablePair) {
@SuppressWarnings("unchecked")
DisplayablePair<Event, Integer> item = (DisplayablePair<Event, Integer>) listItem;
setGraphic(new EventCard(item.getFirst(), item.getSecond() + 1).getRoot());
setOnMouseClicked(event -> mainWindow.handleListClick(item.getSecond()));
setDisable(false);
} else if (listItem instanceof Module) {
setGraphic(new ModuleCard((Module) listItem, getIndex() + 1).getRoot());
setOnMouseClicked(event -> mainWindow.handleListClick(getIndex()));
DisplayablePair item = (DisplayablePair) listItem;
Integer index = ((Integer) item.getSecond());
if (item.getFirst() instanceof Event) {
setGraphic(new EventCard((Event) item.getFirst(), index + 1).getRoot());
} else {
assert item.getFirst() instanceof Module;
setGraphic(new ModuleCard((Module) item.getFirst(), index + 1).getRoot());
}
setOnMouseClicked(event -> mainWindow.handleListClick(index));
setDisable(false);
} else if (listItem instanceof Title) {
setGraphic(new TitleCard((Title) listItem).getRoot());
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/modulo/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class MainWindow extends UiPart<Stage> {
private ListPanel listPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
private DescriptionWindow descriptionWindow;
private RightPanel rightPanel;

@FXML
Expand Down Expand Up @@ -78,6 +79,7 @@ public MainWindow(Stage primaryStage, Logic logic) {
setWindowDefaultSize(logic.getGuiSettings());

helpWindow = new HelpWindow();
descriptionWindow = new DescriptionWindow();
}

public Stage getPrimaryStage() {
Expand Down Expand Up @@ -139,6 +141,19 @@ public void handleHelp() {
}
}

/**
* Opens the description window with the given description.
*
* @param description Description to show.
*/
public void handleDescription(String description, String moduleName) {
if (descriptionWindow.isShowing()) {
descriptionWindow.hide();
}
descriptionWindow = new DescriptionWindow(description, moduleName);
descriptionWindow.show();
}

void show() {
primaryStage.show();
}
Expand All @@ -153,6 +168,7 @@ private void handleExit() {
logic.setGuiSettings(guiSettings);
helpWindow.hide();
primaryStage.hide();
descriptionWindow.hide();
}

public ListPanel getListPanel() {
Expand Down Expand Up @@ -195,6 +211,7 @@ private CommandResult executeCommand(String commandText) throws CommandException
/**
* Shows event list as callback from EventButton.
*/
@FXML
public void handleEventButton() {
try {
this.executeCommand("list e");
Expand All @@ -207,6 +224,7 @@ public void handleEventButton() {
/**
* Shows module list as callback from ModuleButton.
*/
@FXML
public void handleModuleButton() {
try {
this.executeCommand("list m");
Expand Down
19 changes: 2 additions & 17 deletions src/main/java/modulo/ui/RightPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public class RightPanel extends UiPart<Region> {

private static final String FXML = "DetailsWindow.fxml";
private static final String FXML = "RightPanel.fxml";
private ObservableList<Event> eventList;
private MainWindow mainWindow;

Expand All @@ -42,22 +42,7 @@ public RightPanel(Displayable displayable, MainWindow mainWindow) {
} else {
deadlineListView.setItems(FXCollections.emptyObservableList());
}
rightPanelDescription = new RightPanelDescription(displayable);
slideEventCard.getChildren().setAll(rightPanelDescription.getRoot());
deadlineListView.setCellFactory(listView -> new ListViewCell(mainWindow));
}

/**
* Updates this component.
*/
public void updateStatus() {
if (displayable instanceof Event) {
deadlineListView.setItems(FXCollections.observableArrayList(((Event) displayable).getDeadlines()));
} else {
assert displayable instanceof Module;
deadlineListView.setItems(FXCollections.observableArrayList(((Module) displayable).getEvents()));
}
rightPanelDescription = new RightPanelDescription(displayable);
rightPanelDescription = new RightPanelDescription(displayable, mainWindow);
slideEventCard.getChildren().setAll(rightPanelDescription.getRoot());
deadlineListView.setCellFactory(listView -> new ListViewCell(mainWindow));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/modulo/ui/RightPanelDeadlineCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public class RightPanelDeadlineCard extends UiPart<Region> {

private static final String FXML = "DeadlineListCard.fxml";
private static final String FXML = "RightPanelDeadlineCard.fxml";

public final Deadline deadline;

Expand Down
Loading

0 comments on commit 22550fd

Please sign in to comment.