chore: purge dead weight code

This commit is contained in:
Zhongheng Liu 2025-12-04 17:46:52 +01:00
commit 8747537901
Signed by: steven
GPG key ID: F69B980899C1C09D
7 changed files with 3 additions and 469 deletions

View file

@ -17,10 +17,7 @@ package client;
import static com.google.inject.Guice.createInjector; import static com.google.inject.Guice.createInjector;
import client.scenes.AddStepsCtrl;
import client.scenes.MainCtrl; import client.scenes.MainCtrl;
import client.scenes.AddIngredientCtrl;
import client.scenes.AddNameCtrl;
import client.scenes.FoodpalApplicationCtrl; import client.scenes.FoodpalApplicationCtrl;
import client.utils.ServerUtils; import client.utils.ServerUtils;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -46,13 +43,9 @@ public class Main extends Application {
System.err.println(msg); System.err.println(msg);
return; return;
} }
var addName = FXML.load(AddNameCtrl.class, "client", "scenes", "AddName.fxml");
var foodpal = FXML.load(FoodpalApplicationCtrl.class, "client", "scenes", "FoodpalApplication.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); var mainCtrl = INJECTOR.getInstance(MainCtrl.class);
mainCtrl.setup(primaryStage, addName, foodpal, addIngredient, addStep); mainCtrl.setup(primaryStage, foodpal);
} }
} }

View file

@ -23,7 +23,6 @@ import com.google.inject.Binder;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.Scopes; import com.google.inject.Scopes;
import client.scenes.AddNameCtrl;
import client.scenes.MainCtrl; import client.scenes.MainCtrl;
public class MyModule implements Module { public class MyModule implements Module {
@ -31,7 +30,6 @@ public class MyModule implements Module {
@Override @Override
public void configure(Binder binder) { public void configure(Binder binder) {
binder.bind(MainCtrl.class).in(Scopes.SINGLETON); binder.bind(MainCtrl.class).in(Scopes.SINGLETON);
binder.bind(AddNameCtrl.class).in(Scopes.SINGLETON);
binder.bind(FoodpalApplicationCtrl.class).in(Scopes.SINGLETON); binder.bind(FoodpalApplicationCtrl.class).in(Scopes.SINGLETON);
binder.bind(IngredientListCtrl.class).in(Scopes.SINGLETON); binder.bind(IngredientListCtrl.class).in(Scopes.SINGLETON);
binder.bind(RecipeStepListCtrl.class).in(Scopes.SINGLETON); binder.bind(RecipeStepListCtrl.class).in(Scopes.SINGLETON);

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -78,24 +78,6 @@ public class FoodpalApplicationCtrl implements LocaleAware {
@FXML @FXML
public Button printRecipeButton; public Button printRecipeButton;
@FXML
public Label ingredientsLabel;
@FXML
public Label preparationLabel;
@FXML
private ListView<String> ingredientsListView;
@FXML
private Button addIngredientButton;
@FXML
private ListView<String> preparationListView;
@FXML
private Button addPreparationStepButton;
@Inject @Inject
public FoodpalApplicationCtrl( public FoodpalApplicationCtrl(
MainCtrl mainCtrl, MainCtrl mainCtrl,
@ -311,28 +293,6 @@ public class FoodpalApplicationCtrl implements LocaleAware {
editableTitleArea.getChildren().add(edit); 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 // Language buttons
@FXML @FXML
@ -347,14 +307,6 @@ public class FoodpalApplicationCtrl implements LocaleAware {
System.out.println("Recipe printed"); 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" * Clones a recipe, when clicking on the button "clone"
*/ */

View file

@ -32,51 +32,23 @@ public class MainCtrl implements LocaleAware {
@FXML @FXML
private Stage primaryStage; private Stage primaryStage;
@FXML
private AddNameCtrl addNameCtrl;
private Scene addName;
@FXML @FXML
private FoodpalApplicationCtrl foodpalCtrl; private FoodpalApplicationCtrl foodpalCtrl;
private Scene foodpal; 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 @Inject
public MainCtrl(LocaleManager localeManager) { public MainCtrl(LocaleManager localeManager) {
this.localeManager = localeManager; this.localeManager = localeManager;
} }
public void setup(Stage primaryStage, public void setup(Stage primaryStage,
Pair<AddNameCtrl, Parent> addName, Pair<FoodpalApplicationCtrl, Parent> foodpal) throws IOException, InterruptedException {
Pair<FoodpalApplicationCtrl, Parent> foodpal,
Pair<AddIngredientCtrl, Parent> addIngredient,
Pair<AddStepsCtrl, Parent> addStep) throws IOException, InterruptedException {
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
this.addNameCtrl = addName.getKey();
this.addName = new Scene(addName.getValue());
this.foodpalCtrl = foodpal.getKey(); this.foodpalCtrl = foodpal.getKey();
this.foodpal = new Scene(foodpal.getValue()); 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(); showFoodpal();
primaryStage.show(); primaryStage.show();
@ -85,9 +57,7 @@ public class MainCtrl implements LocaleAware {
@Override @Override
public void updateText() { public void updateText() {
addNameTitle = getLocaleString("add.recipe.title"); // nothing here, no actual text objects managed by MainCtrl
addStepTitle = getLocaleString("add.step.title");
addIngredientTitle = getLocaleString("add.ingredient.title");
} }
@Override @Override
@ -95,47 +65,9 @@ public class MainCtrl implements LocaleAware {
return localeManager; 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() { public void showFoodpal() {
primaryStage.setTitle("FoodPal"); primaryStage.setTitle("FoodPal");
primaryStage.setScene(foodpal); primaryStage.setScene(foodpal);
foodpalCtrl.refresh(); 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);
}
});
}
} }