下面列出了javafx.scene.control.TextInputDialog#setHeaderText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Displays a small window allowing the user to enter a name for the new
* preference
*
* @author formalhaut69
* @return A tuple, the first item is a Boolean indicating whether the user
* selected to proceed with the operation or not, the second is the name of
* the file requested by the user.
*/
public static Tuple<Boolean, String> getName() {
String returnedName = "";
// opens up a slightly different dialog window to allow the user to name the
// preference when it is being saved
// create a text input dialog
TextInputDialog td = new TextInputDialog();
td.setTitle("Preference name");
// setHeaderText
td.setHeaderText("Enter a name for the preference");
Optional<String> result = td.showAndWait();
if (result.isPresent()) {
returnedName = td.getEditor().getText();
}
return new Tuple<>(result.isPresent(), returnedName);
}
/**
* @param title null if user pressed cancel, or the text entered if pressed
* OK (if pressed OK with no text entered, empty string is
* brought back
* @param textlength the maximum length of text to enter
* @return
*/
public String showModalTextEntry(String title, int textlength) {
logger.fine("NormalTextEntry " + title + " - " + textlength);
logger.fine(" prepare to launch dialog");
TextInputDialog dialog = new TextInputDialog();
dialog.setHeaderText("Enter Update Note below");
dialog.setContentText("");
Optional<String> result = dialog.showAndWait();
logger.fine(" dialog is displayed");
if (!result.isPresent())
return null;
return result.get();
}
@FXML
public void showUrlDialog() {
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle("Load remote world");
dialog.setHeaderText("Enter the URL to the remote world you want to load");
dialog.setGraphic(null);
dialog.setResult(serverSettingsController.lastBrowsedURL);
dialog.showAndWait().ifPresent(s -> {
try {
loadRemote(new URI(s));
serverSettingsController.lastBrowsedURL = s;
worldInput.setText(s);
} catch (URISyntaxException | IllegalArgumentException e) {
log.warn("Malformed input uri", e);
ExceptionDialog d = new ExceptionDialog(e);
d.setTitle("Malformed input");
d.showAndWait();
}
});
}
/**
* This method will be called internally by the above method when a non standard layout is detected.
*
* @return the arduino path wrapped in an optional, or nothing if cancel is pressed.
*/
private Optional<String> getArduinoPathWithDialog() {
String savedPath = Preferences.userNodeForPackage(ArduinoLibraryInstaller.class)
.get(ARDUINO_CUSTOM_PATH, homeDirectory);
Path libsPath = Paths.get(savedPath, "libraries");
if (Files.exists(libsPath)) return Optional.of(savedPath);
TextInputDialog dialog = new TextInputDialog(savedPath);
dialog.setTitle("Manually enter Arduino Path");
dialog.setHeaderText("Please manually enter the full path to the Arduino folder");
dialog.setContentText("Arduino Path");
Optional<String> path = dialog.showAndWait();
path.ifPresent((p) -> Preferences.userNodeForPackage(ArduinoLibraryInstaller.class).put(ARDUINO_CUSTOM_PATH, p));
return path;
}
/**
* show an input dialog
*
* @param swingParent
* @param title
* @param message
* @param initialValue
* @return
*/
private static String showInput(final Component swingParent, final String title, final String message, final String initialValue) {
final Single<String> input = new Single<>(null);
if (Platform.isFxApplicationThread()) {
final TextInputDialog dialog = new TextInputDialog(initialValue != null ? initialValue : "");
dialog.setTitle(title);
dialog.setHeaderText(message);
final Optional<String> result = dialog.showAndWait();
result.ifPresent(input::set);
} else if (javax.swing.SwingUtilities.isEventDispatchThread()) {
input.set(JOptionPane.showInputDialog(swingParent, message, initialValue));
} else {
try {
SwingUtilities.invokeAndWait(() -> input.set(showInput(swingParent, title, message, initialValue)));
} catch (Exception e) {
Basic.caught(e);
}
}
return input.get();
}
@FXML
public void addLinkAction() {
try {
// http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8
TextInputDialog dialog = new TextInputDialog("http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8");
dialog.setTitle(message("HTTPLiveStreaming"));
dialog.setHeaderText(message("InputAddress"));
dialog.setContentText("HLS(.m3u8)");
dialog.getEditor().setPrefWidth(500);
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<String> result = dialog.showAndWait();
if (!result.isPresent()) {
return;
}
String address = result.get();
addLink(address);
} catch (Exception e) {
logger.error(e.toString());
}
}
@FXML
protected void plusAction() {
try {
TextInputDialog dialog = new TextInputDialog("https://");
dialog.setTitle(message("DownloadManage"));
dialog.setHeaderText(message("InputAddress"));
dialog.setContentText("");
dialog.getEditor().setPrefWidth(500);
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<String> result = dialog.showAndWait();
if (!result.isPresent()) {
return;
}
String address = result.get();
download(address);
} catch (Exception e) {
logger.error(e.toString());
}
}
@FXML
public void plusAction() {
TextInputDialog dialog = new TextInputDialog("");
dialog.setTitle(message("ManageLanguages"));
dialog.setHeaderText(message("InputLangaugeName"));
dialog.setContentText("");
dialog.getEditor().setPrefWidth(200);
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<String> result = dialog.showAndWait();
if (!result.isPresent() || result.get().trim().isBlank()) {
return;
}
langName = result.get().trim();
langLabel.setText(langName);
loadLanguage(null);
}
public void actionPerformed(ActionEvent event) {
final SamplesViewer viewer = ((SamplesViewer) getViewer());
final int index;
final String selectedAttribute = viewer.getSamplesTableView().getASelectedAttribute();
if (selectedAttribute != null)
index = viewer.getSamplesTableView().getAttributes().indexOf(selectedAttribute);
else
index = viewer.getSamplesTableView().getSampleCount();
String name = null;
if (Platform.isFxApplicationThread()) {
TextInputDialog dialog = new TextInputDialog("Attribute");
dialog.setTitle("New attribute");
dialog.setHeaderText("Enter attribute name:");
Optional<String> result = dialog.showAndWait();
if (result.isPresent()) {
name = result.get().trim();
}
} else if (javax.swing.SwingUtilities.isEventDispatchThread()) {
name = JOptionPane.showInputDialog(getViewer().getFrame(), "Enter new attribute name", "Untitled");
}
if (name != null)
executeImmediately("new attribute='" + name + "' position=" + index + ";");
}
@FXML
public void editAction(ActionEvent event) {
// load current selection and allow user to change value
int index = lwBootstrappingNodes.getSelectionModel().getSelectedIndex();
String nodeAddress = lwBootstrappingNodes.getSelectionModel().getSelectedItem();
TextInputDialog input = new TextInputDialog();
DialogUtils.decorateDialogWithIcon(input);
input.getEditor().setText(nodeAddress);
input.setTitle("Edit Node Address");
input.setHeaderText("Enter node address");
Optional<String> result = input.showAndWait();
if(result.isPresent()) {
String newNodeAddress = result.get().trim();
if (!newNodeAddress.isEmpty() && !containsAddress(newNodeAddress)) {
addresses.add(index, newNodeAddress);
addresses.remove(nodeAddress);
}
}
}
@FXML
@Override
public void saveAsAction() {
MediaList selected = tableView.getSelectionModel().getSelectedItem();
if (selected == null || selected.getMedias() == null) {
return;
}
TextInputDialog dialog = new TextInputDialog("");
dialog.setTitle(message("ManageMediaLists"));
dialog.setHeaderText(message("InputMediaListName"));
dialog.setContentText("");
dialog.getEditor().setPrefWidth(400);
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<String> result = dialog.showAndWait();
if (!result.isPresent() || result.get().trim().isBlank()) {
return;
}
String newName = result.get().trim();
for (MediaList list : tableData) {
if (list.getName().equals(newName)) {
popError(message("AlreadyExisted"));
return;
}
}
if (TableMediaList.set(newName, selected.getMedias())) {
popSuccessful();
tableData.add(MediaList.create().setName(newName).setMedias(selected.getMedias()));
} else {
popFailed();
}
}
@FXML
@Override
public void saveAction() {
if (mediaListName == null || mediaListName.isBlank()) {
if (tableData.isEmpty()) {
tableLabel.setText("");
return;
}
TextInputDialog dialog = new TextInputDialog("");
dialog.setTitle(message("ManageMediaLists"));
dialog.setHeaderText(message("InputMediaListName"));
dialog.setContentText("");
dialog.getEditor().setPrefWidth(400);
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<String> result = dialog.showAndWait();
if (!result.isPresent() || result.get().trim().isBlank()) {
return;
}
mediaListName = result.get().trim();
}
if (TableMediaList.set(mediaListName, tableData)) {
tableLabel.setText(message("MediaList") + ": " + mediaListName);
if (parentController != null) {
parentController.popSuccessful();
if (parentController instanceof MediaListController) {
((MediaListController) parentController).update(mediaListName);
}
}
} else {
if (parentController != null) {
parentController.popFailed();
}
}
}
public static String showInputDialog(String header, String content, String defaultValue) {
TextInputDialog dialog = new TextInputDialog(defaultValue);
dialog.setTitle(QiniuValueConsts.MAIN_TITLE);
dialog.setHeaderText(header);
dialog.setContentText(content);
Optional<String> result = dialog.showAndWait();
return result.orElse(null);
}
public void onHeader() {
TextInputDialog input = new TextInputDialog();
input.setTitle("New Header");
input.setContentText("Label: ");
input.setHeaderText("Please enter header text.");
Optional<String> result = input.showAndWait();
result.ifPresent(name -> {
checkListFormNode.addHeader(name);
fireContentChanged();
});
}
@FXML
public void addAction(ActionEvent event) {
// request node address from user and add
TextInputDialog input = new TextInputDialog();
DialogUtils.decorateDialogWithIcon(input);
input.getEditor().setPromptText("Enter address");
input.setTitle("New Node Address");
input.setHeaderText("Enter new node address");
Optional<String> result = input.showAndWait();
if (result.isPresent()) {
String nodeAddress = result.get().trim();
addItemIgnoreDuplicate(nodeAddress);
}
}
@FXML
void onNewMeasurment(ActionEvent event) {
newMeasurmentButton.setDisable(true);
TextInputDialog dialog = new TextInputDialog("lengthOfThing");
dialog.setTitle("Add new measurment to "+typeOfVitaminString);
dialog.setHeaderText("This measurment will be added to all instances of the vitamin");
dialog.setContentText("New measurment name:");
// Traditional way to get the response value.
Optional<String> result = dialog.showAndWait();
// The Java 8 way to get the response value (with lambda expression).
result.ifPresent(name -> {
TextInputDialog dialog2 = new TextInputDialog("0.0");
dialog2.setTitle("Set value of "+name);
dialog2.setHeaderText("This value will be added to all instances of the vitamin");
dialog2.setContentText(name+" = ");
// Traditional way to get the response value.
Optional<String> result2 = dialog2.showAndWait();
result2.ifPresent(name2 -> {
setupKeyValueToTable(name,name2,sizeOfVitaminString);
for(String size:Vitamins.listVitaminSizes(typeOfVitaminString)) {
Vitamins.getConfiguration(typeOfVitaminString, size).put(name,name2);
}
});
newMeasurmentButton.setDisable(false);
});
}
public static Optional<String> askInputFromUser(String title, String msg) {
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle(title);
dialog.setHeaderText(null);
dialog.setContentText(msg);
return dialog.showAndWait();
}
public static Optional<String> askInputFromUser(String title, String msg) {
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle(title);
dialog.setHeaderText(null);
dialog.setContentText(msg);
return dialog.showAndWait();
}
/** Save the layout. Prompt for a new filename, validate, possibly confirm an overwrite, and then save.
* @return <code>true</code> if layout save has been initiated (may take some time to complete)
*/
private boolean saveLayout()
{
final TextInputDialog prompt = new TextInputDialog();
prompt.setTitle(getText());
prompt.setHeaderText(Messages.SaveDlgHdr);
positionDialog(prompt);
while (true)
{
final String filename = prompt.showAndWait().orElse(null);
// Canceled?
if (filename == null)
return false;
// OK to save?
if (! validateFilename(filename))
{
// Ask again
prompt.setHeaderText(Messages.SaveDlgErrHdr);
continue;
}
else
prompt.setHeaderText(Messages.SaveDlgHdr);
// Done if save succeeded.
if (saveState(filename))
return true;
}
}
@FXML
@Override
public void addAction() {
try {
TextInputDialog dialog = new TextInputDialog("docs.oracle.com");
dialog.setTitle(message("SSLVerificationByPass"));
dialog.setHeaderText(message("InputAddress"));
dialog.setContentText("");
dialog.getEditor().setPrefWidth(500);
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<String> result = dialog.showAndWait();
if (!result.isPresent()) {
return;
}
String address = result.get().trim();
if (address.isBlank()) {
return;
}
for (CertificateBypass p : tableData) {
if (p.getHost().equals(address)) {
return;
}
}
if (TableBrowserBypassSSL.write(address)) {
CertificateBypass newdata = TableBrowserBypassSSL.read(address);
if (newdata != null) {
tableData.add(newdata);
tableView.refresh();
popSuccessful();
} else {
popFailed();
}
} else {
popFailed();
}
} catch (Exception e) {
logger.error(e.toString());
}
}