All Downloads are FREE. Search and download functionalities are using the official Maven repository.

wallettemplate.utils.BitcoinUIModel Maven / Gradle / Ivy

There is a newer version: 0.14.7
Show newest version
package wallettemplate.utils;

import org.bitcoinj.core.*;
import javafx.application.Platform;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;

import java.util.Date;

/**
 * A class that exposes relevant bitcoin stuff as JavaFX bindable properties.
 */
public class BitcoinUIModel {
    private SimpleObjectProperty
address = new SimpleObjectProperty<>(); private SimpleObjectProperty balance = new SimpleObjectProperty<>(Coin.ZERO); private SimpleDoubleProperty syncProgress = new SimpleDoubleProperty(-1); private ProgressBarUpdater syncProgressUpdater = new ProgressBarUpdater(); public BitcoinUIModel() { } public BitcoinUIModel(Wallet wallet) { setWallet(wallet); } public void setWallet(Wallet wallet) { wallet.addEventListener(new AbstractWalletEventListener() { @Override public void onWalletChanged(Wallet wallet) { super.onWalletChanged(wallet); update(wallet); } }, Platform::runLater); update(wallet); } private void update(Wallet wallet) { balance.set(wallet.getBalance()); address.set(wallet.currentReceiveAddress()); } private class ProgressBarUpdater extends DownloadProgressTracker { @Override protected void progress(double pct, int blocksLeft, Date date) { super.progress(pct, blocksLeft, date); Platform.runLater(() -> syncProgress.set(pct / 100.0)); } @Override protected void doneDownload() { super.doneDownload(); Platform.runLater(() -> syncProgress.set(1.0)); } } public DownloadProgressTracker getDownloadProgressTracker() { return syncProgressUpdater; } public ReadOnlyDoubleProperty syncProgressProperty() { return syncProgress; } public ReadOnlyObjectProperty
addressProperty() { return address; } public ReadOnlyObjectProperty balanceProperty() { return balance; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy