From 874753790143877c3201c85dbaf4d94077de666d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 4 Dec 2025 17:46:52 +0100 Subject: [PATCH] chore: purge dead weight code --- client/src/main/java/client/Main.java | 9 +- client/src/main/java/client/MyModule.java | 2 - .../java/client/scenes/AddIngredientCtrl.java | 115 ------------------ .../main/java/client/scenes/AddNameCtrl.java | 112 ----------------- .../main/java/client/scenes/AddStepsCtrl.java | 114 ----------------- .../client/scenes/FoodpalApplicationCtrl.java | 48 -------- .../src/main/java/client/scenes/MainCtrl.java | 72 +---------- 7 files changed, 3 insertions(+), 469 deletions(-) delete mode 100644 client/src/main/java/client/scenes/AddIngredientCtrl.java delete mode 100644 client/src/main/java/client/scenes/AddNameCtrl.java delete mode 100644 client/src/main/java/client/scenes/AddStepsCtrl.java diff --git a/client/src/main/java/client/Main.java b/client/src/main/java/client/Main.java index e2f58d6..55d7fa7 100644 --- a/client/src/main/java/client/Main.java +++ b/client/src/main/java/client/Main.java @@ -17,10 +17,7 @@ package client; import static com.google.inject.Guice.createInjector; -import client.scenes.AddStepsCtrl; import client.scenes.MainCtrl; -import client.scenes.AddIngredientCtrl; -import client.scenes.AddNameCtrl; import client.scenes.FoodpalApplicationCtrl; import client.utils.ServerUtils; import com.google.inject.Injector; @@ -46,13 +43,9 @@ public class Main extends Application { System.err.println(msg); return; } - - var addName = FXML.load(AddNameCtrl.class, "client", "scenes", "AddName.fxml"); var foodpal = FXML.load(FoodpalApplicationCtrl.class, "client", "scenes", "FoodpalApplication.fxml"); - var addIngredient = FXML.load(AddIngredientCtrl.class, "client", "scenes", "AddIngredient.fxml"); - var addStep = FXML.load(AddStepsCtrl.class, "client", "scenes", "AddSteps.fxml"); var mainCtrl = INJECTOR.getInstance(MainCtrl.class); - mainCtrl.setup(primaryStage, addName, foodpal, addIngredient, addStep); + mainCtrl.setup(primaryStage, foodpal); } } \ No newline at end of file diff --git a/client/src/main/java/client/MyModule.java b/client/src/main/java/client/MyModule.java index a5dd197..4f3464e 100644 --- a/client/src/main/java/client/MyModule.java +++ b/client/src/main/java/client/MyModule.java @@ -23,7 +23,6 @@ import com.google.inject.Binder; import com.google.inject.Module; import com.google.inject.Scopes; -import client.scenes.AddNameCtrl; import client.scenes.MainCtrl; public class MyModule implements Module { @@ -31,7 +30,6 @@ public class MyModule implements Module { @Override public void configure(Binder binder) { binder.bind(MainCtrl.class).in(Scopes.SINGLETON); - binder.bind(AddNameCtrl.class).in(Scopes.SINGLETON); binder.bind(FoodpalApplicationCtrl.class).in(Scopes.SINGLETON); binder.bind(IngredientListCtrl.class).in(Scopes.SINGLETON); binder.bind(RecipeStepListCtrl.class).in(Scopes.SINGLETON); diff --git a/client/src/main/java/client/scenes/AddIngredientCtrl.java b/client/src/main/java/client/scenes/AddIngredientCtrl.java deleted file mode 100644 index 70d6924..0000000 --- a/client/src/main/java/client/scenes/AddIngredientCtrl.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2021 Delft University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package client.scenes; - -import client.utils.LocaleAware; -import client.utils.LocaleManager; -import client.utils.ServerUtils; -import com.google.inject.Inject; -import commons.Recipe; -import jakarta.ws.rs.WebApplicationException; -import javafx.fxml.FXML; -import javafx.scene.control.Alert; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.TextField; -import javafx.scene.input.KeyEvent; -import javafx.stage.Modality; - -import java.io.IOException; - -public class AddIngredientCtrl implements LocaleAware { - - private final ServerUtils server; - private final MainCtrl mainCtrl; - private final FoodpalApplicationCtrl foodpalCtrl; - - private final LocaleManager localeManager; - - @FXML - public TextField ingredient; - - @FXML - public Button okButton; - - @FXML - public Button cancelButton; - - @FXML - public Label ingredientLabel; - - @Inject - public AddIngredientCtrl(ServerUtils server, MainCtrl mainCtrl, - FoodpalApplicationCtrl foodpalCtrl, LocaleManager localeManager) { - this.mainCtrl = mainCtrl; - this.server = server; - this.foodpalCtrl = foodpalCtrl; - this.localeManager = localeManager; - } - - @Override - public void updateText() { - ingredientLabel.setText(getLocaleString("add.ingredient.label")); - okButton.setText(getLocaleString("button.ok")); - cancelButton.setText(getLocaleString("button.cancel")); - } - - @Override - public LocaleManager getLocaleManager() { - return localeManager; - } - - public void cancel() throws IOException, InterruptedException { - clearFields(); - mainCtrl.showFoodpal(); - } - - public void ok() throws IOException, InterruptedException { - try { - Recipe selected = foodpalCtrl.getSelectedRecipe(); - server.addRecipeIngredient(selected, ingredient.getText()); - } catch (WebApplicationException e) { - - var alert = new Alert(Alert.AlertType.ERROR); - alert.initModality(Modality.APPLICATION_MODAL); - alert.setContentText(e.getMessage()); - alert.showAndWait(); - return; - } - - - clearFields(); - mainCtrl.showFoodpal(); - } - - private void clearFields() { - ingredient.clear(); - } - - public void keyPressed(KeyEvent e) throws IOException, InterruptedException { - switch (e.getCode()) { - case ENTER: - ok(); - break; - case ESCAPE: - cancel(); - break; - default: - break; - } - } - -} \ No newline at end of file diff --git a/client/src/main/java/client/scenes/AddNameCtrl.java b/client/src/main/java/client/scenes/AddNameCtrl.java deleted file mode 100644 index 73f86e6..0000000 --- a/client/src/main/java/client/scenes/AddNameCtrl.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2021 Delft University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package client.scenes; - -import client.utils.LocaleAware; -import client.utils.LocaleManager; -import client.utils.ServerUtils; -import com.google.inject.Inject; - -import jakarta.ws.rs.WebApplicationException; -import javafx.fxml.FXML; -import javafx.scene.control.Alert; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.TextField; -import javafx.scene.input.KeyEvent; -import javafx.stage.Modality; - -import java.io.IOException; - -public class AddNameCtrl implements LocaleAware { - - private final ServerUtils server; - private final MainCtrl mainCtrl; - - private final LocaleManager localeManager; - - @FXML - public TextField recipeName; - - @FXML - public Label recipeNameLabel; - - @FXML - public Button cancelButton; - - @FXML - public Button okButton; - - @Inject - public AddNameCtrl(ServerUtils server, MainCtrl mainCtrl, LocaleManager localeManager) { - this.mainCtrl = mainCtrl; - this.server = server; - this.localeManager = localeManager; - } - - @Override - public void updateText() { - recipeNameLabel.setText(getLocaleString("add.recipe.label")); - okButton.setText(getLocaleString("button.ok")); - cancelButton.setText(getLocaleString("button.cancel")); - } - - @Override - public LocaleManager getLocaleManager() { - return localeManager; - } - - public void cancel() throws IOException, InterruptedException { - clearFields(); - mainCtrl.showFoodpal(); - } - - public void ok() throws IOException, InterruptedException { - try { - server.addRecipeName(recipeName.getText()); - } catch (WebApplicationException e) { - - var alert = new Alert(Alert.AlertType.ERROR); - alert.initModality(Modality.APPLICATION_MODAL); - alert.setContentText(e.getMessage()); - alert.showAndWait(); - return; - } catch (IOException | InterruptedException e) { - throw new RuntimeException(e); - } - - clearFields(); - mainCtrl.showFoodpal(); - } - - private void clearFields() { - recipeName.clear(); - } - - public void keyPressed(KeyEvent e) throws IOException, InterruptedException { - switch (e.getCode()) { - case ENTER: - ok(); - break; - case ESCAPE: - cancel(); - break; - default: - break; - } - } - -} \ No newline at end of file diff --git a/client/src/main/java/client/scenes/AddStepsCtrl.java b/client/src/main/java/client/scenes/AddStepsCtrl.java deleted file mode 100644 index abd9f51..0000000 --- a/client/src/main/java/client/scenes/AddStepsCtrl.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2021 Delft University of Technology - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package client.scenes; - -import client.utils.LocaleAware; -import client.utils.LocaleManager; -import client.utils.ServerUtils; -import com.google.inject.Inject; -import commons.Recipe; -import jakarta.ws.rs.WebApplicationException; -import javafx.fxml.FXML; -import javafx.scene.control.Alert; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.TextField; -import javafx.scene.input.KeyEvent; -import javafx.stage.Modality; - -import java.io.IOException; - -public class AddStepsCtrl implements LocaleAware { - - private final ServerUtils server; - private final MainCtrl mainCtrl; - private final FoodpalApplicationCtrl foodpalCtrl; - private final LocaleManager localeManager; - - @FXML - public TextField preparationStep; - - @FXML - public Button okButton; - - @FXML - public Button cancelButton; - - @FXML - public Label preparationStepLabel; - - @Inject - public AddStepsCtrl(ServerUtils server, MainCtrl mainCtrl, - FoodpalApplicationCtrl foodpalCtrl, LocaleManager localeManager) { - this.mainCtrl = mainCtrl; - this.server = server; - this.foodpalCtrl = foodpalCtrl; - this.localeManager = localeManager; - } - - @Override - public void updateText() { - preparationStepLabel.setText(getLocaleString("add.step.label")); - okButton.setText(getLocaleString("button.ok")); - cancelButton.setText(getLocaleString("button.cancel")); - } - - @Override - public LocaleManager getLocaleManager() { - return localeManager; - } - - public void cancel() throws IOException, InterruptedException { - clearFields(); - mainCtrl.showFoodpal(); - } - - public void ok() throws IOException, InterruptedException { - try { - Recipe selected = foodpalCtrl.getSelectedRecipe(); - server.addRecipeStep(selected, preparationStep.getText()); - } catch (WebApplicationException e) { - - var alert = new Alert(Alert.AlertType.ERROR); - alert.initModality(Modality.APPLICATION_MODAL); - alert.setContentText(e.getMessage()); - alert.showAndWait(); - return; - } - - - clearFields(); - mainCtrl.showFoodpal(); - } - - private void clearFields() { - preparationStep.clear(); - } - - public void keyPressed(KeyEvent e) throws IOException, InterruptedException { - switch (e.getCode()) { - case ENTER: - ok(); - break; - case ESCAPE: - cancel(); - break; - default: - break; - } - } - -} \ No newline at end of file diff --git a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java index c0aecfc..e50a983 100644 --- a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java +++ b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java @@ -78,24 +78,6 @@ public class FoodpalApplicationCtrl implements LocaleAware { @FXML public Button printRecipeButton; - @FXML - public Label ingredientsLabel; - - @FXML - public Label preparationLabel; - - @FXML - private ListView ingredientsListView; - - @FXML - private Button addIngredientButton; - - @FXML - private ListView preparationListView; - - @FXML - private Button addPreparationStepButton; - @Inject public FoodpalApplicationCtrl( MainCtrl mainCtrl, @@ -311,28 +293,6 @@ public class FoodpalApplicationCtrl implements LocaleAware { editableTitleArea.getChildren().add(edit); } - /** - * You can add ingredients. you get send to a different scene that creates the ingredient - * It doesn't automatically refresh yet so before you can see the new ingredient you have to first click on a - * different recipe and come back after - */ - @FXML - private void addIngredient() { - System.out.println("Add ingredient clicked"); - mainCtrl.showAddIngredient(); - } - - /** - * You can add steps. you get send to a different scene that creates the Step - * It doesn't automatically refresh yet so before you can see the new step you have to first click on a - * different recipe and come back after - */ - @FXML - private void addPreparationStep() { - System.out.println("Add preparation step clicked"); - mainCtrl.showAddSteps(); - - } // Language buttons @FXML @@ -347,14 +307,6 @@ public class FoodpalApplicationCtrl implements LocaleAware { System.out.println("Recipe printed"); } - /** - * Get the recipe that was selected - * @return the selected recipe - */ - public Recipe getSelectedRecipe() { - return recipeList.getSelectionModel().getSelectedItem(); - } - /** * Clones a recipe, when clicking on the button "clone" */ diff --git a/client/src/main/java/client/scenes/MainCtrl.java b/client/src/main/java/client/scenes/MainCtrl.java index 0ad2f49..1f439c9 100644 --- a/client/src/main/java/client/scenes/MainCtrl.java +++ b/client/src/main/java/client/scenes/MainCtrl.java @@ -32,51 +32,23 @@ public class MainCtrl implements LocaleAware { @FXML private Stage primaryStage; - @FXML - private AddNameCtrl addNameCtrl; - private Scene addName; - @FXML private FoodpalApplicationCtrl foodpalCtrl; private Scene foodpal; - @FXML - private AddIngredientCtrl addIngredientCtrl; - private Scene addIngredient; - - @FXML - private AddStepsCtrl addStepsCtrl; - private Scene addStep; - - private String addNameTitle = "add.name.title"; - private String addIngredientTitle = "add.step.title"; - private String addStepTitle = "add.ingredient.title"; - @Inject public MainCtrl(LocaleManager localeManager) { this.localeManager = localeManager; } public void setup(Stage primaryStage, - Pair addName, - Pair foodpal, - Pair addIngredient, - Pair addStep) throws IOException, InterruptedException { + Pair foodpal) throws IOException, InterruptedException { this.primaryStage = primaryStage; - this.addNameCtrl = addName.getKey(); - this.addName = new Scene(addName.getValue()); - this.foodpalCtrl = foodpal.getKey(); this.foodpal = new Scene(foodpal.getValue()); - this.addIngredientCtrl = addIngredient.getKey(); - this.addIngredient = new Scene(addIngredient.getValue()); - - this.addStepsCtrl = addStep.getKey(); - this.addStep = new Scene(addStep.getValue()); - showFoodpal(); primaryStage.show(); @@ -85,9 +57,7 @@ public class MainCtrl implements LocaleAware { @Override public void updateText() { - addNameTitle = getLocaleString("add.recipe.title"); - addStepTitle = getLocaleString("add.step.title"); - addIngredientTitle = getLocaleString("add.ingredient.title"); + // nothing here, no actual text objects managed by MainCtrl } @Override @@ -95,47 +65,9 @@ public class MainCtrl implements LocaleAware { return localeManager; } - public void showAddName() { - primaryStage.setTitle(addNameTitle); - primaryStage.setScene(addName); - addName.setOnKeyPressed(e -> { - try { - addNameCtrl.keyPressed(e); - } catch (IOException | InterruptedException ex) { - throw new RuntimeException(ex); - } - }); - } - public void showFoodpal() { primaryStage.setTitle("FoodPal"); primaryStage.setScene(foodpal); foodpalCtrl.refresh(); } - - public void showAddIngredient() { - primaryStage.setTitle(addIngredientTitle); - primaryStage.setScene(addIngredient); - addIngredient.setOnKeyPressed(e -> { - try { - addIngredientCtrl.keyPressed(e); - } catch (IOException | InterruptedException ex) { - throw new RuntimeException(ex); - } - }); - - } - - public void showAddSteps() { - primaryStage.setTitle(addStepTitle); - primaryStage.setScene(addStep); - addStep.setOnKeyPressed(e -> { - try { - addStepsCtrl.keyPressed(e); - } catch (IOException | InterruptedException ex) { - throw new RuntimeException(ex); - } - }); - - } } \ No newline at end of file