Skip to content
Snippets Groups Projects
Commit f2396afd authored by Robert Goldmann's avatar Robert Goldmann
Browse files

Fixed #48 - allow suer to choose currency

parent 1926bf07
Branches
Tags
1 merge request!58merge new_database_structure into master
......@@ -4,6 +4,7 @@ public class Settings
{
private String url;
private String secret;
private String currency;
private boolean restActivated;
public Settings()
......@@ -31,6 +32,16 @@ public class Settings
this.secret = secret;
}
public String getCurrency()
{
return currency;
}
public void setCurrency(String currency)
{
this.currency = currency;
}
public boolean isRestActivated()
{
return restActivated;
......
......@@ -33,12 +33,13 @@ public class HomeController implements Refreshable
{
this.controller = controller;
HomeController thisController = this;
listView.setCellFactory(new Callback<ListView<CategoryBudget>, ListCell<CategoryBudget>>()
{
@Override
public ListCell<CategoryBudget> call(ListView<CategoryBudget> param)
{
return new CategoryBudgetCell();
return new CategoryBudgetCell(thisController);
}
});
......@@ -78,8 +79,8 @@ public class HomeController implements Refreshable
{
Budget budget = new Budget(controller.getPayments());
double remaining = budget.getIncomeSum() + budget.getPaymentSum();
labelBudget.setText(String.valueOf(Helpers.NUMBER_FORMAT.format(remaining).replace(".", ",")) + " ");
labelStartBudget.setText("von " + String.valueOf(Helpers.NUMBER_FORMAT.format(budget.getIncomeSum()).replace(".", ",")) + " verbleibend");
labelBudget.setText(String.valueOf(Helpers.NUMBER_FORMAT.format(remaining).replace(".", ",")) + " " + controller.getSettings().getCurrency());
labelStartBudget.setText("von " + String.valueOf(Helpers.NUMBER_FORMAT.format(budget.getIncomeSum()).replace(".", ",")) + " " + controller.getSettings().getCurrency() + " verbleibend");
double factor = remaining / budget.getIncomeSum();
if(factor < 0)
......@@ -90,6 +91,11 @@ public class HomeController implements Refreshable
}
}
public Controller getController()
{
return controller;
}
@Override
public void refresh()
{
......
......@@ -169,8 +169,8 @@ public class PaymentController implements Refreshable
private void refreshCounter()
{
Budget budget = new Budget(listView.getItems());
labelIncomes.setText(String.valueOf(Helpers.NUMBER_FORMAT.format(budget.getIncomeSum()).replace(".", ",")) + " ");
labelPayments.setText(String.valueOf(Helpers.NUMBER_FORMAT.format(budget.getPaymentSum()).replace(".", ",")) + " ");
labelIncomes.setText(String.valueOf(Helpers.NUMBER_FORMAT.format(budget.getIncomeSum()).replace(".", ",")) + " " + controller.getSettings().getCurrency());
labelPayments.setText(String.valueOf(Helpers.NUMBER_FORMAT.format(budget.getPaymentSum()).replace(".", ",")) + " " + controller.getSettings().getCurrency());
}
public void deleteNormalPayment(NormalPayment payment)
......
......@@ -22,6 +22,8 @@ public class SettingsController
@FXML private Label labelURL;
@FXML private TextField textFieldSecret;
@FXML private Label labelSecret;
@FXML private TextField textFieldCurrency;
@FXML private Label labelCurrency;
@FXML private Button buttonSave;
@FXML private RadioButton radioButtonRestActivated;
@FXML private RadioButton radioButtonRestDeactivated;
......@@ -35,6 +37,7 @@ public class SettingsController
{
textFieldURL.setText(controller.getSettings().getUrl());
textFieldSecret.setText(controller.getSettings().getSecret());
textFieldCurrency.setText(controller.getSettings().getCurrency());
if(controller.getSettings().isRestActivated())
{
radioButtonRestActivated.setSelected(true);
......@@ -48,8 +51,10 @@ public class SettingsController
anchorPaneMain.setStyle("-fx-background-color: #F4F4F4;");
labelSecret.setStyle("-fx-text-fill: " + controller.getBundle().getString("color.text"));
labelURL.setStyle("-fx-text-fill: " + controller.getBundle().getString("color.text"));
labelCurrency.setStyle("-fx-text-fill: " + controller.getBundle().getString("color.text"));
buttonSave.setStyle("-fx-background-color: #2E79B9; -fx-text-fill: white; -fx-font-weight: bold; -fx-font-size: 16;");
textFieldURL.setPromptText("z.B. https://yourdomain.de");
textFieldCurrency.setPromptText("z.B. €, CHF, $");
ToggleGroup toggleGroup = new ToggleGroup();
radioButtonRestActivated.setToggleGroup(toggleGroup);
......@@ -60,14 +65,18 @@ public class SettingsController
{
String url = textFieldURL.getText().trim();
String secret = textFieldSecret.getText().trim();
String currency = textFieldCurrency.getText().trim();
if(url != null && !url.equals(""))
{
if(secret != null && !secret.equals(""))
{
if(currency != null && !currency.equals(""))
{
if(controller.getSettings() != null)
{
controller.getSettings().setUrl(url);
controller.getSettings().setSecret(secret);
controller.getSettings().setCurrency(currency);
controller.getSettings().setRestActivated(radioButtonRestActivated.isSelected());
}
else
......@@ -75,6 +84,7 @@ public class SettingsController
Settings settings = new Settings();
settings.setUrl(url);
settings.setSecret(secret);
settings.setCurrency(currency);
settings.setRestActivated(radioButtonRestActivated.isSelected());
controller.setSettings(settings);
}
......@@ -92,6 +102,11 @@ public class SettingsController
controller.showNotification("Erfolgreich gespeichert");
}
else
{
AlertGenerator.showAlert(AlertType.WARNING, "Warnung", "", "Bitte gib deine gewünschte Währung ein!", controller.getIcon(), controller.getStage(), null, false);
}
}
else
{
AlertGenerator.showAlert(AlertType.WARNING, "Warnung", "", "Das Server Passwortfeld darf nicht leer sein!", controller.getIcon(), controller.getStage(), null, false);
}
......
......@@ -31,7 +31,12 @@
<Font name="System Bold" size="16.0" />
</font>
</Label>
<Label fx:id="labelSecret1" prefHeight="25.0" text="Übertrag:">
<Label fx:id="labelCurrency" prefHeight="25.0" text="Währung:">
<font>
<Font name="System Bold" size="16.0" />
</font>
</Label>
<Label fx:id="labelSecret11" prefHeight="25.0" text="Übertrag:">
<font>
<Font name="System Bold" size="16.0" />
</font>
......@@ -45,6 +50,7 @@
<children>
<TextField fx:id="textFieldURL" />
<TextField fx:id="textFieldSecret" />
<TextField fx:id="textFieldCurrency" />
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<RadioButton fx:id="radioButtonRestActivated" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="aktiviert">
......
......@@ -2,6 +2,7 @@ package de.deadlocker8.budgetmaster.ui.cells;
import de.deadlocker8.budgetmaster.logic.CategoryBudget;
import de.deadlocker8.budgetmaster.logic.Helpers;
import de.deadlocker8.budgetmaster.ui.HomeController;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
......@@ -14,6 +15,13 @@ import tools.ConvertTo;
public class CategoryBudgetCell extends ListCell<CategoryBudget>
{
private final double HEIGHT = 40.0;
private HomeController homeController;
public CategoryBudgetCell(HomeController homeController)
{
super();
this.homeController = homeController;
}
@Override
protected void updateItem(CategoryBudget item, boolean empty)
......@@ -51,7 +59,7 @@ public class CategoryBudgetCell extends ListCell<CategoryBudget>
hbox.getChildren().add(r);
HBox.setHgrow(r, Priority.ALWAYS);
Label labelBudget = new Label(String.valueOf(Helpers.NUMBER_FORMAT.format(item.getBudget() / 100.0)).replace(".", ",") + " ");
Label labelBudget = new Label(String.valueOf(Helpers.NUMBER_FORMAT.format(item.getBudget() / 100.0)).replace(".", ",") + " " + homeController.getController().getSettings().getCurrency());
labelBudget.setPrefHeight(HEIGHT);
labelBudget.setStyle("-fx-font-weight: bold; -fx-font-size: 16; -fx-text-fill: #212121;");
labelBudget.setAlignment(Pos.CENTER);
......
......@@ -116,7 +116,7 @@ public class PaymentCell extends ListCell<Payment>
hbox.getChildren().add(r);
HBox.setHgrow(r, Priority.ALWAYS);
Label labelBudget = new Label(String.valueOf(Helpers.NUMBER_FORMAT.format(item.getAmount() / 100.0)).replace(".", ",") + " ");
Label labelBudget = new Label(String.valueOf(Helpers.NUMBER_FORMAT.format(item.getAmount() / 100.0)).replace(".", ",") + " " + paymentController.getController().getSettings().getCurrency());
labelBudget.setPrefHeight(HEIGHT);
labelBudget.setStyle("-fx-font-weight: bold; -fx-font-size: 16; -fx-text-fill: #247A2D");
labelBudget.setAlignment(Pos.CENTER);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment