Search in sources :

Example 11 with Tooltip

use of javafx.scene.control.Tooltip in project jgnash by ccavanaugh.

the class ImportPageTwoController method buildTableView.

private void buildTableView() {
    final TableColumn<ImportTransaction, ImportState> stateColumn = new TableColumn<>();
    stateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getState()));
    stateColumn.setCellFactory(param -> {
        TableCell<ImportTransaction, ImportState> cell = new ImportStateTableCell();
        cell.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
            if (event.getClickCount() > 1) {
                final ImportTransaction t = tableView.getItems().get(((TableCell<?, ?>) event.getSource()).getTableRow().getIndex());
                if (t.getState() == ImportState.EQUAL) {
                    t.setState(ImportState.NOT_EQUAL);
                } else if (t.getState() == ImportState.NOT_EQUAL) {
                    t.setState(ImportState.EQUAL);
                } else if (t.getState() == ImportState.NEW) {
                    t.setState(ImportState.IGNORE);
                } else if (t.getState() == ImportState.IGNORE) {
                    t.setState(ImportState.NEW);
                }
                Platform.runLater(tableView::refresh);
            }
        });
        return cell;
    });
    tableView.getColumns().add(stateColumn);
    final TableColumn<ImportTransaction, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
    dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDatePosted()));
    dateColumn.setCellFactory(param -> new ShortDateTableCell<>());
    tableView.getColumns().add(dateColumn);
    final TableColumn<ImportTransaction, String> numberColumn = new TableColumn<>(resources.getString("Column.Num"));
    numberColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getCheckNumber()));
    tableView.getColumns().add(numberColumn);
    final TableColumn<ImportTransaction, String> payeeColumn = new TableColumn<>(resources.getString("Column.Payee"));
    payeeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPayee()));
    tableView.getColumns().add(payeeColumn);
    final TableColumn<ImportTransaction, String> memoColumn = new TableColumn<>(resources.getString("Column.Memo"));
    memoColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getMemo()));
    tableView.getColumns().add(memoColumn);
    final TableColumn<ImportTransaction, Account> accountColumn = new TableColumn<>(resources.getString("Column.Account"));
    accountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getAccount());
        }
        return null;
    });
    accountColumn.setCellFactory(param -> new AccountComboBoxTableCell<>());
    accountColumn.setEditable(true);
    accountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setAccount(event.getNewValue());
        lastAccount = event.getNewValue();
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(accountColumn);
    incomeAccountColumn = new TableColumn<>(resources.getString("Column.Income"));
    incomeAccountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getGainsAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getGainsAccount());
        }
        return null;
    });
    incomeAccountColumn.setCellFactory(param -> new IncomeAccountComboBoxTableCell<>());
    incomeAccountColumn.setEditable(true);
    incomeAccountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setGainsAccount(event.getNewValue());
        lastGainsAccount = event.getNewValue();
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(incomeAccountColumn);
    expenseAccountColumn = new TableColumn<>(resources.getString("Column.Expense"));
    expenseAccountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getFeesAccount() != null) {
            if (param.getValue().getFees().compareTo(BigDecimal.ZERO) != 0) {
                return new SimpleObjectProperty<>(param.getValue().getFeesAccount());
            } else {
                return new SimpleObjectProperty<>(NOP_EXPENSE_ACCOUNT);
            }
        }
        return null;
    });
    expenseAccountColumn.setCellFactory(param -> new ExpenseAccountComboBoxTableCell<>());
    expenseAccountColumn.setEditable(true);
    expenseAccountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setFeesAccount(event.getNewValue());
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(expenseAccountColumn);
    final TableColumn<ImportTransaction, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
    amountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getAmount()));
    amountColumn.setCellFactory(param -> new BigDecimalTableCell<>(numberFormat));
    amountColumn.setCellFactory(param -> {
        final TableCell<ImportTransaction, BigDecimal> cell = new BigDecimalTableCell<>(numberFormat);
        cell.indexProperty().addListener((observable, oldValue, newValue) -> {
            final int index = newValue.intValue();
            if (index >= 0 && index < tableView.itemsProperty().get().size()) {
                cell.setTooltip(new Tooltip(tableView.itemsProperty().get().get(index).getToolTip()));
            }
        });
        return cell;
    });
    tableView.getColumns().add(amountColumn);
    typeColumn = new TableColumn<>(resources.getString("Column.Type"));
    typeColumn.setCellValueFactory(param -> {
        TransactionType transactionType = TransactionType.SINGLENTRY;
        if (param.getValue().isInvestmentTransaction()) {
            transactionType = param.getValue().getTransactionType();
        } else if (!param.getValue().getAccount().equals(baseAccount)) {
            transactionType = TransactionType.DOUBLEENTRY;
        }
        return new SimpleStringProperty(transactionType.toString());
    });
    tableView.getColumns().add(typeColumn);
}
Also used : Account(jgnash.engine.Account) TransactionType(jgnash.engine.TransactionType) ImportState(jgnash.convert.imports.ImportState) LocalDate(java.time.LocalDate) ImportTransaction(jgnash.convert.imports.ImportTransaction) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) TableCell(javafx.scene.control.TableCell) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) Tooltip(javafx.scene.control.Tooltip) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty)

