001package conexp.fx.gui.dialog;
002
003/*
004 * #%L
005 * Concept Explorer FX
006 * %%
007 * Copyright (C) 2010 - 2023 Francesco Kriegel
008 * %%
009 * This program is free software: you can redistribute it and/or modify
010 * it under the terms of the GNU General Public License as
011 * published by the Free Software Foundation, either version 3 of the
012 * License, or (at your option) any later version.
013 * 
014 * This program is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 * 
019 * You should have received a copy of the GNU General Public
020 * License along with this program.  If not, see
021 * <http://www.gnu.org/licenses/gpl-3.0.html>.
022 * #L%
023 */
024
025import javafx.event.EventHandler;
026import javafx.scene.Scene;
027import javafx.scene.SceneBuilder;
028import javafx.scene.layout.BorderPane;
029import javafx.stage.Modality;
030import javafx.stage.Stage;
031import javafx.stage.StageBuilder;
032import javafx.stage.StageStyle;
033import javafx.stage.Window;
034import javafx.stage.WindowEvent;
035
036public abstract class SimpleDialog {
037
038  protected final Stage      stage;
039  protected final Scene      scene;
040  protected final BorderPane pane;
041
042  protected SimpleDialog(final String title, final Window parent) {
043    super();
044    this.pane = new BorderPane();
045    this.scene = SceneBuilder.create().root(pane).build();
046    this.stage = StageBuilder.create().title(title).style(StageStyle.UTILITY).scene(scene).build();
047    this.stage.initModality(Modality.WINDOW_MODAL);
048    this.stage.initOwner(parent);
049    this.stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
050
051      @Override
052      public final void handle(final WindowEvent event) {
053        onClose();
054      }
055    });
056  }
057
058  protected abstract void onClose();
059
060  public void show() {
061    stage.show();
062  }
063
064  public void showAndWait() {
065    stage.showAndWait();
066  }
067}