diff --git a/app/src/main/java/code/App.java b/app/src/main/java/code/App.java index 20649d0..181ddd2 100644 --- a/app/src/main/java/code/App.java +++ b/app/src/main/java/code/App.java @@ -38,18 +38,18 @@ private void drawUI(Stage primaryStage) throws IOException, URISyntaxException { Model model = new Model(); Scene login = new Scene(view.getLoginUI().getRoot()); view.setScene(login); - Controller controller = new Controller(view, model); + Controller controller; ServerConnection connection = new ServerConnection("localhost", 8100); if (connection.isOnline()) { + controller = new Controller(view, model); // System.out.println("Server is online"); controller.addListenersToList(); } else { // System.out.println("Server is offline"); view.goToOfflineUI(); } - primaryStage.setScene(login); primaryStage.setTitle(AppConfig.APP_NAME); primaryStage.setResizable(true); diff --git a/app/src/main/java/code/client/Controllers/Controller.java b/app/src/main/java/code/client/Controllers/Controller.java index ee2931f..32a7e54 100644 --- a/app/src/main/java/code/client/Controllers/Controller.java +++ b/app/src/main/java/code/client/Controllers/Controller.java @@ -3,26 +3,17 @@ import java.io.*; import java.net.URISyntaxException; import java.util.*; - import code.client.View.RecipeListUI; import code.client.View.RecipeUI; import code.client.View.View; import code.server.AccountRequestHandler; import code.server.IRecipeDb; - import java.net.URL; -import javafx.animation.*; import javafx.application.Platform; import javafx.collections.ObservableList; import javafx.event.ActionEvent; -import javafx.geometry.Pos; import javafx.scene.control.*; -import javafx.scene.input.Clipboard; -import javafx.scene.input.ClipboardContent; import javafx.scene.layout.GridPane; -import javafx.scene.paint.Color; -import javafx.scene.text.*; -import javafx.util.Duration; import code.client.Model.*; import code.client.View.AppAlert; import code.client.View.AppFrameMic; @@ -43,7 +34,6 @@ public class Controller { private IRecipeDb recipeDb; private RecipeCSVWriter recipeWriter; private RecipeCSVReader recipeReader; - private String defaultButtonStyle, onStyle, offStyle, blinkStyle; private String filter; // Audio Stuff @@ -57,10 +47,6 @@ public Controller(View view, Model model) { this.view = view; this.model = model; filter = "none"; - defaultButtonStyle = "-fx-font-style: italic; -fx-background-color: #FFFFFF; -fx-font-weight: bold; -fx-font: 11 arial;"; - onStyle = "-fx-font-style: italic; -fx-background-color: #90EE90; -fx-font-weight: bold; -fx-font: 11 arial;"; - offStyle = "-fx-font-style: italic; -fx-background-color: #FF7377; -fx-font-weight: bold; -fx-font: 11 arial;"; - blinkStyle = "-fx-background-color: #00FFFF; -fx-border-width: 0;"; this.view.getAppFrameHome().setNewRecipeButtonAction(event -> { try { @@ -85,17 +71,28 @@ public Controller(View view, Model model) { } } + private void handleNewButton(ActionEvent event) throws URISyntaxException, IOException { + view.goToAudioCapture(); + AppFrameMic mic = this.view.getAppFrameMic(); + mic.setGoToDetailedButtonAction(this::handleDetailedViewFromNewRecipeButton); + mic.setGoToHomeButtonAction(this::handleHomeButton); + mic.setRecordIngredientsButtonAction(this::handleRecordIngredients); + mic.setRecordMealTypeButtonAction(event1 -> { + try { + handleRecordMealType(event1); + } catch (IOException | URISyntaxException e) { + e.printStackTrace(); + } + }); + + } + private void handleRecipePostButton(ActionEvent event) throws IOException { view.getDetailedView().getRefreshButton().setVisible(false); Recipe postedRecipe = view.getDetailedView().getDisplayedRecipe(); Date currTime = new Date(); postedRecipe.setDate(currTime.getTime()); - - Button saveButtonFromDetailed = view.getDetailedView().getSaveButton(); - saveButtonFromDetailed.setStyle(blinkStyle); - PauseTransition pause = new PauseTransition(Duration.seconds(2.5)); - pause.setOnFinished(f -> saveButtonFromDetailed.setStyle(defaultButtonStyle)); - pause.play(); + view.callSaveAnimation(); Writer writer = new StringWriter(); recipeWriter = new RecipeCSVWriter(writer); @@ -111,6 +108,17 @@ private void handleRecipePostButton(ActionEvent event) throws IOException { } } + private void handleLogOutOutButton(ActionEvent event) { + clearCredentials(); + view.goToLoginUI(); + view.getLoginUI().getUsernameTextField().clear(); + view.getLoginUI().getPasswordField().clear(); + } + + private void handleHomeButton(ActionEvent event) { + goToRecipeList(); + } + private void goToRecipeList() { getUserRecipeList(); displayUserRecipes(); @@ -118,8 +126,8 @@ private void goToRecipeList() { addListenersToList(); MenuButton filterMenuButton = this.view.getAppFrameHome().getFilterMenuButton(); MenuButton sortMenuButton = this.view.getAppFrameHome().getSortMenuButton(); - setActiveState(filterMenuButton, 9); - setActiveState(sortMenuButton, 9); + view.setActiveState(filterMenuButton, 9); + view.setActiveState(sortMenuButton, 9); RecipeListUI recipeListUI = this.view.getAppFrameHome().getRecipeList(); RecipeSorter recipeSorter = new RecipeSorter(recipeListUI.getRecipeDB().getList()); @@ -148,22 +156,6 @@ private void displayUserRecipes() { recipeListUI.update(filter); } - private void handleNewButton(ActionEvent event) throws URISyntaxException, IOException { - view.goToAudioCapture(); - AppFrameMic mic = this.view.getAppFrameMic(); - mic.setGoToDetailedButtonAction(this::handleDetailedViewFromNewRecipeButton); - mic.setGoToHomeButtonAction(this::handleHomeButton); - mic.setRecordIngredientsButtonAction(this::handleRecordIngredients); - mic.setRecordMealTypeButtonAction(event1 -> { - try { - handleRecordMealType(event1); - } catch (IOException | URISyntaxException e) { - e.printStackTrace(); - } - }); - - } - private void addFilterListeners() { MenuButton filterMenuButton = this.view.getAppFrameHome().getFilterMenuButton(); ObservableList filterMenuItems = filterMenuButton.getItems(); @@ -174,7 +166,7 @@ private void addFilterListeners() { int index = i; filterMenuItems.get(index).setOnAction(e -> { filter = filterTypes[index]; - setActiveState(filterMenuButton, index); + view.setActiveState(filterMenuButton, index); this.view.getAppFrameHome().updateDisplay(filterTypes[index]); addListenersToList(); }); @@ -204,32 +196,11 @@ private void setSortAction(ObservableList sortMenuItems, int index, Ru } private void sortList(MenuButton sortMenuButton, int index) { - setActiveState(sortMenuButton, index); + view.setActiveState(sortMenuButton, index); this.view.getAppFrameHome().updateDisplay(filter); addListenersToList(); } - private void setActiveState(MenuButton items, int index) { - for (int i = 0; i < NONE_INDEX + 1; i++) { - if (i == index) { - items.getItems().get(i).setStyle("-fx-background-color: #90EE90"); - } else { - items.getItems().get(i).setStyle("-fx-background-color: transparent;"); - } - } - } - - private void handleLogOutOutButton(ActionEvent event) { - clearCredentials(); - view.goToLoginUI(); - view.getLoginUI().getUsernameTextField().clear(); - view.getLoginUI().getPasswordField().clear(); - } - - private void handleHomeButton(ActionEvent event) { - goToRecipeList(); - } - public void addListenersToList() { addSortingListener(); addFilterListeners(); @@ -248,7 +219,7 @@ public void addListenersToList() { currRecipe.getDetailsButton().setOnAction(e -> { view.goToDetailedView(currRecipe.getRecipe(), true); view.getDetailedView().getRecipeDetailsUI().setEditable(false); - changeEditButtonColor(view.getDetailedView().getEditButton()); + view.changeEditButtonColor(view.getDetailedView().getEditButton()); handleDetailedViewListeners(); }); } @@ -271,12 +242,6 @@ private void handleDetailedViewFromNewRecipeButton(ActionEvent event) { handleDetailedViewListeners(); }); thread.start(); - AppFrameMic mic = view.getAppFrameMic(); - mic.getRecordingIngredientsLabel() - .setText("Processing mealType and ingredients. Please wait."); - mic.getRecordingIngredientsLabel() - .setStyle("-fx-font-weight: bold; -fx-font: 20 arial;"); - mic.getRecordingIngredientsLabel().setVisible(true); } catch (Exception exception) { AppAlert.show("Connection Error", "Something went wrong. Please check your connection and try again."); exception.printStackTrace(); @@ -323,7 +288,7 @@ private void handleDetailedViewListeners() { private void handleEditButton(ActionEvent event) { Button edit = view.getDetailedView().getEditButton(); view.getDetailedView().getRecipeDetailsUI().setEditable(); - changeEditButtonColor(edit); + view.changeEditButtonColor(edit); } private void handleDeleteButton(ActionEvent event) throws IOException { @@ -365,37 +330,7 @@ private void handleShareButton(ActionEvent event) { } private void showShareRecipe(Hyperlink textArea) { - String styleAlert = "-fx-background-color: #F1FFCB; -fx-font-weight: bold; -fx-font: 14 arial"; - - GridPane gridPane = new GridPane(); - gridPane.setMaxWidth(Double.MAX_VALUE); - gridPane.add(textArea, 0, 0); - gridPane.setStyle(styleAlert); - gridPane.setPrefSize(220, 220); - gridPane.setAlignment(Pos.TOP_CENTER); - textArea.setTextAlignment(TextAlignment.CENTER); - Button copyButton = new Button("Copy to Clipboard"); - copyButton.setOnAction(event -> { - Clipboard clipboard = Clipboard.getSystemClipboard(); - ClipboardContent content = new ClipboardContent(); - content.putString(textArea.getText()); - clipboard.setContent(content); - }); - gridPane.add(copyButton, 0, 3); - - Alert alert = new Alert(Alert.AlertType.INFORMATION); - alert.setTitle("Share this recipe!"); - alert.setHeaderText("Share this recipe with a friend!"); - alert.getDialogPane().setContent(gridPane); - alert.showAndWait(); - } - - private void changeEditButtonColor(Button edit) { - if (view.getDetailedView().getRecipeDetailsUI().isEditable()) { - edit.setStyle(onStyle); - } else { - edit.setStyle(offStyle); - } + view.displaySharedRecipeUI(textArea); } private void handleGoToCreateLogin(ActionEvent event) { @@ -434,14 +369,14 @@ private void handleRefreshButton(ActionEvent event) throws URISyntaxException, I } } - //////////////////////////////////////// +/////////////////////////////// ACCOUNT MANAGEMENT /////////////////////////////////// private void handleCreateAcc(ActionEvent event) { GridPane grid = view.getAccountCreationUI().getRoot(); String username = view.getAccountCreationUI().getUsernameTextField().getText(); String password = view.getAccountCreationUI().getPasswordField().getText(); if (username.isEmpty() || password.isEmpty()) { - showErrorPane(grid, "Error. Please provide a username and password."); + view.showErrorPane(grid, "Error. Please provide a username and password."); return; } @@ -455,46 +390,18 @@ private void handleCreateAcc(ActionEvent event) { if (response.contains("Offline")) { view.goToOfflineUI(); } else { - showSuccessPane(grid); + view.showSuccessPane(grid); view.goToLoginUI(); } } else { view.goToCreateAcc(); Platform.runLater( - () -> showErrorPane(grid, "Error. This username is already taken. Please choose another one.")); + () -> view.showErrorPane(grid, "Error. This username is already taken. Please choose another one.")); } }); thread.start(); } - private void showErrorPane(GridPane grid, String errorMessage) { - Text errorText = new Text(errorMessage); - errorText.setFont(Font.font("Arial", FontWeight.BOLD, 16)); - errorText.setFill(Color.RED); - - grid.add(errorText, 1, 6); - - // Fade away after 5 seconds - Timeline timeline = new Timeline( - new KeyFrame(Duration.seconds(0), new KeyValue(errorText.opacityProperty(), 1.0)), - new KeyFrame(Duration.seconds(5), new KeyValue(errorText.opacityProperty(), 0.0))); - timeline.play(); - } - - private void showSuccessPane(GridPane grid) { - Text successText = new Text("Successfully created an account!\nPlease login to access it."); - successText.setFont(Font.font("Arial", FontWeight.BOLD, 16)); - successText.setFill(Color.GREEN); - - grid.add(successText, 1, 6); - - // Fade away after 5 seconds - Timeline timeline = new Timeline( - new KeyFrame(Duration.seconds(0), new KeyValue(successText.opacityProperty(), 1.0)), - new KeyFrame(Duration.seconds(5), new KeyValue(successText.opacityProperty(), 0.0))); - timeline.play(); - } - private boolean isUsernameTaken(String username, String password) { // Check if the username is already taken String response = model.performAccountRequest("GET", username, password); @@ -505,7 +412,6 @@ private boolean isUsernameTaken(String username, String password) { return (!response.equals("Username is not found")); } - //////////////////////////////////////// private void handleLoginButton(ActionEvent event) { String username = view.getLoginUI().getUsernameTextField().getText(); String password = view.getLoginUI().getPasswordField().getText(); @@ -513,7 +419,7 @@ private void handleLoginButton(ActionEvent event) { // Perform login logic here if (username.isEmpty() || password.isEmpty()) { // Display an error message if username or password is empty - showErrorPane(grid, "Error. Please provide a username and password."); + view.showErrorPane(grid, "Error. Please provide a username and password."); return; } @@ -532,7 +438,7 @@ private void handleLoginButton(ActionEvent event) { } else { view.goToLoginUI(); Platform.runLater( - () -> showLoginSuccessPane(grid, false)); + () -> view.showLoginSuccessPane(grid, false)); } }); thread.start(); @@ -579,25 +485,6 @@ private void loadCredentials() { } } - private void showLoginSuccessPane(GridPane grid, boolean loginSuccessful) { - Text successText; - if (loginSuccessful) { - successText = new Text("Login successful! Welcome to Pantry Pal."); - successText.setFill(Color.GREEN); - } else { - successText = new Text("Account does not exist. Please try again."); - successText.setFill(Color.RED); - } - - successText.setFont(Font.font("Arial", FontWeight.BOLD, 16)); - grid.add(successText, 1, 6); - - Timeline timeline = new Timeline( - new KeyFrame(Duration.seconds(0), new KeyValue(successText.opacityProperty(), 1.0)), - new KeyFrame(Duration.seconds(5), new KeyValue(successText.opacityProperty(), 0.0))); - timeline.play(); - } - private boolean performLogin(String username, String password) { // Will add logic for failed login later String response = model.performAccountRequest("GET", username, password); @@ -617,8 +504,9 @@ private boolean performLogin(String username, String password) { account = new Account(accountId, username, password); return true; } + /////////////////////////////// ACCOUNT MANAGEMENT /////////////////////////////////// - /////////////////////////////// AUDIOMANAGEMENT/////////////////////////////////// + /////////////////////////////// AUDIO MANAGEMENT/////////////////////////////////// public void handleRecordMealType(ActionEvent event) throws IOException, URISyntaxException { recordMealType(); } diff --git a/app/src/main/java/code/client/Model/AppConfig.java b/app/src/main/java/code/client/Model/AppConfig.java index e4b9463..e3b00ac 100644 --- a/app/src/main/java/code/client/Model/AppConfig.java +++ b/app/src/main/java/code/client/Model/AppConfig.java @@ -7,7 +7,7 @@ public class AppConfig { public static final String RECIPE_CSV_FILE = "recipes.csv"; public static final String CREDENTIALS_CSV_FILE = "userCredentials.csv"; // API - public static final boolean MOCKING_ON = false; + public static final boolean MOCKING_ON = true; public static final String AUDIO_FILE = "recording.wav"; public static final AudioFileFormat.Type AUDIO_TYPE = AudioFileFormat.Type.WAVE; public static final String API_KEY = "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"; diff --git a/app/src/main/java/code/client/Model/Model.java b/app/src/main/java/code/client/Model/Model.java index a9c47ec..c3c0bb5 100644 --- a/app/src/main/java/code/client/Model/Model.java +++ b/app/src/main/java/code/client/Model/Model.java @@ -70,9 +70,13 @@ public String performRecipeRequest(String method, String recipe, String userId) } BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String tempResponse = ""; String line; while ((line = in.readLine()) != null) { - response += line + "\n"; + tempResponse += line + "\n"; + } + if( !(tempResponse.toLowerCase().contains("error")) ) { + response = tempResponse; } in.close(); } catch (Exception ex) { diff --git a/app/src/main/java/code/client/View/AppFrameHome.java b/app/src/main/java/code/client/View/AppFrameHome.java index f0728fd..8999386 100644 --- a/app/src/main/java/code/client/View/AppFrameHome.java +++ b/app/src/main/java/code/client/View/AppFrameHome.java @@ -2,7 +2,7 @@ package code.client.View; import javafx.scene.control.*; - +import javafx.scene.control.ScrollPane.ScrollBarPolicy; import javafx.scene.layout.*; import javafx.scene.text.*; import java.io.*; @@ -18,7 +18,7 @@ class Footer extends HBox { this.setPrefSize(620, 60); this.setStyle("-fx-background-color: #F0F8FF;"); this.setSpacing(15); - + this.setAlignment(Pos.CENTER); String defaultButtonStyle = "-fx-font-style: italic; -fx-background-color: #FFFFFF; -fx-font-weight: bold; -fx-font: 11 arial;"; newButton = new Button("New Recipe"); @@ -74,15 +74,6 @@ class Header extends HBox { sortMenuButton.getItems().addAll(sortNewToOld, sortOldToNew, sortAToZ, sortZToA); - // EventHandler event1 = new EventHandler() { - // public void handle(ActionEvent e) { - // System.out.println(((MenuItem) e.getSource()).getText() + " selected"); - // } - // }; - - // sortMenuButton.getItems().get(2).setOnAction(event1); - // sortMenuButton.getItems().get(3).setOnAction(event1); - this.setPrefSize(620, 60); this.setStyle("-fx-background-color: #F0F8FF;"); @@ -107,32 +98,27 @@ public class AppFrameHome extends BorderPane { private Footer footer; private RecipeListUI recipeList; private Button newButton, logOutButton; - private StackPane stack; AppFrameHome() throws IOException { - stack = new StackPane(); header = new Header(); recipeList = new RecipeListUI(); footer = new Footer(); ScrollPane scroller = new ScrollPane(recipeList); - scroller.setFitToWidth(true); - scroller.setFitToHeight(true); - + scroller.setMaxSize(400,400); + scroller.setVbarPolicy(ScrollBarPolicy.ALWAYS); this.setTop(header); this.setCenter(scroller); this.setBottom(footer); - scroller.setFitToWidth(true); newButton = footer.getNewButton(); logOutButton = footer.getLogOutButton(); BorderPane.setAlignment(this, Pos.CENTER); + } - public StackPane getRoot() { - stack.getChildren().clear(); - stack.getChildren().add(this); + public BorderPane getRoot() { this.updateDisplay("none"); - return stack; + return this; } public void updateDisplay(String filter) { diff --git a/app/src/main/java/code/client/View/RecipeListUI.java b/app/src/main/java/code/client/View/RecipeListUI.java index 03c1cc9..547b88c 100644 --- a/app/src/main/java/code/client/View/RecipeListUI.java +++ b/app/src/main/java/code/client/View/RecipeListUI.java @@ -15,8 +15,7 @@ public class RecipeListUI extends VBox { this.setSpacing(5); // this.setPrefSize(700, 600); this.setStyle("-fx-background-color: #F0F8FF;"); - VBox.setVgrow(this, Priority.ALWAYS); - this.setFillWidth(true); + //VBox.setVgrow(this, Priority.ALWAYS); // this.setAlignment(Pos.CENTER); } diff --git a/app/src/main/java/code/client/View/RecipeUI.java b/app/src/main/java/code/client/View/RecipeUI.java index d923a3c..a704fa3 100644 --- a/app/src/main/java/code/client/View/RecipeUI.java +++ b/app/src/main/java/code/client/View/RecipeUI.java @@ -40,6 +40,7 @@ public class RecipeUI extends HBox { MealTagStyler.styleTags(recipe, mealType); this.getChildren().add(style); this.setPrefSize(50, 50); + this.setMinSize(50, 50); } public Recipe getRecipe() { diff --git a/app/src/main/java/code/client/View/View.java b/app/src/main/java/code/client/View/View.java index 459db44..2fd6fd6 100644 --- a/app/src/main/java/code/client/View/View.java +++ b/app/src/main/java/code/client/View/View.java @@ -4,8 +4,26 @@ import java.net.URISyntaxException; import code.server.Recipe; +import javafx.animation.KeyFrame; +import javafx.animation.KeyValue; +import javafx.animation.PauseTransition; +import javafx.animation.Timeline; +import javafx.geometry.Pos; import javafx.scene.Parent; import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.scene.control.Hyperlink; +import javafx.scene.control.MenuButton; +import javafx.scene.input.Clipboard; +import javafx.scene.input.ClipboardContent; +import javafx.scene.layout.GridPane; +import javafx.scene.paint.Color; +import javafx.scene.text.Font; +import javafx.scene.text.FontWeight; +import javafx.scene.text.Text; +import javafx.scene.text.TextAlignment; +import javafx.util.Duration; public class View { private AppFrameHome home; @@ -16,6 +34,7 @@ public class View { private Scene mainScene; private OfflineUI offlineScreen; private LoadingUI loadingUI; + private String blinkStyle, defaultButtonStyle, onStyle, offStyle; public View() throws IOException, URISyntaxException { offlineScreen = new OfflineUI(); @@ -25,6 +44,9 @@ public View() throws IOException, URISyntaxException { detailedRecipe = new DetailsAppFrame(); createAcc = new AccountCreationUI(); loadingUI = new LoadingUI(); + defaultButtonStyle = "-fx-font-style: italic; -fx-background-color: #FFFFFF; -fx-font-weight: bold; -fx-font: 11 arial;"; + onStyle = "-fx-font-style: italic; -fx-background-color: #90EE90; -fx-font-weight: bold; -fx-font: 11 arial;"; + offStyle = "-fx-font-style: italic; -fx-background-color: #FF7377; -fx-font-weight: bold; -fx-font: 11 arial;"; } public Parent getMainScene() { @@ -91,4 +113,104 @@ public LoginUI getLoginUI() { public AccountCreationUI getAccountCreationUI() { return createAcc; } + + public void callSaveAnimation() { + blinkStyle = "-fx-background-color: #00FFFF; -fx-border-width: 0;"; + Button saveButtonFromDetailed = detailedRecipe.getSaveButton(); + saveButtonFromDetailed.setStyle(blinkStyle); + PauseTransition pause = new PauseTransition(Duration.seconds(2.5)); + pause.setOnFinished(f -> saveButtonFromDetailed.setStyle(defaultButtonStyle)); + pause.play(); + } + + public void setActiveState(MenuButton items, int index) { + for (int i = 0; i < 4; i++) { + if (i == index) { + items.getItems().get(i).setStyle("-fx-background-color: #90EE90"); + } else { + items.getItems().get(i).setStyle("-fx-background-color: transparent;"); + } + } + } + + public void displaySharedRecipeUI(Hyperlink textArea) { + String styleAlert = "-fx-background-color: #F1FFCB; -fx-font-weight: bold; -fx-font: 14 arial"; + + GridPane gridPane = new GridPane(); + gridPane.setMaxWidth(Double.MAX_VALUE); + gridPane.add(textArea, 0, 0); + gridPane.setStyle(styleAlert); + gridPane.setPrefSize(220, 220); + gridPane.setAlignment(Pos.TOP_CENTER); + textArea.setTextAlignment(TextAlignment.CENTER); + Button copyButton = new Button("Copy to Clipboard"); + copyButton.setOnAction(event -> { + Clipboard clipboard = Clipboard.getSystemClipboard(); + ClipboardContent content = new ClipboardContent(); + content.putString(textArea.getText()); + clipboard.setContent(content); + }); + gridPane.add(copyButton, 0, 3); + + Alert alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("Share this recipe!"); + alert.setHeaderText("Share this recipe with a friend!"); + alert.getDialogPane().setContent(gridPane); + alert.showAndWait(); + } + + public void changeEditButtonColor(Button edit) { + if (detailedRecipe.getRecipeDetailsUI().isEditable()) { + edit.setStyle(onStyle); + } else { + edit.setStyle(offStyle); + } + } + + public void showLoginSuccessPane(GridPane grid, boolean loginSuccessful) { + Text successText; + if (loginSuccessful) { + successText = new Text("Login successful! Welcome to Pantry Pal."); + successText.setFill(Color.GREEN); + } else { + successText = new Text("Account does not exist. Please try again."); + successText.setFill(Color.RED); + } + + successText.setFont(Font.font("Arial", FontWeight.BOLD, 16)); + grid.add(successText, 1, 6); + + Timeline timeline = new Timeline( + new KeyFrame(Duration.seconds(0), new KeyValue(successText.opacityProperty(), 1.0)), + new KeyFrame(Duration.seconds(5), new KeyValue(successText.opacityProperty(), 0.0))); + timeline.play(); + } + + public void showErrorPane(GridPane grid, String errorMessage) { + Text errorText = new Text(errorMessage); + errorText.setFont(Font.font("Arial", FontWeight.BOLD, 16)); + errorText.setFill(Color.RED); + + grid.add(errorText, 1, 6); + + // Fade away after 5 seconds + Timeline timeline = new Timeline( + new KeyFrame(Duration.seconds(0), new KeyValue(errorText.opacityProperty(), 1.0)), + new KeyFrame(Duration.seconds(5), new KeyValue(errorText.opacityProperty(), 0.0))); + timeline.play(); + } + + public void showSuccessPane(GridPane grid) { + Text successText = new Text("Successfully created an account!\nPlease login to access it."); + successText.setFont(Font.font("Arial", FontWeight.BOLD, 16)); + successText.setFill(Color.GREEN); + + grid.add(successText, 1, 6); + + // Fade away after 5 seconds + Timeline timeline = new Timeline( + new KeyFrame(Duration.seconds(0), new KeyValue(successText.opacityProperty(), 1.0)), + new KeyFrame(Duration.seconds(5), new KeyValue(successText.opacityProperty(), 0.0))); + timeline.play(); + } } diff --git a/app/src/main/java/code/server/AppServer.java b/app/src/main/java/code/server/AppServer.java index 4d7b6f4..a4eaed4 100644 --- a/app/src/main/java/code/server/AppServer.java +++ b/app/src/main/java/code/server/AppServer.java @@ -38,7 +38,7 @@ public void start() throws IOException { // create a map to store data // create a server httpServer = HttpServer.create( - new InetSocketAddress(hostName, port), + new InetSocketAddress("0.0.0.0", port), 0); // create the context to map urls httpServer.createContext(AppConfig.RECIPE_PATH, new RecipeRequestHandler(recipeDb)); diff --git a/app/src/main/java/code/server/mocking/MockServer.java b/app/src/main/java/code/server/mocking/MockServer.java index d29c6df..e9f815a 100644 --- a/app/src/main/java/code/server/mocking/MockServer.java +++ b/app/src/main/java/code/server/mocking/MockServer.java @@ -45,7 +45,7 @@ public void start() throws IOException { // create a map to store data // create a server httpServer = HttpServer.create( - new InetSocketAddress(hostName, port), + new InetSocketAddress("0.0.0.0", port), 0); // create the context to map urls httpServer.createContext(AppConfig.RECIPE_PATH, new RecipeRequestHandler(recipeDb));