use of com.kyj.fx.voeditor.visual.component.popup.BaseDialogComposite in project Gargoyle by callakrsos.
the class DialogUtil method showInputDialog.
public static Optional<Pair<String, String>> showInputDialog(Window owner, String title, String message, String inputValue, Predicate<String> satisfied) {
BaseDialogComposite composite = new BaseDialogComposite(title, message);
Button btnOk = new Button("OK");
btnOk.setMinWidth(80d);
Button btnCancel = new Button("Cancel");
btnCancel.setMinWidth(80d);
composite.addButton(btnOk);
composite.addButton(btnCancel);
TextField text = new TextField();
composite.setGraphic(text);
Optional<Pair<String, String>> empty = Optional.empty();
SimpleObjectProperty<Optional<Pair<String, String>>> prop = new SimpleObjectProperty<>(empty);
// Modal
composite.show(owner, stage -> {
stage.initModality(Modality.APPLICATION_MODAL);
text.requestFocus();
text.addEventHandler(KeyEvent.KEY_RELEASED, ev -> {
if (ev.getCode() == KeyCode.ENTER) {
Optional<Pair<String, String>> pair = Optional.of(new Pair<>("OK", text.getText()));
prop.set(pair);
if (satisfied != null) {
if (satisfied.test(text.getText())) {
stage.close();
}
}
} else {
if (satisfied != null) {
if (satisfied.test(text.getText())) {
btnOk.setDisable(false);
} else
btnOk.setDisable(true);
}
}
});
btnOk.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
Optional<Pair<String, String>> pair = Optional.of(new Pair<>("OK", text.getText()));
prop.set(pair);
stage.close();
});
btnCancel.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
stage.close();
});
});
return prop.get();
// Create the custom dialog.
// Dialog<Pair<String, String>> dialog = new Dialog<>();
// dialog.setTitle(title);
// dialog.setHeaderText(message);
// TextField text = new TextField();
// text.setFocusTraversable(true);
//
// dialog.setGraphic(text);
// text.requestFocus();
//
// // Set the button types.
// ButtonType okBtn = new ButtonType("OK", ButtonData.OK_DONE);
//
// dialog.getDialogPane().getButtonTypes().add(okBtn);
//
// dialog.setResultConverter(dialogButton -> {
// if (dialogButton == okBtn) {
// return new Pair<>("OK", text.getText());
// } else {
// return null;
// }
// });
//
// if (inputValue != null && inputValue != "") {
// text.setText(inputValue);
// }
//
// dialog.initModality(Modality.APPLICATION_MODAL);
// dialog.initOwner(owner);
// dialog.getGraphic().requestFocus();
// // dialog.initModality(Modality.APPLICATION_MODAL);
// // graphic.setFocusTraversable(true);
//
// Optional<Pair<String, String>> result = dialog.showAndWait();
//
// result.ifPresent(consumer);
//
// return result;
}
use of com.kyj.fx.voeditor.visual.component.popup.BaseDialogComposite in project Gargoyle by callakrsos.
the class DialogUtil method showInputCustomDialog.
/**
* Graphics 부분을 커스텀 처리할 수 있는 InputDialog
*
* @작성자 : KYJ
* @작성일 : 2016. 10. 21.
* @param owner
* @param title
* @param message
* @param customGrahics
* @return
*/
public static <T extends Node, V> Optional<Pair<String, V>> showInputCustomDialog(Window owner, String title, String message, CustomInputDialogAction<T, V> customGrahics) {
BaseDialogComposite composite = new BaseDialogComposite(title, message);
Button btnOk = new Button("OK");
btnOk.setMinWidth(80d);
Button btnCancel = new Button("Cancel");
btnCancel.setMinWidth(80d);
composite.addButton(btnOk);
composite.addButton(btnCancel);
Optional<Pair<String, V>> empty = Optional.empty();
SimpleObjectProperty<Optional<Pair<String, V>>> prop = new SimpleObjectProperty<>(empty);
T node = customGrahics.getNode();
composite.setGraphic(node);
// Modal
composite.show(owner, stage -> {
stage.initModality(Modality.APPLICATION_MODAL);
stage.initStyle(StageStyle.UTILITY);
node.requestFocus();
stage.addEventHandler(KeyEvent.KEY_PRESSED, ev -> {
if (ev.getCode() == KeyCode.ENTER) {
Optional<Pair<String, V>> pair = Optional.of(new Pair<>("OK", customGrahics.okClickValue()));
prop.set(pair);
stage.close();
}
});
btnOk.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
Optional<Pair<String, V>> pair = Optional.of(new Pair<>("OK", customGrahics.okClickValue()));
prop.set(pair);
stage.close();
});
btnCancel.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
Optional<Pair<String, V>> pair = Optional.of(new Pair<>("Cancel", customGrahics.cancelClickValue()));
prop.set(pair);
stage.close();
});
});
return prop.get();
}
Aggregations