Example 12 with Tooltip

use of javafx.scene.control.Tooltip in project jgnash by ccavanaugh.

the class IncomeExpensePayeePieChartDialogController method updateCharts.

private void updateCharts() {
    final Account account = accountComboBox.getValue();
    if (account != null) {
        final ObservableList<PieChart.Data>[] chartData = createPieDataSet(account);
        creditPieChart.setData(chartData[CREDIT]);
        debitPieChart.setData(chartData[DEBIT]);
        final NumberFormat numberFormat = CommodityFormat.getFullNumberFormat(account.getCurrencyNode());
        // Calculate the totals for percentage value
        final double creditTotal = chartData[CREDIT].parallelStream().mapToDouble(PieChart.Data::getPieValue).sum();
        final double debitTotal = chartData[DEBIT].parallelStream().mapToDouble(PieChart.Data::getPieValue).sum();
        final NumberFormat percentFormat = NumberFormat.getPercentInstance();
        percentFormat.setMaximumFractionDigits(1);
        percentFormat.setMinimumFractionDigits(1);
        // Install tooltips on the data after it has been added to the chart
        creditPieChart.getData().forEach(data -> Tooltip.install(data.getNode(), new Tooltip((data.getNode().getUserData() + "\n" + numberFormat.format(data.getPieValue()) + "(" + percentFormat.format(data.getPieValue() / creditTotal)) + ")")));
        // Install tooltips on the data after it has been added to the chart
        debitPieChart.getData().forEach(data -> Tooltip.install(data.getNode(), new Tooltip(((data.getNode().getUserData()) + "\n" + numberFormat.format(data.getPieValue()) + "(" + percentFormat.format(data.getPieValue() / debitTotal)) + ")")));
        creditPieChart.centerSubTitleProperty().set(numberFormat.format(creditTotal));
        debitPieChart.centerSubTitleProperty().set(numberFormat.format(debitTotal));
    } else {
        creditPieChart.setData(FXCollections.emptyObservableList());
        creditPieChart.setTitle("No Data");
        debitPieChart.setData(FXCollections.emptyObservableList());
        debitPieChart.setTitle("No Data");
    }
}
Also used : Account(jgnash.engine.Account) PieChart(javafx.scene.chart.PieChart) ObservableList(javafx.collections.ObservableList) Tooltip(javafx.scene.control.Tooltip) NumberFormat(java.text.NumberFormat)

Example 13 with Tooltip

use of javafx.scene.control.Tooltip in project jgnash by ccavanaugh.

