Skip to content

Commit

Permalink
Add about box
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Chwedczuk committed Dec 31, 2021
1 parent 8775123 commit 10d4282
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 6 deletions.
4 changes: 3 additions & 1 deletion gui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@
<includes>
<include>**/*.fxml</include>
<include>**/*.css</include>
<!-- icons -->
<!-- icons & images -->
<include>**/*.png</include>
<include>**/*.jpg</include>
<include>**/*.jpeg</include>
</includes>
<filtering>false</filtering>
</resource>
Expand Down
3 changes: 2 additions & 1 deletion gui/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

// Allow @FXML injection to private fields.
opens pl.marcinchwedczuk.elfviewer.gui.mainwindow;
exports pl.marcinchwedczuk.elfviewer.gui.mainwindow.renderer.dto;
opens pl.marcinchwedczuk.elfviewer.gui.aboutdialog;
opens pl.marcinchwedczuk.elfviewer.gui.mainwindow.renderer.dto;
exports pl.marcinchwedczuk.elfviewer.gui.mainwindow.renderer.dto;
}
10 changes: 10 additions & 0 deletions gui/src/main/java/pl/marcinchwedczuk/elfviewer/gui/App.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
package pl.marcinchwedczuk.elfviewer.gui;

import javafx.application.Application;
import javafx.application.HostServices;
import javafx.stage.Stage;
import pl.marcinchwedczuk.elfviewer.gui.mainwindow.MainWindow;

/**
* JavaFX App
*/
public class App extends Application {
private static HostServices hostServices = null;
public static HostServices hostServices() {
if (hostServices == null) {
throw new IllegalStateException();
}
return hostServices;
}

@Override
public void start(Stage stage) {
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
e.printStackTrace();
showExceptionDialog(e);
});

hostServices = this.getHostServices();
MainWindow.showOn(stage);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>

<GridPane fx:id="rootElement" hgap="4.0" vgap="4.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="pl.marcinchwedczuk.elfviewer.gui.aboutdialog.AboutDialog">
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="ALWAYS" />
</rowConstraints>
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" />
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" />
</columnConstraints>
<children>
<ImageView fitWidth="200.0" pickOnBounds="true" preserveRatio="true" GridPane.rowSpan="2147483647">
<image>
<Image url="@about-panache.jpg" />
</image>
</ImageView>
<AnchorPane GridPane.columnIndex="1">
<children>
<Button cancelButton="true" defaultButton="true" layoutX="163.0" layoutY="314.0" minWidth="100.0" mnemonicParsing="false" onAction="#guiClose" text="OK" />
<Label layoutX="3.0" layoutY="14.0" text="Elf Viewer">
<font>
<Font name="System Bold" size="24.0" />
</font>
</Label>
<Label layoutX="3.0" layoutY="43.0" text="by Marcin &quot;0xmarcin&quot; Chwedczuk" />
<Label layoutX="3.0" layoutY="60.0" text="MIT License" />
<Hyperlink layoutX="166.0" layoutY="89.0" onAction="#linkIcons8" text="icons8.com" />
<Label layoutX="3.0" layoutY="92.0" text="This program uses icons from:" />
<Hyperlink layoutY="134.0" onAction="#linkSourceCode" text="Source Code (GitHub)" />
<Hyperlink layoutY="159.0" onAction="#linkBugReport" text="Report Bug (GitHub)" />
</children>
<GridPane.margin>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
</GridPane.margin>
</AnchorPane>
</children>
<padding>
<Insets bottom="4.0" left="4.0" right="4.0" top="4.0" />
</padding>
</GridPane>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package pl.marcinchwedczuk.elfviewer.gui.aboutdialog;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
import pl.marcinchwedczuk.elfviewer.gui.App;

import java.io.IOException;

public class AboutDialog {
public static AboutDialog show(Window owner) {
try {
FXMLLoader loader = new FXMLLoader(
AboutDialog.class.getResource("AboutDialog.fxml"));

Stage childWindow = new Stage();
childWindow.initOwner(owner);
childWindow.initModality(Modality.WINDOW_MODAL);
childWindow.initStyle(StageStyle.UTILITY);
childWindow.setTitle("About...");
childWindow.setScene(new Scene(loader.load()));
childWindow.setResizable(false);
childWindow.sizeToScene();

AboutDialog controller = loader.getController();
childWindow.show();
return controller;
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@FXML
private GridPane rootElement;

@FXML
private void guiClose() {
((Stage)rootElement.getScene().getWindow()).close();
}

@FXML
private void linkIcons8() {
App.hostServices().showDocument("https://icons8.com/");
}

@FXML
private void linkSourceCode() {
App.hostServices().showDocument("https://github.com/marcin-chwedczuk/elf-viewer");
}

@FXML
private void linkBugReport() {
App.hostServices().showDocument("https://github.com/marcin-chwedczuk/elf-viewer/issues");
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pl.marcinchwedczuk.elfviewer.elfreader.elf.arch.LongNativeWord;
import pl.marcinchwedczuk.elfviewer.elfreader.elf.shared.ElfFile;
import pl.marcinchwedczuk.elfviewer.elfreader.io.FileSystemFile;
import pl.marcinchwedczuk.elfviewer.gui.aboutdialog.AboutDialog;
import pl.marcinchwedczuk.elfviewer.gui.mainwindow.renderer.NothingRenderer;

import java.io.File;
Expand All @@ -43,7 +44,7 @@ public static MainWindow showOn(Stage window) {
}
});

controller.window = window;
controller.thisWindow = window;

window.show();

Expand All @@ -53,7 +54,7 @@ public static MainWindow showOn(Stage window) {
}
}

private Window window;
private Window thisWindow;

@FXML
private TextField filterText;
Expand Down Expand Up @@ -161,7 +162,7 @@ private void tableViewKeyPressed(KeyEvent event) {

@FXML
private void guiOpen() {
File f = openFileChooser.showOpenDialog(window);
File f = openFileChooser.showOpenDialog(thisWindow);
if (f != null) {
loadElfFile(f);
}
Expand All @@ -174,7 +175,7 @@ private void guiExit() {

@FXML
private void guiAbout() {

AboutDialog.show(thisWindow);
}

@FXML
Expand Down

0 comments on commit 10d4282

Please sign in to comment.