diff --git a/drongo b/drongo index 40dab593..b2f5f5ff 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 40dab5933702c5b12913337dc618a68652c445e4 +Subproject commit b2f5f5ffebfc0ce9f0d992f3ac3b59965661491b diff --git a/src/main/java/com/sparrowwallet/sparrow/control/AddressTreeTable.java b/src/main/java/com/sparrowwallet/sparrow/control/AddressTreeTable.java index 2f3e620c..7996afd8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/AddressTreeTable.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/AddressTreeTable.java @@ -5,6 +5,7 @@ import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.event.ReceiveActionEvent; import com.sparrowwallet.sparrow.event.ReceiveToEvent; +import com.sparrowwallet.sparrow.event.ShowTransactionsCountEvent; import com.sparrowwallet.sparrow.io.Config; import com.sparrowwallet.sparrow.wallet.Entry; import com.sparrowwallet.sparrow.wallet.NodeEntry; @@ -45,6 +46,15 @@ public class AddressTreeTable extends CoinTreeTable { labelCol.setSortable(false); getColumns().add(labelCol); + TreeTableColumn countCol = new TreeTableColumn<>("Transactions"); + countCol.setCellValueFactory((TreeTableColumn.CellDataFeatures param) -> { + return new ReadOnlyObjectWrapper<>(param.getValue().getValue().getChildren().size()); + }); + countCol.setCellFactory(p -> new NumberCell()); + countCol.setSortable(false); + countCol.setVisible(Config.get().isShowAddressTransactionCount()); + getColumns().add(countCol); + TreeTableColumn amountCol = new TreeTableColumn<>("Value"); amountCol.setCellValueFactory((TreeTableColumn.CellDataFeatures param) -> { return new ReadOnlyObjectWrapper<>(param.getValue().getValue().getValue()); @@ -53,6 +63,19 @@ public class AddressTreeTable extends CoinTreeTable { amountCol.setSortable(false); getColumns().add(amountCol); + ContextMenu contextMenu = new ContextMenu(); + CheckMenuItem showCountItem = new CheckMenuItem("Show Transaction Count"); + contextMenu.setOnShowing(event -> { + showCountItem.setSelected(Config.get().isShowAddressTransactionCount()); + }); + showCountItem.setOnAction(event -> { + boolean show = !Config.get().isShowAddressTransactionCount(); + Config.get().setShowAddressTransactionCount(show); + EventManager.get().post(new ShowTransactionsCountEvent(show)); + }); + contextMenu.getItems().add(showCountItem); + getColumns().forEach(col -> col.setContextMenu(contextMenu)); + setEditable(true); setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY); @@ -147,4 +170,8 @@ public class AddressTreeTable extends CoinTreeTable { Entry rootEntry = getRoot().getValue(); rootEntry.updateLabel(entry); } + + public void showTransactionsCount(boolean show) { + getColumns().stream().filter(col -> col.getText().equals("Transactions")).forEach(col -> col.setVisible(show)); + } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/NumberCell.java b/src/main/java/com/sparrowwallet/sparrow/control/NumberCell.java new file mode 100644 index 00000000..c221f81c --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/control/NumberCell.java @@ -0,0 +1,28 @@ +package com.sparrowwallet.sparrow.control; + +import com.sparrowwallet.sparrow.wallet.Entry; +import javafx.scene.control.TreeTableCell; +import org.controlsfx.tools.Platform; + +public class NumberCell extends TreeTableCell { + public NumberCell() { + super(); + getStyleClass().add("number-cell"); + if(Platform.getCurrent() == Platform.OSX) { + getStyleClass().add("number-field"); + } + } + + @Override + protected void updateItem(Number amount, boolean empty) { + super.updateItem(amount, empty); + + if(empty || amount == null) { + setText(null); + setGraphic(null); + } else { + setText(amount.toString()); + setGraphic(null); + } + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/event/ShowTransactionsCountEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/ShowTransactionsCountEvent.java new file mode 100644 index 00000000..c4c14177 --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/ShowTransactionsCountEvent.java @@ -0,0 +1,13 @@ +package com.sparrowwallet.sparrow.event; + +public class ShowTransactionsCountEvent { + private final boolean showCount; + + public ShowTransactionsCountEvent(boolean showCount) { + this.showCount = showCount; + } + + public boolean isShowCount() { + return showCount; + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Config.java b/src/main/java/com/sparrowwallet/sparrow/io/Config.java index dad23f04..6ac601c5 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Config.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Config.java @@ -43,6 +43,7 @@ public class Config { private boolean hideEmptyUsedAddresses = false; private boolean showTransactionHex = true; private boolean showLoadingLog = true; + private boolean showAddressTransactionCount = false; private boolean preventSleep = false; private List recentWalletFiles; private Integer keyDerivationPeriod; @@ -278,6 +279,15 @@ public class Config { flush(); } + public boolean isShowAddressTransactionCount() { + return showAddressTransactionCount; + } + + public void setShowAddressTransactionCount(boolean showAddressTransactionCount) { + this.showAddressTransactionCount = showAddressTransactionCount; + flush(); + } + public boolean isPreventSleep() { return preventSleep; } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/AddressesController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/AddressesController.java index 80abbbc4..ad47a22c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/AddressesController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/AddressesController.java @@ -125,6 +125,12 @@ public class AddressesController extends WalletFormController implements Initial } } + @Subscribe + public void showTransactionsCount(ShowTransactionsCountEvent event) { + receiveTable.showTransactionsCount(event.isShowCount()); + changeTable.showTransactionsCount(event.isShowCount()); + } + public void exportReceiveAddresses(ActionEvent event) { exportAddresses(KeyPurpose.RECEIVE); } diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/wallet.css b/src/main/resources/com/sparrowwallet/sparrow/wallet/wallet.css index b91688a8..d56c7c93 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/wallet.css +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/wallet.css @@ -58,6 +58,10 @@ -fx-text-fill: derive(white, -15%); } +.number-cell { + -fx-alignment: center-right; +} + .label-cell .text-field { -fx-padding: 0; }