diff --git a/app/src/main/java/cse/gradle/Controller.java b/app/src/main/java/cse/gradle/Controller.java index 5d4ba50..0bfc7eb 100644 --- a/app/src/main/java/cse/gradle/Controller.java +++ b/app/src/main/java/cse/gradle/Controller.java @@ -12,6 +12,7 @@ import cse.gradle.View.UserLogin; import javafx.beans.value.ObservableValue; import javafx.scene.Scene; +import javafx.scene.image.Image; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; import javafx.stage.Stage; @@ -108,6 +109,7 @@ public void saveRecipe(AppFramePopUp popUp, View appScenes, Recipe recipe, Recip recipe.setCategory(popUp.getCategoryField().getText()); recipe.setIngredients(popUp.getIngredientsField().getText()); recipe.setInstructions(popUp.getInstructionsField().getText()); + recipe.setImgURL(popUp.getRecipe().getImgUrl()); // Update the recipe in the database String response = model.putRecipe(recipe.getId().toString(), recipe); @@ -127,6 +129,9 @@ public void saveRecipe(AppFramePopUp popUp, View appScenes, Recipe recipe, Recip String filterOption = rList.getMealTypeDropDown().getValue(); String sortOption = rList.getSortDropDown().getValue(); syncRecipeListWithModel(appScenes, sortOption, filterOption); + + // After saving disable regenreate button + //popUp.getRegenerateButton().setDisable(true); } catch (Exception e) { if (e.getMessage().equals("Error: Server down")) appScenes.displayServerDownConstructor(); @@ -336,11 +341,17 @@ private void syncRecipeListWithModel(View appScenes, String sortOption, String f // TODO: Replace this method with an API call to the HTTP server using Model void handleRegenerateButton(AppFramePopUp popUp, View appScenes, Recipe recipe, RecipeList rList){ Recipe newRecipe = new RecipeGenerator().regenerateRecipe(recipe); + String imageURLString = model.performImageGenerateRequest(newRecipe.getName()); + + newRecipe.setImgURL(imageURLString); + popUp.getImageView().setImage(new Image(newRecipe.getImgUrl())); popUp.getNameField().setText(newRecipe.getName()); popUp.getCategoryField().setText(newRecipe.getCategory()); popUp.getIngredientsField().setText(newRecipe.getIngredients()); popUp.getInstructionsField().setText(newRecipe.getInstructions()); + popUp.setRecipe(newRecipe); rList.refresh(); + System.out.println("Calling regenerate button"); } } diff --git a/app/src/main/java/cse/gradle/View.java b/app/src/main/java/cse/gradle/View.java index 71f78b8..dd8f936 100644 --- a/app/src/main/java/cse/gradle/View.java +++ b/app/src/main/java/cse/gradle/View.java @@ -482,6 +482,15 @@ public Button getShareButton() { public Button getRegenerateButton(){ return regenerateButton; } + public ImageView getImageView(){ + return imgView; + } + public Recipe getRecipe(){ + return recipe; + } + public void setRecipe(Recipe r){ + this.recipe = r; + } } class RecipeList extends BorderPane {