From 15990146bdc89a38c47507b386134b94e5764850 Mon Sep 17 00:00:00 2001 From: yooplo Date: Sat, 2 Nov 2024 20:55:33 +0800 Subject: [PATCH 1/2] Add onclick function to UI tag class to display tag details on display - works as intended Small issue might be found - bug found might be that cattag does not update the category --- .../seedu/address/model/tag/TagCategory.java | 2 +- .../java/seedu/address/ui/MainWindow.java | 16 ++++++++++++---- src/main/java/seedu/address/ui/TagCard.java | 19 ++++++++++++++++++- .../java/seedu/address/ui/TagListPanel.java | 7 +++++-- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/main/java/seedu/address/model/tag/TagCategory.java b/src/main/java/seedu/address/model/tag/TagCategory.java index 574d930f1de..6b89b0d150d 100644 --- a/src/main/java/seedu/address/model/tag/TagCategory.java +++ b/src/main/java/seedu/address/model/tag/TagCategory.java @@ -4,7 +4,7 @@ * Provides categories to sort Tags into, as well as colour codes for display in the UI. */ public enum TagCategory { - GENERAL("#3E7B91"), + GENERAL("#ECECEC"), // Light Grey for default color ACADEMICS("#FFD700"), // Gold ACTIVITIES("#1E90FF"), // Dodger Blue NETWORKING("#32CD32"), // Lime Green diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index dea30e94aa3..7ec0f5532bb 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -119,13 +119,13 @@ void fillInnerParts() { personListPanel = new PersonListPanel(logic.getFilteredPersonList()); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); - tagListPanel = new TagListPanel(logic.getListOfCurrentTags()); + tagListPanel = new TagListPanel(logic.getListOfCurrentTags(), this); tagsListPanelPlaceholder.getChildren().add(tagListPanel.getRoot()); resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); if (logic.getFilteredPersonList().isEmpty()) { - resultDisplay.setFeedbackToUser(LIST_EMPTY_MESSAGE); + updateResultDisplay(LIST_EMPTY_MESSAGE); } StatusBarFooter statusBarFooter = new StatusBarFooter(logic.getCampusConnectFilePath()); @@ -155,6 +155,14 @@ private void populateTagsList() { tagListPanel.updateTagList(logic.getListOfCurrentTags()); } + /** + * Updates the ResultDisplay + * @param details the String to be displayed + */ + public void updateResultDisplay(String details) { + resultDisplay.setFeedbackToUser(details); + } + /** * Opens the help window or focuses on it if it's already opened. */ @@ -197,7 +205,7 @@ private CommandResult executeCommand(String commandText) throws CommandException CommandResult commandResult = logic.execute(commandText); logger.info("Result: " + commandResult.getFeedbackToUser()); populateTagsList(); - resultDisplay.setFeedbackToUser(commandResult.getFeedbackToUser()); + updateResultDisplay(commandResult.getFeedbackToUser()); if (commandResult.isShowHelp()) { handleHelp(); } @@ -209,7 +217,7 @@ private CommandResult executeCommand(String commandText) throws CommandException return commandResult; } catch (CommandException | ParseException e) { logger.info("An error occurred while executing command: " + commandText); - resultDisplay.setFeedbackToUser(e.getMessage()); + updateResultDisplay(e.getMessage()); throw e; } } diff --git a/src/main/java/seedu/address/ui/TagCard.java b/src/main/java/seedu/address/ui/TagCard.java index 86b15df984a..e60e7ff9f6d 100644 --- a/src/main/java/seedu/address/ui/TagCard.java +++ b/src/main/java/seedu/address/ui/TagCard.java @@ -1,6 +1,7 @@ package seedu.address.ui; import javafx.fxml.FXML; +import javafx.scene.control.Alert; import javafx.scene.control.Label; import javafx.scene.layout.HBox; import javafx.scene.layout.Region; @@ -20,12 +21,28 @@ public class TagCard extends UiPart { @FXML private Label tagName; + private MainWindow mainWindow; + /** * Creates a {@code TagCard} with the given {@code Tag} and index to display. */ - public TagCard(Tag tag, int displayedIndex) { + public TagCard(Tag tag, int displayedIndex, MainWindow mainWindow) { super(FXML); + this.mainWindow = mainWindow; this.tag = tag; tagName.setText((displayedIndex + 1) + ". " + tag.tagName); + + String color = tag.getTagColour(); + tagName.setStyle("-fx-text-fill: " + color + ";"); + + tagName.setOnMouseClicked(event -> showTagDetails()); + } + + /** + * Displays tag details in the ResultDisplay component of MainWindow. + */ + private void showTagDetails() { + String details = "Tag Name: " + tag.tagName + "\nCategory: " + tag.getTagCategory().toString(); + mainWindow.updateResultDisplay(details); } } diff --git a/src/main/java/seedu/address/ui/TagListPanel.java b/src/main/java/seedu/address/ui/TagListPanel.java index 25a324053a5..0c10a6883b7 100644 --- a/src/main/java/seedu/address/ui/TagListPanel.java +++ b/src/main/java/seedu/address/ui/TagListPanel.java @@ -22,13 +22,16 @@ public class TagListPanel extends UiPart { @FXML private ListView tagListView; + private MainWindow mainWindow; + /** * Creates a {@code TagListPanel} with the given {@code ObservableList}. */ - public TagListPanel(ObservableList tagList) { + public TagListPanel(ObservableList tagList, MainWindow mainWindow) { super(FXML); tagListView.setItems(FXCollections.observableArrayList(tagList)); tagListView.setCellFactory(listView -> new TagListViewCell()); + this.mainWindow = mainWindow; } /** @@ -52,7 +55,7 @@ protected void updateItem(Tag tag, boolean empty) { setGraphic(null); setText(null); } else { - setGraphic(new TagCard(tag, getIndex()).getRoot()); + setGraphic(new TagCard(tag, getIndex(), mainWindow).getRoot()); } } } From 79063f6bb092d9411f36a420226ceae24d35395f Mon Sep 17 00:00:00 2001 From: yooplo Date: Sat, 2 Nov 2024 21:02:05 +0800 Subject: [PATCH 2/2] Checkstyle fix --- src/main/java/seedu/address/ui/TagCard.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/seedu/address/ui/TagCard.java b/src/main/java/seedu/address/ui/TagCard.java index e60e7ff9f6d..83be42e0943 100644 --- a/src/main/java/seedu/address/ui/TagCard.java +++ b/src/main/java/seedu/address/ui/TagCard.java @@ -1,7 +1,6 @@ package seedu.address.ui; import javafx.fxml.FXML; -import javafx.scene.control.Alert; import javafx.scene.control.Label; import javafx.scene.layout.HBox; import javafx.scene.layout.Region;