Add busy animtion to wallet pw window, add visibility handling

This commit is contained in:
Manfred Karrer 2016-06-27 14:02:52 +02:00
parent 2bbf8e532b
commit 4800764156
3 changed files with 45 additions and 35 deletions

View file

@ -16,8 +16,14 @@ public class BusyAnimation extends Pane {
private ImageView img1, img2;
private int incr;
private int rotation1, rotation2;
private boolean animate;
public BusyAnimation() {
this(true);
}
public BusyAnimation(boolean animate) {
this.animate = animate;
setMinSize(24, 24);
setMaxSize(24, 24);
@ -28,39 +34,45 @@ public class BusyAnimation extends Pane {
img2 = new ImageView();
img2.setId("spinner");
sceneProperty().addListener((obs, oldVal, newVal) -> {
if (newVal == null) {
stop();
} else {
play();
}
});
getChildren().addAll(img1, img2);
sceneProperty().addListener((obs, oldVal, newVal) -> {
if (newVal == null)
stop();
else
else if (animate)
play();
});
updateVisibility();
}
private void update() {
public void play() {
animate = true;
updateVisibility();
if (timer != null)
timer.stop();
timer = UserThread.runPeriodically(this::updateAnimation, 100, TimeUnit.MILLISECONDS);
}
public void stop() {
animate = false;
if (timer != null) {
timer.stop();
timer = null;
}
updateVisibility();
}
private void updateAnimation() {
rotation1 += incr;
rotation2 -= incr;
img1.setRotate(rotation1);
img2.setRotate(rotation2);
}
public void play() {
stop();
timer = UserThread.runPeriodically(this::update, 100, TimeUnit.MILLISECONDS);
}
public void stop() {
if (timer != null) {
timer.stop();
timer = null;
}
private void updateVisibility() {
setVisible(animate);
setManaged(animate);
}
}

View file

@ -407,12 +407,12 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
splashP2PNetworkBusyAnimation.setPrefSize(24, 24);
splashP2PNetworkErrorMsgListener = (ov, oldValue, newValue) -> {
if (newValue != null)
if (newValue != null) {
splashP2PNetworkLabel.setId("splash-error-state-msg");
splashP2PNetworkBusyAnimation.setVisible(newValue == null);
splashP2PNetworkBusyAnimation.setManaged(newValue == null);
splashP2PNetworkBusyAnimation.stop();
} else if (model.splashP2PNetworkVisible.get()) {
splashP2PNetworkBusyAnimation.play();
}
};
model.p2pNetworkWarnMsg.addListener(splashP2PNetworkErrorMsgListener);
@ -431,8 +431,10 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
model.p2PNetworkIconId.addListener(splashP2PNetworkIconIdListener);
splashP2PNetworkVisibleListener = (ov, oldValue, newValue) -> {
splashP2PNetworkBusyAnimation.setVisible(newValue);
splashP2PNetworkBusyAnimation.setManaged(newValue);
if (newValue)
splashP2PNetworkBusyAnimation.play();
else
splashP2PNetworkBusyAnimation.stop();
};
model.splashP2PNetworkVisible.addListener(splashP2PNetworkVisibleListener);

View file

@ -23,8 +23,8 @@ import io.bitsquare.btc.WalletService;
import io.bitsquare.common.UserThread;
import io.bitsquare.common.util.Tuple2;
import io.bitsquare.crypto.ScryptUtil;
import io.bitsquare.gui.components.BusyAnimation;
import io.bitsquare.gui.components.PasswordTextField;
import io.bitsquare.gui.components.indicator.TxConfidenceIndicator;
import io.bitsquare.gui.main.overlays.Overlay;
import io.bitsquare.gui.main.overlays.popups.Popup;
import io.bitsquare.gui.util.Transitions;
@ -183,9 +183,7 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
}
private void addButtons() {
TxConfidenceIndicator spinner = new TxConfidenceIndicator();
spinner.setVisible(false);
spinner.setManaged(spinner.isVisible());
BusyAnimation busyAnimation = new BusyAnimation(false);
unlockButton = new Button("Unlock");
unlockButton.setDefaultButton(true);
@ -196,8 +194,7 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
Wallet wallet = walletService.getWallet();
KeyCrypterScrypt keyCrypterScrypt = (KeyCrypterScrypt) wallet.getKeyCrypter();
if (keyCrypterScrypt != null) {
spinner.setVisible(true);
spinner.setManaged(spinner.isVisible());
busyAnimation.play();
ScryptUtil.deriveKeyWithScrypt(keyCrypterScrypt, password, aesKey -> {
if (wallet.checkAESKey(aesKey)) {
if (aesKeyHandler != null)
@ -205,8 +202,7 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
hide();
} else {
spinner.setVisible(false);
spinner.setManaged(spinner.isVisible());
busyAnimation.stop();
UserThread.runAfter(() -> new Popup()
.warning("You entered the wrong password.\n\n" +
@ -238,7 +234,7 @@ public class WalletPasswordWindow extends Overlay<WalletPasswordWindow> {
GridPane.setRowIndex(hBox, ++rowIndex);
GridPane.setColumnIndex(hBox, 1);
if (hideCloseButton)
hBox.getChildren().addAll(unlockButton, forgotPasswordButton, spinner);
hBox.getChildren().addAll(unlockButton, forgotPasswordButton, busyAnimation);
else
hBox.getChildren().addAll(unlockButton, cancelButton);
gridPane.getChildren().add(hBox);