the class IncomeExpensePieChartDialogController 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 = CommodityFormat.getFullNumberFormat(defaultCurrency);
        final ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
        double total = a.getTreeBalance(startDatePicker.getValue(), endDatePicker.getValue(), defaultCurrency).doubleValue();
        for (final Account child : a.getChildren()) {
            double balance = child.getTreeBalance(startDatePicker.getValue(), endDatePicker.getValue(), defaultCurrency).doubleValue();
            if (balance > 0 || balance < 0) {
                final String label = child.getName() + " - " + numberFormat.format(balance);
                final PieChart.Data data = new PieChart.Data(label, balance / total * 100);
                // nodes are created lazily.  Set the user data (Account) after the node is created
                data.nodeProperty().addListener((observable, oldValue, newValue) -> newValue.setUserData(child));
                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((((Account) data.getNode().getUserData()).getName() + " - " + percentFormat.format(data.getPieValue() / 100d)))));
        // Indicate the node can be clicked on to zoom into the next account level
        for (final PieChart.Data data : pieChart.getData()) {
            data.getNode().setOnMouseEntered(event -> {
                final Account account = (Account) data.getNode().getUserData();
                if (account.isParent()) {
                    data.getNode().setCursor(CustomCursor.getZoomInCursor());
                } else {
                    data.getNode().setCursor(Cursor.DEFAULT);
                }
                nodeFocused = true;
            });
            data.getNode().setOnMouseExited(event -> nodeFocused = false);
            // zoom in on click if this is a parent account
            data.getNode().setOnMouseClicked(event -> {
                if (data.getNode().getUserData() != null) {
                    if (((Account) data.getNode().getUserData()).isParent()) {
                        accountComboBox.setValue((Account) data.getNode().getUserData());
                    }
                }
            });
        }
        final String title;
        // pick an appropriate title
        if (a.getAccountType() == AccountType.EXPENSE) {
            title = resources.getString("Title.PercentExpense");
        } else if (a.getAccountType() == AccountType.INCOME) {
            title = resources.getString("Title.PercentIncome");
        } else {
            title = resources.getString("Title.PercentDist");
        }
        pieChart.setTitle(title);
        pieChart.centerTitleProperty().set(accountComboBox.getValue().getName());
        pieChart.centerSubTitleProperty().set(numberFormat.format(total));
    // abs() on all values won't work if children aren't of uniform sign,
    // then again, this chart is not right to display those trees
    //boolean negate = total != null && total.signum() < 0;
    } else {
        pieChart.setData(FXCollections.emptyObservableList());
        pieChart.setTitle("No Data");
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) PieChart(javafx.scene.chart.PieChart) Tooltip(javafx.scene.control.Tooltip) Engine(jgnash.engine.Engine) NumberFormat(java.text.NumberFormat)

Example 14 with Tooltip

use of javafx.scene.control.Tooltip in project trex-stateless-gui by cisco-system-traffic-generator.

the class TrexApp method speedupTooltip.

/**
     * Speeding up displaying tootlip for JDK 8 ref:
     * http://stackoverflow.com/questions/26854301/control-javafx-tooltip-delay
     */
private void speedupTooltip() {
    try {
        Tooltip tooltip = new Tooltip();
        Field fieldBehavior = tooltip.getClass().getDeclaredField("BEHAVIOR");
        fieldBehavior.setAccessible(true);
        Object objBehavior = fieldBehavior.get(tooltip);
        Field fieldTimer = objBehavior.getClass().getDeclaredField("activationTimer");
        fieldTimer.setAccessible(true);
        Timeline objTimer = (Timeline) fieldTimer.get(objBehavior);
        objTimer.getKeyFrames().clear();
        objTimer.getKeyFrames().add(new KeyFrame(new Duration(250)));
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
        LOG.error(e);
    }
}
Also used : Field(java.lang.reflect.Field) Timeline(javafx.animation.Timeline) Tooltip(javafx.scene.control.Tooltip) KeyFrame(javafx.animation.KeyFrame) Duration(javafx.util.Duration)

Example 15 with Tooltip

use of javafx.scene.control.Tooltip in project trex-stateless-gui by cisco-system-traffic-generator.

the class StatsTableGenerator method generateXStatPane.

