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 java.awt.Desktop;
026import java.net.URI;
027
028import conexp.fx.gui.ConExpFX;
029import javafx.geometry.InsetsBuilder;
030import javafx.scene.control.Hyperlink;
031import javafx.scene.control.HyperlinkBuilder;
032import javafx.scene.control.Label;
033import javafx.scene.control.LabelBuilder;
034import javafx.scene.image.Image;
035import javafx.scene.image.ImageView;
036import javafx.scene.image.ImageViewBuilder;
037import javafx.scene.layout.HBox;
038import javafx.scene.layout.HBoxBuilder;
039import javafx.scene.layout.VBox;
040import javafx.scene.layout.VBoxBuilder;
041
042public final class InfoDialog extends FXDialog<Void> {
043
044  private final ConExpFX cfx;
045
046  public InfoDialog(final ConExpFX cfx) {
047    super(cfx.primaryStage, Style.INFO, "Info", "", content(cfx));
048    this.cfx = cfx;
049  }
050
051  private static VBox content(final ConExpFX cfx) {
052    final Hyperlink homepage =
053        HyperlinkBuilder.create().text("http://lat.inf.tu-dresden.de/~francesco").onAction(ev -> {
054          try {
055            Desktop.getDesktop().browse(new URI("http://lat.inf.tu-dresden.de/~francesco"));
056          } catch (Exception e) {
057            new ErrorDialog(cfx.primaryStage, e).showAndWait();
058          }
059        }).build();
060    final Hyperlink email = HyperlinkBuilder.create().text("mailto:francesco.kriegel@tu-dresden.de").onAction(ev -> {
061      try {
062        Desktop.getDesktop().mail(new URI("mailto:francesco.kriegel@tu-dresden.de"));
063      } catch (Exception e) {
064        new ErrorDialog(cfx.primaryStage, e).showAndWait();
065      }
066    }).build();
067    final Label label = LabelBuilder
068        .create()
069        .text("Concept Explorer FX\r\n" + "(c) 2010-2018, Francesco Kriegel, TU Dresden\r\n" + "GNU General Public License v3 (GPL-3)")
070        .build();
071    final ImageView icon =
072        imageView("image/conexp-fx.png", 64, "http://lat.inf.tu-dresden.de/~francesco/conexp-fx/conexp-fx.html");
073    final HBox title = HBoxBuilder
074        .create()
075        .spacing(4)
076        .padding(InsetsBuilder.create().left(0).top(0).right(0).bottom(0).build())
077        .children(icon, label)
078        .build();
079    final VBox contact = VBoxBuilder
080        .create()
081        .spacing(0)
082        .padding(InsetsBuilder.create().left(0).top(0).right(0).bottom(0).build())
083        .children(email, homepage)
084        .build();
085    final HBox icons1 = HBoxBuilder
086        .create()
087        .spacing(5)
088        .padding(InsetsBuilder.create().left(0).top(0).right(0).bottom(0).build())
089        .children(
090            imageView("image/logo_tu_black.png", 40, "http://tu-dresden.de/en"),
091            imageView("image/ganter.gif", 40, "http://tu-dresden.de/Members/bernhard.ganter"))
092        .build();
093    final HBox icons2 = HBoxBuilder
094        .create()
095        .spacing(5)
096        .padding(InsetsBuilder.create().left(0).top(0).right(0).bottom(0).build())
097        .children(
098            imageView("image/Javafx_logo_color.png", 40, "http://docs.oracle.com/javafx/"),
099            imageView("image/apache.png", 40, "http://www.apache.org/licenses/LICENSE-2.0.html"),
100            imageView("image/mavenlogo_builtby_w.gif", 40, "http://maven.apache.org/"))
101        .build();
102    return VBoxBuilder
103        .create()
104        .spacing(5)
105        .padding(InsetsBuilder.create().left(10).top(10).right(10).bottom(10).build())
106        .children(title, contact, icons1, icons2)
107        .build();
108  }
109
110  private static ImageView imageView(final String image, final int h, final String url) {
111    final Image i = new Image(ConExpFX.class.getResourceAsStream(image));
112    final double r = i.getWidth() / i.getHeight();
113    return ImageViewBuilder.create().onMouseClicked(ev -> {
114      try {
115        Desktop.getDesktop().browse(new URI(url));
116      } catch (Exception e) {
117        e.printStackTrace();
118      }
119    }).image(i).fitHeight(h).fitWidth(r * h).build();
120  }
121}