mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 13:16:44 +00:00
Merge pull request #1204 from krzyczak/master
toggle bitcoin unit on clicking a bitcoin value label
This commit is contained in:
commit
e1d9d54da3
1 changed files with 23 additions and 0 deletions
|
@ -10,19 +10,40 @@ import javafx.scene.control.MenuItem;
|
||||||
import javafx.scene.control.Tooltip;
|
import javafx.scene.control.Tooltip;
|
||||||
import javafx.scene.input.Clipboard;
|
import javafx.scene.input.Clipboard;
|
||||||
import javafx.scene.input.ClipboardContent;
|
import javafx.scene.input.ClipboardContent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.scene.input.MouseEvent;
|
||||||
|
|
||||||
public class CopyableCoinLabel extends CopyableLabel {
|
public class CopyableCoinLabel extends CopyableLabel {
|
||||||
private final LongProperty valueProperty = new SimpleLongProperty(-1);
|
private final LongProperty valueProperty = new SimpleLongProperty(-1);
|
||||||
private final Tooltip tooltip;
|
private final Tooltip tooltip;
|
||||||
private final CoinContextMenu contextMenu;
|
private final CoinContextMenu contextMenu;
|
||||||
|
|
||||||
|
private BitcoinUnit bitcoinUnit;
|
||||||
|
|
||||||
public CopyableCoinLabel() {
|
public CopyableCoinLabel() {
|
||||||
this("Unknown");
|
this("Unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final EventHandler<MouseEvent> toggleBitcoinUnit = event -> {
|
||||||
|
if(bitcoinUnit == null) {
|
||||||
|
bitcoinUnit = Config.get().getBitcoinUnit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bitcoinUnit == BitcoinUnit.SATOSHIS) {
|
||||||
|
bitcoinUnit = BitcoinUnit.BTC;
|
||||||
|
} else {
|
||||||
|
bitcoinUnit = BitcoinUnit.SATOSHIS;
|
||||||
|
}
|
||||||
|
|
||||||
|
refresh(Config.get().getUnitFormat(), bitcoinUnit);
|
||||||
|
};
|
||||||
|
|
||||||
public CopyableCoinLabel(String text) {
|
public CopyableCoinLabel(String text) {
|
||||||
super(text);
|
super(text);
|
||||||
valueProperty().addListener((observable, oldValue, newValue) -> setValueAsText((Long)newValue, Config.get().getUnitFormat(), Config.get().getBitcoinUnit()));
|
valueProperty().addListener((observable, oldValue, newValue) -> setValueAsText((Long)newValue, Config.get().getUnitFormat(), Config.get().getBitcoinUnit()));
|
||||||
|
|
||||||
|
setOnMouseClicked(toggleBitcoinUnit);
|
||||||
|
|
||||||
tooltip = new Tooltip();
|
tooltip = new Tooltip();
|
||||||
contextMenu = new CoinContextMenu();
|
contextMenu = new CoinContextMenu();
|
||||||
}
|
}
|
||||||
|
@ -63,6 +84,8 @@ public class CopyableCoinLabel extends CopyableLabel {
|
||||||
unit = (value >= BitcoinUnit.getAutoThreshold() ? BitcoinUnit.BTC : BitcoinUnit.SATOSHIS);
|
unit = (value >= BitcoinUnit.getAutoThreshold() ? BitcoinUnit.BTC : BitcoinUnit.SATOSHIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.bitcoinUnit = unit;
|
||||||
|
|
||||||
if(unit.equals(BitcoinUnit.BTC)) {
|
if(unit.equals(BitcoinUnit.BTC)) {
|
||||||
tooltip.setText(satsValue);
|
tooltip.setText(satsValue);
|
||||||
setText(btcValue);
|
setText(btcValue);
|
||||||
|
|
Loading…
Reference in a new issue