use of jgnash.util.function.ParentAccountPredicate in project jgnash by ccavanaugh.
the class IncomeExpensePieChartDialogController method initialize.
@FXML
public void initialize() {
// Respect animation preference
pieChart.animatedProperty().set(Options.animationsEnabledProperty().get());
accountComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null && newValue.getParent().getAccountType() != AccountType.ROOT) {
pieChart.setCursor(CustomCursor.getZoomOutCursor());
} else {
pieChart.setCursor(Cursor.DEFAULT);
}
});
final Preferences preferences = Preferences.userNodeForPackage(IncomeExpensePieChartDialogController.class).node("IncomeExpensePieChart");
accountComboBox.setPredicate(new ParentAccountPredicate());
if (preferences.get(LAST_ACCOUNT, null) != null) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final Account account = engine.getAccountByUuid(preferences.get(LAST_ACCOUNT, null));
if (account != null) {
accountComboBox.setValue(account);
}
}
startDatePicker.setValue(endDatePicker.getValue().minusYears(1));
final ChangeListener<Object> listener = (observable, oldValue, newValue) -> {
if (newValue != null) {
updateChart();
preferences.put(LAST_ACCOUNT, accountComboBox.getValue().getUuid());
}
};
accountComboBox.valueProperty().addListener(listener);
startDatePicker.valueProperty().addListener(listener);
endDatePicker.valueProperty().addListener(listener);
pieChart.setLegendSide(Side.BOTTOM);
// zoom out
pieChart.setOnMouseClicked(event -> {
if (!nodeFocused && accountComboBox.getValue().getParent().getAccountType() != AccountType.ROOT) {
accountComboBox.setValue(accountComboBox.getValue().getParent());
}
});
// Push the initial load to the end of the platform thread for better startup and nicer visual effect
Platform.runLater(this::updateChart);
}
Aggregations