Search in sources :

Example 6 with ChangeListener

use of javafx.beans.value.ChangeListener in project SmartCity-Market by TechnionYP5777.

the class ManageEmployeesTab method initialize.

@Override
public void initialize(URL location, ResourceBundle __) {
    userTxt.textProperty().addListener((observable, oldValue, newValue) -> enableFinishBtn());
    passTxt.textProperty().addListener((observable, oldValue, newValue) -> enableFinishBtn());
    securityAnswerTxt.textProperty().addListener((observable, oldValue, newValue) -> enableFinishBtn());
    radioBtnCont.addRadioButtons(Arrays.asList(new RadioButton[] { workerRadioBtn, managerRadioBtn }));
    securityCombo.getItems().addAll(SecurityQuestions.getQuestions());
    RequiredFieldValidator validator2 = new RequiredFieldValidator();
    validator2.setMessage("Input Required");
    validator2.setIcon(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.WARNING).size("1em").styleClass("error").build());
    userTxt.getValidators().add(validator2);
    userTxt.focusedProperty().addListener((o, oldVal, newVal) -> {
        if (!newVal)
            userTxt.validate();
    });
    RequiredFieldValidator validator3 = new RequiredFieldValidator();
    validator3.setMessage("Input Required");
    validator3.setIcon(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.WARNING).size("1em").styleClass("error").build());
    passTxt.getValidators().add(validator3);
    passTxt.focusedProperty().addListener((o, oldVal, newVal) -> {
        if (!newVal)
            passTxt.validate();
    });
    RequiredFieldValidator validator4 = new RequiredFieldValidator();
    validator4.setMessage("Input Required");
    validator4.setIcon(GlyphsBuilder.create(FontAwesomeIconView.class).glyph(FontAwesomeIcon.WARNING).size("1em").styleClass("error").build());
    securityAnswerTxt.getValidators().add(validator4);
    securityAnswerTxt.focusedProperty().addListener((o, oldVal, newVal) -> {
        if (!newVal)
            securityAnswerTxt.validate();
    });
    createEmployeesList();
    searchEmployee.textProperty().addListener(obs -> {
        String filter = searchEmployee.getText();
        filteredDataEmployees.setPredicate(filter == null || filter.length() == 0 ? s -> true : s -> s.contains(filter));
    });
    employeesList.setCellFactory(CheckBoxListCell.forListView(new Callback<String, ObservableValue<Boolean>>() {

        @Override
        public ObservableValue<Boolean> call(String item) {
            BooleanProperty observable = new SimpleBooleanProperty();
            observable.set(selectedEmployees.contains(item));
            observable.addListener((obs, wasSelected, isNowSelected) -> {
                if (isNowSelected)
                    selectedEmployees.add(item);
                else
                    selectedEmployees.remove(item);
                enableRemoveButton();
            });
            return observable;
        }
    }));
    securityCombo.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {

        @Override
        public void changed(ObservableValue<? extends String> __, String oldValue, String newValue) {
            enableFinishBtn();
        }
    });
    enableFinishBtn();
    enableRemoveButton();
}
Also used : JFXButton(com.jfoenix.controls.JFXButton) Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) GlyphsBuilder(de.jensd.fx.glyphs.GlyphsBuilder) JFXPasswordField(com.jfoenix.controls.JFXPasswordField) URL(java.net.URL) CheckBoxListCell(javafx.scene.control.cell.CheckBoxListCell) FXCollections(javafx.collections.FXCollections) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected) HashSet(java.util.HashSet) Logger(org.apache.log4j.Logger) RequiredFieldValidator(com.jfoenix.validation.RequiredFieldValidator) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) SecurityQuestions(GuiUtils.SecurityQuestions) FontAwesomeIconView(de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) JFXComboBox(com.jfoenix.controls.JFXComboBox) Callback(javafx.util.Callback) CriticalError(SMExceptions.CommonExceptions.CriticalError) RadioButtonEnabler(GuiUtils.RadioButtonEnabler) StackTraceUtil(UtilsImplementations.StackTraceUtil) JFXListView(com.jfoenix.controls.JFXListView) FilteredList(javafx.collections.transformation.FilteredList) Manager(EmployeeImplementations.Manager) WorkerAlreadyExists(EmployeeDefs.AEmployeeException.WorkerAlreadyExists) FXML(javafx.fxml.FXML) InjectionFactory(UtilsImplementations.InjectionFactory) BooleanProperty(javafx.beans.property.BooleanProperty) ActionEvent(javafx.event.ActionEvent) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) JFXRadioButton(com.jfoenix.controls.JFXRadioButton) WorkerDoesNotExist(EmployeeDefs.AEmployeeException.WorkerDoesNotExist) RadioButton(javafx.scene.control.RadioButton) FontAwesomeIcon(de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon) IManager(EmployeeContracts.IManager) ObservableValue(javafx.beans.value.ObservableValue) Login(BasicCommonClasses.Login) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) JFXTextField(com.jfoenix.controls.JFXTextField) InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Callback(javafx.util.Callback) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) JFXRadioButton(com.jfoenix.controls.JFXRadioButton) RadioButton(javafx.scene.control.RadioButton) FontAwesomeIconView(de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView) RequiredFieldValidator(com.jfoenix.validation.RequiredFieldValidator)

