-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace default textinput dialog with custom textfield dialog
- Loading branch information
Showing
2 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/main/java/com/sparrowwallet/sparrow/control/TextfieldDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.sparrowwallet.sparrow.control; | ||
|
||
import com.sparrowwallet.sparrow.AppServices; | ||
import javafx.application.Platform; | ||
import javafx.beans.NamedArg; | ||
import javafx.scene.control.*; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.image.ImageView; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.layout.Priority; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TextfieldDialog extends Dialog<String> { | ||
private static final Logger log = LoggerFactory.getLogger(TextAreaDialog.class); | ||
|
||
private final TextField textField; | ||
private final String defaultValue; | ||
|
||
public TextfieldDialog() { | ||
this(""); | ||
} | ||
|
||
public TextfieldDialog(String defaultValue) { | ||
this(defaultValue, true); | ||
} | ||
|
||
public TextfieldDialog(@NamedArg("defaultValue") String defaultValue, @NamedArg("editable") boolean editable) { | ||
final DialogPane dialogPane = getDialogPane(); | ||
setDialogPane(dialogPane); | ||
|
||
Image image = new Image("/image/sparrow-small.png"); | ||
dialogPane.setGraphic(new ImageView(image)); | ||
|
||
HBox hbox = new HBox(); | ||
this.textField = new TextField(defaultValue); | ||
this.textField.setMaxWidth(Double.MAX_VALUE); | ||
this.textField.setEditable(editable); | ||
hbox.getChildren().add(textField); | ||
HBox.setHgrow(this.textField, Priority.ALWAYS); | ||
|
||
this.defaultValue = defaultValue; | ||
|
||
dialogPane.setContent(hbox); | ||
dialogPane.getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm()); | ||
AppServices.setStageIcon(dialogPane.getScene().getWindow()); | ||
|
||
dialogPane.getStyleClass().add("text-input-dialog"); | ||
dialogPane.getButtonTypes().add(ButtonType.OK); | ||
if(editable) { | ||
dialogPane.getButtonTypes().add(ButtonType.CANCEL); | ||
} | ||
|
||
Platform.runLater(textField::requestFocus); | ||
|
||
setResultConverter((dialogButton) -> { | ||
ButtonBar.ButtonData data = dialogButton == null ? null : dialogButton.getButtonData(); | ||
return data == ButtonBar.ButtonData.OK_DONE ? textField.getText() : null; | ||
}); | ||
|
||
dialogPane.setPrefWidth(600); | ||
dialogPane.setPrefHeight(230); | ||
AppServices.moveToActiveWindowScreen(this); | ||
} | ||
|
||
public final TextField getEditor() { | ||
return textField; | ||
} | ||
|
||
public final String getDefaultValue() { | ||
return defaultValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters