Search in sources :

Example 1 with ParentAccountPredicate

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);
}
Also used : DoughnutChart(jgnash.uifx.control.DoughnutChart) Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) StackPane(javafx.scene.layout.StackPane) ParentAccountPredicate(jgnash.util.function.ParentAccountPredicate) Side(javafx.geometry.Side) AccountComboBox(jgnash.uifx.control.AccountComboBox) NumberFormat(java.text.NumberFormat) ResourceBundle(java.util.ResourceBundle) AccountType(jgnash.engine.AccountType) Tooltip(javafx.scene.control.Tooltip) CurrencyNode(jgnash.engine.CurrencyNode) ObjectProperty(javafx.beans.property.ObjectProperty) InjectFXML(jgnash.uifx.util.InjectFXML) Preferences(java.util.prefs.Preferences) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Cursor(javafx.scene.Cursor) PieChart(javafx.scene.chart.PieChart) CommodityFormat(jgnash.text.CommodityFormat) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LocalDate(java.time.LocalDate) CustomCursor(jgnash.resource.cursor.CustomCursor) Account(jgnash.engine.Account) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) DatePickerEx(jgnash.uifx.control.DatePickerEx) Options(jgnash.uifx.Options) Account(jgnash.engine.Account) ParentAccountPredicate(jgnash.util.function.ParentAccountPredicate) Preferences(java.util.prefs.Preferences) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Aggregations

NumberFormat (java.text.NumberFormat)1 LocalDate (java.time.LocalDate)1 Objects (java.util.Objects)1 ResourceBundle (java.util.ResourceBundle)1 Preferences (java.util.prefs.Preferences)1 Platform (javafx.application.Platform)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 ChangeListener (javafx.beans.value.ChangeListener)1 FXCollections (javafx.collections.FXCollections)1 ObservableList (javafx.collections.ObservableList)1 FXML (javafx.fxml.FXML)1 Side (javafx.geometry.Side)1 Cursor (javafx.scene.Cursor)1 Scene (javafx.scene.Scene)1 PieChart (javafx.scene.chart.PieChart)1 Tooltip (javafx.scene.control.Tooltip)1 StackPane (javafx.scene.layout.StackPane)1 Stage (javafx.stage.Stage)1 Account (jgnash.engine.Account)1