Skip to content

Commit

Permalink
Add CSS to view
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxunn committed Oct 24, 2023
1 parent 4763eca commit 1e0ccf7
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/main/java/seedu/address/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@ public class CommandResult {
/** The application should exit. */
private final boolean exit;

private String state;

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

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

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

public String checkState() {
return state;
}

@Override
public boolean equals(Object other) {
if (other == this) {
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, false, true);
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true, "exit");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class HelpCommand extends Command {

@Override
public CommandResult execute(Model model) {
return new CommandResult(SHOWING_HELP_MESSAGE, true, false);
return new CommandResult(SHOWING_HELP_MESSAGE, true, false, "help");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ListCommand extends Command {

public static final String MESSAGE_SUCCESS = "Listed all persons";

public static final String state = "list";

@Override
public CommandResult execute(Model model) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/logic/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
public class ViewCommand extends Command {

public static final String COMMAND_WORD = "view";
public static final String state = "view";


public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Views the person identified by the index number used.\n"
Expand All @@ -39,6 +41,7 @@ public CommandResult execute(Model model) throws CommandException {


if (targetIndex.getZeroBased() < 0 || targetIndex.getZeroBased() >= model.getFilteredPersonList().size()) {
logger.info(targetIndex.getZeroBased() + "+ " + model.getFilteredPersonList().size());
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Expand All @@ -47,7 +50,7 @@ public CommandResult execute(Model model) throws CommandException {

logger.info("Target Index: " + targetIndex.getZeroBased());
logger.info("Client to View: " + personToView);
return new CommandResult(MESSAGE_SUCCESS);
return new CommandResult(MESSAGE_SUCCESS, false, false, "view");
}
@Override
public boolean equals(Object other) {
Expand Down
59 changes: 56 additions & 3 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

import java.util.logging.Logger;

import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextInputControl;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.StackPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.scene.Scene;
import seedu.address.commons.core.GuiSettings;
import seedu.address.model.person.Person;
import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.Logic;
import javafx.stage.StageStyle;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
Expand All @@ -28,12 +33,17 @@ public class MainWindow extends UiPart<Stage> {
private final Logger logger = LogsCenter.getLogger(getClass());

private Stage primaryStage;

private Logic logic;

// Independent Ui parts residing in this Ui container
private PersonListPanel personListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
private ViewWindow viewWindow;
@FXML
private StackPane viewWindowPlaceholder;


@FXML
private StackPane commandBoxPlaceholder;
Expand Down Expand Up @@ -64,14 +74,15 @@ public MainWindow(Stage primaryStage, Logic logic) {
this.primaryStage = primaryStage;
this.logic = logic;


// Configure the UI
setWindowDefaultSize(logic.getGuiSettings());

setAccelerators();

helpWindow = new HelpWindow();
}


public Stage getPrimaryStage() {
return primaryStage;
}
Expand Down Expand Up @@ -109,7 +120,6 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
}
});
}

/**
* Fills up all the placeholders of this window.
*/
Expand Down Expand Up @@ -166,7 +176,40 @@ private void handleExit() {
helpWindow.hide();
primaryStage.hide();
}
@FXML
public void handleView(Person selectedPerson, int displayedIndex) {
logger.info("handleView");
showViewWindow(selectedPerson, displayedIndex);
}


private void showViewWindow(Person selectedPerson, int displayedIndex) {
try {
if (viewWindow != null && viewWindowPlaceholder != null) {
clearViewContent();
viewWindowPlaceholder.getChildren().add(viewWindow.getRoot());
personListPanelPlaceholder.setVisible(false);
personListPanelPlaceholder.setManaged(false);
viewWindowPlaceholder.setVisible(true);
viewWindowPlaceholder.setManaged(true);
} else {

}
} catch (Exception e) {
e.printStackTrace();
}
}

public void clearViewContent() {
viewWindowPlaceholder.getChildren().clear();
}

private void hideViewWindow() {
if (viewWindow != null && viewWindowPlaceholder != null) {
viewWindowPlaceholder.setVisible(false);
personListPanelPlaceholder.setVisible(true);
}
}
public PersonListPanel getPersonListPanel() {
return personListPanel;
}
Expand All @@ -177,9 +220,11 @@ public PersonListPanel getPersonListPanel() {
* @see seedu.address.logic.Logic#execute(String)
*/
private CommandResult executeCommand(String commandText) throws CommandException, ParseException {

try {
CommandResult commandResult = logic.execute(commandText);
logger.info("Result: " + commandResult.getFeedbackToUser());
logger.info("reached here: " + logic.getFilteredPersonList());
resultDisplay.setFeedbackToUser(commandResult.getFeedbackToUser());

if (commandResult.isShowHelp()) {
Expand All @@ -190,12 +235,20 @@ private CommandResult executeCommand(String commandText) throws CommandException
handleExit();
}

if (commandResult.checkState().equals("view")) {
ObservableList<Person> allPersons = logic.getFilteredPersonList();
Person selectedPerson = allPersons.get(0);
viewWindow = new ViewWindow(selectedPerson, 1);

handleView(selectedPerson, 0);
} else {
hideViewWindow();
}
return commandResult;
} catch (CommandException | ParseException e) {
logger.info("An error occurred while executing command: " + commandText);
resultDisplay.setFeedbackToUser(e.getMessage());
throw e;
}
}

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

import java.util.Comparator;
import java.util.logging.Logger;

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.commons.core.LogsCenter;
import seedu.address.logic.commands.ViewCommand;
import seedu.address.model.person.Person;

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

private static final String FXML = "ViewWindow.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 id;
@FXML
private Label phone;
@FXML
private Label address;
@FXML
private Label email;
@FXML
private FlowPane tags;

@FXML
private Label otherInfo;
private static final Logger logger = LogsCenter.getLogger(ViewWindow.class);

/**
* Creates a {@code PersonCode} with the given {@code Person} and index to display.
*/
public ViewWindow(Person person, int displayedIndex) {
super(FXML);
this.person = person;
id.setText(displayedIndex + ".");
name.setText(person.getName().fullName);
phone.setText(person.getPhone().value);
address.setText(person.getAddress().value);
email.setText(person.getEmail().value);

Label label = new Label(person.getType().value);
if (person.isClient()) {
label.getStyleClass().add("client-label");
} else {
label.getStyleClass().add("lead-label");
}
tags.getChildren().add(label);
person.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
}
}
Binary file added src/main/resources/images/profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/images/smartphone-call.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
<StackPane fx:id="personListPanelPlaceholder" VBox.vgrow="ALWAYS"/>
<StackPane fx:id="viewWindowPlaceholder" visible= "false"/>
</VBox>

<StackPane fx:id="statusbarPlaceholder" VBox.vgrow="NEVER" />
</VBox>
</Scene>
Expand Down
21 changes: 21 additions & 0 deletions src/main/resources/view/ViewWindow.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#cardPane {
-fx-background-color: #FBFBD4;
}
.label {
-fx-font-family: "Arial";
-fx-font-size: 18px;
}
.cell_big_label {
-fx-font-size: 24px;
-fx-font-weight: bold;
-fx-text-fill: #666;
-fx-padding: 10px;
}


.cell_small_label {
-fx-font-size: 18px;
-fx-text-fill: #999;
-fx-padding: 5px;
}

Loading

0 comments on commit 1e0ccf7

Please sign in to comment.