Example 7 with ChangeListener

use of javafx.beans.value.ChangeListener in project jmeter by apache.

the class RenderInBrowser method createScene.

private void createScene(final String htmlContent) {
    Platform.setImplicitExit(false);
    Platform.runLater(new Runnable() {

        @Override
        public void run() {
            WebView view = new WebView();
            engine = view.getEngine();
            engine.setOnStatusChanged(event -> SwingUtilities.invokeLater(() -> lblStatus.setText(event.getData())));
            engine.getLoadWorker().workDoneProperty().addListener((ChangeListener<Number>) (observableValue, oldValue, newValue) -> SwingUtilities.invokeLater(() -> progressBar.setValue(newValue.intValue())));
            engine.getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() {

                @Override
                public void changed(ObservableValue<? extends Throwable> o, Throwable old, final Throwable value) {
                    if (engine.getLoadWorker().getState() == State.FAILED) {
                        SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(resultsScrollPane, (value != null) ? engine.getLocation() + "\n" + value.getMessage() : engine.getLocation() + "\nUnexpected error.", "Loading error...", JOptionPane.ERROR_MESSAGE));
                    }
                }
            });
            jfxPanel.setScene(new Scene(view));
        }
    });
}
Also used : Scene(javafx.scene.Scene) WebView(javafx.scene.web.WebView) JMeterUtils(org.apache.jmeter.util.JMeterUtils) WebEngine(javafx.scene.web.WebEngine) BorderFactory(javax.swing.BorderFactory) SampleResult(org.apache.jmeter.samplers.SampleResult) JFXPanel(javafx.embed.swing.JFXPanel) JOptionPane(javax.swing.JOptionPane) Platform(javafx.application.Platform) Dimension(java.awt.Dimension) SwingUtilities(javax.swing.SwingUtilities) JLabel(javax.swing.JLabel) State(javafx.concurrent.Worker.State) ObservableValue(javafx.beans.value.ObservableValue) BorderLayout(java.awt.BorderLayout) ChangeListener(javafx.beans.value.ChangeListener) JProgressBar(javax.swing.JProgressBar) JPanel(javax.swing.JPanel) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) WebView(javafx.scene.web.WebView) Scene(javafx.scene.Scene)

Example 8 with ChangeListener

use of javafx.beans.value.ChangeListener in project bitsquare by bitsquare.

the class OfferBookChartView method getOfferTable.

private Tuple4<TableView<OfferListItem>, VBox, Button, Label> getOfferTable(Offer.Direction direction) {
    TableView<OfferListItem> tableView = new TableView<>();
    tableView.setMinHeight(109);
    tableView.setPrefHeight(121);
    //530
    tableView.setMinWidth(480);
    // price
    TableColumn<OfferListItem, OfferListItem> priceColumn = new TableColumn<>();
    priceColumn.textProperty().bind(priceColumnLabel);
    //130
    priceColumn.setMinWidth(115);
    //130
    priceColumn.setMaxWidth(115);
    priceColumn.setSortable(false);
    priceColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    priceColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                private Offer offer;

                ChangeListener<Number> listener = new ChangeListener<Number>() {

                    @Override
                    public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                        if (offer != null && offer.getPrice() != null) {
                            setText(formatter.formatPrice(offer.getPrice()));
                            model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
                        }
                    }
                };

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty) {
                        if (offerListItem.offer.getPrice() == null) {
                            this.offer = offerListItem.offer;
                            model.priceFeedService.currenciesUpdateFlagProperty().addListener(listener);
                            setText("N/A");
                        } else {
                            setText(formatter.formatPrice(offerListItem.offer.getPrice()));
                        }
                    } else {
                        if (listener != null)
                            model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
                        this.offer = null;
                        setText("");
                    }
                }
            };
        }
    });
    // volume
    TableColumn<OfferListItem, OfferListItem> volumeColumn = new TableColumn<>();
    //125
    volumeColumn.setMinWidth(115);
    volumeColumn.setSortable(false);
    volumeColumn.textProperty().bind(volumeColumnLabel);
    volumeColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    volumeColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                private Offer offer;

                ChangeListener<Number> listener = new ChangeListener<Number>() {

                    @Override
                    public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                        if (offer != null && offer.getPrice() != null) {
                            setText(formatter.formatVolume(offer.getOfferVolume()));
                            model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
                        }
                    }
                };

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty) {
                        this.offer = offerListItem.offer;
                        if (offer.getPrice() == null) {
                            this.offer = offerListItem.offer;
                            model.priceFeedService.currenciesUpdateFlagProperty().addListener(listener);
                            setText("N/A");
                        } else {
                            setText(formatter.formatVolume(offer.getOfferVolume()));
                        }
                    } else {
                        if (listener != null)
                            model.priceFeedService.currenciesUpdateFlagProperty().removeListener(listener);
                        this.offer = null;
                        setText("");
                    }
                }
            };
        }
    });
    // amount
    TableColumn<OfferListItem, OfferListItem> amountColumn = new TableColumn<>("Amount in BTC");
    //125
    amountColumn.setMinWidth(115);
    amountColumn.setSortable(false);
    amountColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    amountColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty)
                        setText(formatter.formatCoin(offerListItem.offer.getAmount()));
                    else
                        setText("");
                }
            };
        }
    });
    // accumulated
    TableColumn<OfferListItem, OfferListItem> accumulatedColumn = new TableColumn<>("Sum in BTC");
    //130
    accumulatedColumn.setMinWidth(100);
    accumulatedColumn.setSortable(false);
    accumulatedColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    accumulatedColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty)
                        setText(formatter.formatRoundedDoubleWithPrecision(offerListItem.accumulated, 4));
                    else
                        setText("");
                }
            };
        }
    });
    if (direction == Offer.Direction.BUY) {
        tableView.getColumns().add(accumulatedColumn);
        tableView.getColumns().add(volumeColumn);
        tableView.getColumns().add(amountColumn);
        tableView.getColumns().add(priceColumn);
    } else {
        tableView.getColumns().add(priceColumn);
        tableView.getColumns().add(amountColumn);
        tableView.getColumns().add(volumeColumn);
        tableView.getColumns().add(accumulatedColumn);
    }
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    Label placeholder = new Label("Currently there are no offers available");
    placeholder.setWrapText(true);
    tableView.setPlaceholder(placeholder);
    Label titleLabel = new Label();
    titleLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16; -fx-alignment: center");
    UserThread.execute(() -> titleLabel.prefWidthProperty().bind(tableView.widthProperty()));
    boolean isSellOffer = direction == Offer.Direction.SELL;
    Button button = new Button();
    ImageView iconView = new ImageView();
    iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white");
    button.setGraphic(iconView);
    button.setGraphicTextGap(10);
    button.setText(isSellOffer ? "I want to buy bitcoin" : "I want to sell bitcoin");
    button.setMinHeight(40);
    button.setId(isSellOffer ? "buy-button-big" : "sell-button-big");
    button.setOnAction(e -> {
        if (isSellOffer) {
            model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode());
            navigation.navigateTo(MainView.class, BuyOfferView.class);
        } else {
            model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode());
            navigation.navigateTo(MainView.class, SellOfferView.class);
        }
    });
    VBox vBox = new VBox();
    vBox.setSpacing(10);
    vBox.setFillWidth(true);
    vBox.setMinHeight(190);
    vBox.getChildren().addAll(titleLabel, tableView, button);
    button.prefWidthProperty().bind(vBox.widthProperty());
    return new Tuple4<>(tableView, vBox, button, titleLabel);
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) Tuple4(io.bitsquare.common.util.Tuple4) Offer(io.bitsquare.trade.offer.Offer) ListChangeListener(javafx.collections.ListChangeListener) ChangeListener(javafx.beans.value.ChangeListener) ImageView(javafx.scene.image.ImageView) VBox(javafx.scene.layout.VBox)

