Skip to content
Snippets Groups Projects
Commit 04e34ae4 authored by Karsch Lukas's avatar Karsch Lukas
Browse files

now displaying recipe images in preview and recipe view

parent 0814037f
No related branches found
No related tags found
No related merge requests found
......@@ -8,13 +8,6 @@ public class IngredientSearchResultLabel extends Label {
public IngredientSearchResultLabel(RecipeComponent component) {
super(component.getName());
setStyle("-fx-padding: 4px;");
setOnMouseEntered(e -> {
setStyle("-fx-padding: 4px;" + "-fx-background-color: #DEDEDE;");
setCursor(Cursor.HAND);
});
setOnMouseExited(e -> {
setStyle("-fx-padding: 4px;");
setCursor(Cursor.DEFAULT);
});
setCursor(Cursor.HAND);
}
}
......@@ -2,6 +2,8 @@ package mi.hdm.components;
import javafx.scene.Cursor;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import mi.hdm.recipes.Category;
......@@ -44,7 +46,12 @@ public class RecipeVbox extends VBox {
HBox categoryHbox = new HBox();
categoryHbox.getChildren().addAll(categoryLabels);
this.getChildren().addAll(recipeName, recipeDescription, categoryHbox);
ImageView recipeImage = new ImageView(new Image(recipe.getImageURL().toString()));
recipeImage.setPreserveRatio(true);
recipeImage.setFitWidth(150);
recipeImage.setFitHeight(150);
this.getChildren().addAll(recipeImage, recipeName, recipeDescription, categoryHbox);
this.setPrefWidth(180);
this.setPrefHeight(250);
......
......@@ -6,12 +6,9 @@ import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import mi.hdm.recipes.Recipe;
import mi.hdm.recipes.RecipeManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
public class RecipeViewController extends BaseController {
private static final Logger log = LogManager.getLogger(RecipeViewController.class);
......@@ -50,7 +47,8 @@ public class RecipeViewController extends BaseController {
//TODO: display recipe description, preparation and ingredients
//idea for solution from: https://stackoverflow.com/questions/22710053/how-can-i-show-an-image-using-the-imageview-component-in-javafx-and-fxml
Image image = new Image(recipe.getImage());
log.debug("Trying to load image for recipe from '{}'", recipe.getImageURL());
Image image = new Image(recipe.getImageURL().toString());
recipeImage.setImage(image);
}
}
package mi.hdm.recipes;
import mi.hdm.exceptions.InvalidRecipeException;
import mi.hdm.filesystem.FileManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.net.URL;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
......@@ -22,7 +22,7 @@ public class Recipe implements RecipeComponent {
private NutritionTable nutritionTable;
private final LocalDateTime creationTime;
private String filepathForImage;
private URL filepathForImage;
/**
* This constructor will create a new recipe and calculate the nutrition values for the recipe by its ingredients.
......@@ -77,7 +77,7 @@ public class Recipe implements RecipeComponent {
this.creationTime = LocalDateTime.now();
this.code = calculateUniqueCode();
filepathForImage = FileManager.getAbsolutePathFromResourceFolder("/images/dish-fork-and-knife.png");
filepathForImage = Recipe.class.getResource("/images/dish-fork-and-knife.png");
}
public Recipe(
......@@ -101,7 +101,7 @@ public class Recipe implements RecipeComponent {
this.creationTime = creationTime;
this.code = code;
//TODO: fix filepath
filepathForImage = FileManager.getAbsolutePathFromResourceFolder("/images/dish-fork-and-knife.png");
filepathForImage = Recipe.class.getResource("/images/dish-fork-and-knife.png");
}
public void setName(String name) {
......@@ -224,12 +224,12 @@ public class Recipe implements RecipeComponent {
}
return result;
}
public void setImage(String path) {
public void setImage(URL path) {
filepathForImage = path;
}
public String getImage() {
public URL getImageURL() {
return filepathForImage;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment