|
| 1 | +/** |
| 2 | + * @file About.java |
| 3 | + * |
| 4 | + */ |
| 5 | +/* Copyright (C) 2022 by Arjan van Vught mailto:[email protected] |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | +
|
| 14 | + * The above copyright notice and this permission notice shall be included in |
| 15 | + * all copies or substantial portions of the Software. |
| 16 | +
|
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | + * THE SOFTWARE. |
| 24 | + */ |
| 25 | + |
| 26 | +package org.gd32.dmx; |
| 27 | + |
| 28 | +import java.awt.Color; |
| 29 | +import java.awt.Desktop; |
| 30 | +import java.io.IOException; |
| 31 | +import java.net.URI; |
| 32 | + |
| 33 | +import javax.swing.GroupLayout; |
| 34 | +import javax.swing.GroupLayout.Alignment; |
| 35 | +import javax.swing.JDialog; |
| 36 | +import javax.swing.JLabel; |
| 37 | +import javax.swing.JTextField; |
| 38 | +import javax.swing.JTextPane; |
| 39 | +import javax.swing.LayoutStyle.ComponentPlacement; |
| 40 | +import javax.swing.SwingConstants; |
| 41 | +import javax.swing.event.HyperlinkEvent; |
| 42 | +import javax.swing.event.HyperlinkListener; |
| 43 | + |
| 44 | +public class About extends JDialog { |
| 45 | + private static final long serialVersionUID = 989628609152233931L; |
| 46 | + private JTextField txtArjan; |
| 47 | + private JLabel lblBuildNumber; |
| 48 | + |
| 49 | + public static void main(String[] args) { |
| 50 | + try { |
| 51 | + About dialog = new About(); |
| 52 | + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
| 53 | + dialog.setVisible(true); |
| 54 | + } catch (Exception e) { |
| 55 | + e.printStackTrace(); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + public About() { |
| 60 | + getContentPane().setBackground(Color.WHITE); |
| 61 | + setModal(true); |
| 62 | + setResizable(false); |
| 63 | + setTitle("About"); |
| 64 | + setBounds(100, 100, 439, 170); |
| 65 | + |
| 66 | + JTextPane htmlURL = new JTextPane(); |
| 67 | + htmlURL.setEditable(false); |
| 68 | + htmlURL.setContentType("text/html"); |
| 69 | + htmlURL.setText("<html>Website <a href=\"http://www.gd32-dmx.org\">http://www.gd32-dmx.org</a></html>"); |
| 70 | + htmlURL.addHyperlinkListener(new HyperlinkListener() { |
| 71 | + @Override |
| 72 | + public void hyperlinkUpdate(HyperlinkEvent e) { |
| 73 | + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
| 74 | + String url = e.getURL().toString(); |
| 75 | + try { |
| 76 | + Desktop.getDesktop().browse(URI.create(url)); |
| 77 | + } catch (IOException e1) { |
| 78 | + e1.printStackTrace(); |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + }); |
| 83 | + |
| 84 | + JTextPane htmlGitHub = new JTextPane(); |
| 85 | + htmlGitHub.setEditable(false); |
| 86 | + htmlGitHub.setContentType("text/html"); |
| 87 | + htmlGitHub.setText( |
| 88 | + "<html>Source <a href=\"https://github.com/vanvught/GD32F-Firmware-Update-UI\">https://github.com/vanvught/GD32F-Firmware-Update-UI</a></html>\""); |
| 89 | + htmlGitHub.addHyperlinkListener(new HyperlinkListener() { |
| 90 | + @Override |
| 91 | + public void hyperlinkUpdate(HyperlinkEvent e) { |
| 92 | + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
| 93 | + String url = e.getURL().toString(); |
| 94 | + try { |
| 95 | + Desktop.getDesktop().browse(URI.create(url)); |
| 96 | + } catch (IOException e1) { |
| 97 | + e1.printStackTrace(); |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + }); |
| 102 | + |
| 103 | + JTextPane htmlDonate = new JTextPane(); |
| 104 | + htmlDonate.setEditable(false); |
| 105 | + htmlDonate.setContentType("text/html"); |
| 106 | + htmlDonate.setText( |
| 107 | + "<html>PayPal.Me <b>Donate</b> <a href=\"https://paypal.me/AvanVught\">https://paypal.me/AvanVught</a></html>\""); |
| 108 | + htmlDonate.addHyperlinkListener(new HyperlinkListener() { |
| 109 | + @Override |
| 110 | + public void hyperlinkUpdate(HyperlinkEvent e) { |
| 111 | + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
| 112 | + String url = e.getURL().toString(); |
| 113 | + try { |
| 114 | + Desktop.getDesktop().browse(URI.create(url)); |
| 115 | + } catch (IOException e1) { |
| 116 | + e1.printStackTrace(); |
| 117 | + } |
| 118 | + } |
| 119 | + } |
| 120 | + }); |
| 121 | + |
| 122 | + txtArjan = new JTextField(); |
| 123 | + txtArjan.setBorder(null); |
| 124 | + txtArjan.setHorizontalAlignment(SwingConstants.CENTER); |
| 125 | + txtArjan.setText("(C) 2022 Arjan van Vught"); |
| 126 | + txtArjan.setEditable(false); |
| 127 | + txtArjan.setColumns(10); |
| 128 | + |
| 129 | + lblBuildNumber = new JLabel("Build.Number"); |
| 130 | + |
| 131 | + JLabel lblBuild = new JLabel("Version:"); |
| 132 | + GroupLayout groupLayout = new GroupLayout(getContentPane()); |
| 133 | + groupLayout.setHorizontalGroup( |
| 134 | + groupLayout.createParallelGroup(Alignment.LEADING) |
| 135 | + .addGroup(groupLayout.createSequentialGroup() |
| 136 | + .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) |
| 137 | + .addGroup(groupLayout.createSequentialGroup() |
| 138 | + .addGap(6) |
| 139 | + .addComponent(htmlURL, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) |
| 140 | + .addComponent(txtArjan, GroupLayout.PREFERRED_SIZE, 430, GroupLayout.PREFERRED_SIZE) |
| 141 | + .addGroup(groupLayout.createSequentialGroup() |
| 142 | + .addGap(6) |
| 143 | + .addComponent(htmlGitHub, GroupLayout.PREFERRED_SIZE, 365, GroupLayout.PREFERRED_SIZE)) |
| 144 | + .addGroup(groupLayout.createSequentialGroup() |
| 145 | + .addContainerGap() |
| 146 | + .addComponent(htmlDonate, GroupLayout.PREFERRED_SIZE, 295, GroupLayout.PREFERRED_SIZE))) |
| 147 | + .addGap(9)) |
| 148 | + .addGroup(groupLayout.createSequentialGroup() |
| 149 | + .addContainerGap() |
| 150 | + .addComponent(lblBuild) |
| 151 | + .addPreferredGap(ComponentPlacement.RELATED) |
| 152 | + .addComponent(lblBuildNumber, GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE) |
| 153 | + .addGap(281)) |
| 154 | + ); |
| 155 | + groupLayout.setVerticalGroup( |
| 156 | + groupLayout.createParallelGroup(Alignment.LEADING) |
| 157 | + .addGroup(groupLayout.createSequentialGroup() |
| 158 | + .addGap(7) |
| 159 | + .addComponent(htmlURL, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) |
| 160 | + .addGap(6) |
| 161 | + .addComponent(htmlGitHub, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) |
| 162 | + .addGap(9) |
| 163 | + .addComponent(htmlDonate, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) |
| 164 | + .addPreferredGap(ComponentPlacement.RELATED) |
| 165 | + .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) |
| 166 | + .addComponent(lblBuild) |
| 167 | + .addComponent(lblBuildNumber)) |
| 168 | + .addPreferredGap(ComponentPlacement.RELATED) |
| 169 | + .addComponent(txtArjan, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) |
| 170 | + .addGap(25)) |
| 171 | + ); |
| 172 | + getContentPane().setLayout(groupLayout); |
| 173 | + |
| 174 | + } |
| 175 | + |
| 176 | + public void setBuildNumber(String buildNumber) { |
| 177 | + lblBuildNumber.setText(buildNumber); |
| 178 | + } |
| 179 | +} |
0 commit comments