Search in sources :

Example 6 with BudgetPeriodDescriptor

use of jgnash.engine.budget.BudgetPeriodDescriptor in project jgnash by ccavanaugh.

the class BudgetTableController method focusCurrentPeriod.

private void focusCurrentPeriod() {
    final LocalDate now = LocalDate.now();
    final List<BudgetPeriodDescriptor> budgetPeriodDescriptorList = budgetResultsModel.getDescriptorList();
    for (int i = 0; i < budgetPeriodDescriptorList.size(); i++) {
        final BudgetPeriodDescriptor budgetPeriodDescriptor = budgetPeriodDescriptorList.get(i);
        if (budgetPeriodDescriptor.isBetween(now)) {
            final int index = Math.max(Math.min(i, periodCount.subtract(visibleColumnCount).intValue()), 0);
            Platform.runLater(() -> horizontalScrollBar.setValue(index));
            break;
        }
    }
}
Also used : BudgetPeriodDescriptor(jgnash.engine.budget.BudgetPeriodDescriptor) LocalDate(java.time.LocalDate)

Example 7 with BudgetPeriodDescriptor

use of jgnash.engine.budget.BudgetPeriodDescriptor 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());
            return new SimpleObjectProperty<>(goal.setScale(accountProperty().get().getCurrencyNode().getScale(), MathConstants.roundingMode));
        }
        return new SimpleObjectProperty<>(BigDecimal.ZERO);
    });
    amountColumn.setCellFactory(cell -> new BigDecimalTableCell<>(numberFormat));
    /// fTextFieldTableCell.forTableColumn()
    amountColumn.setOnEditCommit(event -> {
        final BudgetPeriodDescriptor descriptor = event.getTableView().getItems().get(event.getTablePosition().getRow());
        budgetGoalProperty().get().setGoal(descriptor.getStartPeriod(), descriptor.getEndPeriod(), event.getNewValue());
    });
    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 8 with BudgetPeriodDescriptor

use of jgnash.engine.budget.BudgetPeriodDescriptor in project jgnash by ccavanaugh.

the class BudgetGoalDialog method performFillAction.

private void performFillAction() {
    BigDecimal fillAmount = fillAmountField.getDecimal();
    for (BudgetPeriodDescriptor descriptor : getDescriptors()) {
        budgetGoal.setGoal(descriptor.getStartPeriod(), descriptor.getEndPeriod(), fillAmount);
    }
    model.fireTableDataChanged();
}
Also used : BudgetPeriodDescriptor(jgnash.engine.budget.BudgetPeriodDescriptor) BigDecimal(java.math.BigDecimal)

Example 9 with BudgetPeriodDescriptor

use of jgnash.engine.budget.BudgetPeriodDescriptor in project jgnash by ccavanaugh.

the class BudgetPanel method buildPeriodPanels.

private List<BudgetPeriodPanel> buildPeriodPanels() {
    final List<BudgetPeriodDescriptor> descriptors = BudgetPeriodDescriptorFactory.getDescriptors(budgetYear, activeBudget.getBudgetPeriod());
    final List<BudgetPeriodPanel> newPanels = new ArrayList<>();
    for (BudgetPeriodDescriptor descriptor : descriptors) {
        BudgetPeriodPanel panel = new BudgetPeriodPanel(new BudgetPeriodModel(descriptor, tableModel));
        newPanels.add(panel);
    }
    return newPanels;
}
Also used : ArrayList(java.util.ArrayList) BudgetPeriodDescriptor(jgnash.engine.budget.BudgetPeriodDescriptor)

Aggregations

BudgetPeriodDescriptor (jgnash.engine.budget.BudgetPeriodDescriptor)9 BigDecimal (java.math.BigDecimal)5 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)3 TableColumn (javafx.scene.control.TableColumn)3 Account (jgnash.engine.Account)3 FXML (javafx.fxml.FXML)2 TreeTableColumn (javafx.scene.control.TreeTableColumn)2 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 SpinnerValueFactory (javafx.scene.control.SpinnerValueFactory)1 AccountGroup (jgnash.engine.AccountGroup)1 CurrencyNode (jgnash.engine.CurrencyNode)1