mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-07 14:42:51 -04:00
integrate bitcoinj WalletAppKit
This commit is contained in:
parent
227985fdc7
commit
328ecf34fe
15 changed files with 408 additions and 112 deletions
|
@ -1,13 +1,18 @@
|
|||
package io.bitsquare.gui;
|
||||
|
||||
import com.google.bitcoin.core.DownloadListener;
|
||||
import com.google.inject.Inject;
|
||||
import io.bitsquare.BitSquare;
|
||||
import io.bitsquare.btc.IWalletFacade;
|
||||
import io.bitsquare.di.GuiceFXMLLoader;
|
||||
import io.bitsquare.gui.trade.TradeController;
|
||||
import io.bitsquare.gui.util.Icons;
|
||||
import io.bitsquare.settings.Settings;
|
||||
import io.bitsquare.trade.Direction;
|
||||
import io.bitsquare.trade.orderbook.OrderBookFilter;
|
||||
import javafx.animation.FadeTransition;
|
||||
import javafx.animation.Interpolator;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
|
@ -15,61 +20,59 @@ import javafx.fxml.FXML;
|
|||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ToggleButton;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.util.Duration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Currency;
|
||||
import java.util.Date;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class MainController implements Initializable, INavigationController
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(MainController.class);
|
||||
|
||||
private Settings settings;
|
||||
private OrderBookFilter orderBookFilter;
|
||||
private IWalletFacade walletFacade;
|
||||
private IChildController childController;
|
||||
private ToggleGroup toggleGroup;
|
||||
private ToggleButton prevToggleButton;
|
||||
private Image prevToggleButtonIcon;
|
||||
public ProgressBar networkSyncProgressBar;
|
||||
public Label networkSyncInfoLabel;
|
||||
|
||||
@FXML
|
||||
public Pane contentPane;
|
||||
public HBox leftNavPane, rightNavPane;
|
||||
public HBox leftNavPane, rightNavPane, footerContainer;
|
||||
|
||||
@Inject
|
||||
public MainController(Settings settings, OrderBookFilter orderBookFilter)
|
||||
public MainController(Settings settings, OrderBookFilter orderBookFilter, IWalletFacade walletFacade)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.orderBookFilter = orderBookFilter;
|
||||
this.walletFacade = walletFacade;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb)
|
||||
{
|
||||
toggleGroup = new ToggleGroup();
|
||||
buildNavigation();
|
||||
|
||||
ToggleButton homeButton = addNavButton(leftNavPane, "Overview", Icons.HOME, Icons.HOME, INavigationController.HOME);
|
||||
ToggleButton buyButton = addNavButton(leftNavPane, "Buy BTC", Icons.NAV_BUY, Icons.NAV_BUY_ACTIVE, INavigationController.TRADE, Direction.BUY);
|
||||
ToggleButton sellButton = addNavButton(leftNavPane, "Sell BTC", Icons.NAV_SELL, Icons.NAV_SELL_ACTIVE, INavigationController.TRADE, Direction.SELL);
|
||||
addNavButton(leftNavPane, "Orders", Icons.ORDERS, Icons.ORDERS, INavigationController.ORDERS);
|
||||
addNavButton(leftNavPane, "History", Icons.HISTORY, Icons.HISTORY, INavigationController.HISTORY);
|
||||
addNavButton(leftNavPane, "Funds", Icons.FUNDS, Icons.FUNDS, INavigationController.FUNDS);
|
||||
addNavButton(leftNavPane, "Message", Icons.MSG, Icons.MSG, INavigationController.MSG);
|
||||
addCurrencyComboBox();
|
||||
addNavButton(rightNavPane, "Settings", Icons.SETTINGS, Icons.SETTINGS, INavigationController.SETTINGS);
|
||||
buildFooter();
|
||||
|
||||
|
||||
sellButton.fire();
|
||||
//homeButton.fire();
|
||||
walletFacade.initWallet(new ProgressBarUpdater());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IChildController navigateToView(String fxmlView, String title)
|
||||
{
|
||||
|
@ -99,6 +102,34 @@ public class MainController implements Initializable, INavigationController
|
|||
return childController;
|
||||
}
|
||||
|
||||
private void buildNavigation()
|
||||
{
|
||||
toggleGroup = new ToggleGroup();
|
||||
|
||||
ToggleButton homeButton = addNavButton(leftNavPane, "Overview", Icons.HOME, Icons.HOME, INavigationController.HOME);
|
||||
ToggleButton buyButton = addNavButton(leftNavPane, "Buy BTC", Icons.NAV_BUY, Icons.NAV_BUY_ACTIVE, INavigationController.TRADE, Direction.BUY);
|
||||
ToggleButton sellButton = addNavButton(leftNavPane, "Sell BTC", Icons.NAV_SELL, Icons.NAV_SELL_ACTIVE, INavigationController.TRADE, Direction.SELL);
|
||||
addNavButton(leftNavPane, "Orders", Icons.ORDERS, Icons.ORDERS, INavigationController.ORDERS);
|
||||
addNavButton(leftNavPane, "History", Icons.HISTORY, Icons.HISTORY, INavigationController.HISTORY);
|
||||
addNavButton(leftNavPane, "Funds", Icons.FUNDS, Icons.FUNDS, INavigationController.FUNDS);
|
||||
addNavButton(leftNavPane, "Message", Icons.MSG, Icons.MSG, INavigationController.MSG);
|
||||
addCurrencyComboBox();
|
||||
addNavButton(rightNavPane, "Settings", Icons.SETTINGS, Icons.SETTINGS, INavigationController.SETTINGS);
|
||||
|
||||
sellButton.fire();
|
||||
//homeButton.fire();
|
||||
}
|
||||
|
||||
private void buildFooter()
|
||||
{
|
||||
networkSyncInfoLabel = new Label();
|
||||
networkSyncInfoLabel.setText("Synchronize with network...");
|
||||
networkSyncProgressBar = new ProgressBar();
|
||||
networkSyncProgressBar.setPrefWidth(200);
|
||||
networkSyncProgressBar.setProgress(-1);
|
||||
footerContainer.getChildren().addAll(networkSyncProgressBar, networkSyncInfoLabel);
|
||||
}
|
||||
|
||||
private ToggleButton addNavButton(Pane parent, String title, String iconId, String iconIdActivated, String navTarget)
|
||||
{
|
||||
return addNavButton(parent, title, iconId, iconIdActivated, navTarget, null);
|
||||
|
@ -162,4 +193,40 @@ public class MainController implements Initializable, INavigationController
|
|||
holder.getChildren().add(currencyComboBox);
|
||||
rightNavPane.getChildren().add(holder);
|
||||
}
|
||||
|
||||
private void setProgress(double percent)
|
||||
{
|
||||
networkSyncProgressBar.setProgress(percent / 100.0);
|
||||
networkSyncInfoLabel.setText("Synchronize with network: " + (int) percent + "%");
|
||||
}
|
||||
|
||||
private void doneDownload()
|
||||
{
|
||||
networkSyncInfoLabel.setText("Sync with network: Done");
|
||||
|
||||
FadeTransition fade = new FadeTransition(Duration.millis(700), footerContainer);
|
||||
fade.setToValue(0.0);
|
||||
fade.setCycleCount(1);
|
||||
fade.setInterpolator(Interpolator.EASE_BOTH);
|
||||
fade.play();
|
||||
fade.setOnFinished(e -> footerContainer.getChildren().clear());
|
||||
}
|
||||
|
||||
private class ProgressBarUpdater extends DownloadListener
|
||||
{
|
||||
@Override
|
||||
protected void progress(double percent, int blocksSoFar, Date date)
|
||||
{
|
||||
super.progress(percent, blocksSoFar, date);
|
||||
Platform.runLater(() -> MainController.this.setProgress(percent));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doneDownload()
|
||||
{
|
||||
super.doneDownload();
|
||||
Platform.runLater(MainController.this::doneDownload);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue