Skip to content

Commit

Permalink
Merge pull request #93 from LHeng1/branch-ui-compare
Browse files Browse the repository at this point in the history
Add basic UI for compare function
  • Loading branch information
LHeng1 authored Oct 27, 2023
2 parents fba375f + 1146a74 commit 9c1c066
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/main/java/seedu/address/logic/commands/CompareCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Gpa;
import seedu.address.model.person.Person;
import seedu.address.ui.CompareWindow;


/**
Expand Down Expand Up @@ -42,7 +42,6 @@ public CompareCommand(Index index1, Index index2) {

@Override
public CommandResult execute(Model model) throws CommandException {
String compareMessage;
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();

Expand All @@ -55,21 +54,10 @@ public CommandResult execute(Model model) throws CommandException {
Person personToCompare1 = lastShownList.get(index1.getZeroBased());
Person personToCompare2 = lastShownList.get(index2.getZeroBased());

model.updateFilteredPersonList(person -> person.equals(personToCompare1)
|| person.equals(personToCompare2));
new CompareWindow(personToCompare1, personToCompare2).show();

Gpa gpa1 = personToCompare1.getGpa();
Gpa gpa2 = personToCompare2.getGpa();
return new CommandResult("Comparison successful! ");

if (gpa1.compareTo(gpa2) == 0) {
compareMessage = "They have the same GPA, do look out for other criteria!";
} else if (gpa1.compareTo(gpa2) > 0) {
compareMessage = personToCompare1.getName() + " has a higher GPA!";
} else {
compareMessage = personToCompare2.getName() + " has a higher GPA!";
}

return new CommandResult("Comparison successful! " + compareMessage);
} catch (IndexOutOfBoundsException e) {
throw new CommandException("Error: One or both of the specified applicants"
+ " were not found in the list.");
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/seedu/address/ui/CompareWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package seedu.address.ui;

import java.io.IOException;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import seedu.address.MainApp;
import seedu.address.model.person.Gpa;
import seedu.address.model.person.Person;

/**
* The Compare Pop-up Window. Provides a separate JavaFX stage when a "compare" command is inputted.
* This window is used to display and compare the details of two applicants,
* including student number, name, and their relevant achievements.
*/
public class CompareWindow extends Stage {
@FXML
private Label person1StuNum;
@FXML
private Label person2StuNum;
@FXML
private Label person1Name;
@FXML
private Label person1Gpa;
@FXML
private Label person2Name;
@FXML
private Label person2Gpa;
@FXML
private Label nameLabel;
@FXML
private Label gpaLabel;
@FXML
private Rectangle gpa1Highlight;
@FXML
private Rectangle gpa2Highlight;

/**
* Creates a new instance of the CompareWindow with information about two persons to be compared.
*
* @param person1 The first person for comparison.
* @param person2 The second person for comparison.
*/
public CompareWindow(Person person1, Person person2) {
FXMLLoader fxmlLoader = new FXMLLoader(MainApp.class.getResource("/view/CompareWindow.fxml"));
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException e) {
throw new RuntimeException(e);
}

setTitle("Comparison Result");

Gpa gpa1 = person1.getGpa();
Gpa gpa2 = person2.getGpa();

person1StuNum.setText(person1.getStudentNumber().toString());
person1Name.setText(person1.getName().toString());
person1Gpa.setText(gpa1.toString());

person2StuNum.setText(person2.getStudentNumber().toString());
person2Name.setText(person2.getName().toString());
person2Gpa.setText(gpa2.toString());

if (gpa1.compareTo(gpa2) > 0) {
gpa1Highlight.setOpacity(0.33);
} else if (gpa1.compareTo(gpa2) < 0) {
gpa2Highlight.setOpacity(0.33);
}

Scene scene = new Scene(fxmlLoader.getRoot());
setWidth(900);
setHeight(600);
setScene(scene);
}
}
42 changes: 42 additions & 0 deletions src/main/resources/view/CompareWindow.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.shape.Rectangle?>

<GridPane alignment="CENTER" gridLinesVisible="true" hgap="10.0" style="-fx-background-color: #616B6f;" vgap="10" xmlns="http://javafx.com/javafx/20.0.1" xmlns:fx="http://javafx.com/fxml/1">
<padding>
<Insets bottom="100.0" left="100.0" right="100.0" top="100.0" />
</padding>
<Label fx:id="person1Name" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="80.0" textAlignment="CENTER" textFill="WHITE" GridPane.rowIndex="1" />
<Label fx:id="nameLabel" alignment="CENTER" prefWidth="40.0" text="Name" textAlignment="CENTER" textFill="WHITE" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
<Label fx:id="person2Name" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="81.0" textAlignment="CENTER" textFill="WHITE" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Label fx:id="person1Gpa" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="79.0" textAlignment="CENTER" textFill="WHITE" GridPane.rowIndex="2" />
<Label fx:id="gpaLabel" text="GPA" textFill="WHITE" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
<Label fx:id="person2Gpa" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="79.0" textAlignment="CENTER" textFill="WHITE" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Label fx:id="stuNumLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="101.0" text="Student No." textAlignment="CENTER" textFill="WHITE" GridPane.columnIndex="1" />
<Label fx:id="interviewScoreLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="105.0" text="Interview Score" textAlignment="CENTER" textFill="WHITE" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="moduleGradeLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="105.0" text="Module Grade" textAlignment="CENTER" textFill="WHITE" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label fx:id="ccaNumberLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="105.0" text="CCA Number" textAlignment="CENTER" textFill="WHITE" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Rectangle fx:id="gpa1Highlight" arcHeight="5.0" arcWidth="5.0" fill="#ffe100" height="25.0" opacity="0.0" stroke="WHITE" strokeType="INSIDE" width="80.0" GridPane.rowIndex="2" />
<Rectangle fx:id="gpa2Highlight" arcHeight="5.0" arcWidth="5.0" fill="#ffe100" height="25.0" opacity="0.0" stroke="WHITE" strokeType="INSIDE" width="80.0" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Label fx:id="person1StuNum" alignment="CENTER" prefHeight="17.0" prefWidth="79.0" textAlignment="CENTER" textFill="WHITE" />
<Label fx:id="person2StuNum" alignment="CENTER" prefHeight="17.0" prefWidth="79.0" textAlignment="CENTER" textFill="WHITE" GridPane.columnIndex="2" />
<columnConstraints>
<ColumnConstraints prefWidth="80.0" />
<ColumnConstraints prefWidth="100.0" />
<ColumnConstraints prefWidth="80.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints prefHeight="25.0" />
<RowConstraints maxHeight="66.00002034505209" minHeight="15.333333333333343" prefHeight="25.0" />
<RowConstraints maxHeight="66.00002034505209" minHeight="10.666656494140625" prefHeight="25.0" />
<RowConstraints maxHeight="66.00002034505209" minHeight="15.333333333333343" prefHeight="25.0" />
<RowConstraints maxHeight="66.00002034505209" minHeight="15.333333333333343" prefHeight="25.0" />
<RowConstraints maxHeight="66.00002034505209" minHeight="15.333333333333343" prefHeight="25.0" />
<RowConstraints maxHeight="60.0" minHeight="9.33331298828125" prefHeight="50.0" />
</rowConstraints>
</GridPane>

0 comments on commit 9c1c066

Please sign in to comment.