Example 9 with ChangeListener

use of javafx.beans.value.ChangeListener in project jgnash by ccavanaugh.

the class BudgetTableController method initialize.

@FXML
private void initialize() {
    final Preferences preferences = Preferences.userNodeForPackage(BudgetTableController.class);
    runningTotalsButton.selectedProperty().setValue(preferences.getBoolean(RUNNING_TOTALS, false));
    rateLimitExecutor = new ScheduledThreadPoolExecutor(1, new DefaultDaemonThreadFactory(), new ThreadPoolExecutor.DiscardPolicy());
    tableWidthChangeListener = (observable, oldValue, newValue) -> {
        if (newValue != null && !oldValue.equals(newValue)) {
            optimizeColumnWidths();
        }
    };
    updateHeights();
    yearSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(LocalDate.now().getYear() - YEAR_MARGIN, LocalDate.now().getYear() + YEAR_MARGIN, LocalDate.now().getYear(), 1));
    accountTreeView.getStylesheets().addAll(StyleClass.HIDE_VERTICAL_CSS);
    accountTreeView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
    accountTreeView.setShowRoot(false);
    accountTreeView.setEditable(true);
    accountTreeView.fixedCellSizeProperty().bind(rowHeight);
    accountSummaryTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    accountSummaryTable.getStylesheets().addAll(StyleClass.HIDE_VERTICAL_CSS, StyleClass.HIDE_HORIZONTAL_CSS);
    accountSummaryTable.setItems(expandedAccountList);
    accountSummaryTable.fixedCellSizeProperty().bind(rowHeight);
    accountSummaryTable.setSelectionModel(new NullTableViewSelectionModel<>(accountSummaryTable));
    accountTypeTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    accountTypeTable.getStylesheets().add(StyleClass.HIDE_HEADER_CSS);
    accountTypeTable.setItems(accountGroupList);
    accountTypeTable.fixedCellSizeProperty().bind(rowHeight);
    accountTypeTable.prefHeightProperty().bind(rowHeight.multiply(Bindings.size(accountGroupList)).add(BORDER_MARGIN));
    accountTypeTable.setSelectionModel(new NullTableViewSelectionModel<>(accountTypeTable));
    accountGroupPeriodSummaryTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    accountGroupPeriodSummaryTable.getStylesheets().addAll(StyleClass.HIDE_HEADER_CSS, StyleClass.HIDE_HORIZONTAL_CSS, StyleClass.HIDE_VERTICAL_CSS);
    accountGroupPeriodSummaryTable.setItems(accountGroupList);
    accountGroupPeriodSummaryTable.fixedCellSizeProperty().bind(rowHeight);
    accountGroupPeriodSummaryTable.prefHeightProperty().bind(rowHeight.multiply(Bindings.size(accountGroupList)).add(BORDER_MARGIN));
    accountGroupPeriodSummaryTable.setSelectionModel(new NullTableViewSelectionModel<>(accountGroupPeriodSummaryTable));
    buildAccountTreeTable();
    buildAccountTypeTable();
    buildAccountSummaryTable();
    buildAccountGroupSummaryTable();
    accountSummaryTable.maxWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
    accountGroupPeriodSummaryTable.maxWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
    accountSummaryTable.minWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
    accountGroupPeriodSummaryTable.minWidthProperty().bind(minSummaryColumnWidth.multiply(3.0).add(BORDER_MARGIN));
    accountTreeView.expandedItemCountProperty().addListener((observable, oldValue, newValue) -> JavaFXUtils.runLater(this::updateExpandedAccountList));
    final ChangeListener<Object> budgetChangeListener = (observable, oldValue, newValue) -> handleBudgetChange();
    budget.addListener(budgetChangeListener);
    yearSpinner.valueProperty().addListener(budgetChangeListener);
    runningTotalsButton.selectedProperty().addListener(budgetChangeListener);
    visibleColumnCount.addListener(budgetChangeListener);
    runningTotalsButton.selectedProperty().addListener((observable, oldValue, newValue) -> preferences.putBoolean(RUNNING_TOTALS, newValue));
    /* Setting the tables as un-managed effectively removes these tables from the GridPane.  The tables are
           redundant if showing the amounts as running balances. */
    accountSummaryTable.managedProperty().bind(runningTotalsButton.selectedProperty().not());
    accountGroupPeriodSummaryTable.managedProperty().bind(runningTotalsButton.selectedProperty().not());
    horizontalScrollBar.setMin(0);
    horizontalScrollBar.maxProperty().bind(periodCount.subtract(visibleColumnCount));
    horizontalScrollBar.setUnitIncrement(1);
    horizontalScrollBar.disableProperty().bind(periodCount.lessThanOrEqualTo(1));
    // shift the table right and left with the ScrollBar value
    horizontalScrollBar.valueProperty().addListener((observable, oldValue, newValue) -> {
        /* must be synchronized to prevent a race condition from multiple events and an out of
                     * bounds exception */
        synchronized (this) {
            /* don't try unless columns exist.  This can occur if the UI is not large enough to display
                         * a minimum of one period of information.
                         */
            if (periodTable.getColumns().size() > 0) {
                final int newIndex = (int) Math.round(newValue.doubleValue());
                if (newIndex > index) {
                    while (newIndex > index) {
                        handleShiftRight();
                    }
                } else if (newIndex < index) {
                    while (newIndex < index) {
                        handleShiftLeft();
                    }
                }
            }
        }
    });
    ThemeManager.fontScaleProperty().addListener((observable, oldValue, newValue) -> updateHeights());
}
Also used : Pos(javafx.geometry.Pos) Engine(jgnash.engine.Engine) BigDecimal(java.math.BigDecimal) Budget(jgnash.engine.budget.Budget) MessageProperty(jgnash.engine.message.MessageProperty) DefaultDaemonThreadFactory(jgnash.util.DefaultDaemonThreadFactory) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) TreeTableCell(javafx.scene.control.TreeTableCell) BudgetPeriodDescriptor(jgnash.engine.budget.BudgetPeriodDescriptor) TableView(javafx.scene.control.TableView) NullTableViewSelectionModel(jgnash.uifx.control.NullTableViewSelectionModel) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) MessageListener(jgnash.engine.message.MessageListener) HBox(javafx.scene.layout.HBox) NotNull(jgnash.util.NotNull) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Spinner(javafx.scene.control.Spinner) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) JavaFXUtils(jgnash.uifx.util.JavaFXUtils) AccountGroup(jgnash.engine.AccountGroup) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) BudgetGoal(jgnash.engine.budget.BudgetGoal) List(java.util.List) LocalDate(java.time.LocalDate) Optional(java.util.Optional) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableList(javafx.collections.ObservableList) Message(jgnash.engine.message.Message) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) BudgetPeriodResults(jgnash.engine.budget.BudgetPeriodResults) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TreeItem(javafx.scene.control.TreeItem) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) DoubleProperty(javafx.beans.property.DoubleProperty) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Bindings(javafx.beans.binding.Bindings) IntegerProperty(javafx.beans.property.IntegerProperty) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) TreeTableView(javafx.scene.control.TreeTableView) ResourceBundle(java.util.ResourceBundle) ThemeManager(jgnash.uifx.skin.ThemeManager) GridPane(javafx.scene.layout.GridPane) Label(javafx.scene.control.Label) Comparators(jgnash.engine.Comparators) FXMLUtils(jgnash.uifx.util.FXMLUtils) BudgetResultsModel(jgnash.engine.budget.BudgetResultsModel) CheckBox(javafx.scene.control.CheckBox) MainView(jgnash.uifx.views.main.MainView) Preferences(java.util.prefs.Preferences) TimeUnit(java.util.concurrent.TimeUnit) TreeTableColumn(javafx.scene.control.TreeTableColumn) CommodityFormat(jgnash.text.CommodityFormat) StageUtils(jgnash.uifx.util.StageUtils) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) StyleClass(jgnash.uifx.skin.StyleClass) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) Account(jgnash.engine.Account) ChangeListener(javafx.beans.value.ChangeListener) ScrollBar(javafx.scene.control.ScrollBar) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Preferences(java.util.prefs.Preferences) DefaultDaemonThreadFactory(jgnash.util.DefaultDaemonThreadFactory) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) FXML(javafx.fxml.FXML)

