Search in sources :

Example 1 with Tag

use of jgnash.engine.Tag in project jgnash by ccavanaugh.

the class SlipController method splitsAction.

@FXML
private void splitsAction() {
    final SplitTransactionDialog splitsDialog = new SplitTransactionDialog();
    splitsDialog.accountProperty().setValue(accountProperty().get());
    splitsDialog.getTransactionEntries().setAll(transactionEntries);
    final boolean wasSplit = transactionEntries.get().size() > 0;
    // Show the dialog and process the transactions when it closes
    splitsDialog.show(slipType, () -> {
        transactionEntries.setAll(splitsDialog.getTransactionEntries());
        if (transactionEntries.get().size() > 0) {
            amountField.setDecimal(splitsDialog.getBalance().abs());
        } else if (wasSplit) {
            // spits were cleared out
            amountField.setDecimal(BigDecimal.ZERO);
        }
        // If valid splits exist and the user has requested concatenation, show a preview of what will happen
        concatenated.setValue(Options.concatenateMemosProperty().get() && !transactionEntries.isEmpty());
        if (concatenated.get()) {
            memoTextField.setText(Transaction.getMemo(transactionEntries));
        }
        if (transactionEntries.get().size() > 0) {
            // process the tags from the split transaction
            final Set<Tag> tags = new HashSet<>();
            for (final TransactionEntry entry : transactionEntries.get()) {
                tags.addAll(entry.getTags());
            }
            tagPane.setSelectedTags(tags);
            tagPane.refreshTagView();
        } else if (wasSplit) {
            // clear out all the prior split entries
            tagPane.clearSelectedTags();
        }
    });
}
Also used : Tag(jgnash.engine.Tag) TransactionEntry(jgnash.engine.TransactionEntry) HashSet(java.util.HashSet) FXML(javafx.fxml.FXML)

Example 2 with Tag

use of jgnash.engine.Tag in project jgnash by ccavanaugh.

the class TransactionTagDialogController method loadTags.

private void loadTags() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final List<Tag> tagList = new ArrayList<>(engine.getTags());
    Collections.sort(tagList);
    for (final Tag tag : tagList) {
        final CheckBox checkBox = new CheckBox(tag.getName());
        checkBox.setGraphic(MaterialDesignLabel.fromInteger(tag.getShape(), MaterialDesignLabel.DEFAULT_SIZE * TransactionTagPane.ICON_SCALE, tag.getColor()));
        checkBox.setUserData(tag);
        TilePane.setAlignment(checkBox, Pos.BASELINE_LEFT);
        tilePane.getChildren().add(checkBox);
    }
    tagsLoaded.set(true);
}
Also used : CheckBox(javafx.scene.control.CheckBox) ArrayList(java.util.ArrayList) Tag(jgnash.engine.Tag) Engine(jgnash.engine.Engine)

Example 3 with Tag

use of jgnash.engine.Tag in project jgnash by ccavanaugh.

the class TagManagerDialogController method handleDuplicateAction.

@FXML
private void handleDuplicateAction() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    for (final Tag tag : tagListView.getSelectionModel().getSelectedItems()) {
        try {
            final Tag newTag = (Tag) tag.clone();
            if (!engine.addTag(newTag)) {
                StaticUIMethods.displayError(resources.getString("Message.Error.TagDuplicate"));
            }
        } catch (final CloneNotSupportedException e) {
            Logger.getLogger(TagManagerDialogController.class.getName()).log(Level.SEVERE, e.toString(), e);
        }
    }
}
Also used : Tag(jgnash.engine.Tag) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Example 4 with Tag

use of jgnash.engine.Tag in project jgnash by ccavanaugh.

the class TransactionTagPieChartDialogController method updateChart.

