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

Update PersonCardFields to use Icons #118

Merged
merged 3 commits into from
Oct 23, 2024
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
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ dependencies {
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.0'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4'

implementation 'org.kordamp.ikonli:ikonli-core:12.3.0'
implementation group: 'org.kordamp.ikonli', name: 'ikonli-fontawesome5-pack', version: '12.3.1'
implementation 'org.kordamp.ikonli:ikonli-javafx:12.3.1'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the use of icon pack package!!


testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public PersonCard(Person person, int displayedIndex) {
}
private void createFields() {
name.setText(person.getName().fullName);
phone.setText("Phone:", person.getPhone().value);
address.setText("Address:", person.getAddress().value);
email.setText("Email:", person.getEmail().value);
job.setText("Job:", person.getJob().value);
income.setText("Income:", person.getIncome().toString());
phone.setFields("fas-phone-alt", person.getPhone().value);
address.setFields("fas-building", person.getAddress().value);
email.setFields("fas-envelope", person.getEmail().value);
job.setFields("fas-briefcase", person.getJob().value);
income.setFields("fas-dollar-sign", person.getIncome().toString());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider standardizing icon variable names based on their semantic usage rather than the default names!

For example, instead of:
fas-envelope > emailIcon
fas-dollar-sign > incomeIcon

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colinhia Could you open an issue for this? Seems like a useful change but not a priority!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does sound like a great idea! Will open an issue for this, thanks for the suggestion!

remark.setText(person.getRemark().value);
cardFields.getChildren().addAll(phone, address, email, job, income);
}
Expand Down
29 changes: 20 additions & 9 deletions src/main/java/seedu/address/ui/PersonCardField.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
package seedu.address.ui;

import org.kordamp.ikonli.javafx.FontIcon;

import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Paint;

/**
* Represents a labelled field in the PersonCard
*/
public class PersonCardField extends HBox {
private Label field;
private FontIcon icon;
private Label value;

/**
* Creates a template {@code PersonCardField} to display.
*/
public PersonCardField() {
super(5);
field = new Label();
field.setStyle("-fx-font-weight: bold;");
icon = new FontIcon();
icon.setIconColor(Paint.valueOf("darkgray"));

HBox iconWrapper = new HBox();
iconWrapper.setPrefWidth(20);
iconWrapper.setAlignment(Pos.CENTER);
iconWrapper.getChildren().add(icon);

value = new Label();
HBox.setHgrow(value, Priority.ALWAYS);
value.setWrapText(true);
getChildren().addAll(field, value);
getChildren().addAll(iconWrapper, value);
}

/**
* Updates the {@code Label} {@code field} and {@code value} with the corresponding strings.
* @param fieldText The String to be updated into field.
* @param valueText The String to be updated in value.
* Updates the {@code PersonCardField} {@code Icon} and {@code Value} with the corresponding strings.
*
* @param iconLiteral The IconLiteral to be set for the icon.
* @param valueText The String to be updated in value.
*/
public void setText(String fieldText, String valueText) {
this.field.setText(fieldText);
public void setFields(String iconLiteral, String valueText) {
this.icon.setIconLiteral(iconLiteral);
this.value.setText(valueText);
}
}