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

refactored CategoryBudget (now uses category class)

parent 31866cf0
No related branches found
No related tags found
1 merge request!160merge v1_4_0 into master
package de.deadlocker8.budgetmaster.logic;
import de.deadlocker8.budgetmaster.logic.utils.Strings;
import javafx.scene.paint.Color;
import tools.Localization;
public class CategoryBudget
{
private String name;
private Color color;
private Category category;
private double budget;
public CategoryBudget(String name, Color color, double budget)
public CategoryBudget(Category category, double budget)
{
this.name = name;
this.color = color;
this.category = category;
this.budget = budget;
}
public String getName()
{
//TODO this is not safe! --> if user wishes to name a category "NONE" --> use ID to identify NONE-category instead
if(name != null && name.equals("NONE"))
{
return Localization.getString(Strings.CATEGORY_NONE);
}
return name;
}
public void setName(String name)
{
this.name = name;
}
public Color getColor()
public Category getCategory()
{
return color;
return category;
}
public void setColor(Color color)
public void setCategory(Category category)
{
this.color = color;
this.category = category;
}
public double getBudget()
......@@ -55,6 +34,6 @@ public class CategoryBudget
@Override
public String toString()
{
return "CategoryBudget [name=" + name + ", color=" + color + ", budget=" + budget + "]";
return "CategoryBudget [category=" + category + ", budget=" + budget + "]";
}
}
\ No newline at end of file
......@@ -244,7 +244,7 @@ public class ReportGenerator
for(CategoryBudget budget : categoryBudgets)
{
PdfPCell cellName = new PdfPCell(new Phrase(budget.getName(), font));
PdfPCell cellName = new PdfPCell(new Phrase(budget.getCategory().getName(), font));
cellName.setBackgroundColor(new BaseColor(Color.WHITE));
cellName.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cellName);
......
package de.deadlocker8.budgetmaster.ui.cells;
import de.deadlocker8.budgetmaster.logic.Category;
import de.deadlocker8.budgetmaster.logic.CategoryBudget;
import de.deadlocker8.budgetmaster.logic.utils.Helpers;
import de.deadlocker8.budgetmaster.ui.controller.HomeController;
......@@ -31,17 +32,18 @@ public class CategoryBudgetCell extends ListCell<CategoryBudget>
if(!empty)
{
HBox hbox = new HBox();
Category currentCategory = item.getCategory();
Label labelCircle = new Label(item.getName().substring(0, 1).toUpperCase());
Label labelCircle = new Label(currentCategory.getName().substring(0, 1).toUpperCase());
labelCircle.setPrefWidth(HEIGHT);
labelCircle.setPrefHeight(HEIGHT);
labelCircle.setAlignment(Pos.CENTER);
labelCircle.getStyleClass().add("greylabel");
String textColor = ConvertTo.toRGBHex(ConvertTo.getAppropriateTextColor(item.getColor()));
labelCircle.setStyle("-fx-background-color: " + ConvertTo.toRGBHex(item.getColor()) + "; -fx-background-radius: 50%; -fx-text-fill: " + textColor + "; -fx-font-weight: bold; -fx-font-size: 20;");
String textColor = ConvertTo.toRGBHex(ConvertTo.getAppropriateTextColor(currentCategory.getColor()));
labelCircle.setStyle("-fx-background-color: " + ConvertTo.toRGBHex(currentCategory.getColor()) + "; -fx-background-radius: 50%; -fx-text-fill: " + textColor + "; -fx-font-weight: bold; -fx-font-size: 20;");
hbox.getChildren().add(labelCircle);
Label labelName = new Label(item.getName());
Label labelName = new Label(currentCategory.getName());
labelName.setPrefHeight(HEIGHT);
labelName.setStyle("-fx-font-weight: bold; -fx-font-size: 16; -fx-text-fill: #212121");
labelName.setAlignment(Pos.CENTER);
......
......@@ -59,7 +59,7 @@ public class CategoryBudgetGet implements Route
for(Category currentCategory : handler.getCategories())
{
budgets.add(new CategoryBudget(currentCategory.getName(), currentCategory.getColor(), 0));
budgets.add(new CategoryBudget(currentCategory, 0));
CategoryBudget currentBudget = budgets.get(budgets.size() - 1);
for(Payment currentPayment : payments)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment