org.controlsfx.samples.dialogs.HelloDialog 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 static org.controlsfx.dialog.Dialog.ACTION_NO;
import static org.controlsfx.dialog.Dialog.ACTION_YES;
import static org.controlsfx.dialog.Dialog.ACTION_CANCEL;
import impl.org.controlsfx.i18n.Localization;
import impl.org.controlsfx.i18n.Translations;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.SelectionModel;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleButton;
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.text.Font;
import javafx.stage.Stage;
import javafx.util.Pair;
import org.controlsfx.ControlsFXSample;
import org.controlsfx.control.ButtonBar.ButtonType;
import org.controlsfx.control.SegmentedButton;
import org.controlsfx.control.action.Action;
import org.controlsfx.dialog.Dialog;
import org.controlsfx.dialog.DialogAction;
import org.controlsfx.dialog.Dialogs;
import org.controlsfx.dialog.DialogsAccessor;
import org.controlsfx.samples.Utils;
public class HelloDialog extends ControlsFXSample {
private final ComboBox styleCombobox = new ComboBox<>();
private final CheckBox cbUseLightweightDialog = new CheckBox();
private final CheckBox cbShowMasthead = new CheckBox();
private final CheckBox cbSetOwner = new CheckBox();
private final CheckBox cbCustomGraphic = new CheckBox();
@Override
public String getSampleName() {
return "Dialogs (Deprecated)";
}
@Override
public String getJavaDocURL() {
return Utils.JAVADOC_BASE + "org/controlsfx/dialog/Dialogs.html";
}
@Override
public String getSampleDescription() {
return "The Dialogs class is a simple (yet flexible) API for showing the most common forms of "
+ "(modal) UI dialogs. This class contains a fluent API to make "
+ "building and customizing the pre-built dialogs really easy, "
+ "but for those developers who want complete control, you may "
+ "be interested in instead using the Dialog class (which "
+ "is what all of these pre-built dialogs use as well).";
}
private static final String WINDOWS = "Windows";
private static final String MAC_OS = "Mac OS";
private static final String LINUX = "Linux";
private Stage stage;
private ToggleButton createToggle(final String caption) {
final ToggleButton btn = new ToggleButton(caption);
btn.selectedProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue extends Boolean> arg0,
Boolean oldValue, Boolean newValue) {
DialogsAccessor.setMacOS(MAC_OS.equals(caption));
DialogsAccessor.setWindows(WINDOWS.equals(caption));
DialogsAccessor.setLinux(LINUX.equals(caption));
}
});
return btn;
}
private boolean includeOwner() {
return cbSetOwner.isSelected() || cbUseLightweightDialog.isSelected();
}
@Override
public Node getPanel(final Stage stage) {
this.stage = stage;
// VBox vbox = new VBox(10);
// vbox.setAlignment(Pos.CENTER);
GridPane grid = new GridPane();
grid.setPadding(new Insets(10, 10, 10, 10));
grid.setHgap(10);
grid.setVgap(10);
int row = 0;
// *******************************************************************
// Information Dialog
// *******************************************************************
grid.add(createLabel("Information Dialog: "), 0, row);
final Button Hyperlink2 = new Button("Show");
Hyperlink2.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent e) {
configureSampleDialog(
Dialogs.create()
.title("JavaFX")
.masthead(
isMastheadVisible() ? "Wouldn't this be nice?"
: null)
.message(
"A collection of pre-built JavaFX dialogs?\nSeems like a great idea to me..."))
.showInformation();
}
});
grid.add(new HBox(10, Hyperlink2), 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(new EventHandler() {
@Override
public void handle(ActionEvent e) {
Action response = configureSampleDialog(
Dialogs.create()
.title("You do want dialogs right?")
.masthead(
isMastheadVisible() ? "Just Checkin'"
: null)
.message(
"I was a bit worried that you might not want them, so I wanted to double check."))
.actions(
!cbShowCancel.isSelected() ? new Action[] {
ACTION_YES, ACTION_NO } : new Action[0])
.showConfirm();
System.out.println("response: " + response);
}
});
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(new EventHandler() {
@Override
public void handle(ActionEvent e) {
Action response = configureSampleDialog(
Dialogs.create()
.title("I'm warning you!")
.masthead(
isMastheadVisible() ? "I'm glad I didn't need to use this..."
: null)
.message("This is a warning")).showWarning();
System.out.println("response: " + response);
}
});
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(new EventHandler() {
@Override
public void handle(ActionEvent e) {
Action response = configureSampleDialog(
Dialogs.create()
.title("It looks like you're making a bad decision")
.message("Exception Encountered")
.masthead(
isMastheadVisible() ? "Better change your mind - this is really your last chance! Even longer text that should probably wrap"
: null)).showError();
System.out.println("response: " + response);
}
});
grid.add(new HBox(10, Hyperlink7a), 1, row);
row++;
// *******************************************************************
// More Details Dialog
// *******************************************************************
grid.add(createLabel("'Exception' Dialog: "), 0, row);
final Button Hyperlink5a = new Button("Show");
Hyperlink5a.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent e) {
Action response = configureSampleDialog(
Dialogs.create()
.title("It looks like you're making a bad decision")
.message(
"Better change your mind - this is really your last chance!")
.masthead(
isMastheadVisible() ? "Exception Encountered"
: null)).showException(
new RuntimeException("Exception text"));
System.out.println("response: " + response);
}
});
final Button Hyperlink5b = new Button("Open in new window");
Hyperlink5b.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent e) {
Action response = configureSampleDialog(
Dialogs.create()
.message(
"Better change your mind - this is really your last chance!")
.title("It looks like you're making a bad decision")
.masthead(
isMastheadVisible() ? "Exception Encountered"
: null))
.showExceptionInNewWindow(
new RuntimeException(
"Pending Bad Decision Exception"));
System.out.println("response: " + response);
}
});
grid.add(new HBox(10, Hyperlink5a, Hyperlink5b), 1, row);
row++;
// *******************************************************************
// Input Dialog (with masthead)
// *******************************************************************
grid.add(createLabel("Input Dialog: "), 0, row);
final Button Hyperlink8 = new Button("TextField");
Hyperlink8.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent e) {
Optional response = configureSampleDialog(
Dialogs.create()
.title("Name Check")
.masthead(
isMastheadVisible() ? "Please type in your name"
: null)
.message("What is your name?")).showTextInput();
System.out.println("response: " + response);
}
});
final Button Hyperlink9 = new Button("Initial Value Set");
Hyperlink9.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent e) {
Optional response = configureSampleDialog(
Dialogs.create()
.title("Name Guess")
.masthead(
isMastheadVisible() ? "Name Guess"
: null).message("Pick a name?"))
.showTextInput("Jonathan");
System.out.println("response: " + response);
}
});
final Button Hyperlink10 = new Button("Set Choices (< 10)");
Hyperlink10.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent e) {
Optional response = configureSampleDialog(
Dialogs.create()
.title("Name Guess")
.masthead(
isMastheadVisible() ? "Name Guess"
: null).message("Pick a name?"))
.showChoices("Matthew", "Jonathan", "Ian", "Sue",
"Hannah");
System.out.println("response: " + response);
}
});
final Button Hyperlink11 = new Button("Set Choices (>= 10)");
Hyperlink11.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent e) {
Optional response = configureSampleDialog(
Dialogs.create()
.title("Name Guess")
.masthead(
isMastheadVisible() ? "Name Guess"
: null).message("Pick a name?"))
.showChoices("Matthew", "Jonathan", "Ian", "Sue",
"Hannah", "Julia", "Denise", "Stephan",
"Sarah", "Ron", "Ingrid");
System.out.println("response: " + response);
}
});
grid.add(
new HBox(10, Hyperlink8, Hyperlink9, Hyperlink10, Hyperlink11),
1, row);
row++;
// *******************************************************************
// Command links
// *******************************************************************
grid.add(createLabel("Other pre-built dialogs: "), 0, row);
final Button Hyperlink12 = new Button("Command Links");
Hyperlink12.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent e) {
List links = Arrays
.asList(buildCommandLink(
"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."),
buildCommandLink(
"Manually create a network profile",
"This creates a new network profile or locates an existing one and saves it on your computer",
true /*default*/),
buildCommandLink("Create an ad hoc network",
"This creates a temporary network for sharing files or and Internet connection"));
Action response = configureSampleDialog(
Dialogs.create()
.title("Manually connect to wireless network")
.masthead(
isMastheadVisible() ? "Manually connect to wireless network"
: null)
.message("How do you want to add a network?"))
.showCommandLinks(links);
System.out.println("response: " + response);
}
});
final Button Hyperlink12a = new Button("Font Chooser");
Hyperlink12a.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent e) {
Optional response = configureSampleDialog(Dialogs.create())
.showFontSelector(null);
System.out.println("font: " + response);
}
});
final Button Hyperlink12b = new Button("Progress");
Hyperlink12b.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent e) {
Task