Search in sources :

Example 26 with SimpleObjectProperty

use of javafx.beans.property.SimpleObjectProperty in project jgnash by ccavanaugh.

the class BudgetGoalsDialogController method initialize.

@FXML
private void initialize() {
    buttonBar.buttonOrderProperty().bind(Options.buttonOrderProperty());
    endRowSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 1));
    startRowSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 1));
    periodComboBox.getItems().addAll(Period.values());
    patternComboBox.getItems().addAll(Pattern.values());
    patternComboBox.setValue(Pattern.EveryRow);
    fillAllDecimalTextField.emptyWhenZeroProperty().set(false);
    fillPatternAmountDecimalTextField.emptyWhenZeroProperty().set(false);
    fillAllDecimalTextField.setDecimal(BigDecimal.ZERO);
    fillPatternAmountDecimalTextField.setDecimal(BigDecimal.ZERO);
    goalTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    goalTable.setEditable(true);
    final TableColumn<BudgetPeriodDescriptor, String> periodColumn = new TableColumn<>(resources.getString("Column.Period"));
    periodColumn.setEditable(false);
    periodColumn.setCellValueFactory(param -> {
        if (param != null) {
            return new SimpleStringProperty(param.getValue().getPeriodDescription());
        }
        return new SimpleStringProperty("");
    });
    periodColumn.setSortable(false);
    goalTable.getColumns().add(periodColumn);
    final TableColumn<BudgetPeriodDescriptor, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
    amountColumn.setEditable(true);
    amountColumn.setSortable(false);
    amountColumn.setCellValueFactory(param -> {
        if (param != null) {
            final BudgetPeriodDescriptor descriptor = param.getValue();
            final BigDecimal goal = budgetGoal.get().getGoal(descriptor.getStartPeriod(), descriptor.getEndPeriod(), descriptor.getStartDate().isLeapYear());
            return new SimpleObjectProperty<>(goal.setScale(accountProperty().get().getCurrencyNode().getScale(), MathConstants.roundingMode));
        }
        return new SimpleObjectProperty<>(BigDecimal.ZERO);
    });
    amountColumn.setCellFactory(cell -> new BigDecimalTableCell<>(numberFormat));
    amountColumn.setOnEditCommit(event -> {
        final BudgetPeriodDescriptor descriptor = event.getTableView().getItems().get(event.getTablePosition().getRow());
        budgetGoalProperty().get().setGoal(descriptor.getStartPeriod(), descriptor.getEndPeriod(), event.getNewValue(), descriptor.getStartDate().isLeapYear());
    });
    goalTable.getColumns().add(amountColumn);
    periodComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            budgetGoalProperty().get().setBudgetPeriod(newValue);
            final List<BudgetPeriodDescriptor> descriptors = getDescriptors();
            goalTable.getItems().setAll(descriptors);
            descriptorSize.set(descriptors.size());
        }
    });
    budgetGoalProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            periodComboBox.setValue(newValue.getBudgetPeriod());
        }
    });
    // the spinner factory max values do not like being bound; Set value instead
    descriptorSize.addListener((observable, oldValue, newValue) -> {
        ((SpinnerValueFactory.IntegerSpinnerValueFactory) endRowSpinner.getValueFactory()).setMax(newValue.intValue());
        ((SpinnerValueFactory.IntegerSpinnerValueFactory) startRowSpinner.getValueFactory()).setMax(newValue.intValue());
        endRowSpinner.getValueFactory().setValue(newValue.intValue());
    });
    // account has changed; update currency related properties
    accountProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            final CurrencyNode currencyNode = newValue.getCurrencyNode();
            currencyLabel.setText(currencyNode.getSymbol());
            fillAllDecimalTextField.scaleProperty().set(currencyNode.getScale());
            fillAllDecimalTextField.minScaleProperty().set(currencyNode.getScale());
            fillPatternAmountDecimalTextField.scaleProperty().set(currencyNode.getScale());
            fillPatternAmountDecimalTextField.minScaleProperty().set(currencyNode.getScale());
            final NumberFormat decimalFormat = NumberFormat.getInstance();
            if (decimalFormat instanceof DecimalFormat) {
                decimalFormat.setMinimumFractionDigits(currencyNode.getScale());
                decimalFormat.setMaximumFractionDigits(currencyNode.getScale());
            }
            numberFormat.set(decimalFormat);
        }
    });
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) DecimalFormat(java.text.DecimalFormat) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) BudgetPeriodDescriptor(jgnash.engine.budget.BudgetPeriodDescriptor) NumberFormat(java.text.NumberFormat) FXML(javafx.fxml.FXML)

