From 1318888e5b37a2d76270c5c330e63d4b5dcf779e Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 29 Jul 2014 00:37:51 -0400 Subject: added start of menu bar added about bow --- src/cuchaz/enigma/gui/AboutDialog.java | 86 ++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/cuchaz/enigma/gui/AboutDialog.java (limited to 'src/cuchaz/enigma/gui/AboutDialog.java') 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 @@ +package cuchaz.enigma.gui; + +import java.awt.Color; +import java.awt.Container; +import java.awt.Cursor; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.WindowConstants; + +import cuchaz.enigma.Constants; +import cuchaz.enigma.Util; + +public class AboutDialog +{ + public static void show( JFrame parent ) + { + // init frame + final JFrame frame = new JFrame( Constants.Name + " - About" ); + final Container pane = frame.getContentPane(); + pane.setLayout( new FlowLayout() ); + + // load the content + try + { + String html = Util.readResourceToString( "/about.html" ); + html = String.format( html, Constants.Name, Constants.Version ); + JLabel label = new JLabel( html ); + label.setHorizontalAlignment( JLabel.CENTER ); + pane.add( label ); + } + catch( IOException ex ) + { + throw new Error( ex ); + } + + // show the link + String html = "%s"; + html = String.format( html, Constants.Url, Constants.Url ); + JButton link = new JButton( html ); + link.addActionListener( new ActionListener( ) + { + @Override + public void actionPerformed( ActionEvent event ) + { + Util.openUrl( Constants.Url ); + } + } ); + link.setBorderPainted( false ); + link.setOpaque( false ); + link.setBackground( Color.WHITE ); + link.setCursor( new Cursor( Cursor.HAND_CURSOR ) ); + link.setFocusable( false ); + JPanel linkPanel = new JPanel(); + linkPanel.add( link ); + pane.add( linkPanel ); + + // show ok button + JButton okButton = new JButton( "Ok" ); + pane.add( okButton ); + okButton.addActionListener( new ActionListener( ) + { + @Override + public void actionPerformed( ActionEvent arg0 ) + { + frame.dispose(); + } + } ); + + // show the frame + pane.doLayout(); + frame.setSize( 400, 220 ); + frame.setResizable( false ); + frame.setLocationRelativeTo( parent ); + frame.setVisible( true ); + frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); + } +} -- cgit v1.2.3