public GridPane generateXStatPane(boolean full, Port port, boolean notempty, String filter, boolean resetCounters) {
    if (full) {
        statXTable.getChildren().clear();
        Util.optimizeMemory();
    }
    Map<String, Long> xstatsList = port.getXstats();
    Map<String, Long> xstatsListPinned = port.getXstatsPinned();
    String pinnedChar = "✖";
    String notPinnedChar = "✚";
    /*String pinnedChar = "☑";
        String notPinnedChar = "☐";*/
    rowIndex = 0;
    addHeaderCell(statXTable, "xstats-header0", "Counter", 0, WIDTH_COL_0 * 1.5);
    addHeaderCell(statXTable, "xstats-header1", "Value", 1, WIDTH_COL_1);
    addHeaderCell(statXTable, "xstats-header2", "Pin", 2, WIDTH_COL_PIN);
    rowIndex = 1;
    odd = true;
    xstatsListPinned.forEach((k, v) -> {
        if (v != null) {
            if (resetCounters) {
                fixCounter(port.getIndex(), k, v);
            }
            Node check = new Label(pinnedChar);
            GridPane.setHalignment(check, HPos.CENTER);
            addXstatRow(statXTable, (event) -> xstatsListPinned.remove(k, v), "xstat-red", "xstat-green", new Tooltip("Click '" + pinnedChar + "' to un-pin the counter."), "xstats-val-0-" + rowIndex, k, WIDTH_COL_0 * 1.5, 0, "xstats-val-1-" + rowIndex, String.valueOf(v - getShadowCounter(port.getIndex(), k)), WIDTH_COL_1, 1, "xstats-val-2-" + rowIndex, pinnedChar, WIDTH_COL_PIN, 2);
        }
    });
    xstatsList.forEach((k, v) -> {
        if (v != null && (!notempty || (notempty && (v - getShadowCounter(port.getIndex(), k) != 0))) && xstatsListPinned.get(k) == null) {
            if ((filter == null || filter.trim().length() == 0) || k.contains(filter)) {
                if (resetCounters) {
                    fixCounter(port.getIndex(), k, v);
                }
                Node check = new Label(notPinnedChar);
                GridPane.setHalignment(check, HPos.CENTER);
                addXstatRow(statXTable, (event) -> xstatsListPinned.put(k, v), "xstat-green", "xstat-red", new Tooltip("Click '" + notPinnedChar + "' to pin the counter.\nPinned counter is always visible."), "xstats-val-0-" + rowIndex, k, WIDTH_COL_0 * 1.5, 0, "xstats-val-1-" + rowIndex, String.valueOf(v - getShadowCounter(port.getIndex(), k)), WIDTH_COL_1, 1, "xstats-val-2-" + rowIndex, notPinnedChar, WIDTH_COL_PIN, 2);
            }
        }
    });
    GridPane gp = new GridPane();
    gp.setGridLinesVisible(false);
    gp.add(statXTable, 1, 1, 1, 2);
    return gp;
}
Also used : GridPane(javafx.scene.layout.GridPane) Node(javafx.scene.Node) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label)

Aggregations

Tooltip (javafx.scene.control.Tooltip)34 Button (javafx.scene.control.Button)12 Label (javafx.scene.control.Label)9 Node (javafx.scene.Node)5 IOException (java.io.IOException)4 Account (jgnash.engine.Account)4 DockTab (com.kyj.fx.voeditor.visual.component.dock.tab.DockTab)3 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)3 Contract (io.bitsquare.trade.Contract)3 BigDecimal (java.math.BigDecimal)3 Insets (javafx.geometry.Insets)3 Scene (javafx.scene.Scene)3 PieChart (javafx.scene.chart.PieChart)3 TextField (javafx.scene.control.TextField)3 NotNull (org.jetbrains.annotations.NotNull)3 BusyAnimation (io.bitsquare.gui.components.BusyAnimation)2 TextFieldWithCopyIcon (io.bitsquare.gui.components.TextFieldWithCopyIcon)2 PaymentAccountContractData (io.bitsquare.payment.PaymentAccountContractData)2 Offer (io.bitsquare.trade.offer.Offer)2 NumberFormat (java.text.NumberFormat)2