Example 27 with SimpleObjectProperty

use of javafx.beans.property.SimpleObjectProperty in project jgnash by ccavanaugh.

the class EditExchangeRatesController method initialize.

@FXML
void initialize() {
    exchangeRateField.scaleProperty().set(MathConstants.EXCHANGE_RATE_ACCURACY);
    exchangeRateTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    exchangeRateTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    final TableColumn<ExchangeRateHistoryNode, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
    dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLocalDate()));
    dateColumn.setCellFactory(cell -> new ShortDateTableCell<>());
    exchangeRateTable.getColumns().add(dateColumn);
    final NumberFormat decimalFormat = NumberFormat.getInstance();
    if (decimalFormat instanceof DecimalFormat) {
        decimalFormat.setMinimumFractionDigits(MathConstants.EXCHANGE_RATE_ACCURACY);
        decimalFormat.setMaximumFractionDigits(MathConstants.EXCHANGE_RATE_ACCURACY);
    }
    final TableColumn<ExchangeRateHistoryNode, BigDecimal> rateColumn = new TableColumn<>(resources.getString("Column.ExchangeRate"));
    rateColumn.setCellValueFactory(param -> {
        if (param == null || selectedExchangeRate.get() == null) {
            return null;
        }
        if (selectedExchangeRate.get().getRateId().startsWith(baseCurrencyComboBox.getValue().getSymbol())) {
            return new SimpleObjectProperty<>(param.getValue().getRate());
        }
        return new SimpleObjectProperty<>(BigDecimal.ONE.divide(param.getValue().getRate(), MathConstants.mathContext));
    });
    rateColumn.setCellFactory(cell -> new BigDecimalTableCell<>(decimalFormat));
    exchangeRateTable.getColumns().add(rateColumn);
    baseCurrencyComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> handleExchangeRateSelectionChange());
    targetCurrencyComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> handleExchangeRateSelectionChange());
    selectedHistoryNode.bind(exchangeRateTable.getSelectionModel().selectedItemProperty());
    deleteButton.disableProperty().bind(selectedHistoryNode.isNull());
    clearButton.disableProperty().bind(exchangeRateField.textProperty().isEmpty());
    addButton.disableProperty().bind(exchangeRateField.textProperty().isEmpty().or(Bindings.equal(baseCurrencyComboBox.getSelectionModel().selectedItemProperty(), targetCurrencyComboBox.getSelectionModel().selectedItemProperty())));
    selectedExchangeRate.addListener((observable, oldValue, newValue) -> JavaFXUtils.runLater(EditExchangeRatesController.this::loadExchangeRateHistory));
    selectedHistoryNode.addListener((observable, oldValue, newValue) -> JavaFXUtils.runLater(EditExchangeRatesController.this::updateForm));
    MessageBus.getInstance().registerListener(this, MessageChannel.COMMODITY);
    // Install a listener to unregister from the message bus when the window closes
    parent.addListener((observable, oldValue, scene) -> {
        if (scene != null) {
            scene.windowProperty().addListener((observable1, oldValue1, window) -> window.addEventHandler(WindowEvent.WINDOW_HIDING, event -> {
                handleStopAction();
                Logger.getLogger(EditExchangeRatesController.class.getName()).info("Unregistered from the message bus");
                MessageBus.getInstance().unregisterListener(EditExchangeRatesController.this, MessageChannel.COMMODITY);
            }));
        }
    });
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) CurrencyUpdateFactory(jgnash.net.currency.CurrencyUpdateFactory) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) MathConstants(jgnash.engine.MathConstants) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) MessageBus(jgnash.engine.message.MessageBus) Bindings(javafx.beans.binding.Bindings) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) ExchangeRate(jgnash.engine.ExchangeRate) BigDecimal(java.math.BigDecimal) Task(javafx.concurrent.Task) MessageProperty(jgnash.engine.message.MessageProperty) ProgressBar(javafx.scene.control.ProgressBar) ResourceBundle(java.util.ResourceBundle) MessageChannel(jgnash.engine.message.MessageChannel) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) CurrencyNode(jgnash.engine.CurrencyNode) MessageListener(jgnash.engine.message.MessageListener) ObjectProperty(javafx.beans.property.ObjectProperty) InjectFXML(jgnash.uifx.util.InjectFXML) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) ExchangeRateHistoryNode(jgnash.engine.ExchangeRateHistoryNode) FXMLUtils(jgnash.uifx.util.FXMLUtils) DecimalFormat(java.text.DecimalFormat) Logger(java.util.logging.Logger) JavaFXUtils(jgnash.uifx.util.JavaFXUtils) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) FXML(javafx.fxml.FXML) ResourceUtils(jgnash.resource.util.ResourceUtils) CurrencyComboBox(jgnash.uifx.control.CurrencyComboBox) List(java.util.List) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LocalDate(java.time.LocalDate) Optional(java.util.Optional) DecimalTextField(jgnash.uifx.control.DecimalTextField) WorkerStateEvent(javafx.concurrent.WorkerStateEvent) DatePickerEx(jgnash.uifx.control.DatePickerEx) Message(jgnash.engine.message.Message) DecimalFormat(java.text.DecimalFormat) ExchangeRateHistoryNode(jgnash.engine.ExchangeRateHistoryNode) LocalDate(java.time.LocalDate) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) NumberFormat(java.text.NumberFormat) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Example 28 with SimpleObjectProperty

