summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui/AboutDialog.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/AboutDialog.java')
-rw-r--r--src/main/java/cuchaz/enigma/gui/AboutDialog.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/AboutDialog.java b/src/main/java/cuchaz/enigma/gui/AboutDialog.java
new file mode 100644
index 0000000..a874399
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/AboutDialog.java
@@ -0,0 +1,70 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma.gui;
12
13import java.awt.Color;
14import java.awt.Container;
15import java.awt.Cursor;
16import java.awt.FlowLayout;
17import java.io.IOException;
18
19import javax.swing.*;
20
21import cuchaz.enigma.Constants;
22import cuchaz.enigma.Util;
23
24public class AboutDialog {
25
26 public static void show(JFrame parent) {
27 // init frame
28 final JFrame frame = new JFrame(Constants.Name + " - About");
29 final Container pane = frame.getContentPane();
30 pane.setLayout(new FlowLayout());
31
32 // load the content
33 try {
34 String html = Util.readResourceToString("/about.html");
35 html = String.format(html, Constants.Name, Constants.Version);
36 JLabel label = new JLabel(html);
37 label.setHorizontalAlignment(JLabel.CENTER);
38 pane.add(label);
39 } catch (IOException ex) {
40 throw new Error(ex);
41 }
42
43 // show the link
44 String html = "<html><a href=\"%s\">%s</a></html>";
45 html = String.format(html, Constants.Url, Constants.Url);
46 JButton link = new JButton(html);
47 link.addActionListener(event -> Util.openUrl(Constants.Url));
48 link.setBorderPainted(false);
49 link.setOpaque(false);
50 link.setBackground(Color.WHITE);
51 link.setCursor(new Cursor(Cursor.HAND_CURSOR));
52 link.setFocusable(false);
53 JPanel linkPanel = new JPanel();
54 linkPanel.add(link);
55 pane.add(linkPanel);
56
57 // show ok button
58 JButton okButton = new JButton("Ok");
59 pane.add(okButton);
60 okButton.addActionListener(arg0 -> frame.dispose());
61
62 // show the frame
63 pane.doLayout();
64 frame.setSize(400, 220);
65 frame.setResizable(false);
66 frame.setLocationRelativeTo(parent);
67 frame.setVisible(true);
68 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
69 }
70}