diff options
Diffstat (limited to 'src/cuchaz/enigma/gui/AboutDialog.java')
| -rw-r--r-- | src/cuchaz/enigma/gui/AboutDialog.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/gui/AboutDialog.java b/src/cuchaz/enigma/gui/AboutDialog.java new file mode 100644 index 0000000..2584182 --- /dev/null +++ b/src/cuchaz/enigma/gui/AboutDialog.java | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | package cuchaz.enigma.gui; | ||
| 2 | |||
| 3 | import java.awt.Color; | ||
| 4 | import java.awt.Container; | ||
| 5 | import java.awt.Cursor; | ||
| 6 | import java.awt.FlowLayout; | ||
| 7 | import java.awt.event.ActionEvent; | ||
| 8 | import java.awt.event.ActionListener; | ||
| 9 | import java.io.IOException; | ||
| 10 | |||
| 11 | import javax.swing.Box; | ||
| 12 | import javax.swing.BoxLayout; | ||
| 13 | import javax.swing.JButton; | ||
| 14 | import javax.swing.JFrame; | ||
| 15 | import javax.swing.JLabel; | ||
| 16 | import javax.swing.JPanel; | ||
| 17 | import javax.swing.WindowConstants; | ||
| 18 | |||
| 19 | import cuchaz.enigma.Constants; | ||
| 20 | import cuchaz.enigma.Util; | ||
| 21 | |||
| 22 | public class AboutDialog | ||
| 23 | { | ||
| 24 | public static void show( JFrame parent ) | ||
| 25 | { | ||
| 26 | // init frame | ||
| 27 | final JFrame frame = new JFrame( Constants.Name + " - About" ); | ||
| 28 | final Container pane = frame.getContentPane(); | ||
| 29 | pane.setLayout( new FlowLayout() ); | ||
| 30 | |||
| 31 | // load the content | ||
| 32 | try | ||
| 33 | { | ||
| 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 | } | ||
| 40 | catch( IOException ex ) | ||
| 41 | { | ||
| 42 | throw new Error( ex ); | ||
| 43 | } | ||
| 44 | |||
| 45 | // show the link | ||
| 46 | String html = "<html><a href=\"%s\">%s</a></html>"; | ||
| 47 | html = String.format( html, Constants.Url, Constants.Url ); | ||
| 48 | JButton link = new JButton( html ); | ||
| 49 | link.addActionListener( new ActionListener( ) | ||
| 50 | { | ||
| 51 | @Override | ||
| 52 | public void actionPerformed( ActionEvent event ) | ||
| 53 | { | ||
| 54 | Util.openUrl( Constants.Url ); | ||
| 55 | } | ||
| 56 | } ); | ||
| 57 | link.setBorderPainted( false ); | ||
| 58 | link.setOpaque( false ); | ||
| 59 | link.setBackground( Color.WHITE ); | ||
| 60 | link.setCursor( new Cursor( Cursor.HAND_CURSOR ) ); | ||
| 61 | link.setFocusable( false ); | ||
| 62 | JPanel linkPanel = new JPanel(); | ||
| 63 | linkPanel.add( link ); | ||
| 64 | pane.add( linkPanel ); | ||
| 65 | |||
| 66 | // show ok button | ||
| 67 | JButton okButton = new JButton( "Ok" ); | ||
| 68 | pane.add( okButton ); | ||
| 69 | okButton.addActionListener( new ActionListener( ) | ||
| 70 | { | ||
| 71 | @Override | ||
| 72 | public void actionPerformed( ActionEvent arg0 ) | ||
| 73 | { | ||
| 74 | frame.dispose(); | ||
| 75 | } | ||
| 76 | } ); | ||
| 77 | |||
| 78 | // show the frame | ||
| 79 | pane.doLayout(); | ||
| 80 | frame.setSize( 400, 220 ); | ||
| 81 | frame.setResizable( false ); | ||
| 82 | frame.setLocationRelativeTo( parent ); | ||
| 83 | frame.setVisible( true ); | ||
| 84 | frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); | ||
| 85 | } | ||
| 86 | } | ||