use of javafx.beans.property.SimpleObjectProperty in project NMEAParser by tvesalainen.

the class MainApp method start.

@Override
public void start(Stage stage) throws Exception {
    Locale locale = Locale.getDefault();
    bundle = I18n.get(locale);
    // preferences
    preferences = new ViewerPreferences();
    ViewerPage preferencesPage = ViewerPage.loadPreferencePage(preferences, "/fxml/preferences.fxml", bundle);
    service = new ViewerService(executor, preferences, locale);
    StringBinding colorBinding = service.bindBackgroundColors();
    StringExpression styleExpression = Bindings.concat("-fx-base: ", colorBinding, ";", "-fx-font-family: ", preferences.getBinding("fontFamily"), ";");
    preferencesPage.getParent().styleProperty().bind(styleExpression);
    // pages
    ViewerPage sailPage1 = ViewerPage.loadPage(service, "/fxml/sailPage1.fxml", bundle, styleExpression);
    service.start();
    Property<Integer> currentPage = new SimpleObjectProperty<>(0);
    preferences.bindInteger("currentPage", 0, currentPage);
    Scene scene = new ViewerScene(stage, currentPage, preferencesPage, sailPage1);
    scene.getStylesheets().add("/styles/Styles.css");
    stage.setScene(scene);
    // stage.setFullScreen(true);
    I18n.bind(stage.titleProperty(), "mainTitle");
    I18n.bind(stage.fullScreenExitHintProperty(), "fullScreenExitHint");
    stage.show();
}
Also used : Locale(java.util.Locale) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) StringBinding(javafx.beans.binding.StringBinding) StringExpression(javafx.beans.binding.StringExpression) Scene(javafx.scene.Scene)

Example 29 with SimpleObjectProperty

use of javafx.beans.property.SimpleObjectProperty in project POL-POM-5 by PlayOnLinux.

the class InstallationsFeaturePanelSkin method createContent.

/**
 * {@inheritDoc}
 */
