diff --git a/src/main/java/com/sparrowwallet/sparrow/control/FeeRatesChart.java b/src/main/java/com/sparrowwallet/sparrow/control/FeeRatesChart.java index 79da0549..540318ac 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/FeeRatesChart.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/FeeRatesChart.java @@ -6,6 +6,7 @@ import javafx.scene.chart.Axis; import javafx.scene.chart.LineChart; import javafx.scene.chart.XYChart; +import java.util.Iterator; import java.util.Map; public class FeeRatesChart extends LineChart { @@ -24,8 +25,10 @@ public class FeeRatesChart extends LineChart { public void update(Map targetBlocksFeeRates) { feeRateSeries.getData().clear(); - for(Integer targetBlocks : targetBlocksFeeRates.keySet()) { - XYChart.Data data = new XYChart.Data<>(Integer.toString(targetBlocks), targetBlocksFeeRates.get(targetBlocks)); + for(Iterator targetBlocksIter = targetBlocksFeeRates.keySet().iterator(); targetBlocksIter.hasNext(); ) { + Integer targetBlocks = targetBlocksIter.next(); + String category = targetBlocks + (targetBlocksIter.hasNext() ? "" : "+"); + XYChart.Data data = new XYChart.Data<>(category, targetBlocksFeeRates.get(targetBlocks)); feeRateSeries.getData().add(data); } @@ -44,7 +47,7 @@ public class FeeRatesChart extends LineChart { XYChart.Data data = feeRateSeries.getData().get(i); Node symbol = lookup(".chart-line-symbol.data" + i); if(symbol != null) { - if(data.getXValue().equals(targetBlocks.toString())) { + if(data.getXValue().replace("+", "").equals(targetBlocks.toString())) { symbol.getStyleClass().add("selected"); selectedTargetBlocks = targetBlocks; } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java index d341b29a..fee6a1d1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java @@ -320,7 +320,7 @@ public class TransactionDiagram extends GridPane { @Override public String getLabel() { - return additionalInputs.size() + " more"; + return additionalInputs.size() + " more..."; } public List getAdditionalInputs() { diff --git a/src/main/java/com/sparrowwallet/sparrow/control/UtxosChart.java b/src/main/java/com/sparrowwallet/sparrow/control/UtxosChart.java index 561c6f55..a1e30e06 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/UtxosChart.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/UtxosChart.java @@ -10,13 +10,15 @@ import javafx.scene.chart.BarChart; import javafx.scene.chart.XYChart; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; public class UtxosChart extends BarChart { private static final int MAX_BARS = 8; private static final String OTHER_CATEGORY = "Other"; - private Entry selectedEntry; + private List selectedEntries; + private int totalUtxos; private XYChart.Series utxoSeries; @@ -36,6 +38,7 @@ public class UtxosChart extends BarChart { .sorted((o1, o2) -> (int) (o2.getYValue().longValue() - o1.getYValue().longValue())) .collect(Collectors.toList()); + totalUtxos = utxoDataList.size(); if(utxoDataList.size() > MAX_BARS) { Long otherTotal = utxoDataList.subList(MAX_BARS - 1, utxoDataList.size()).stream().mapToLong(data -> data.getYValue().longValue()).sum(); utxoDataList = utxoDataList.subList(0, MAX_BARS - 1); @@ -58,14 +61,14 @@ public class UtxosChart extends BarChart { utxoSeries.getData().remove(utxoDataList.size() - 1, utxoSeries.getData().size()); } - if(selectedEntry != null) { - select(selectedEntry); + if(selectedEntries != null) { + select(selectedEntries); } } - public void select(Entry entry) { - Node selectedBar = lookup(".chart-bar.selected"); - if(selectedBar != null) { + public void select(List entries) { + Set selectedBars = lookupAll(".chart-bar.selected"); + for(Node selectedBar : selectedBars) { selectedBar.getStyleClass().remove("selected"); } @@ -73,11 +76,14 @@ public class UtxosChart extends BarChart { XYChart.Data data = utxoSeries.getData().get(i); Node bar = lookup(".data" + i); 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"); - this.selectedEntry = entry; } } } + + this.selectedEntries = entries; } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/UtxosTreeTable.java b/src/main/java/com/sparrowwallet/sparrow/control/UtxosTreeTable.java index a21aaaa2..268bab53 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/UtxosTreeTable.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/UtxosTreeTable.java @@ -4,6 +4,7 @@ import com.sparrowwallet.drongo.wallet.WalletNode; import com.sparrowwallet.sparrow.wallet.*; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.scene.control.Label; +import javafx.scene.control.SelectionMode; import javafx.scene.control.TreeTableColumn; import javafx.scene.control.TreeTableView; @@ -72,6 +73,8 @@ public class UtxosTreeTable extends TreeTableView { setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY); amountCol.setSortType(TreeTableColumn.SortType.DESCENDING); getSortOrder().add(amountCol); + + getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); } public void updateAll(WalletUtxosEntry rootEntry) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index f150512e..6b9feaae 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -76,6 +76,8 @@ public class SendController extends WalletFormController implements Initializabl private final BooleanProperty userFeeSet = new SimpleBooleanProperty(false); + private final ObjectProperty utxoSelectorProperty = new SimpleObjectProperty<>(null); + private final ObjectProperty walletTransactionProperty = new SimpleObjectProperty<>(null); private final BooleanProperty insufficientInputsProperty = new SimpleBooleanProperty(false); @@ -163,12 +165,13 @@ public class SendController extends WalletFormController implements Initializabl targetBlocks.setLabelFormatter(new StringConverter() { @Override 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 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); @@ -365,6 +368,10 @@ public class SendController extends WalletFormController implements Initializabl return targetBlocks.lookup(".thumb"); } + public void setUtxoSelector(UtxoSelector utxoSelector) { + utxoSelectorProperty.set(utxoSelector); + } + public void setMaxInput(ActionEvent event) { } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java index 80a3e383..1f6fe992 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java @@ -7,11 +7,14 @@ import com.sparrowwallet.sparrow.control.UtxosTreeTable; import com.sparrowwallet.sparrow.event.WalletEntryLabelChangedEvent; import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent; import com.sparrowwallet.sparrow.event.WalletNodesChangedEvent; +import javafx.collections.ListChangeListener; import javafx.fxml.FXML; import javafx.fxml.Initializable; import java.net.URL; +import java.util.List; import java.util.ResourceBundle; +import java.util.stream.Collectors; public class UtxosController extends WalletFormController implements Initializable { @@ -31,9 +34,9 @@ public class UtxosController extends WalletFormController implements Initializab utxosTable.initialize(getWalletForm().getWalletUtxosEntry()); utxosChart.initialize(getWalletForm().getWalletUtxosEntry()); - utxosTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { - Entry entry = newValue.getValue(); - utxosChart.select(entry); + utxosTable.getSelectionModel().getSelectedIndices().addListener((ListChangeListener) c -> { + List selectedEntries = utxosTable.getSelectionModel().getSelectedCells().stream().map(tp -> tp.getTreeItem().getValue()).collect(Collectors.toList()); + utxosChart.select(selectedEntries); }); }