Example 10 with ChangeListener

use of javafx.beans.value.ChangeListener in project jgnash by ccavanaugh.

the class AccountBalanceChartController method initialize.

@FXML
public void initialize() {
    accountComboBox.setPredicate(AccountComboBox.getShowAllPredicate());
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    periodComboBox.getItems().addAll(ReportPeriod.MONTHLY, ReportPeriod.QUARTERLY, ReportPeriod.YEARLY);
    periodComboBox.setValue(ReportPeriod.values()[preferences.getInt(REPORT_PERIOD, ReportPeriod.MONTHLY.ordinal())]);
    defaultCurrency = engine.getDefaultCurrency();
    numberFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
    barChart.getStylesheets().addAll(CHART_CSS);
    barChart.getYAxis().setLabel(defaultCurrency.getSymbol());
    barChart.barGapProperty().set(BAR_GAP);
    barChart.setCategoryGap(CATEGORY_GAP);
    barChart.setLegendVisible(false);
    barChart.getXAxis().setLabel(resources.getString("Column.Period"));
    barChart.getYAxis().setLabel(resources.getString("Column.Balance") + " : " + defaultCurrency.getSymbol());
    // Respect animation preference
    barChart.animatedProperty().set(Options.animationsEnabledProperty().get());
    startDatePicker.setValue(DateUtils.getFirstDayOfTheMonth(endDatePicker.getValue().minusMonths(12)));
    // Force a defaults
    includeSubAccounts.setSelected(preferences.getBoolean(SUB_ACCOUNTS, true));
    runningBalanceRadioButton.setSelected(preferences.getBoolean(RUNNING_BALANCE, true));
    endingBalanceRadioButton.setSelected(preferences.getBoolean(ENDING_BALANCE, false));
    invertBalanceCheckBox.setSelected(preferences.getBoolean(INVERT_BALANCES, true));
    restoreSelectedAccounts();
    accountComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            defaultCurrency = newValue.getCurrencyNode();
            numberFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
            Platform.runLater(AccountBalanceChartController.this::updateChart);
            Platform.runLater(AccountBalanceChartController.this::saveSelectedAccounts);
        }
    });
    // Generic listener.  No super efficient but reduces listener count
    final ChangeListener<Object> listener = (observable, oldValue, newValue) -> {
        if (newValue != null) {
            Platform.runLater(AccountBalanceChartController.this::updateChart);
            preferences.putBoolean(ENDING_BALANCE, endingBalanceRadioButton.isSelected());
            preferences.putBoolean(RUNNING_BALANCE, runningBalanceRadioButton.isSelected());
            preferences.putBoolean(SUB_ACCOUNTS, includeSubAccounts.isSelected());
            preferences.putInt(REPORT_PERIOD, periodComboBox.getValue().ordinal());
            preferences.putBoolean(INVERT_BALANCES, invertBalanceCheckBox.isSelected());
        }
    };
    // load the initial aux account combo
    addAuxAccountCombo(null);
    periodComboBox.valueProperty().addListener(listener);
    startDatePicker.valueProperty().addListener(listener);
    endDatePicker.valueProperty().addListener(listener);
    runningBalanceRadioButton.selectedProperty().addListener(listener);
    endingBalanceRadioButton.selectedProperty().addListener(listener);
    includeSubAccounts.selectedProperty().addListener(listener);
    invertBalanceCheckBox.selectedProperty().addListener(listener);
    // Push the initial load to the end of the platform thread for better startup and a nicer visual effect
    Platform.runLater(this::updateChart);
}
Also used : Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) EngineFactory(jgnash.engine.EngineFactory) StackPane(javafx.scene.layout.StackPane) XYChart(javafx.scene.chart.XYChart) VBox(javafx.scene.layout.VBox) AccountComboBox(jgnash.uifx.control.AccountComboBox) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) EncodeDecode(jgnash.util.EncodeDecode) BigDecimal(java.math.BigDecimal) Nullable(jgnash.util.Nullable) ResourceBundle(java.util.ResourceBundle) ComboBox(javafx.scene.control.ComboBox) AccountType(jgnash.engine.AccountType) Tooltip(javafx.scene.control.Tooltip) CurrencyNode(jgnash.engine.CurrencyNode) DateUtils(jgnash.time.DateUtils) ObjectProperty(javafx.beans.property.ObjectProperty) InjectFXML(jgnash.uifx.util.InjectFXML) Collection(java.util.Collection) CheckBox(javafx.scene.control.CheckBox) BarChart(javafx.scene.chart.BarChart) Collectors(java.util.stream.Collectors) Preferences(java.util.prefs.Preferences) StoredObject(jgnash.engine.StoredObject) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) CommodityFormat(jgnash.text.CommodityFormat) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) RadioButton(javafx.scene.control.RadioButton) Account(jgnash.engine.Account) ReportPeriodUtils(jgnash.report.ReportPeriodUtils) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) ReportPeriod(jgnash.report.ReportPeriod) DatePickerEx(jgnash.uifx.control.DatePickerEx) Options(jgnash.uifx.Options) StoredObject(jgnash.engine.StoredObject) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Aggregations

ChangeListener (javafx.beans.value.ChangeListener)25 ObservableValue (javafx.beans.value.ObservableValue)11 ObservableList (javafx.collections.ObservableList)11 FXCollections (javafx.collections.FXCollections)10 FXML (javafx.fxml.FXML)10 ResourceBundle (java.util.ResourceBundle)8 Platform (javafx.application.Platform)8 Stage (javafx.stage.Stage)8 List (java.util.List)7 Scene (javafx.scene.Scene)7 Account (jgnash.engine.Account)7 BigDecimal (java.math.BigDecimal)6 NumberFormat (java.text.NumberFormat)6 Objects (java.util.Objects)6 Preferences (java.util.prefs.Preferences)6 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)6 Tooltip (javafx.scene.control.Tooltip)6 ImageView (javafx.scene.image.ImageView)6 Engine (jgnash.engine.Engine)6 EngineFactory (jgnash.engine.EngineFactory)6