/
MainView.java
835 lines (697 loc) · 35.4 KB
/
MainView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.desktop.main;
import bisq.desktop.Navigation;
import bisq.desktop.common.view.CachingViewLoader;
import bisq.desktop.common.view.FxmlView;
import bisq.desktop.common.view.InitializableView;
import bisq.desktop.common.view.View;
import bisq.desktop.common.view.ViewLoader;
import bisq.desktop.components.AutoTooltipButton;
import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.components.AutoTooltipToggleButton;
import bisq.desktop.components.BusyAnimation;
import bisq.desktop.main.account.AccountView;
import bisq.desktop.main.dao.DaoView;
import bisq.desktop.main.funds.FundsView;
import bisq.desktop.main.market.MarketView;
import bisq.desktop.main.market.offerbook.OfferBookChartView;
import bisq.desktop.main.offer.BuyOfferView;
import bisq.desktop.main.offer.SellOfferView;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.portfolio.PortfolioView;
import bisq.desktop.main.settings.SettingsView;
import bisq.desktop.main.shared.PriceFeedComboBoxItem;
import bisq.desktop.main.support.SupportView;
import bisq.desktop.util.DisplayUtils;
import bisq.desktop.util.Transitions;
import bisq.core.dao.monitoring.DaoStateMonitoringService;
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.LanguageUtil;
import bisq.core.locale.Res;
import bisq.common.BisqException;
import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.Version;
import bisq.common.util.Tuple2;
import bisq.common.util.Utilities;
import javax.inject.Inject;
import com.jfoenix.controls.JFXBadge;
import com.jfoenix.controls.JFXComboBox;
import com.jfoenix.controls.JFXProgressBar;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.Separator;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.TextAlignment;
import javafx.geometry.Insets;
import javafx.geometry.NodeOrientation;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import static javafx.scene.layout.AnchorPane.setBottomAnchor;
import static javafx.scene.layout.AnchorPane.setLeftAnchor;
import static javafx.scene.layout.AnchorPane.setRightAnchor;
import static javafx.scene.layout.AnchorPane.setTopAnchor;
@FxmlView
@Slf4j
public class MainView extends InitializableView<StackPane, MainViewModel>
implements DaoStateMonitoringService.Listener {
// If after 30 sec we have not got connected we show "open network settings" button
private final static int SHOW_TOR_SETTINGS_DELAY_SEC = 90;
private Label versionLabel;
@Setter
private Runnable onUiReadyHandler;
public static StackPane getRootContainer() {
return MainView.rootContainer;
}
public static void blurLight() {
transitions.blur(MainView.rootContainer, Transitions.DEFAULT_DURATION, -0.6, false, 5);
}
public static void blurUltraLight() {
transitions.blur(MainView.rootContainer, Transitions.DEFAULT_DURATION, -0.6, false, 2);
}
public static void darken() {
transitions.darken(MainView.rootContainer, Transitions.DEFAULT_DURATION, false);
}
public static void removeEffect() {
transitions.removeEffect(MainView.rootContainer);
}
private static Transitions transitions;
private static StackPane rootContainer;
private final ViewLoader viewLoader;
private final Navigation navigation;
private final ToggleGroup navButtons = new ToggleGroup();
private ChangeListener<String> walletServiceErrorMsgListener;
private ChangeListener<String> btcSyncIconIdListener;
private ChangeListener<String> splashP2PNetworkErrorMsgListener;
private ChangeListener<String> splashP2PNetworkIconIdListener;
private ChangeListener<Boolean> splashP2PNetworkVisibleListener;
private BusyAnimation splashP2PNetworkBusyAnimation;
private Label splashP2PNetworkLabel;
private ProgressBar btcSyncIndicator, p2pNetworkProgressBar;
private Label btcSplashInfo;
private Popup p2PNetworkWarnMsgPopup, btcNetworkWarnMsgPopup;
private final DaoStateMonitoringService daoStateMonitoringService;
@Inject
public MainView(MainViewModel model,
CachingViewLoader viewLoader,
Navigation navigation,
Transitions transitions,
DaoStateMonitoringService daoStateMonitoringService) {
super(model);
this.viewLoader = viewLoader;
this.navigation = navigation;
MainView.transitions = transitions;
this.daoStateMonitoringService = daoStateMonitoringService;
}
@Override
protected void initialize() {
MainView.rootContainer = root;
if (LanguageUtil.isDefaultLanguageRTL())
MainView.rootContainer.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
ToggleButton marketButton = new NavButton(MarketView.class, Res.get("mainView.menu.market").toUpperCase());
ToggleButton buyButton = new NavButton(BuyOfferView.class, Res.get("mainView.menu.buyBtc").toUpperCase());
ToggleButton sellButton = new NavButton(SellOfferView.class, Res.get("mainView.menu.sellBtc").toUpperCase());
ToggleButton portfolioButton = new NavButton(PortfolioView.class, Res.get("mainView.menu.portfolio").toUpperCase());
ToggleButton fundsButton = new NavButton(FundsView.class, Res.get("mainView.menu.funds").toUpperCase());
ToggleButton supportButton = new NavButton(SupportView.class, Res.get("mainView.menu.support"));
ToggleButton settingsButton = new NavButton(SettingsView.class, Res.get("mainView.menu.settings"));
ToggleButton accountButton = new NavButton(AccountView.class, Res.get("mainView.menu.account"));
ToggleButton daoButton = new NavButton(DaoView.class, Res.get("mainView.menu.dao"));
JFXBadge portfolioButtonWithBadge = new JFXBadge(portfolioButton);
JFXBadge supportButtonWithBadge = new JFXBadge(supportButton);
JFXBadge daoButtonWithBadge = new JFXBadge(daoButton);
daoButtonWithBadge.getStyleClass().add("new");
JFXBadge accountButtonWithBadge = new JFXBadge(accountButton);
accountButtonWithBadge.getStyleClass().add("new");
Locale locale = GlobalSettings.getLocale();
DecimalFormat currencyFormat = (DecimalFormat) NumberFormat.getNumberInstance(locale);
currencyFormat.setMinimumFractionDigits(2);
currencyFormat.setMaximumFractionDigits(2);
root.sceneProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
newValue.addEventHandler(KeyEvent.KEY_RELEASED, keyEvent -> {
if (Utilities.isAltOrCtrlPressed(KeyCode.DIGIT1, keyEvent)) {
marketButton.fire();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.DIGIT2, keyEvent)) {
buyButton.fire();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.DIGIT3, keyEvent)) {
sellButton.fire();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.DIGIT4, keyEvent)) {
portfolioButton.fire();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.DIGIT5, keyEvent)) {
fundsButton.fire();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.DIGIT6, keyEvent)) {
supportButton.fire();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.DIGIT7, keyEvent)) {
settingsButton.fire();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.DIGIT8, keyEvent)) {
accountButton.fire();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.DIGIT9, keyEvent)) {
if (daoButton.isVisible())
daoButton.fire();
}
});
}
});
Tuple2<ComboBox<PriceFeedComboBoxItem>, VBox> marketPriceBox = getMarketPriceBox();
ComboBox<PriceFeedComboBoxItem> priceComboBox = marketPriceBox.first;
priceComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) ->
model.setPriceFeedComboBoxItem(newValue));
ChangeListener<PriceFeedComboBoxItem> selectedPriceFeedItemListener = (observable, oldValue, newValue) -> {
if (newValue != null)
priceComboBox.getSelectionModel().select(newValue);
};
model.getSelectedPriceFeedComboBoxItemProperty().addListener(selectedPriceFeedItemListener);
priceComboBox.setItems(model.getPriceFeedComboBoxItems());
Tuple2<Label, VBox> availableBalanceBox = getBalanceBox(Res.get("mainView.balance.available"));
availableBalanceBox.first.textProperty().bind(model.getAvailableBalance());
availableBalanceBox.first.setPrefWidth(100);
availableBalanceBox.first.tooltipProperty().bind(new ObjectBinding<>() {
{
bind(model.getAvailableBalance());
bind(model.getMarketPrice());
}
@Override
protected Tooltip computeValue() {
String tooltipText = Res.get("mainView.balance.available");
try {
String preferredTradeCurrency = model.getPreferences().getPreferredTradeCurrency().getCode();
double availableBalance = Double.parseDouble(
model.getAvailableBalance().getValue().replace("BTC", ""));
double marketPrice = Double.parseDouble(model.getMarketPrice(preferredTradeCurrency).getValue());
tooltipText += "\n" + currencyFormat.format(availableBalance * marketPrice) +
" " + preferredTradeCurrency;
} catch (NullPointerException | NumberFormatException e) {
// Either the balance or market price is not available yet
}
return new Tooltip(tooltipText);
}
});
Tuple2<Label, VBox> reservedBalanceBox = getBalanceBox(Res.get("mainView.balance.reserved.short"));
reservedBalanceBox.first.textProperty().bind(model.getReservedBalance());
reservedBalanceBox.first.tooltipProperty().bind(new ObjectBinding<>() {
{
bind(model.getReservedBalance());
bind(model.getMarketPrice());
}
@Override
protected Tooltip computeValue() {
String tooltipText = Res.get("mainView.balance.reserved");
try {
String preferredTradeCurrency = model.getPreferences().getPreferredTradeCurrency().getCode();
double reservedBalance = Double.parseDouble(
model.getReservedBalance().getValue().replace("BTC", ""));
double marketPrice = Double.parseDouble(model.getMarketPrice(preferredTradeCurrency).getValue());
tooltipText += "\n" + currencyFormat.format(reservedBalance * marketPrice) +
" " + preferredTradeCurrency;
} catch (NullPointerException | NumberFormatException e) {
// Either the balance or market price is not available yet
}
return new Tooltip(tooltipText);
}
});
Tuple2<Label, VBox> lockedBalanceBox = getBalanceBox(Res.get("mainView.balance.locked.short"));
lockedBalanceBox.first.textProperty().bind(model.getLockedBalance());
lockedBalanceBox.first.tooltipProperty().bind(new ObjectBinding<>() {
{
bind(model.getLockedBalance());
bind(model.getMarketPrice());
}
@Override
protected Tooltip computeValue() {
String tooltipText = Res.get("mainView.balance.locked");
try {
String preferredTradeCurrency = model.getPreferences().getPreferredTradeCurrency().getCode();
double lockedBalance = Double.parseDouble(
model.getLockedBalance().getValue().replace("BTC", ""));
double marketPrice = Double.parseDouble(model.getMarketPrice(preferredTradeCurrency).getValue());
tooltipText += "\n" + currencyFormat.format(lockedBalance * marketPrice) +
" " + preferredTradeCurrency;
} catch (NullPointerException | NumberFormatException e) {
// Either the balance or market price is not available yet
}
return new Tooltip(tooltipText);
}
});
HBox primaryNav = new HBox(marketButton, getNavigationSeparator(), buyButton,
getNavigationSeparator(), sellButton, getNavigationSeparator(),
portfolioButtonWithBadge, getNavigationSeparator(), fundsButton);
primaryNav.setAlignment(Pos.CENTER);
primaryNav.getStyleClass().add("nav-primary");
HBox.setHgrow(primaryNav, Priority.SOMETIMES);
HBox secondaryNav = new HBox(supportButtonWithBadge, getNavigationSeparator(),
settingsButton, getNavigationSeparator(), accountButtonWithBadge,
getNavigationSeparator(), daoButtonWithBadge);
secondaryNav.getStyleClass().add("nav-secondary");
HBox.setHgrow(secondaryNav, Priority.SOMETIMES);
secondaryNav.setAlignment(Pos.CENTER);
HBox priceAndBalance = new HBox(marketPriceBox.second, getNavigationSeparator(), availableBalanceBox.second,
getNavigationSeparator(), reservedBalanceBox.second, getNavigationSeparator(), lockedBalanceBox.second);
priceAndBalance.setMaxHeight(41);
priceAndBalance.setAlignment(Pos.CENTER);
priceAndBalance.setSpacing(9);
priceAndBalance.getStyleClass().add("nav-price-balance");
HBox navPane = new HBox(primaryNav, secondaryNav,
getNavigationSpacer(), priceAndBalance) {{
setLeftAnchor(this, 0d);
setRightAnchor(this, 0d);
setTopAnchor(this, 0d);
setPadding(new Insets(0, 0, 0, 0));
getStyleClass().add("top-navigation");
}};
navPane.setAlignment(Pos.CENTER_LEFT);
AnchorPane contentContainer = new AnchorPane() {{
getStyleClass().add("content-pane");
setLeftAnchor(this, 0d);
setRightAnchor(this, 0d);
setTopAnchor(this, 57d);
setBottomAnchor(this, 0d);
}};
AnchorPane applicationContainer = new AnchorPane(navPane, contentContainer) {{
setId("application-container");
}};
BorderPane baseApplicationContainer = new BorderPane(applicationContainer) {{
setId("base-content-container");
}};
baseApplicationContainer.setBottom(createFooter());
setupBadge(portfolioButtonWithBadge, model.getNumPendingTrades(), model.getShowPendingTradesNotification());
setupBadge(supportButtonWithBadge, model.getNumOpenSupportTickets(), model.getShowOpenSupportTicketsNotification());
setupBadge(daoButtonWithBadge, new SimpleStringProperty(Res.get("shared.new")), model.getShowDaoUpdatesNotification());
setupBadge(accountButtonWithBadge, new SimpleStringProperty(Res.get("shared.new")), model.getShowAccountUpdatesNotification());
navigation.addListener(viewPath -> {
if (viewPath.size() != 2 || viewPath.indexOf(MainView.class) != 0)
return;
Class<? extends View> viewClass = viewPath.tip();
View view = viewLoader.load(viewClass);
contentContainer.getChildren().setAll(view.getRoot());
try {
navButtons.getToggles().stream()
.filter(toggle -> toggle instanceof NavButton)
.filter(button -> viewClass == ((NavButton) button).viewClass)
.findFirst()
.orElseThrow(() -> new BisqException("No button matching %s found", viewClass))
.setSelected(true);
} catch (BisqException e) {
navigation.navigateTo(MainView.class, MarketView.class, OfferBookChartView.class);
}
});
VBox splashScreen = createSplashScreen();
root.getChildren().addAll(baseApplicationContainer, splashScreen);
model.getShowAppScreen().addListener((ov, oldValue, newValue) -> {
if (newValue) {
navigation.navigateToPreviousVisitedView();
transitions.fadeOutAndRemove(splashScreen, 1500, actionEvent -> disposeSplashScreen());
}
});
daoStateMonitoringService.addListener(this);
// Delay a bit to give time for rendering the splash screen
UserThread.execute(() -> onUiReadyHandler.run());
}
///////////////////////////////////////////////////////////////////////////////////////////
// DaoStateMonitoringService.Listener
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onChangeAfterBatchProcessing() {
}
@Override
public void onCheckpointFail() {
new Popup().attention(Res.get("dao.monitor.daoState.checkpoint.popup"))
.useShutDownButton()
.show();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Helpers
///////////////////////////////////////////////////////////////////////////////////////////
@NotNull
private Separator getNavigationSeparator() {
final Separator separator = new Separator(Orientation.VERTICAL);
HBox.setHgrow(separator, Priority.ALWAYS);
separator.setMaxHeight(22);
separator.setMaxWidth(Double.MAX_VALUE);
return separator;
}
@NotNull
private Region getNavigationSpacer() {
final Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
return spacer;
}
private Tuple2<Label, VBox> getBalanceBox(String text) {
Label balanceDisplay = new Label();
balanceDisplay.getStyleClass().add("nav-balance-display");
Label label = new Label(text);
label.getStyleClass().add("nav-balance-label");
label.maxWidthProperty().bind(balanceDisplay.widthProperty());
label.setPadding(new Insets(0, 0, 0, 0));
VBox vBox = new VBox();
vBox.setAlignment(Pos.CENTER_LEFT);
vBox.getChildren().addAll(balanceDisplay, label);
return new Tuple2<>(balanceDisplay, vBox);
}
private ListCell<PriceFeedComboBoxItem> getPriceFeedComboBoxListCell() {
return new ListCell<>() {
@Override
protected void updateItem(PriceFeedComboBoxItem item, boolean empty) {
super.updateItem(item, empty);
if (!empty && item != null) {
textProperty().bind(item.displayStringProperty);
} else {
textProperty().unbind();
}
}
};
}
private Tuple2<ComboBox<PriceFeedComboBoxItem>, VBox> getMarketPriceBox() {
VBox marketPriceBox = new VBox();
marketPriceBox.setAlignment(Pos.CENTER_LEFT);
ComboBox<PriceFeedComboBoxItem> priceComboBox = new JFXComboBox<>();
priceComboBox.setVisibleRowCount(12);
priceComboBox.setFocusTraversable(false);
priceComboBox.setId("price-feed-combo");
priceComboBox.setPadding(new Insets(0, -4, -4, 0));
priceComboBox.setCellFactory(p -> getPriceFeedComboBoxListCell());
ListCell<PriceFeedComboBoxItem> buttonCell = getPriceFeedComboBoxListCell();
buttonCell.setId("price-feed-combo");
priceComboBox.setButtonCell(buttonCell);
Label marketPriceLabel = new Label();
updateMarketPriceLabel(marketPriceLabel);
marketPriceLabel.getStyleClass().add("nav-balance-label");
marketPriceLabel.setPadding(new Insets(-2, 0, 4, 9));
marketPriceBox.getChildren().addAll(priceComboBox, marketPriceLabel);
model.getMarketPriceUpdated().addListener((observable, oldValue, newValue) ->
updateMarketPriceLabel(marketPriceLabel));
return new Tuple2<>(priceComboBox, marketPriceBox);
}
@NotNull
private String getPriceProvider() {
return model.getIsFiatCurrencyPriceFeedSelected().get() ? "BitcoinAverage" : "Poloniex";
}
private void updateMarketPriceLabel(Label label) {
if (model.getIsPriceAvailable().get()) {
if (model.getIsExternallyProvidedPrice().get()) {
label.setText(Res.get("mainView.marketPriceWithProvider.label", getPriceProvider()));
label.setTooltip(new Tooltip(getPriceProviderTooltipString()));
} else {
label.setText(Res.get("mainView.marketPrice.bisqInternalPrice"));
final Tooltip tooltip = new Tooltip(Res.get("mainView.marketPrice.tooltip.bisqInternalPrice"));
label.setTooltip(tooltip);
}
} else {
label.setText("");
label.setTooltip(null);
}
}
@NotNull
private String getPriceProviderTooltipString() {
String res;
if (model.getIsFiatCurrencyPriceFeedSelected().get()) {
res = Res.get("mainView.marketPrice.tooltip",
"https://bitcoinaverage.com",
"",
DisplayUtils.formatTime(model.getPriceFeedService().getLastRequestTimeStampBtcAverage()),
model.getPriceFeedService().getProviderNodeAddress());
} else {
String altcoinExtra = "\n" + Res.get("mainView.marketPrice.tooltip.altcoinExtra");
res = Res.get("mainView.marketPrice.tooltip",
"https://poloniex.com",
altcoinExtra,
DisplayUtils.formatTime(model.getPriceFeedService().getLastRequestTimeStampPoloniex()),
model.getPriceFeedService().getProviderNodeAddress());
}
return res;
}
private VBox createSplashScreen() {
VBox vBox = new VBox();
vBox.setAlignment(Pos.CENTER);
vBox.setSpacing(10);
vBox.setId("splash");
ImageView logo = new ImageView();
logo.setId("image-splash-logo");
// createBitcoinInfoBox
btcSplashInfo = new AutoTooltipLabel();
btcSplashInfo.textProperty().bind(model.getBtcInfo());
walletServiceErrorMsgListener = (ov, oldValue, newValue) -> {
btcSplashInfo.setId("splash-error-state-msg");
btcSplashInfo.getStyleClass().add("error-text");
};
model.getWalletServiceErrorMsg().addListener(walletServiceErrorMsgListener);
btcSyncIndicator = new JFXProgressBar();
btcSyncIndicator.setPrefWidth(305);
btcSyncIndicator.progressProperty().bind(model.getCombinedSyncProgress());
ImageView btcSyncIcon = new ImageView();
btcSyncIcon.setVisible(false);
btcSyncIcon.setManaged(false);
btcSyncIconIdListener = (ov, oldValue, newValue) -> {
btcSyncIcon.setId(newValue);
btcSyncIcon.setVisible(true);
btcSyncIcon.setManaged(true);
btcSyncIndicator.setVisible(false);
btcSyncIndicator.setManaged(false);
};
model.getBtcSplashSyncIconId().addListener(btcSyncIconIdListener);
HBox blockchainSyncBox = new HBox();
blockchainSyncBox.setSpacing(10);
blockchainSyncBox.setAlignment(Pos.CENTER);
blockchainSyncBox.setPadding(new Insets(40, 0, 0, 0));
blockchainSyncBox.setPrefHeight(50);
blockchainSyncBox.getChildren().addAll(btcSplashInfo, btcSyncIcon);
// create P2PNetworkBox
splashP2PNetworkLabel = new AutoTooltipLabel();
splashP2PNetworkLabel.setWrapText(true);
splashP2PNetworkLabel.setMaxWidth(500);
splashP2PNetworkLabel.setTextAlignment(TextAlignment.CENTER);
splashP2PNetworkLabel.getStyleClass().add("sub-info");
splashP2PNetworkLabel.textProperty().bind(model.getP2PNetworkInfo());
Button showTorNetworkSettingsButton = new AutoTooltipButton(Res.get("settings.net.openTorSettingsButton"));
showTorNetworkSettingsButton.setVisible(false);
showTorNetworkSettingsButton.setManaged(false);
showTorNetworkSettingsButton.setOnAction(e -> model.getTorNetworkSettingsWindow().show());
splashP2PNetworkBusyAnimation = new BusyAnimation(false);
splashP2PNetworkErrorMsgListener = (ov, oldValue, newValue) -> {
if (newValue != null) {
splashP2PNetworkLabel.setId("splash-error-state-msg");
splashP2PNetworkLabel.getStyleClass().remove("sub-info");
splashP2PNetworkLabel.getStyleClass().add("error-text");
splashP2PNetworkBusyAnimation.setDisable(true);
splashP2PNetworkBusyAnimation.stop();
showTorNetworkSettingsButton.setVisible(true);
showTorNetworkSettingsButton.setManaged(true);
if (model.getUseTorForBTC().get()) {
// If using tor for BTC, hide the BTC status since tor is not working
btcSyncIndicator.setVisible(false);
btcSplashInfo.setVisible(false);
}
} else if (model.getSplashP2PNetworkAnimationVisible().get()) {
splashP2PNetworkBusyAnimation.setDisable(false);
splashP2PNetworkBusyAnimation.play();
}
};
model.getP2pNetworkWarnMsg().addListener(splashP2PNetworkErrorMsgListener);
ImageView splashP2PNetworkIcon = new ImageView();
splashP2PNetworkIcon.setId("image-connection-tor");
splashP2PNetworkIcon.setVisible(false);
splashP2PNetworkIcon.setManaged(false);
HBox.setMargin(splashP2PNetworkIcon, new Insets(0, 0, 5, 0));
Timer showTorNetworkSettingsTimer = UserThread.runAfter(() -> {
showTorNetworkSettingsButton.setVisible(true);
showTorNetworkSettingsButton.setManaged(true);
}, SHOW_TOR_SETTINGS_DELAY_SEC);
splashP2PNetworkIconIdListener = (ov, oldValue, newValue) -> {
splashP2PNetworkIcon.setId(newValue);
splashP2PNetworkIcon.setVisible(true);
splashP2PNetworkIcon.setManaged(true);
// if we can connect in 10 sec. we know that tor is working
showTorNetworkSettingsTimer.stop();
};
model.getP2PNetworkIconId().addListener(splashP2PNetworkIconIdListener);
splashP2PNetworkVisibleListener = (ov, oldValue, newValue) -> {
splashP2PNetworkBusyAnimation.setDisable(!newValue);
if (newValue) splashP2PNetworkBusyAnimation.play();
};
model.getSplashP2PNetworkAnimationVisible().addListener(splashP2PNetworkVisibleListener);
HBox splashP2PNetworkBox = new HBox();
splashP2PNetworkBox.setSpacing(10);
splashP2PNetworkBox.setAlignment(Pos.CENTER);
splashP2PNetworkBox.setPrefHeight(40);
splashP2PNetworkBox.getChildren().addAll(splashP2PNetworkLabel, splashP2PNetworkBusyAnimation, splashP2PNetworkIcon, showTorNetworkSettingsButton);
vBox.getChildren().addAll(logo, blockchainSyncBox, btcSyncIndicator, splashP2PNetworkBox);
return vBox;
}
private void disposeSplashScreen() {
model.getWalletServiceErrorMsg().removeListener(walletServiceErrorMsgListener);
model.getBtcSplashSyncIconId().removeListener(btcSyncIconIdListener);
model.getP2pNetworkWarnMsg().removeListener(splashP2PNetworkErrorMsgListener);
model.getP2PNetworkIconId().removeListener(splashP2PNetworkIconIdListener);
model.getSplashP2PNetworkAnimationVisible().removeListener(splashP2PNetworkVisibleListener);
btcSplashInfo.textProperty().unbind();
btcSyncIndicator.progressProperty().unbind();
splashP2PNetworkLabel.textProperty().unbind();
model.onSplashScreenRemoved();
}
private AnchorPane createFooter() {
// line
Separator separator = new Separator();
separator.setId("footer-pane-line");
separator.setPrefHeight(1);
setLeftAnchor(separator, 0d);
setRightAnchor(separator, 0d);
setTopAnchor(separator, 0d);
// BTC
Label btcInfoLabel = new AutoTooltipLabel();
btcInfoLabel.setId("footer-pane");
btcInfoLabel.textProperty().bind(model.getBtcInfo());
ProgressBar blockchainSyncIndicator = new JFXProgressBar(-1);
blockchainSyncIndicator.setPrefWidth(80);
blockchainSyncIndicator.setMaxHeight(10);
blockchainSyncIndicator.progressProperty().bind(model.getCombinedSyncProgress());
model.getWalletServiceErrorMsg().addListener((ov, oldValue, newValue) -> {
if (newValue != null) {
btcInfoLabel.setId("splash-error-state-msg");
btcInfoLabel.getStyleClass().add("error-text");
if (btcNetworkWarnMsgPopup == null) {
btcNetworkWarnMsgPopup = new Popup().warning(newValue);
btcNetworkWarnMsgPopup.show();
}
} else {
btcInfoLabel.setId("footer-pane");
if (btcNetworkWarnMsgPopup != null)
btcNetworkWarnMsgPopup.hide();
}
});
model.getCombinedSyncProgress().addListener((ov, oldValue, newValue) -> {
if ((double) newValue >= 1) {
blockchainSyncIndicator.setVisible(false);
blockchainSyncIndicator.setManaged(false);
}
});
HBox blockchainSyncBox = new HBox();
blockchainSyncBox.setSpacing(10);
blockchainSyncBox.setAlignment(Pos.CENTER);
blockchainSyncBox.getChildren().addAll(btcInfoLabel, blockchainSyncIndicator);
setLeftAnchor(blockchainSyncBox, 10d);
setBottomAnchor(blockchainSyncBox, 7d);
// version
versionLabel = new AutoTooltipLabel();
versionLabel.setId("footer-pane");
versionLabel.setTextAlignment(TextAlignment.CENTER);
versionLabel.setAlignment(Pos.BASELINE_CENTER);
versionLabel.setText("v" + Version.VERSION);
root.widthProperty().addListener((ov, oldValue, newValue) ->
versionLabel.setLayoutX(((double) newValue - versionLabel.getWidth()) / 2));
setBottomAnchor(versionLabel, 7d);
model.getNewVersionAvailableProperty().addListener((observable, oldValue, newValue) -> {
versionLabel.getStyleClass().removeAll("version-new", "version");
if (newValue) {
versionLabel.getStyleClass().add("version-new");
versionLabel.setOnMouseClicked(e -> model.onOpenDownloadWindow());
versionLabel.setText("v" + Version.VERSION + " " + Res.get("mainView.version.update"));
} else {
versionLabel.getStyleClass().add("version");
versionLabel.setOnMouseClicked(null);
versionLabel.setText("v" + Version.VERSION);
}
});
// P2P Network
Label p2PNetworkLabel = new AutoTooltipLabel();
p2PNetworkLabel.setId("footer-pane");
p2PNetworkLabel.textProperty().bind(model.getP2PNetworkInfo());
ImageView p2PNetworkIcon = new ImageView();
setRightAnchor(p2PNetworkIcon, 10d);
setBottomAnchor(p2PNetworkIcon, 5d);
p2PNetworkIcon.setOpacity(0.4);
p2PNetworkIcon.idProperty().bind(model.getP2PNetworkIconId());
p2PNetworkLabel.idProperty().bind(model.getP2pNetworkLabelId());
model.getP2pNetworkWarnMsg().addListener((ov, oldValue, newValue) -> {
if (newValue != null) {
p2PNetworkWarnMsgPopup = new Popup().warning(newValue);
p2PNetworkWarnMsgPopup.show();
} else if (p2PNetworkWarnMsgPopup != null) {
p2PNetworkWarnMsgPopup.hide();
}
});
model.getUpdatedDataReceived().addListener((observable, oldValue, newValue) -> {
p2PNetworkIcon.setOpacity(1);
p2pNetworkProgressBar.setProgress(0);
});
p2pNetworkProgressBar = new JFXProgressBar(-1);
p2pNetworkProgressBar.setMaxHeight(2);
p2pNetworkProgressBar.prefWidthProperty().bind(p2PNetworkLabel.widthProperty());
VBox vBox = new VBox();
vBox.setAlignment(Pos.CENTER_RIGHT);
vBox.getChildren().addAll(p2PNetworkLabel, p2pNetworkProgressBar);
setRightAnchor(vBox, 33d);
setBottomAnchor(vBox, 5d);
return new AnchorPane(separator, blockchainSyncBox, versionLabel, vBox, p2PNetworkIcon) {{
setId("footer-pane");
setMinHeight(30);
setMaxHeight(30);
}};
}
private void setupBadge(JFXBadge buttonWithBadge, StringProperty badgeNumber, BooleanProperty badgeEnabled) {
buttonWithBadge.textProperty().bind(badgeNumber);
buttonWithBadge.setEnabled(badgeEnabled.get());
badgeEnabled.addListener((observable, oldValue, newValue) -> {
buttonWithBadge.setEnabled(newValue);
buttonWithBadge.refreshBadge();
});
buttonWithBadge.setPosition(Pos.TOP_RIGHT);
buttonWithBadge.setMinHeight(34);
buttonWithBadge.setMaxHeight(34);
}
private class NavButton extends AutoTooltipToggleButton {
private final Class<? extends View> viewClass;
NavButton(Class<? extends View> viewClass, String title) {
super(title);
this.viewClass = viewClass;
this.setToggleGroup(navButtons);
this.getStyleClass().add("nav-button");
// Japanese fonts are dense, increase top nav button text size
if (model.getPreferences().getUserLanguage().equals("ja")) {
this.getStyleClass().add("nav-button-japanese");
}
this.selectedProperty().addListener((ov, oldValue, newValue) -> this.setMouseTransparent(newValue));
this.setOnAction(e -> navigation.navigateTo(MainView.class, viewClass));
}
}
}