org.controlsfx.samples.dialogs.HelloNewDialog Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of controlsfx-samples Show documentation
Show all versions of controlsfx-samples Show documentation
High quality UI controls and other tools to complement the core JavaFX distribution
/**
* Copyright (c) 2013, ControlsFX
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of ControlsFX, any associated website, nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CONTROLSFX BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.controlsfx.samples.dialogs;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceDialog;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputDialog;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
import org.controlsfx.ControlsFXSample;
import org.controlsfx.dialog.CommandLinksDialog;
import org.controlsfx.dialog.CommandLinksDialog.CommandLinksButtonType;
import org.controlsfx.dialog.Wizard.WizardPane;
import org.controlsfx.dialog.ExceptionDialog;
import org.controlsfx.dialog.FontSelectorDialog;
import org.controlsfx.dialog.LoginDialog;
import org.controlsfx.dialog.ProgressDialog;
import org.controlsfx.dialog.Wizard;
import org.controlsfx.dialog.Wizard.LinearFlow;
public class HelloNewDialog extends ControlsFXSample {
@Override
public String getSampleName() {
return "Dialogs (New)";
}
@Override
public String getJavaDocURL() {
// return Utils.JAVADOC_BASE + "org/controlsfx/dialog/Dialogs.html";
return null;
}
@Override
public String getSampleDescription() {
return "";
}
private final ComboBox styleCombobox = new ComboBox<>();
private final ComboBox modalityCombobox = new ComboBox<>();
private final CheckBox cbUseBlocking = new CheckBox();
private final CheckBox cbCloseDialogAutomatically = new CheckBox();
private final CheckBox cbShowMasthead = new CheckBox();
private final CheckBox cbSetOwner = new CheckBox();
private final CheckBox cbCustomGraphic = new CheckBox();
private Stage stage;
@Override
public Node getPanel(Stage stage) {
this.stage = stage;
GridPane grid = new GridPane();
grid.setPadding(new Insets(10, 10, 10, 10));
grid.setHgap(10);
grid.setVgap(10);
int row = 0;
Label javafxDialogs = new Label("JavaFX Dialogs:");
javafxDialogs.setFont(Font.font(25));
grid.add(javafxDialogs, 0, row++, 2, 1);
// *******************************************************************
// Information Dialog
// *******************************************************************
grid.add(createLabel("Information Dialog: "), 0, row);
final Button Hyperlink2 = new Button("Show");
Hyperlink2.setOnAction( (ActionEvent e) -> {
Alert dlg = createAlert(AlertType.INFORMATION);
dlg.setTitle("Custom title");
String optionalMasthead = "Wouldn't this be nice?";
dlg.getDialogPane().setContentText("A collection of pre-built JavaFX dialogs?\nSeems like a great idea to me...");
configureSampleDialog(dlg, optionalMasthead);
// lets get some output when events happen
dlg.setOnShowing(evt -> System.out.println(evt));
dlg.setOnShown(evt -> System.out.println(evt));
dlg.setOnHiding(evt -> System.out.println(evt));
dlg.setOnHidden(evt -> System.out.println(evt));
// dlg.setOnCloseRequest(evt -> evt.consume());
showDialog(dlg);
});
final Button Hyperlink2a = new Button("2 x Buttons (no cancel)");
Hyperlink2a.setOnAction( (ActionEvent e) -> {
Alert dlg = createAlert(AlertType.INFORMATION);
dlg.setTitle("Custom title");
String optionalMasthead = "Wouldn't this be nice?";
dlg.getDialogPane().setContentText("A collection of pre-built JavaFX dialogs?\nSeems like a great idea to me...");
configureSampleDialog(dlg, optionalMasthead);
dlg.getButtonTypes().add(ButtonType.NEXT);
// dlg.setOnCloseRequest(evt -> evt.consume());
showDialog(dlg);
});
grid.add(new HBox(10, Hyperlink2, Hyperlink2a), 1, row);
row++;
// *******************************************************************
// Confirmation Dialog
// *******************************************************************
grid.add(createLabel("Confirmation Dialog: "), 0, row);
final CheckBox cbShowCancel = new CheckBox("Show Cancel Button");
cbShowCancel.setSelected(true);
final Button Hyperlink3 = new Button("Show");
Hyperlink3.setOnAction(e -> {
Alert dlg = createAlert(AlertType.CONFIRMATION);
dlg.setTitle("You do want dialogs right?");
String optionalMasthead = "Just Checkin'";
dlg.getDialogPane().setContentText("I was a bit worried that you might not want them, so I wanted to double check.");
if (!cbShowCancel.isSelected()) {
dlg.getDialogPane().getButtonTypes().remove(ButtonType.CANCEL);
}
configureSampleDialog(dlg, optionalMasthead);
showDialog(dlg);
});
grid.add(new HBox(10, Hyperlink3, cbShowCancel), 1, row);
row++;
// *******************************************************************
// Warning Dialog
// *******************************************************************
grid.add(createLabel("Warning Dialog: "), 0, row);
final Button Hyperlink6a = new Button("Show");
Hyperlink6a.setOnAction(e -> {
Alert dlg = createAlert(AlertType.WARNING);
dlg.setTitle("I'm warning you!");
String optionalMasthead = "This is a warning";
dlg.getDialogPane().setContentText("I'm glad I didn't need to use this...");
configureSampleDialog(dlg, optionalMasthead);
showDialog(dlg);
});
grid.add(new HBox(10, Hyperlink6a), 1, row);
row++;
// *******************************************************************
// Error Dialog
// *******************************************************************
grid.add(createLabel("Error Dialog: "), 0, row);
final Button Hyperlink7a = new Button("Show");
Hyperlink7a.setOnAction(e -> {
Alert dlg = createAlert(AlertType.ERROR);
dlg.setTitle("It looks like you're making a bad decision");
String optionalMasthead = "Exception Encountered";
dlg.getDialogPane().setContentText("Better change your mind - this is really your last chance! (Even longer text that should probably wrap)");
configureSampleDialog(dlg, optionalMasthead);
showDialog(dlg);
});
grid.add(new HBox(10, Hyperlink7a), 1, row);
row++;
// *******************************************************************
// Input Dialog (with header)
// *******************************************************************
grid.add(createLabel("Input Dialog: "), 0, row);
final Button Hyperlink8 = new Button("TextField");
Hyperlink8.setOnAction(e -> {
TextInputDialog dlg = new TextInputDialog("");
dlg.setTitle("Name Check");
String optionalMasthead = "Please type in your name";
dlg.getDialogPane().setContentText("What is your name?");
configureSampleDialog(dlg, optionalMasthead);
showDialog(dlg);
});
final Button Hyperlink9 = new Button("Initial Value Set");
Hyperlink9.setOnAction(e -> {
TextInputDialog dlg = new TextInputDialog("Jonathan");
dlg.setTitle("Name Guess");
String optionalMasthead = "Name Guess";
dlg.getDialogPane().setContentText("Pick a name?");
configureSampleDialog(dlg, optionalMasthead);
showDialog(dlg);
});
final Button Hyperlink10 = new Button("Set Choices (< 10)");
Hyperlink10.setOnAction(e -> {
ChoiceDialog dlg = new ChoiceDialog<>("Jonathan",
"Matthew", "Jonathan", "Ian", "Sue", "Hannah");
dlg.setTitle("Name Guess");
String optionalMasthead = "Name Guess";
dlg.getDialogPane().setContentText("Pick a name?");
configureSampleDialog(dlg, optionalMasthead);
showDialog(dlg);
});
final Button Hyperlink11 = new Button("Set Choices (>= 10)");
Hyperlink11.setOnAction(e -> {
ChoiceDialog dlg = new ChoiceDialog<>("Jonathan",
"Matthew", "Jonathan", "Ian", "Sue",
"Hannah", "Julia", "Denise", "Stephan",
"Sarah", "Ron", "Ingrid");
dlg.setTitle("Name Guess");
String optionalMasthead = "Name Guess";
dlg.getDialogPane().setContentText("Pick a name?");
configureSampleDialog(dlg, optionalMasthead);
showDialog(dlg);
});
grid.add(new HBox(10, Hyperlink8, Hyperlink9, Hyperlink10, Hyperlink11), 1, row);
row++;
// --------- ControlsFX-specific Dialogs
Label controlsfxDialogs = new Label("ControlsFX Dialogs:");
controlsfxDialogs.setFont(Font.font(25));
grid.add(controlsfxDialogs, 0, row++, 2, 1);
// *******************************************************************
// Command links
// *******************************************************************
grid.add(createLabel("Pre-built dialogs: "), 0, row);
final Button Hyperlink12 = new Button("Command Links");
Hyperlink12.setOnAction(e -> {
List links = Arrays
.asList(new CommandLinksButtonType(
"Add a network that is in the range of this computer",
"This shows you a list of networks that are currently available and lets you connect to one.", false),
new CommandLinksButtonType(
"Manually create a network profile",
"This creates a new network profile or locates an existing one and saves it on your computer",
true /*default*/),
new CommandLinksButtonType("Create an ad hoc network",
"This creates a temporary network for sharing files or and Internet connection", false));
CommandLinksDialog dlg = new CommandLinksDialog(links);
dlg.setTitle("Manually connect to wireless network");
String optionalMasthead = "Manually connect to wireless network";
dlg.getDialogPane().setContentText("How do you want to add a network?");
configureSampleDialog(dlg, optionalMasthead);
showDialog(dlg);
});
final Button Hyperlink12a = new Button("Font Selector");
Hyperlink12a.setOnAction(e -> {
FontSelectorDialog dlg = new FontSelectorDialog(null);
configureSampleDialog(dlg, "Please select a font!");
showDialog(dlg);
});
final Button Hyperlink12b = new Button("Progress");
Hyperlink12b.setOnAction((ActionEvent e) -> {
Task