From c4295bc55ed9b7fb75be85803ee32394b3971557 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 27 Nov 2014 00:35:58 +0100 Subject: [PATCH] Remove confirmation spinner where confirmation is not needed #290 --- .../gui/components/BalanceTextField.java | 58 +------- .../BalanceWithConfirmationTextField.java | 135 ++++++++++++++++++ 2 files changed, 137 insertions(+), 56 deletions(-) create mode 100644 src/main/java/io/bitsquare/gui/components/BalanceWithConfirmationTextField.java diff --git a/src/main/java/io/bitsquare/gui/components/BalanceTextField.java b/src/main/java/io/bitsquare/gui/components/BalanceTextField.java index adf6b09e8a..b47d80a983 100644 --- a/src/main/java/io/bitsquare/gui/components/BalanceTextField.java +++ b/src/main/java/io/bitsquare/gui/components/BalanceTextField.java @@ -18,14 +18,11 @@ package io.bitsquare.gui.components; import io.bitsquare.btc.WalletService; -import io.bitsquare.btc.listeners.AddressConfidenceListener; import io.bitsquare.btc.listeners.BalanceListener; -import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator; import io.bitsquare.gui.util.BSFormatter; import org.bitcoinj.core.Address; import org.bitcoinj.core.Coin; -import org.bitcoinj.core.TransactionConfidence; import javafx.scene.control.*; import javafx.scene.effect.*; @@ -35,8 +32,6 @@ import javafx.scene.paint.*; public class BalanceTextField extends AnchorPane { private final TextField textField; - private final Tooltip progressIndicatorTooltip; - private final ConfidenceProgressIndicator progressIndicator; private final Effect fundedEffect = new DropShadow(BlurType.THREE_PASS_BOX, Color.GREEN, 4, 0.0, 0, 0); private final Effect notFundedEffect = new DropShadow(BlurType.THREE_PASS_BOX, Color.ORANGERED, 4, 0.0, 0, 0); @@ -52,33 +47,14 @@ public class BalanceTextField extends AnchorPane { textField.setFocusTraversable(false); textField.setEditable(false); - progressIndicator = new ConfidenceProgressIndicator(); - progressIndicator.setFocusTraversable(false); - progressIndicator.setPrefSize(24, 24); - progressIndicator.setId("funds-confidence"); - progressIndicator.setLayoutY(1); - progressIndicator.setProgress(0); - progressIndicator.setVisible(false); - - progressIndicatorTooltip = new Tooltip("-"); - Tooltip.install(progressIndicator, progressIndicatorTooltip); - - AnchorPane.setRightAnchor(progressIndicator, 0.0); - AnchorPane.setRightAnchor(textField, 55.0); + AnchorPane.setRightAnchor(textField, 0.0); AnchorPane.setLeftAnchor(textField, 0.0); - getChildren().addAll(textField, progressIndicator); + getChildren().addAll(textField); } public void setup(WalletService walletService, Address address, BSFormatter formatter) { this.formatter = formatter; - walletService.addAddressConfidenceListener(new AddressConfidenceListener(address) { - @Override - public void onTransactionConfidenceChanged(TransactionConfidence confidence) { - updateConfidence(confidence); - } - }); - updateConfidence(walletService.getConfidenceForAddress(address)); walletService.addBalanceListener(new BalanceListener(address) { @Override @@ -94,36 +70,6 @@ public class BalanceTextField extends AnchorPane { // Private methods /////////////////////////////////////////////////////////////////////////////////////////// - private void updateConfidence(TransactionConfidence confidence) { - if (confidence != null) { - switch (confidence.getConfidenceType()) { - case UNKNOWN: - progressIndicatorTooltip.setText("Unknown transaction status"); - progressIndicator.setProgress(0); - break; - case PENDING: - progressIndicatorTooltip.setText( - "Seen by " + confidence.numBroadcastPeers() + " peer(s) / 0 " + "confirmations"); - progressIndicator.setProgress(-1.0); - break; - case BUILDING: - progressIndicatorTooltip.setText("Confirmed in " + confidence.getDepthInBlocks() + " block(s)"); - progressIndicator.setProgress(Math.min(1, (double) confidence.getDepthInBlocks() / 6.0)); - break; - case DEAD: - progressIndicatorTooltip.setText("Transaction is invalid."); - progressIndicator.setProgress(0); - break; - } - - if (progressIndicator.getProgress() != 0) { - progressIndicator.setVisible(true); - AnchorPane.setRightAnchor(progressIndicator, 0.0); - AnchorPane.setRightAnchor(textField, 35.0); - } - } - } - private void updateBalance(Coin balance) { textField.setText(formatter.formatCoinWithCode(balance)); if (balance.isPositive()) diff --git a/src/main/java/io/bitsquare/gui/components/BalanceWithConfirmationTextField.java b/src/main/java/io/bitsquare/gui/components/BalanceWithConfirmationTextField.java new file mode 100644 index 0000000000..bf2a4b3af3 --- /dev/null +++ b/src/main/java/io/bitsquare/gui/components/BalanceWithConfirmationTextField.java @@ -0,0 +1,135 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bitsquare is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bitsquare. If not, see . + */ + +package io.bitsquare.gui.components; + +import io.bitsquare.btc.WalletService; +import io.bitsquare.btc.listeners.AddressConfidenceListener; +import io.bitsquare.btc.listeners.BalanceListener; +import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator; +import io.bitsquare.gui.util.BSFormatter; + +import org.bitcoinj.core.Address; +import org.bitcoinj.core.Coin; +import org.bitcoinj.core.TransactionConfidence; + +import javafx.scene.control.*; +import javafx.scene.effect.*; +import javafx.scene.layout.*; +import javafx.scene.paint.*; + +public class BalanceWithConfirmationTextField extends AnchorPane { + + private final TextField textField; + private final Tooltip progressIndicatorTooltip; + private final ConfidenceProgressIndicator progressIndicator; + + private final Effect fundedEffect = new DropShadow(BlurType.THREE_PASS_BOX, Color.GREEN, 4, 0.0, 0, 0); + private final Effect notFundedEffect = new DropShadow(BlurType.THREE_PASS_BOX, Color.ORANGERED, 4, 0.0, 0, 0); + private BSFormatter formatter; + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + + public BalanceWithConfirmationTextField() { + textField = new TextField(); + textField.setFocusTraversable(false); + textField.setEditable(false); + + progressIndicator = new ConfidenceProgressIndicator(); + progressIndicator.setFocusTraversable(false); + progressIndicator.setPrefSize(24, 24); + progressIndicator.setId("funds-confidence"); + progressIndicator.setLayoutY(1); + progressIndicator.setProgress(0); + progressIndicator.setVisible(false); + + progressIndicatorTooltip = new Tooltip("-"); + Tooltip.install(progressIndicator, progressIndicatorTooltip); + + AnchorPane.setRightAnchor(progressIndicator, 0.0); + AnchorPane.setRightAnchor(textField, 55.0); + AnchorPane.setLeftAnchor(textField, 0.0); + + getChildren().addAll(textField, progressIndicator); + } + + public void setup(WalletService walletService, Address address, BSFormatter formatter) { + this.formatter = formatter; + walletService.addAddressConfidenceListener(new AddressConfidenceListener(address) { + @Override + public void onTransactionConfidenceChanged(TransactionConfidence confidence) { + updateConfidence(confidence); + } + }); + updateConfidence(walletService.getConfidenceForAddress(address)); + + walletService.addBalanceListener(new BalanceListener(address) { + @Override + public void onBalanceChanged(Coin balance) { + updateBalance(balance); + } + }); + updateBalance(walletService.getBalanceForAddress(address)); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private methods + /////////////////////////////////////////////////////////////////////////////////////////// + + private void updateConfidence(TransactionConfidence confidence) { + if (confidence != null) { + switch (confidence.getConfidenceType()) { + case UNKNOWN: + progressIndicatorTooltip.setText("Unknown transaction status"); + progressIndicator.setProgress(0); + break; + case PENDING: + progressIndicatorTooltip.setText( + "Seen by " + confidence.numBroadcastPeers() + " peer(s) / 0 " + "confirmations"); + progressIndicator.setProgress(-1.0); + break; + case BUILDING: + progressIndicatorTooltip.setText("Confirmed in " + confidence.getDepthInBlocks() + " block(s)"); + progressIndicator.setProgress(Math.min(1, (double) confidence.getDepthInBlocks() / 6.0)); + break; + case DEAD: + progressIndicatorTooltip.setText("Transaction is invalid."); + progressIndicator.setProgress(0); + break; + } + + if (progressIndicator.getProgress() != 0) { + progressIndicator.setVisible(true); + AnchorPane.setRightAnchor(progressIndicator, 0.0); + AnchorPane.setRightAnchor(textField, 35.0); + } + } + } + + private void updateBalance(Coin balance) { + textField.setText(formatter.formatCoinWithCode(balance)); + if (balance.isPositive()) + textField.setEffect(fundedEffect); + else + textField.setEffect(notFundedEffect); + } + +}