utxo multiple selection, long confirmation indicator

This commit is contained in:
Craig Raw 2020-07-06 09:24:29 +02:00
parent 5860a6e49f
commit 3305d0630a
6 changed files with 39 additions and 17 deletions

View file

@ -6,6 +6,7 @@ import javafx.scene.chart.Axis;
import javafx.scene.chart.LineChart; import javafx.scene.chart.LineChart;
import javafx.scene.chart.XYChart; import javafx.scene.chart.XYChart;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
public class FeeRatesChart extends LineChart<String, Number> { public class FeeRatesChart extends LineChart<String, Number> {
@ -24,8 +25,10 @@ public class FeeRatesChart extends LineChart<String, Number> {
public void update(Map<Integer, Double> targetBlocksFeeRates) { public void update(Map<Integer, Double> targetBlocksFeeRates) {
feeRateSeries.getData().clear(); feeRateSeries.getData().clear();
for(Integer targetBlocks : targetBlocksFeeRates.keySet()) { for(Iterator<Integer> targetBlocksIter = targetBlocksFeeRates.keySet().iterator(); targetBlocksIter.hasNext(); ) {
XYChart.Data<String, Number> data = new XYChart.Data<>(Integer.toString(targetBlocks), targetBlocksFeeRates.get(targetBlocks)); Integer targetBlocks = targetBlocksIter.next();
String category = targetBlocks + (targetBlocksIter.hasNext() ? "" : "+");
XYChart.Data<String, Number> data = new XYChart.Data<>(category, targetBlocksFeeRates.get(targetBlocks));
feeRateSeries.getData().add(data); feeRateSeries.getData().add(data);
} }
@ -44,7 +47,7 @@ public class FeeRatesChart extends LineChart<String, Number> {
XYChart.Data<String, Number> data = feeRateSeries.getData().get(i); XYChart.Data<String, Number> data = feeRateSeries.getData().get(i);
Node symbol = lookup(".chart-line-symbol.data" + i); Node symbol = lookup(".chart-line-symbol.data" + i);
if(symbol != null) { if(symbol != null) {
if(data.getXValue().equals(targetBlocks.toString())) { if(data.getXValue().replace("+", "").equals(targetBlocks.toString())) {
symbol.getStyleClass().add("selected"); symbol.getStyleClass().add("selected");
selectedTargetBlocks = targetBlocks; selectedTargetBlocks = targetBlocks;
} }

View file

@ -320,7 +320,7 @@ public class TransactionDiagram extends GridPane {
@Override @Override
public String getLabel() { public String getLabel() {
return additionalInputs.size() + " more"; return additionalInputs.size() + " more...";
} }
public List<BlockTransactionHashIndex> getAdditionalInputs() { public List<BlockTransactionHashIndex> getAdditionalInputs() {

View file

@ -10,13 +10,15 @@ import javafx.scene.chart.BarChart;
import javafx.scene.chart.XYChart; import javafx.scene.chart.XYChart;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class UtxosChart extends BarChart<String, Number> { public class UtxosChart extends BarChart<String, Number> {
private static final int MAX_BARS = 8; private static final int MAX_BARS = 8;
private static final String OTHER_CATEGORY = "Other"; private static final String OTHER_CATEGORY = "Other";
private Entry selectedEntry; private List<Entry> selectedEntries;
private int totalUtxos;
private XYChart.Series<String, Number> utxoSeries; private XYChart.Series<String, Number> utxoSeries;
@ -36,6 +38,7 @@ public class UtxosChart extends BarChart<String, Number> {
.sorted((o1, o2) -> (int) (o2.getYValue().longValue() - o1.getYValue().longValue())) .sorted((o1, o2) -> (int) (o2.getYValue().longValue() - o1.getYValue().longValue()))
.collect(Collectors.toList()); .collect(Collectors.toList());
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(); Long otherTotal = utxoDataList.subList(MAX_BARS - 1, utxoDataList.size()).stream().mapToLong(data -> data.getYValue().longValue()).sum();
utxoDataList = utxoDataList.subList(0, MAX_BARS - 1); utxoDataList = utxoDataList.subList(0, MAX_BARS - 1);
@ -58,14 +61,14 @@ public class UtxosChart extends BarChart<String, Number> {
utxoSeries.getData().remove(utxoDataList.size() - 1, utxoSeries.getData().size()); utxoSeries.getData().remove(utxoDataList.size() - 1, utxoSeries.getData().size());
} }
if(selectedEntry != null) { if(selectedEntries != null) {
select(selectedEntry); select(selectedEntries);
} }
} }
public void select(Entry entry) { public void select(List<Entry> entries) {
Node selectedBar = lookup(".chart-bar.selected"); Set<Node> selectedBars = lookupAll(".chart-bar.selected");
if(selectedBar != null) { for(Node selectedBar : selectedBars) {
selectedBar.getStyleClass().remove("selected"); selectedBar.getStyleClass().remove("selected");
} }
@ -73,11 +76,14 @@ public class UtxosChart extends BarChart<String, Number> {
XYChart.Data<String, Number> data = utxoSeries.getData().get(i); XYChart.Data<String, Number> data = utxoSeries.getData().get(i);
Node bar = lookup(".data" + i); Node bar = lookup(".data" + i);
if(bar != null) { if(bar != null) {
if(data.getExtraValue() != null && data.getExtraValue().equals(entry)) { if(data.getExtraValue() != null && entries.contains((Entry)data.getExtraValue())) {
bar.getStyleClass().add("selected");
} else if(data.getExtraValue() == null && entries.size() == totalUtxos) {
bar.getStyleClass().add("selected"); bar.getStyleClass().add("selected");
this.selectedEntry = entry;
} }
} }
} }
this.selectedEntries = entries;
} }
} }

View file

@ -4,6 +4,7 @@ import com.sparrowwallet.drongo.wallet.WalletNode;
import com.sparrowwallet.sparrow.wallet.*; import com.sparrowwallet.sparrow.wallet.*;
import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TreeTableColumn; import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView; import javafx.scene.control.TreeTableView;
@ -72,6 +73,8 @@ public class UtxosTreeTable extends TreeTableView<Entry> {
setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY); setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
amountCol.setSortType(TreeTableColumn.SortType.DESCENDING); amountCol.setSortType(TreeTableColumn.SortType.DESCENDING);
getSortOrder().add(amountCol); getSortOrder().add(amountCol);
getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
} }
public void updateAll(WalletUtxosEntry rootEntry) { public void updateAll(WalletUtxosEntry rootEntry) {

View file

@ -76,6 +76,8 @@ public class SendController extends WalletFormController implements Initializabl
private final BooleanProperty userFeeSet = new SimpleBooleanProperty(false); private final BooleanProperty userFeeSet = new SimpleBooleanProperty(false);
private final ObjectProperty<UtxoSelector> utxoSelectorProperty = new SimpleObjectProperty<>(null);
private final ObjectProperty<WalletTransaction> walletTransactionProperty = new SimpleObjectProperty<>(null); private final ObjectProperty<WalletTransaction> walletTransactionProperty = new SimpleObjectProperty<>(null);
private final BooleanProperty insufficientInputsProperty = new SimpleBooleanProperty(false); private final BooleanProperty insufficientInputsProperty = new SimpleBooleanProperty(false);
@ -163,12 +165,13 @@ public class SendController extends WalletFormController implements Initializabl
targetBlocks.setLabelFormatter(new StringConverter<Double>() { targetBlocks.setLabelFormatter(new StringConverter<Double>() {
@Override @Override
public String toString(Double object) { public String toString(Double object) {
return Integer.toString(TARGET_BLOCKS_RANGE.get(object.intValue())); String blocks = Integer.toString(TARGET_BLOCKS_RANGE.get(object.intValue()));
return (object.intValue() == TARGET_BLOCKS_RANGE.size() - 1) ? blocks + "+" : blocks;
} }
@Override @Override
public Double fromString(String string) { public Double fromString(String string) {
return (double)TARGET_BLOCKS_RANGE.indexOf(Integer.valueOf(string)); return (double)TARGET_BLOCKS_RANGE.indexOf(Integer.valueOf(string.replace("+", "")));
} }
}); });
targetBlocks.valueProperty().addListener(targetBlocksListener); targetBlocks.valueProperty().addListener(targetBlocksListener);
@ -365,6 +368,10 @@ public class SendController extends WalletFormController implements Initializabl
return targetBlocks.lookup(".thumb"); return targetBlocks.lookup(".thumb");
} }
public void setUtxoSelector(UtxoSelector utxoSelector) {
utxoSelectorProperty.set(utxoSelector);
}
public void setMaxInput(ActionEvent event) { public void setMaxInput(ActionEvent event) {
} }

View file

@ -7,11 +7,14 @@ import com.sparrowwallet.sparrow.control.UtxosTreeTable;
import com.sparrowwallet.sparrow.event.WalletEntryLabelChangedEvent; import com.sparrowwallet.sparrow.event.WalletEntryLabelChangedEvent;
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent; import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
import com.sparrowwallet.sparrow.event.WalletNodesChangedEvent; import com.sparrowwallet.sparrow.event.WalletNodesChangedEvent;
import javafx.collections.ListChangeListener;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import java.net.URL; import java.net.URL;
import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.stream.Collectors;
public class UtxosController extends WalletFormController implements Initializable { public class UtxosController extends WalletFormController implements Initializable {
@ -31,9 +34,9 @@ public class UtxosController extends WalletFormController implements Initializab
utxosTable.initialize(getWalletForm().getWalletUtxosEntry()); utxosTable.initialize(getWalletForm().getWalletUtxosEntry());
utxosChart.initialize(getWalletForm().getWalletUtxosEntry()); utxosChart.initialize(getWalletForm().getWalletUtxosEntry());
utxosTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { utxosTable.getSelectionModel().getSelectedIndices().addListener((ListChangeListener<Integer>) c -> {
Entry entry = newValue.getValue(); List<Entry> selectedEntries = utxosTable.getSelectionModel().getSelectedCells().stream().map(tp -> tp.getTreeItem().getValue()).collect(Collectors.toList());
utxosChart.select(entry); utxosChart.select(selectedEntries);
}); });
} }