Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic UI for compare function #93

Merged
merged 4 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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

Expand All @@ -55,21 +54,10 @@
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();

Check warning on line 57 in src/main/java/seedu/address/logic/commands/CompareCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/CompareCommand.java#L57

Added line #L57 was not covered by tests

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

Check warning on line 59 in src/main/java/seedu/address/logic/commands/CompareCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/CompareCommand.java#L59

Added line #L59 was not covered by tests

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

Check warning on line 50 in src/main/java/seedu/address/ui/CompareWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/CompareWindow.java#L48-L50

Added lines #L48 - L50 were not covered by tests
try {
fxmlLoader.load();
} catch (IOException e) {
throw new RuntimeException(e);
}

Check warning on line 55 in src/main/java/seedu/address/ui/CompareWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/CompareWindow.java#L52-L55

Added lines #L52 - L55 were not covered by tests

setTitle("Comparison Result");

Check warning on line 57 in src/main/java/seedu/address/ui/CompareWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/CompareWindow.java#L57

Added line #L57 was not covered by tests

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

Check warning on line 60 in src/main/java/seedu/address/ui/CompareWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/CompareWindow.java#L59-L60

Added lines #L59 - L60 were not covered by tests

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

Check warning on line 64 in src/main/java/seedu/address/ui/CompareWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/CompareWindow.java#L62-L64

Added lines #L62 - L64 were not covered by tests

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

Check warning on line 68 in src/main/java/seedu/address/ui/CompareWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/CompareWindow.java#L66-L68

Added lines #L66 - L68 were not covered by tests

if (gpa1.compareTo(gpa2) > 0) {
gpa1Highlight.setOpacity(0.33);

Check warning on line 71 in src/main/java/seedu/address/ui/CompareWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/CompareWindow.java#L71

Added line #L71 was not covered by tests
} else if (gpa1.compareTo(gpa2) < 0) {
gpa2Highlight.setOpacity(0.33);

Check warning on line 73 in src/main/java/seedu/address/ui/CompareWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/CompareWindow.java#L73

Added line #L73 was not covered by tests
}

Scene scene = new Scene(fxmlLoader.getRoot());
setWidth(900);
setHeight(600);
setScene(scene);
}

Check warning on line 80 in src/main/java/seedu/address/ui/CompareWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/CompareWindow.java#L76-L80

Added lines #L76 - L80 were not covered by tests
}
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>
Loading