private void updateChart() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final Account a = accountComboBox.getValue();
    if (a != null) {
        final CurrencyNode defaultCurrency = a.getCurrencyNode();
        final NumberFormat numberFormat = NumericFormats.getFullCommodityFormat(defaultCurrency);
        final ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
        final Map<Tag, BigDecimal> balanceMap = new HashMap<>();
        // Iterate through all the Tags in use
        for (final Tag tag : engine.getTagsInUse()) {
            BigDecimal balance = new BigDecimal(BigInteger.ZERO);
            for (final Account child : a.getChildren()) {
                balance = balance.add(getSumForTag(tag, child));
            }
            if (balance.compareTo(BigDecimal.ZERO) != 0) {
                balanceMap.put(tag, balance);
            }
        }
        // Sum of all the balances
        final BigDecimal total = balanceMap.values().stream().reduce(BigDecimal.ZERO, BigDecimal::add);
        // Iterate and crate each pie slice
        for (final Map.Entry<Tag, BigDecimal> entry : balanceMap.entrySet()) {
            final Tag tag = entry.getKey();
            final BigDecimal balance = entry.getValue();
            final String label = tag.getName() + " - " + numberFormat.format(balance.doubleValue());
            // protect against a div by zero caused by net zero of income and expense
            double value = total.compareTo(BigDecimal.ZERO) == 0 ? 0 : balance.divide(total, MathContext.DECIMAL64).multiply(ONE_HUNDRED).doubleValue();
            final PieChart.Data data = new PieChart.Data(label, value);
            // nodes are created lazily.  Set the user data (Tag) after the node is created
            data.nodeProperty().addListener((observable, oldValue, newValue) -> newValue.setUserData(tag));
            pieChartData.add(data);
        }
        pieChart.setData(pieChartData);
        final NumberFormat percentFormat = NumberFormat.getPercentInstance();
        percentFormat.setMaximumFractionDigits(1);
        percentFormat.setMinimumFractionDigits(1);
        // Install tooltips on the data after it has been added to the chart
        pieChart.getData().forEach(data -> Tooltip.install(data.getNode(), new Tooltip((((Tag) data.getNode().getUserData()).getName() + " - " + percentFormat.format(data.getPieValue() / 100d)))));
        pieChart.setTitle(resources.getString("Title.TransactionTagPieChart"));
        pieChart.centerTitleProperty().set(accountComboBox.getValue().getName());
        pieChart.centerSubTitleProperty().set(numberFormat.format(total));
    } else {
        pieChart.setData(FXCollections.emptyObservableList());
        pieChart.setTitle("No Data");
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) HashMap(java.util.HashMap) Tooltip(javafx.scene.control.Tooltip) BigDecimal(java.math.BigDecimal) PieChart(javafx.scene.chart.PieChart) Tag(jgnash.engine.Tag) HashMap(java.util.HashMap) Map(java.util.Map) Engine(jgnash.engine.Engine) NumberFormat(java.text.NumberFormat)

Example 5 with Tag

use of jgnash.engine.Tag in project jgnash by ccavanaugh.

the class TransactionTagDialogController method setSelectedTags.

void setSelectedTags(final Collection<Tag> tags) {
    // create a copy of the old selection
    originalTagSelection.addAll(tags);
    JavaFXUtils.runLater(() -> {
        while (!tagsLoaded.get()) {
            Thread.onSpinWait();
        }
        for (final Node node : tilePane.getChildren()) {
            for (final Tag tag : tags) {
                if (tag.equals(node.getUserData())) {
                    JavaFXUtils.runLater(() -> ((CheckBox) node).setSelected(true));
                }
            }
        }
    });
}
Also used : Node(javafx.scene.Node) Tag(jgnash.engine.Tag)

Aggregations

Tag (jgnash.engine.Tag)9 Engine (jgnash.engine.Engine)6 FXML (javafx.fxml.FXML)4 InjectFXML (jgnash.uifx.util.InjectFXML)3 ArrayList (java.util.ArrayList)2 Tooltip (javafx.scene.control.Tooltip)2 BigDecimal (java.math.BigDecimal)1 NumberFormat (java.text.NumberFormat)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Node (javafx.scene.Node)1 PieChart (javafx.scene.chart.PieChart)1 CheckBox (javafx.scene.control.CheckBox)1 Label (javafx.scene.control.Label)1 Account (jgnash.engine.Account)1 CurrencyNode (jgnash.engine.CurrencyNode)1 TransactionEntry (jgnash.engine.TransactionEntry)1 MaterialDesignLabel (jgnash.uifx.resource.font.MaterialDesignLabel)1