chore: purge dead weight code
This commit is contained in:
parent
0bec62b9a3
commit
8747537901
7 changed files with 3 additions and 469 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -78,24 +78,6 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
|||
@FXML
|
||||
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
|
||||
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"
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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<AddNameCtrl, Parent> addName,
|
||||
Pair<FoodpalApplicationCtrl, Parent> foodpal,
|
||||
Pair<AddIngredientCtrl, Parent> addIngredient,
|
||||
Pair<AddStepsCtrl, Parent> addStep) throws IOException, InterruptedException {
|
||||
Pair<FoodpalApplicationCtrl, Parent> 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);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue