Skip to content

Commit

Permalink
Merge pull request #1358 from ripcurlx/refactor-infotextfields
Browse files Browse the repository at this point in the history
Refactor infotextfields
  • Loading branch information
ManfredKarrer authored Feb 14, 2018
2 parents ff62954 + 1075298 commit 3d51f9d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ shared.viewContractAsJson=Vertrag im JSON-Format ansehen
shared.contract.title=Vertrag für den Handel mit der ID: {0}
shared.paymentDetails=Zahlungsdetails des BTC-{0}:
shared.securityDeposit=Kaution
shared.yourSecurityDeposit=Deine Kaution
shared.contract=Vertrag
shared.messageArrived=Nachricht angekommen.
shared.messageStoredInMailbox=Nachricht in Postfach gespeichert.
Expand Down
79 changes: 6 additions & 73 deletions gui/src/main/java/io/bisq/gui/components/FundsTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,28 @@

import java.util.concurrent.TimeUnit;

public class FundsTextField extends AnchorPane {
public class FundsTextField extends InfoTextField {
public static final Logger log = LoggerFactory.getLogger(FundsTextField.class);

private final StringProperty amount = new SimpleStringProperty();
private final StringProperty fundsStructure = new SimpleStringProperty();
private final Label infoIcon;
private Boolean hidePopover;
private PopOver infoPopover;

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////


public FundsTextField() {

TextField textField = new TextField();
// might be removed if no styling is necessary
textField.setId("amount-text-field");
textField.setEditable(false);
textField.setPromptText(Res.get("createOffer.fundsBox.totalsNeeded.prompt"));
textField.textProperty().bind(Bindings.concat(amount, " ", fundsStructure));
textField.setFocusTraversable(false);

infoIcon = new Label();
infoIcon.setLayoutY(3);
infoIcon.getStyleClass().addAll("icon", "info");
AwesomeDude.setIcon(infoIcon, AwesomeIcon.INFO_SIGN);
super();
textField.textProperty().unbind();
textField.textProperty().bind(Bindings.concat(textProperty(), " ", fundsStructure));

Label copyIcon = new Label();
copyIcon.setLayoutY(3);
copyIcon.getStyleClass().addAll("icon", "highlight");
Tooltip.install(copyIcon, new Tooltip(Res.get("shared.copyToClipboard")));
AwesomeDude.setIcon(copyIcon, AwesomeIcon.COPY);
copyIcon.setOnMouseClicked(e -> {
String text = getAmount();
String text = getText();
if (text != null && text.length() > 0) {
String copyText;
String[] strings = text.split(" ");
Expand All @@ -87,67 +73,14 @@ public FundsTextField() {
AnchorPane.setRightAnchor(copyIcon, 30.0);
AnchorPane.setRightAnchor(infoIcon, 62.0);
AnchorPane.setRightAnchor(textField, 55.0);
AnchorPane.setLeftAnchor(textField, 0.0);

getChildren().addAll(textField, infoIcon, copyIcon);
}

///////////////////////////////////////////////////////////////////////////////////////////
// Public
///////////////////////////////////////////////////////////////////////////////////////////

public void setContentForInfoPopOver(Node node) {
// As we don't use binding here we need to recreate it on mouse over to reflect the current state
infoIcon.setOnMouseEntered(e -> {
hidePopover = false;
showInfoPopOver(node);
});
infoIcon.setOnMouseExited(e -> {
if (infoPopover != null)
hidePopover = true;
UserThread.runAfter(() -> {
if (hidePopover) {
infoPopover.hide();
hidePopover = false;
}
},250, TimeUnit.MILLISECONDS);
});
}

///////////////////////////////////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////////////////////////////////

private void showInfoPopOver(Node node) {
node.getStyleClass().add("default-text");

if (infoPopover == null) infoPopover = new PopOver(node);

if (infoIcon.getScene() != null) {
infoPopover.setDetachable(false);
infoPopover.setArrowLocation(PopOver.ArrowLocation.RIGHT_TOP);
infoPopover.setArrowIndent(5);

infoPopover.show(infoIcon, -17);
}
getChildren().add(copyIcon);
}

///////////////////////////////////////////////////////////////////////////////////////////
// Getters/Setters
///////////////////////////////////////////////////////////////////////////////////////////

public void setAmount(String amount) {
this.amount.set(amount);
}

public String getAmount() {
return amount.get();
}

public StringProperty amountProperty() {
return amount;
}

public void setFundsStructure(String fundsStructure) {
this.fundsStructure.set(fundsStructure);
}
Expand Down
9 changes: 4 additions & 5 deletions gui/src/main/java/io/bisq/gui/components/InfoTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ public class InfoTextField extends AnchorPane {
public static final Logger log = LoggerFactory.getLogger(InfoTextField.class);

private final StringProperty text = new SimpleStringProperty();
private final Label infoIcon;
protected final Label infoIcon;
protected final TextField textField;
private Boolean hidePopover;
private PopOver infoPopover;

public InfoTextField() {
TextField textField = new TextField();
// might be removed if no styling is necessary
textField = new TextField();
textField.setEditable(false);
textField.setPromptText(Res.get("createOffer.fundsBox.totalsNeeded.prompt"));
textField.textProperty().bind(text);
textField.setFocusTraversable(false);

Expand Down Expand Up @@ -97,7 +96,7 @@ public String getText() {
return text.get();
}

public StringProperty amountProperty() {
public StringProperty textProperty() {
return text;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ private void addBindings() {
marketBasedPriceTextField.textProperty().bindBidirectional(model.marketPriceMargin);
volumeTextField.textProperty().bindBidirectional(model.volume);
volumeTextField.promptTextProperty().bind(model.volumePromptLabel);
totalToPayTextField.amountProperty().bind(model.totalToPay);
totalToPayTextField.textProperty().bind(model.totalToPay);
addressTextField.amountAsCoinProperty().bind(model.dataModel.getMissingCoin());
buyerSecurityDepositInputTextField.textProperty().bindBidirectional(model.buyerSecurityDeposit);

Expand Down Expand Up @@ -544,7 +544,7 @@ private void removeBindings() {
marketBasedPriceLabel.prefWidthProperty().unbind();
volumeTextField.textProperty().unbindBidirectional(model.volume);
volumeTextField.promptTextProperty().unbindBidirectional(model.volume);
totalToPayTextField.amountProperty().unbind();
totalToPayTextField.textProperty().unbind();
addressTextField.amountAsCoinProperty().unbind();
buyerSecurityDepositInputTextField.textProperty().unbindBidirectional(model.buyerSecurityDeposit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ private void close() {
private void addBindings() {
amountTextField.textProperty().bindBidirectional(model.amount);
volumeTextField.textProperty().bindBidirectional(model.volume);
totalToPayTextField.amountProperty().bind(model.totalToPay);
totalToPayTextField.textProperty().bind(model.totalToPay);
addressTextField.amountAsCoinProperty().bind(model.dataModel.missingCoin);
amountTextField.validationResultProperty().bind(model.amountValidationResult);
priceCurrencyLabel.textProperty().bind(createStringBinding(() -> formatter.getCurrencyPair(model.dataModel.getCurrencyCode())));
Expand All @@ -481,7 +481,7 @@ private void addBindings() {
private void removeBindings() {
amountTextField.textProperty().unbindBidirectional(model.amount);
volumeTextField.textProperty().unbindBidirectional(model.volume);
totalToPayTextField.amountProperty().unbind();
totalToPayTextField.textProperty().unbind();
addressTextField.amountAsCoinProperty().unbind();
amountTextField.validationResultProperty().unbind();
priceCurrencyLabel.textProperty().unbind();
Expand Down

0 comments on commit 3d51f9d

Please sign in to comment.