Skip to content

Commit

Permalink
Consider changing photo to image
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzongteo committed Oct 14, 2017
1 parent 9c0ac0d commit 3db35bb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Binary file added default.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package seedu.address.ui;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Random;

import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
Expand Down Expand Up @@ -44,6 +49,8 @@ public class PersonCard extends UiPart<Region> {
private Label email;
@FXML
private FlowPane tags;
@FXML
private ImageView photo;

public PersonCard(ReadOnlyPerson person, int displayedIndex) {
super(FXML);
Expand All @@ -62,6 +69,17 @@ private void bindListeners(ReadOnlyPerson person) {
phone.textProperty().bind(Bindings.convert(person.phoneProperty()));
address.textProperty().bind(Bindings.convert(person.addressProperty()));
email.textProperty().bind(Bindings.convert(person.emailProperty()));

try {
photo.imageProperty().bind(Bindings.bindBidirectional(person.photoProperty()));
File file = new File(person.photoProperty().toString());
String localUrl = file.toURI().toURL().toString();
System.out.println(file + " + local url" + localUrl);
Image image = new Image(localUrl);
photo.setImage(image);
} catch (Exception e){
System.out.println(e);
}
person.tagProperty().addListener((observable, oldValue, newValue) -> {
tags.getChildren().clear();
initTags(person);
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/view/PersonListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.VBox?>

<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<HBox id="cardPane" fx:id="cardPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<GridPane HBox.hgrow="ALWAYS">
<columnConstraints>
Expand All @@ -32,13 +34,11 @@
<Label fx:id="address" styleClass="cell_small_label" text="\$address" />
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
</VBox>
<VBox alignment="CENTER" minHeight="105" GridPane.columnIndex="1">
<padding>
<Insets top="5" right="5" bottom="5" left="15" />
</padding>
<HBox spacing = "5" alignment = "CENTER">
<Label fx:id="photo" styleClass="cell_small_label" text="\$photo" />
<ImageView fitWidth = "170" fitHeight = "227" preserveRatio="true" smooth ="true" />
</HBox>
</VBox>
</GridPane>
</HBox>
5 changes: 4 additions & 1 deletion src/test/java/seedu/address/testutil/PersonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Photo;
import seedu.address.model.person.ReadOnlyPerson;
import seedu.address.model.tag.Tag;
import seedu.address.model.util.SampleDataUtil;
Expand All @@ -21,6 +22,7 @@ public class PersonBuilder {
public static final String DEFAULT_PHONE = "85355255";
public static final String DEFAULT_EMAIL = "[email protected]";
public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111";
public static final String DEFAULT_PHOTO = "/data/default.jpeg";
public static final String DEFAULT_TAGS = "friends";

private Person person;
Expand All @@ -31,8 +33,9 @@ public PersonBuilder() {
Phone defaultPhone = new Phone(DEFAULT_PHONE);
Email defaultEmail = new Email(DEFAULT_EMAIL);
Address defaultAddress = new Address(DEFAULT_ADDRESS);
Photo defaultPhoto = new Photo(DEFAULT_PHOTO);
Set<Tag> defaultTags = SampleDataUtil.getTagSet(DEFAULT_TAGS);
this.person = new Person(defaultName, defaultPhone, defaultEmail, defaultAddress, defaultTags);
this.person = new Person(defaultName, defaultPhone, defaultEmail, defaultAddress, defaultPhoto, defaultTags);
} catch (IllegalValueException ive) {
throw new AssertionError("Default person's values are invalid.");
}
Expand Down

0 comments on commit 3db35bb

Please sign in to comment.