@Override
public ObjectExpression<Node> createContent() {
    final FilteredList<InstallationDTO> filteredInstallations = ConcatenatedList.create(new MappedList<>(getControl().getInstallationCategories().sorted(Comparator.comparing(InstallationCategoryDTO::getName)), InstallationCategoryDTO::getInstallations)).filtered(getControl().getFilter()::filter);
    filteredInstallations.predicateProperty().bind(Bindings.createObjectBinding(() -> getControl().getFilter()::filter, getControl().getFilter().searchTermProperty(), getControl().getFilter().selectedInstallationCategoryProperty()));
    final SortedList<InstallationDTO> sortedInstallations = filteredInstallations.sorted(Comparator.comparing(InstallationDTO::getName));
    final ObservableList<ListWidgetElement<InstallationDTO>> listWidgetEntries = new MappedList<>(sortedInstallations, ListWidgetElement::create);
    final CombinedListWidget<InstallationDTO> combinedListWidget = new CombinedListWidget<>(listWidgetEntries, this.selectedListWidget);
    // bind direction: controller property -> skin property
    getControl().selectedInstallationProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            combinedListWidget.select(newValue);
        } else {
            combinedListWidget.deselect();
        }
    });
    // bind direction: skin property -> controller properties
    combinedListWidget.selectedElementProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            final InstallationDTO selectedItem = newValue.getItem();
            getControl().setSelectedInstallation(selectedItem);
            getControl().setOpenedDetailsPanel(new Installation(selectedItem));
        } else {
            getControl().setSelectedInstallation(null);
            getControl().setOpenedDetailsPanel(new None());
        }
    });
    return new SimpleObjectProperty<>(combinedListWidget);
}
Also used : MappedList(org.phoenicis.javafx.collections.MappedList) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) CombinedListWidget(org.phoenicis.javafx.components.common.widgets.control.CombinedListWidget) Installation(org.phoenicis.javafx.components.installation.panelstates.Installation) ListWidgetElement(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetElement) InstallationDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationDTO) InstallationCategoryDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO) None(org.phoenicis.javafx.components.common.panelstates.None)

Example 30 with SimpleObjectProperty

use of javafx.beans.property.SimpleObjectProperty in project POL-POM-5 by PlayOnLinux.

the class InstallationsFeaturePanelSkin method createSidebar.

/**
 * {@inheritDoc}
 */
@Override
public ObjectExpression<SidebarBase<?, ?, ?>> createSidebar() {
    final SortedList<InstallationCategoryDTO> sortedCategories = getControl().getInstallationCategories().sorted(Comparator.comparing(InstallationCategoryDTO::getName));
    final InstallationSidebar sidebar = new InstallationSidebar(getControl().getFilter(), sortedCategories, this.selectedListWidget);
    // set the default selection
    sidebar.setSelectedListWidget(Optional.ofNullable(getControl().getJavaFxSettingsManager()).map(JavaFxSettingsManager::getInstallationsListType).orElse(ListWidgetType.ICONS_LIST));
    // save changes to the list widget selection to the hard drive
    sidebar.selectedListWidgetProperty().addListener((observable, oldValue, newValue) -> {
        final JavaFxSettingsManager javaFxSettingsManager = getControl().getJavaFxSettingsManager();
        if (newValue != null) {
            javaFxSettingsManager.setInstallationsListType(newValue);
            javaFxSettingsManager.save();
        }
    });
    return new SimpleObjectProperty<>(sidebar);
}
Also used : SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) InstallationSidebar(org.phoenicis.javafx.components.installation.control.InstallationSidebar) JavaFxSettingsManager(org.phoenicis.javafx.settings.JavaFxSettingsManager) InstallationCategoryDTO(org.phoenicis.javafx.views.mainwindow.installations.dto.InstallationCategoryDTO)

Aggregations

SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)37 TableColumn (javafx.scene.control.TableColumn)12 MappedList (org.phoenicis.javafx.collections.MappedList)10 JavaFxSettingsManager (org.phoenicis.javafx.settings.JavaFxSettingsManager)10 BigDecimal (java.math.BigDecimal)9 None (org.phoenicis.javafx.components.common.panelstates.None)8 CombinedListWidget (org.phoenicis.javafx.components.common.widgets.control.CombinedListWidget)8 ListWidgetElement (org.phoenicis.javafx.components.common.widgets.utils.ListWidgetElement)8 Bindings (javafx.beans.binding.Bindings)7 Button (javafx.scene.control.Button)7 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)6 LocalDate (java.time.LocalDate)5 Optional (java.util.Optional)5 ObjectProperty (javafx.beans.property.ObjectProperty)5 ObservableList (javafx.collections.ObservableList)5 FXML (javafx.fxml.FXML)5 Scene (javafx.scene.Scene)5 TableCell (javafx.scene.control.TableCell)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4