Skip to content

Commit

Permalink
Regenerates image
Browse files Browse the repository at this point in the history
  • Loading branch information
EAction13 committed Dec 6, 2023
1 parent 6b47bf8 commit 472e5e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/cse/gradle/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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");
}
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/cse/gradle/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 472e5e7

Please sign in to comment.