Skip to content

Commit

Permalink
Merge pull request #82 from Nixx162/improve-ui
Browse files Browse the repository at this point in the history
Improve UI
  • Loading branch information
zekone authored Nov 2, 2023
2 parents 07ab744 + 7b1f746 commit 785ffeb
Show file tree
Hide file tree
Showing 18 changed files with 322 additions and 56 deletions.
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.event.Event;
import seedu.address.model.person.Person;

/**
Expand All @@ -33,6 +34,9 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();

/** Returns an unmodifiable view of the filtered list of events */
ObservableList<Event> getFilteredEventList();

/**
* Returns the user prefs' address book file path.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.event.Event;
import seedu.address.model.person.Person;
import seedu.address.storage.Storage;

Expand Down Expand Up @@ -71,6 +72,11 @@ public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public ObservableList<Event> getFilteredEventList() {
return model.getFilteredEventList();
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ public class CommandResult {
/** The application should exit. */
private final boolean exit;

private final boolean listEvent;

/**
* Constructs a {@code CommandResult} with the specified fields.
*/
public CommandResult(String feedbackToUser, boolean exit) {
public CommandResult(String feedbackToUser, boolean exit, boolean listEvent) {
this.feedbackToUser = requireNonNull(feedbackToUser);
this.exit = exit;
this.listEvent = listEvent;
}

/**
* Constructs a {@code CommandResult} with the specified {@code feedbackToUser},
* and other fields set to their default value.
*/
public CommandResult(String feedbackToUser) {
this(feedbackToUser, false);
this(feedbackToUser, false, false);
}

public String getFeedbackToUser() {
Expand All @@ -40,6 +43,10 @@ public boolean isExit() {
return exit;
}

public boolean isListEvent() {
return listEvent;
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -53,7 +60,8 @@ public boolean equals(Object other) {

CommandResult otherCommandResult = (CommandResult) other;
return feedbackToUser.equals(otherCommandResult.feedbackToUser)
&& exit == otherCommandResult.exit;
&& exit == otherCommandResult.exit
&& listEvent == otherCommandResult.listEvent;
}

@Override
Expand All @@ -66,6 +74,7 @@ public String toString() {
return new ToStringBuilder(this)
.add("feedbackToUser", feedbackToUser)
.add("exit", exit)
.add("listEvent", listEvent)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ExitCommand extends Command {

@Override
public CommandResult execute(Model model) {
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, true);
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, true, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ public CommandResult execute(Model model) throws CommandException {
: -1) * (sortAscending ? -1 : 1);
});
result += StringUtil.eventListToString(eventList);
return new CommandResult(result);
return new CommandResult(result, false, true);
}
}
54 changes: 54 additions & 0 deletions src/main/java/seedu/address/ui/ContactCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package seedu.address.ui;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import seedu.address.model.person.Person;

/**
* An UI component that displays information of a {@code Person}.
*/
public class ContactCard extends UiPart<Region> {

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

/**
* Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX.
* As a consequence, UI elements' variable names cannot be set to such keywords
* or an exception will be thrown by JavaFX during runtime.
*
* @see <a href="https://github.com/se-edu/addressbook-level4/issues/336">The issue on AddressBook level 4</a>
*/

public final Person person;

@FXML
private HBox cardPane;
@FXML
private Label name;
@FXML
private Label email;
@FXML
private Label mobile;
@FXML
private Label address;
@FXML
private FlowPane tags;

/**
* Creates a {@code PersonCode} with the given {@code Person} and index to display.
*/
public ContactCard(Person person) {
super(FXML);
this.person = person;
name.setText(person.getName().fullName);
mobile.setText("Phone: " + person.getPhone().value);
address.setText(person.getAddress().value);
email.setText(person.getEmail().value);
person.getTags().stream()
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));

}
}
112 changes: 112 additions & 0 deletions src/main/java/seedu/address/ui/EventListWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package seedu.address.ui;

import java.util.logging.Logger;

import javafx.beans.property.SimpleStringProperty;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.event.Event;

/**
* Controller for a help page
*/
public class EventListWindow extends UiPart<Stage> {
private static final Logger logger = LogsCenter.getLogger(EventListWindow.class);
private static final String FXML = "EventListWindow.fxml";

@FXML private TableView<Event> table;
@FXML private TableColumn<Event, Void> indexCol;
@FXML private TableColumn<Event, String> nameCol;
@FXML private TableColumn<Event, String> startCol;
@FXML private TableColumn<Event, String> endCol;
@FXML private TableColumn<Event, String> locCol;
@FXML private TableColumn<Event, String> infoCol;

/**
* Creates a new EventListWindow.
*
* @param root Stage to use as the root of the EventListWindow.
*/
public EventListWindow(Stage root) {
super(FXML, root);
}

/**
* Creates a new EventListWindow.
*/
public EventListWindow() {
this(new Stage());
}

/**
* 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(ObservableList<Event> events) {
logger.fine("Showing help page about the application.");

indexCol.setCellFactory(col -> new TableIndexCell());
nameCol.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getName()));
startCol.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getStartString()));
endCol.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getEndString()));
locCol.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getLocationStr()));
infoCol.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getInformationStr()));

table.setItems(events);

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();
}

class TableIndexCell extends TableCell<Event, Void> {
@Override
public void updateIndex(int index) {
super.updateIndex(index);
if (isEmpty() || index < 0) {
setText(null);
} else {
setText(Integer.toString(index + 1));
}
}
}
}
21 changes: 20 additions & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class MainWindow extends UiPart<Stage> {
private PersonListPanel personListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
private EventListWindow eventListWindow;

@FXML
private StackPane commandBoxPlaceholder;
Expand Down Expand Up @@ -70,6 +71,8 @@ public MainWindow(Stage primaryStage, Logic logic) {

helpWindow = new HelpWindow();

eventListWindow = new EventListWindow();

iNSTANCE = this;
}

Expand Down Expand Up @@ -140,6 +143,18 @@ private void setWindowDefaultSize(GuiSettings guiSettings) {
}
}

/**
* Opens the event list window or focuses on it if it's already opened.
*/
@FXML
public void handleEventList() {
if (!eventListWindow.isShowing()) {
eventListWindow.show(logic.getFilteredEventList());
} else {
eventListWindow.focus();
}
}

/**
* Opens the help window or focuses on it if it's already opened.
*/
Expand All @@ -148,7 +163,7 @@ public void handleHelp() {
if (!helpWindow.isShowing()) {
helpWindow.show();
} else {
helpWindow.focus();
eventListWindow.focus();
}
}

Expand Down Expand Up @@ -183,6 +198,10 @@ private CommandResult executeCommand(String commandText) throws CommandException
logger.info("Result: " + commandResult.getFeedbackToUser());
resultDisplay.setFeedbackToUser(commandResult.getFeedbackToUser());

if (commandResult.isListEvent()) {
handleEventList();
}

if (commandResult.isExit()) {
handleExit();
}
Expand Down
Loading

0 comments on commit 785ffeb

Please sign in to comment.