Make BlurManager static

This commit is contained in:
Manfred Karrer 2015-05-17 00:20:30 +02:00
parent 8d32f87409
commit 68a4178bf3
18 changed files with 70 additions and 83 deletions

View File

@ -610,7 +610,7 @@ public class WalletService {
@Override
protected void doneDownload() {
super.doneDownload();
Threading.USER_THREAD.execute(() -> this.percentage.set(1));
Threading.USER_THREAD.execute(() -> this.percentage.set(1d));
}
public ReadOnlyDoubleProperty percentageProperty() {

View File

@ -30,7 +30,7 @@ public class BootstrapNodes {
public static final int BASE_PORT = 7366; // port will be evaluated from btc network 7366 for mainnet, 7367 for testnet and 7368 for regtest
private static List<Node> bootstrapNodes = Arrays.asList(
//Node.at("digitalocean1.bitsquare.io", "188.226.179.109", BASE_PORT),
Node.at("digitalocean1.bitsquare.io", "188.226.179.109", BASE_PORT),
Node.at("aws1.bitsquare.io", "52.24.144.42", BASE_PORT),
Node.at("aws2.bitsquare.io", "52.11.125.194", BASE_PORT)
);

View File

@ -127,10 +127,9 @@ public final class Node {
@Override
public String toString() {
return Objects.toStringHelper(Node.class.getSimpleName())
.add("name", name)
.add("ip", ip)
.add("port", port)
.toString();
return "Node with: " +
"name='" + name + '\'' +
", ip='" + ip + '\'' +
", port=" + port;
}
}

View File

@ -60,7 +60,7 @@ import static io.bitsquare.app.BitsquareEnvironment.APP_NAME_KEY;
public class BitsquareApp extends Application {
private static final Logger log = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(BitsquareApp.class);
public static final boolean DEV_MODE = true;
public static final boolean DEV_MODE = false;
private static Environment env;
@ -138,8 +138,8 @@ public class BitsquareApp extends Application {
new KeyCodeCombination(KeyCode.Q, KeyCombination.SHORTCUT_DOWN).match(keyEvent))
stop();
else if (new KeyCodeCombination(KeyCode.D, KeyCombination.SHORTCUT_DOWN).match(keyEvent))
if (BitsquareApp.DEV_MODE)
showDebugWindow();
//if (BitsquareApp.DEV_MODE)
showDebugWindow();
});
// configure the primary stage

View File

@ -24,7 +24,7 @@ import java.util.List;
public class OverlayManager {
private final List<OverlayListener> listeners = new ArrayList<>();
private final static List<OverlayListener> listeners = new ArrayList<>();
///////////////////////////////////////////////////////////////////////////////////////////
@ -35,19 +35,19 @@ public class OverlayManager {
public OverlayManager() {
}
public void blurContent() {
public static void blurContent() {
listeners.stream().forEach(OverlayListener::onBlurContentRequested);
}
public void removeBlurContent() {
public static void removeBlurContent() {
listeners.stream().forEach(OverlayListener::onRemoveBlurContentRequested);
}
public void addListener(OverlayListener listener) {
public static void addListener(OverlayListener listener) {
listeners.add(listener);
}
public void removeListener(OverlayListener listener) {
public static void removeListener(OverlayListener listener) {
listeners.remove(listener);
}

View File

@ -55,8 +55,6 @@ public class AddressTextField extends AnchorPane {
private final StringProperty paymentLabel = new SimpleStringProperty();
private final ObjectProperty<Coin> amountAsCoin = new SimpleObjectProperty<>();
private OverlayManager overlayManager;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
@ -114,16 +112,14 @@ public class AddressTextField extends AnchorPane {
popOver.setDetachedTitle("Scan QR code for this address");
popOver.setDetached(true);
popOver.setOnHiding(windowEvent -> {
if (overlayManager != null)
overlayManager.removeBlurContent();
OverlayManager.removeBlurContent();
});
Window window = getScene().getWindow();
double x = Math.round(window.getX() + (window.getWidth() - 320) / 2);
double y = Math.round(window.getY() + (window.getHeight() - 240) / 2);
popOver.show(getScene().getWindow(), x, y);
if (overlayManager != null)
overlayManager.blurContent();
OverlayManager.blurContent();
}
});
@ -176,11 +172,6 @@ public class AddressTextField extends AnchorPane {
this.paymentLabel.set(paymentLabel);
}
// TODO find better solution without OverlayManager dependency
public void setOverlayManager(OverlayManager overlayManager) {
this.overlayManager = overlayManager;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private

View File

@ -39,15 +39,8 @@ public class Popups {
public static Stage primaryStage;
// TODO just temporary, class will be removed completely
public static void setOverlayManager(OverlayManager overlayManager) {
Popups.overlayManager = overlayManager;
}
private static OverlayManager overlayManager;
public static void removeBlurContent() {
overlayManager.removeBlurContent();
OverlayManager.removeBlurContent();
}
// Information
@ -56,7 +49,7 @@ public class Popups {
}
public static void openInfoPopup(String masthead, String message) {
overlayManager.blurContent();
OverlayManager.blurContent();
List<Action> actions = new ArrayList<>();
actions.add(new AbstractAction(BSResources.get("shared.close")) {
@Override
@ -84,7 +77,7 @@ public class Popups {
}
public static Action openConfirmPopup(String title, String masthead, String message) {
overlayManager.blurContent();
OverlayManager.blurContent();
List<Action> actions = new ArrayList<>();
actions.add(new AbstractAction(BSResources.get("shared.ok")) {
@Override
@ -123,7 +116,7 @@ public class Popups {
}
public static void openWarningPopup(String title, String masthead, String message) {
overlayManager.blurContent();
OverlayManager.blurContent();
List<Action> actions = new ArrayList<>();
actions.add(new AbstractAction(BSResources.get("shared.close")) {
@Override
@ -156,7 +149,7 @@ public class Popups {
}
public static void openErrorPopup(String title, String masthead, String message) {
overlayManager.blurContent();
OverlayManager.blurContent();
List<Action> actions = new ArrayList<>();
actions.add(new AbstractAction(BSResources.get("shared.close")) {
@Override
@ -189,7 +182,7 @@ public class Popups {
}
private static void openExceptionPopup(Throwable throwable, String title, String masthead, String message) {
overlayManager.blurContent();
OverlayManager.blurContent();
List<Action> actions = new ArrayList<>();
actions.add(new AbstractAction(BSResources.get("shared.close")) {
@Override

View File

@ -66,7 +66,6 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
private final ViewLoader viewLoader;
private final Navigation navigation;
private final OverlayManager overlayManager;
private final Transitions transitions;
private final String title;
private ChangeListener<String> walletServiceErrorMsgListener;
@ -84,12 +83,11 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
private List<String> persistedFilesCorrupted;
@Inject
public MainView(MainViewModel model, CachingViewLoader viewLoader, Navigation navigation, OverlayManager overlayManager, Transitions transitions,
public MainView(MainViewModel model, CachingViewLoader viewLoader, Navigation navigation, Transitions transitions,
@Named(MainView.TITLE_KEY) String title) {
super(model);
this.viewLoader = viewLoader;
this.navigation = navigation;
this.overlayManager = overlayManager;
this.transitions = transitions;
this.title = title;
}
@ -497,9 +495,7 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
}
private void configureBlurring(Node node) {
Popups.setOverlayManager(overlayManager);
overlayManager.addListener(new OverlayManager.OverlayListener() {
OverlayManager.addListener(new OverlayManager.OverlayListener() {
@Override
public void onBlurContentRequested() {
transitions.blur(node);

View File

@ -160,6 +160,8 @@ class MainViewModel implements ViewModel {
setBitcoinNetworkSyncProgress((double) newValue);
});
setBitcoinNetworkSyncProgress(walletService.downloadPercentageProperty().get());
// Sometimes we don't get the updates, so add an additional setter after 2 seconds
Utilities.setTimeout(2000, () -> setBitcoinNetworkSyncProgress(walletService.downloadPercentageProperty().get()));
walletService.numPeersProperty().addListener((observable, oldValue, newValue) -> {

View File

@ -62,12 +62,10 @@ public class FiatAccountView extends ActivatableViewAndModel<GridPane, FiatAccou
private Wizard wizard;
private final OverlayManager overlayManager;
@Inject
public FiatAccountView(FiatAccountViewModel model, OverlayManager overlayManager) {
public FiatAccountView(FiatAccountViewModel model) {
super(model);
this.overlayManager = overlayManager;
}
@Override
@ -202,7 +200,7 @@ public class FiatAccountView extends ActivatableViewAndModel<GridPane, FiatAccou
model.getCountryNotInAcceptedCountriesList().addListener((ov, oldValue, newValue) -> {
if (newValue) {
overlayManager.blurContent();
OverlayManager.blurContent();
List<Action> actions = new ArrayList<>();
actions.add(new AbstractAction(BSResources.get("shared.no")) {
@Override
@ -228,7 +226,7 @@ public class FiatAccountView extends ActivatableViewAndModel<GridPane, FiatAccou
if (Popups.isYes(response))
model.addCountryToAcceptedCountriesList();
overlayManager.removeBlurContent();
OverlayManager.removeBlurContent();
}
});

View File

@ -54,12 +54,9 @@ public class RegistrationView extends InitializableView<GridPane, RegistrationVi
private Wizard wizard;
private final OverlayManager overlayManager;
@Inject
private RegistrationView(RegistrationViewModel model, OverlayManager overlayManager) {
private RegistrationView(RegistrationViewModel model) {
super(model);
this.overlayManager = overlayManager;
}
@Override
@ -69,9 +66,6 @@ public class RegistrationView extends InitializableView<GridPane, RegistrationVi
addressTextField.setPaymentLabel(model.getPaymentLabel());
addressTextField.setAddress(model.getAddressAsString());
// TODO find better solution
addressTextField.setOverlayManager(overlayManager);
balanceTextField.setup(model.getWalletService(), model.address.get(),
model.getFormatter());
@ -94,7 +88,7 @@ public class RegistrationView extends InitializableView<GridPane, RegistrationVi
model.showTransactionPublishedScreen.addListener((o, oldValue, newValue) -> {
if (newValue) {
overlayManager.blurContent();
OverlayManager.blurContent();
List<Action> actions = new ArrayList<>();
/* actions.add(new AbstractAction(BSResources.get("shared.copyTxId")) {

View File

@ -56,7 +56,7 @@
<Label text="Withdraw to address:" GridPane.rowIndex="2"/>
<TextField fx:id="withdrawToTextField" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
<Button text="Withdraw" defaultButton="true" onAction="#onWithdraw" GridPane.rowIndex="3"
<Button fx:id="withdrawButton" text="Withdraw" defaultButton="true" onAction="#onWithdraw" GridPane.rowIndex="3"
GridPane.columnIndex="1"/>
<columnConstraints>

View File

@ -27,6 +27,8 @@ import io.bitsquare.gui.common.view.FxmlView;
import io.bitsquare.gui.components.Popups;
import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.GUIUtil;
import io.bitsquare.gui.util.validation.BtcAddressValidator;
import io.bitsquare.gui.util.validation.BtcValidator;
import io.bitsquare.trade.TradeManager;
import io.bitsquare.trade.offer.OpenOfferManager;
@ -43,6 +45,7 @@ import java.util.stream.Stream;
import javax.inject.Inject;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
@ -60,8 +63,8 @@ import org.jetbrains.annotations.NotNull;
@FxmlView
public class WithdrawalView extends ActivatableViewAndModel {
@FXML Button withdrawButton;
@FXML TableView<WithdrawalListItem> table;
@FXML Button addNewAddressButton;
@FXML TextField withdrawFromTextField, withdrawToTextField, amountTextField;
@FXML TableColumn<WithdrawalListItem, WithdrawalListItem> labelColumn, addressColumn, balanceColumn, copyColumn,
confidenceColumn;
@ -70,14 +73,19 @@ public class WithdrawalView extends ActivatableViewAndModel {
private TradeManager tradeManager;
private OpenOfferManager openOfferManager;
private final BSFormatter formatter;
private final BtcAddressValidator btcAddressValidator;
private final BtcValidator btcValidator;
private final ObservableList<WithdrawalListItem> addressList = FXCollections.observableArrayList();
@Inject
private WithdrawalView(WalletService walletService, TradeManager tradeManager, OpenOfferManager openOfferManager, BSFormatter formatter) {
private WithdrawalView(WalletService walletService, TradeManager tradeManager, OpenOfferManager openOfferManager, BSFormatter formatter,
BtcAddressValidator btcAddressValidator, BtcValidator btcValidator) {
this.walletService = walletService;
this.tradeManager = tradeManager;
this.openOfferManager = openOfferManager;
this.formatter = formatter;
this.btcAddressValidator = btcAddressValidator;
this.btcValidator = btcValidator;
}
@ -92,8 +100,16 @@ public class WithdrawalView extends ActivatableViewAndModel {
setConfidenceColumnCellFactory();
}
private boolean areInputsValid() {
return btcAddressValidator.validate(withdrawFromTextField.getText()).and(
btcAddressValidator.validate(withdrawToTextField.getText())).and(
btcValidator.validate(amountTextField.getText())).isValid;
}
@Override
public void doActivate() {
withdrawButton.disableProperty().bind(Bindings.createBooleanBinding(() -> !areInputsValid(),
withdrawFromTextField.textProperty(), amountTextField.textProperty(), withdrawToTextField.textProperty()));
table.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (newValue != null) {
@ -124,6 +140,7 @@ public class WithdrawalView extends ActivatableViewAndModel {
@Override
public void doDeactivate() {
addressList.forEach(WithdrawalListItem::cleanup);
withdrawButton.disableProperty().unbind();
}
@FXML
@ -178,6 +195,13 @@ public class WithdrawalView extends ActivatableViewAndModel {
Popups.openErrorPopup("Insufficient amount",
"The amount to transfer is lower the the transaction fee and the min. possible tx value.");
}
withdrawFromTextField.setText("");
withdrawFromTextField.setPromptText("Select a source address from the table");
amountTextField.setText("");
amountTextField.setPromptText("");
withdrawToTextField.setText("");
withdrawToTextField.setPromptText("");
}
private void fillList() {

View File

@ -78,7 +78,6 @@ import static javafx.beans.binding.Bindings.createStringBinding;
public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateOfferViewModel> {
private final Navigation navigation;
private final OverlayManager overlayManager;
@FXML ScrollPane scrollPane;
@FXML ImageView imageView;
@ -124,12 +123,10 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private CreateOfferView(CreateOfferViewModel model, Navigation navigation,
OverlayManager overlayManager) {
private CreateOfferView(CreateOfferViewModel model, Navigation navigation) {
super(model);
this.navigation = navigation;
this.overlayManager = overlayManager;
}
@Override
@ -287,7 +284,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
}
if (newValue) {
overlayManager.blurContent();
OverlayManager.blurContent();
// Dialogs are a bit limited. There is no callback for the InformationDialog button click, so we added
// our own actions.
@ -390,7 +387,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
void onShowPayFundsScreen() {
if (!BitsquareApp.DEV_MODE) {
if (model.getDisplaySecurityDepositInfo()) {
overlayManager.blurContent();
OverlayManager.blurContent();
List<Action> actions = new ArrayList<>();
actions.add(new AbstractAction(BSResources.get("shared.close")) {
@Override

View File

@ -78,7 +78,6 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
private final Navigation navigation;
private final OverlayManager overlayManager;
private final OptionalBtcValidator optionalBtcValidator;
private final OptionalFiatValidator optionalFiatValidator;
private OfferView.OfferActionHandler offerActionHandler;
@ -91,13 +90,11 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
@Inject
OfferBookView(OfferBookViewModel model,
Navigation navigation,
OverlayManager overlayManager,
OptionalBtcValidator optionalBtcValidator,
OptionalFiatValidator optionalFiatValidator) {
super(model);
this.navigation = navigation;
this.overlayManager = overlayManager;
this.optionalBtcValidator = optionalBtcValidator;
this.optionalFiatValidator = optionalFiatValidator;
}
@ -225,7 +222,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
}
private void openSetupScreen() {
overlayManager.blurContent();
OverlayManager.blurContent();
List<Action> actions = new ArrayList<>();
actions.add(new AbstractAction(BSResources.get("shared.ok")) {
@Override
@ -344,7 +341,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
///////////////////////////////////////////////////////////////////////////////////////////
private void openRestrictionsWarning(String restrictionsInfo) {
overlayManager.blurContent();
OverlayManager.blurContent();
List<Action> actions = new ArrayList<>();
actions.add(new AbstractAction(BSResources.get("shared.yes")) {
@Override

View File

@ -74,7 +74,6 @@ import static javafx.beans.binding.Bindings.createStringBinding;
public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOfferViewModel> {
private final Navigation navigation;
private final OverlayManager overlayManager;
@FXML ScrollPane scrollPane;
@FXML ImageView imageView;
@ -113,12 +112,10 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private TakeOfferView(TakeOfferViewModel model, Navigation navigation,
OverlayManager overlayManager) {
private TakeOfferView(TakeOfferViewModel model, Navigation navigation) {
super(model);
this.navigation = navigation;
this.overlayManager = overlayManager;
createListeners();
}
@ -211,7 +208,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
}
if (newValue) {
overlayManager.blurContent();
OverlayManager.blurContent();
// Dialogs are a bit limited. There is no callback for the InformationDialog button click, so we added
// our own actions.
@ -375,7 +372,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
private void setupPaymentScreen() {
if (!BitsquareApp.DEV_MODE) {
if (model.getDisplaySecurityDepositInfo()) {
overlayManager.blurContent();
OverlayManager.blurContent();
List<Action> actions = new ArrayList<>();
actions.add(new AbstractAction(BSResources.get("shared.close")) {
@Override

View File

@ -81,7 +81,6 @@ public class ConfirmFiatReceivedView extends TradeStepDetailsView {
private void onPaymentReceived(ActionEvent actionEvent) {
log.debug("onPaymentReceived");
model.fiatPaymentReceived();
confirmFiatReceivedButton.setDisable(true);
statusLabel.setText("Sending message to trading peer...");
statusProgressIndicator.setVisible(true);
@ -89,6 +88,8 @@ public class ConfirmFiatReceivedView extends TradeStepDetailsView {
root = statusProgressIndicator.getScene().getRoot();
// We deactivate mouse interaction to avoid that user leaves screen
root.setMouseTransparent(true);
model.fiatPaymentReceived();
}

View File

@ -106,10 +106,8 @@ public class NetworkSettingsView extends InitializableView {
}
});
Action response = Popups.openConfirmPopup("Info", "",
"You need to restart the application to apply the change of the Bitcoin network." +
"\n\nDo you want to shutdown now?",
actions);
Action response = Popups.openConfirmPopup("Info", "You need to restart the application to apply the change of the Bitcoin network.",
"Do you want to shutdown now?", actions);
if (Popups.isYes(response))
BitsquareApp.shutDownHandler.run();