All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dua3.utility.fx.controls.InputDialogBuilder Maven / Gradle / Ivy

There is a newer version: 15.0.2
Show newest version
// Copyright 2019 Axel Howind
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.dua3.utility.fx.controls;

import org.jspecify.annotations.Nullable;
import com.dua3.utility.options.Arguments;
import com.dua3.utility.options.Option;
import javafx.beans.binding.Bindings;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.stage.FileChooser;
import javafx.stage.Window;

import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

/**
 * Builder for Alert Dialogs.
 * 

* Provides a fluent interface to create Alerts. */ public class InputDialogBuilder extends AbstractDialogBuilder> implements InputBuilder { private final InputPaneBuilder pb = new InputPaneBuilder(); InputDialogBuilder(@Nullable Window parentWindow) { super(parentWindow); setDialogSupplier(this::createDialog); } private InputDialog createDialog() { InputDialog dlg = new InputDialog(); InputPane dialogPane = pb.build(); dialogPane.init(); dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); final Button okButton = (Button) dialogPane.lookupButton(ButtonType.OK); okButton.disableProperty().bind(Bindings.not(dialogPane.validProperty())); dlg.setDialogPane(dialogPane); return dlg; } @Override public InputDialogBuilder add(String id, String label, Class type, Supplier dflt, InputControl control) { pb.add(id, label, type, dflt, control); return this; } @Override public InputDialogBuilder add(String id, Class type, Supplier dflt, InputControl control) { pb.add(id, type, dflt, control); return this; } @Override public InputDialogBuilder addNode(String id, String label, Node node) { pb.addNode(id, label, node); return this; } @Override public InputDialogBuilder addNode(String id, Node node) { pb.addNode(id, node); return this; } @Override public InputDialogBuilder columns(int columns) { pb.columns(columns); return this; } @Override public InputDialogBuilder string(String id, String label, Supplier dflt, Function> validate) { pb.string(id, label, dflt, validate); return this; } @Override public InputDialogBuilder integer(String id, String label, Supplier dflt, Function> validate) { pb.integer(id, label, dflt, validate); return this; } @Override public InputDialogBuilder decimal(String id, String label, Supplier dflt, Function> validate) { pb.decimal(id, label, dflt, validate); return this; } @Override public InputDialogBuilder checkBox(String id, String label, Supplier dflt, String text, Function> validate) { pb.checkBox(id, label, dflt, text, validate); return this; } @Override public InputDialogBuilder comboBox(String id, String label, Supplier dflt, Class cls, Collection items, Function> validate) { pb.comboBox(id, label, dflt, cls, items, validate); return this; } @Override public InputDialogBuilder comboBoxEx( String id, String label, @Nullable UnaryOperator edit, @Nullable Supplier add, @Nullable BiPredicate, T> remove, Function format, Supplier dflt, Class cls, Collection items, Function> validate) { pb.comboBoxEx(id, label, edit, add, remove, format, dflt, cls, items, validate); return this; } @Override public InputDialogBuilder radioList(String id, String label, Supplier dflt, Class cls, Collection items, Function> validate) { pb.radioList(id, label, dflt, cls, items, validate); return this; } @Override public InputDialogBuilder options(String id, String label, Supplier dflt, Supplier>> options) { pb.options(id, label, dflt, options); return this; } @Override public InputDialogBuilder options(String id, Supplier dflt, Supplier>> options) { pb.options(id, dflt, options); return this; } @Override public InputDialogBuilder chooseFile(String id, String label, Supplier dflt, FileDialogMode mode, boolean existingOnly, Collection filter, Function> validate) { pb.chooseFile(id, label, dflt, mode, existingOnly, filter, validate); return this; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy