Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #206 from conradsoon/v1.4-notes-fix
Browse files Browse the repository at this point in the history
Fixes for `notes`
  • Loading branch information
conradsoon committed Nov 8, 2023
2 parents ada8718 + 22cf1e8 commit abcfadc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
38 changes: 26 additions & 12 deletions src/main/java/seedu/address/ui/NotesWindow.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package seedu.address.ui;

import java.util.List;
import java.util.logging.Logger;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
Expand All @@ -23,7 +24,7 @@ public class NotesWindow extends UiPart<Stage> {
private static final String FXML = "NotesWindow.fxml";

@FXML
private ListView<String> notesListView;
private ListView<Note> notesListView;

private final Person person;

Expand Down Expand Up @@ -67,16 +68,29 @@ public void hide() {
getRoot().hide();
}

public void focus() {
getRoot().requestFocus();
}

private void populateListView(List<Note> notes) {
ObservableList<String> notesObservableList = FXCollections.observableArrayList();
for (Note note : notes) {
notesObservableList.add(note.toString());
}
private void populateListView(ObservableList<Note> notes) {
ObservableList<Note> notesObservableList = FXCollections.observableArrayList(notes);
notesListView.setItems(notesObservableList);
notesListView.setCellFactory(listView -> new ListCell<Note>() {
@Override
protected void updateItem(Note note, boolean empty) {
super.updateItem(note, empty);
if (empty || note == null) {
setText(null);
setGraphic(null);
} else {
Label label = new Label((getIndex() + 1) + ". " + note.toString());
label.setWrapText(true);
label.prefWidthProperty().bind(listView.widthProperty().subtract(40));
setGraphic(label);
}
}
});

// make sure the width is always correct even after resizing the window
notesListView.widthProperty().addListener((observable) -> {
notesListView.refresh();
});
}

@FXML
Expand All @@ -85,7 +99,7 @@ void handleClose() {
stage.close();
}

public ListView<String> getNotesListView() {
public ListView<Note> getNotesListView() {
return notesListView;
}
}
6 changes: 2 additions & 4 deletions src/main/resources/view/NotesWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<?import javafx.scene.control.Label?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.Scene?>
<fx:root resizable="false" title="Notes"
<fx:root title="Notes"
type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<scene>
<Scene>
Expand All @@ -15,9 +15,7 @@
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
<Label text="Notes" style="-fx-font-weight: bold; -fx-font-size: 18px;" />
<ScrollPane fitToWidth="true" prefHeight="300" VBox.vgrow="ALWAYS">
<ListView fx:id="notesListView" />
</ScrollPane>
<ListView fx:id="notesListView" VBox.vgrow="ALWAYS"/>
<Label text="Press ESC to exit" style="-fx-font-size: 12px;" />
<Button text="Close" onAction="#handleClose" />
</VBox>
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/seedu/address/ui/NotesWindowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import org.testfx.framework.junit5.ApplicationTest;

import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.scene.input.KeyCode;
import javafx.stage.Stage;
import seedu.address.model.person.Note;
import seedu.address.model.person.Person;

public class NotesWindowTest extends ApplicationTest {
Expand Down Expand Up @@ -43,9 +45,14 @@ public void setUp() {
@Test
public void displayNotes_correctNumberOfItemsAndContent_displaysExpectedNotes() {
interact(() -> {
List<String> expectedNotes = Arrays.asList("Likes to swim", "Likes to run", "Is a chad");
List<Note> expectedNotes = Arrays.asList(
new Note("Likes to swim"),
new Note("Likes to run"),
new Note("Is a chad")
);
verifyThat("#notesListView", hasItems(3));
assertTrue(notesWindow.getNotesListView().getItems().containsAll(expectedNotes));
ObservableList<Note> actualNotes = notesWindow.getNotesListView().getItems();
assertTrue(actualNotes.containsAll(expectedNotes));
});
}

Expand Down

0 comments on commit abcfadc

Please sign in to comment.