various minor utxo screen improvements, including hiding the utxo chart

This commit is contained in:
Craig Raw 2021-05-17 10:09:19 +02:00
parent d67c5c5218
commit adcddfa84d
8 changed files with 61 additions and 27 deletions

View file

@ -123,6 +123,9 @@ public class AppController implements Initializable {
@FXML @FXML
private CheckMenuItem showLoadingLog; private CheckMenuItem showLoadingLog;
@FXML
private CheckMenuItem showUtxosChart;
@FXML @FXML
private CheckMenuItem showTxHex; private CheckMenuItem showTxHex;
@ -259,6 +262,7 @@ public class AppController implements Initializable {
useHdCameraResolution.setSelected(Config.get().isHdCapture()); useHdCameraResolution.setSelected(Config.get().isHdCapture());
showTxHex.setSelected(Config.get().isShowTransactionHex()); showTxHex.setSelected(Config.get().isShowTransactionHex());
showLoadingLog.setSelected(Config.get().isShowLoadingLog()); showLoadingLog.setSelected(Config.get().isShowLoadingLog());
showUtxosChart.setSelected(Config.get().isShowUtxosChart());
savePSBT.visibleProperty().bind(saveTransaction.visibleProperty().not()); savePSBT.visibleProperty().bind(saveTransaction.visibleProperty().not());
exportWallet.setDisable(true); exportWallet.setDisable(true);
refreshWallet.disableProperty().bind(Bindings.or(exportWallet.disableProperty(), Bindings.or(serverToggle.disableProperty(), AppServices.onlineProperty().not()))); refreshWallet.disableProperty().bind(Bindings.or(exportWallet.disableProperty(), Bindings.or(serverToggle.disableProperty(), AppServices.onlineProperty().not())));
@ -670,6 +674,12 @@ public class AppController implements Initializable {
EventManager.get().post(new LoadingLogChangedEvent(item.isSelected())); EventManager.get().post(new LoadingLogChangedEvent(item.isSelected()));
} }
public void showUtxosChart(ActionEvent event) {
CheckMenuItem item = (CheckMenuItem)event.getSource();
Config.get().setShowUtxosChart(item.isSelected());
EventManager.get().post(new UtxosChartChangedEvent(item.isSelected()));
}
public void showTxHex(ActionEvent event) { public void showTxHex(ActionEvent event) {
CheckMenuItem item = (CheckMenuItem)event.getSource(); CheckMenuItem item = (CheckMenuItem)event.getSource();
Config.get().setShowTransactionHex(item.isSelected()); Config.get().setShowTransactionHex(item.isSelected());

View file

@ -34,7 +34,7 @@ public class DateCell extends TreeTableCell<Entry, Entry> {
if(entry instanceof UtxoEntry) { if(entry instanceof UtxoEntry) {
UtxoEntry utxoEntry = (UtxoEntry)entry; UtxoEntry utxoEntry = (UtxoEntry)entry;
if(utxoEntry.getHashIndex().getHeight() <= 0) { if(utxoEntry.getHashIndex().getHeight() <= 0) {
setText("Unconfirmed " + (utxoEntry.isSpendable() ? "(Spendable)" : "(Not yet spendable)")); setText("Unconfirmed " + (utxoEntry.getHashIndex().getHeight() < 0 ? "Parent " : "") + (utxoEntry.isSpendable() ? "(Spendable)" : "(Not yet spendable)"));
} else { } else {
String date = DATE_FORMAT.format(utxoEntry.getHashIndex().getDate()); String date = DATE_FORMAT.format(utxoEntry.getHashIndex().getDate());
setText(date); setText(date);

View file

@ -44,16 +44,18 @@ public class UtxosChart extends BarChart<String, Number> {
totalUtxos = utxoDataList.size(); totalUtxos = utxoDataList.size();
if(utxoDataList.size() > MAX_BARS) { if(utxoDataList.size() > MAX_BARS) {
Long otherTotal = utxoDataList.subList(MAX_BARS - 1, utxoDataList.size()).stream().mapToLong(data -> data.getYValue().longValue()).sum(); List<Data<String, Number>> otherDataList = utxoDataList.subList(MAX_BARS - 1, utxoDataList.size());
List<Entry> otherEntries = otherDataList.stream().map(data -> (Entry)data.getExtraValue()).collect(Collectors.toList());
Long otherTotal = otherDataList.stream().mapToLong(data -> data.getYValue().longValue()).sum();
utxoDataList = utxoDataList.subList(0, MAX_BARS - 1); utxoDataList = utxoDataList.subList(0, MAX_BARS - 1);
utxoDataList.add(new XYChart.Data<>(OTHER_CATEGORY, otherTotal)); utxoDataList.add(new XYChart.Data<>(OTHER_CATEGORY, otherTotal, otherEntries));
} }
for(int i = 0; i < utxoDataList.size(); i++) { for(int i = 0; i < utxoDataList.size(); i++) {
XYChart.Data<String, Number> newData = utxoDataList.get(i); XYChart.Data<String, Number> newData = utxoDataList.get(i);
if(i < utxoSeries.getData().size()) { if(i < utxoSeries.getData().size()) {
XYChart.Data<String, Number> existingData = utxoSeries.getData().get(i); XYChart.Data<String, Number> existingData = utxoSeries.getData().get(i);
if(!newData.getXValue().equals(existingData.getXValue()) || !newData.getYValue().equals(existingData.getYValue()) || (newData.getExtraValue() != null && !newData.getExtraValue().equals(existingData.getExtraValue()))) { if(!newData.getXValue().equals(existingData.getXValue()) || !newData.getYValue().equals(existingData.getYValue()) || (newData.getExtraValue() instanceof Entry && !newData.getExtraValue().equals(existingData.getExtraValue()))) {
utxoSeries.getData().set(i, newData); utxoSeries.getData().set(i, newData);
} }
} else { } else {
@ -87,7 +89,8 @@ public class UtxosChart extends BarChart<String, Number> {
for(int i = 0; i < utxoSeries.getData().size(); i++) { for(int i = 0; i < utxoSeries.getData().size(); i++) {
XYChart.Data<String, Number> data = utxoSeries.getData().get(i); XYChart.Data<String, Number> data = utxoSeries.getData().get(i);
if((data.getExtraValue() != null && entries.contains((Entry)data.getExtraValue())) || (data.getExtraValue() == null && entries.size() == totalUtxos)) { if((data.getExtraValue() instanceof Entry && entries.contains((Entry)data.getExtraValue())) ||
(data.getExtraValue() instanceof List && entries.containsAll((List)data.getExtraValue()))) {
Node bar = lookup(".data" + i); Node bar = lookup(".data" + i);
if(bar != null) { if(bar != null) {
bar.getStyleClass().add("selected"); bar.getStyleClass().add("selected");

View file

@ -0,0 +1,13 @@
package com.sparrowwallet.sparrow.event;
public class UtxosChartChangedEvent {
private final boolean visible;
public UtxosChartChangedEvent(boolean visible) {
this.visible = visible;
}
public boolean isVisible() {
return visible;
}
}

View file

@ -41,6 +41,7 @@ public class Config {
private boolean hideEmptyUsedAddresses = false; private boolean hideEmptyUsedAddresses = false;
private boolean showTransactionHex = true; private boolean showTransactionHex = true;
private boolean showLoadingLog = false; private boolean showLoadingLog = false;
private boolean showUtxosChart = true;
private List<File> recentWalletFiles; private List<File> recentWalletFiles;
private Integer keyDerivationPeriod; private Integer keyDerivationPeriod;
private File hwi; private File hwi;
@ -257,6 +258,15 @@ public class Config {
flush(); flush();
} }
public boolean isShowUtxosChart() {
return showUtxosChart;
}
public void setShowUtxosChart(boolean showUtxosChart) {
this.showUtxosChart = showUtxosChart;
flush();
}
public List<File> getRecentWalletFiles() { public List<File> getRecentWalletFiles() {
return recentWalletFiles; return recentWalletFiles;
} }

View file

@ -50,6 +50,9 @@ public class UtxosController extends WalletFormController implements Initializab
utxosChart.select(selectedEntries); utxosChart.select(selectedEntries);
updateSendSelected(Config.get().getBitcoinUnit()); updateSendSelected(Config.get().getBitcoinUnit());
}); });
utxosChart.managedProperty().bind(utxosChart.visibleProperty());
utxosChart.setVisible(Config.get().isShowUtxosChart());
} }
private void updateSendSelected(BitcoinUnit unit) { private void updateSendSelected(BitcoinUnit unit) {
@ -167,4 +170,9 @@ public class UtxosController extends WalletFormController implements Initializab
public void includeMempoolOutputsChangedEvent(IncludeMempoolOutputsChangedEvent event) { public void includeMempoolOutputsChangedEvent(IncludeMempoolOutputsChangedEvent event) {
utxosTable.refresh(); utxosTable.refresh();
} }
@Subscribe
public void utxosChartChanged(UtxosChartChangedEvent event) {
utxosChart.setVisible(event.isVisible());
}
} }

View file

@ -89,6 +89,7 @@
<CheckMenuItem fx:id="hideEmptyUsedAddresses" mnemonicParsing="false" text="Hide Empty Used Addresses" onAction="#hideEmptyUsedAddresses"/> <CheckMenuItem fx:id="hideEmptyUsedAddresses" mnemonicParsing="false" text="Hide Empty Used Addresses" onAction="#hideEmptyUsedAddresses"/>
<CheckMenuItem fx:id="useHdCameraResolution" mnemonicParsing="false" text="Use HD Camera Resolution" onAction="#useHdCameraResolution"/> <CheckMenuItem fx:id="useHdCameraResolution" mnemonicParsing="false" text="Use HD Camera Resolution" onAction="#useHdCameraResolution"/>
<CheckMenuItem fx:id="showLoadingLog" mnemonicParsing="false" text="Show Wallet Loading Log" onAction="#showLoadingLog" /> <CheckMenuItem fx:id="showLoadingLog" mnemonicParsing="false" text="Show Wallet Loading Log" onAction="#showLoadingLog" />
<CheckMenuItem fx:id="showUtxosChart" mnemonicParsing="false" text="Show UTXOs Chart" onAction="#showUtxosChart" />
<CheckMenuItem fx:id="showTxHex" mnemonicParsing="false" text="Show Transaction Hex" onAction="#showTxHex"/> <CheckMenuItem fx:id="showTxHex" mnemonicParsing="false" text="Show Transaction Hex" onAction="#showTxHex"/>
<SeparatorMenuItem /> <SeparatorMenuItem />
<MenuItem fx:id="minimizeToTray" mnemonicParsing="false" text="Minimize to System Tray" accelerator="Shortcut+Y" onAction="#minimizeToTray"/> <MenuItem fx:id="minimizeToTray" mnemonicParsing="false" text="Minimize to System Tray" accelerator="Shortcut+Y" onAction="#minimizeToTray"/>

View file

@ -19,15 +19,8 @@
<Insets left="25.0" right="25.0" top="15.0" bottom="25.0" /> <Insets left="25.0" right="25.0" top="15.0" bottom="25.0" />
</padding> </padding>
<center> <center>
<GridPane hgap="10.0" vgap="10.0"> <VBox spacing="10.0">
<columnConstraints> <BorderPane VBox.vgrow="ALWAYS">
<ColumnConstraints percentWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints percentHeight="60" />
<RowConstraints percentHeight="40" />
</rowConstraints>
<BorderPane GridPane.columnIndex="0" GridPane.rowIndex="0">
<top> <top>
<Label styleClass="utxos-treetable-label" text="Unspent Transaction Outputs"/> <Label styleClass="utxos-treetable-label" text="Unspent Transaction Outputs"/>
</top> </top>
@ -45,18 +38,14 @@
</HBox> </HBox>
</bottom> </bottom>
</BorderPane> </BorderPane>
<BorderPane GridPane.columnIndex="0" GridPane.rowIndex="1"> <UtxosChart fx:id="utxosChart" legendVisible="false" verticalGridLinesVisible="false" animated="false" prefHeight="250">
<center> <xAxis>
<UtxosChart fx:id="utxosChart" legendVisible="false" verticalGridLinesVisible="false" animated="false"> <CategoryAxis side="BOTTOM" animated="false" />
<xAxis> </xAxis>
<CategoryAxis side="BOTTOM" animated="false" /> <yAxis>
</xAxis> <NumberAxis side="LEFT" />
<yAxis> </yAxis>
<NumberAxis side="LEFT" /> </UtxosChart>
</yAxis> </VBox>
</UtxosChart>
</center>
</BorderPane>
</GridPane>
</center> </center>
</BorderPane> </BorderPane>