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/Constants.java | 3 ++
src/cuchaz/enigma/Util.java | 44 +++++++++++++++++
src/cuchaz/enigma/gui/AboutDialog.java | 86 ++++++++++++++++++++++++++++++++++
src/cuchaz/enigma/gui/Gui.java | 28 +++++++++--
4 files changed, 157 insertions(+), 4 deletions(-)
create mode 100644 src/cuchaz/enigma/gui/AboutDialog.java
(limited to 'src/cuchaz')
diff --git a/src/cuchaz/enigma/Constants.java b/src/cuchaz/enigma/Constants.java
index 0978714..a8c4f44 100644
--- a/src/cuchaz/enigma/Constants.java
+++ b/src/cuchaz/enigma/Constants.java
@@ -13,6 +13,9 @@ package cuchaz.enigma;
public class Constants
{
+ public static final String Name = "Enigma";
+ public static final String Version = "0.1";
+ public static final String Url = "http://www.cuchazinteractive.com/enigma";
public static final int MiB = 1024*1024; // 1 mebibyte
public static final int KiB = 1024; // 1 kebibyte
}
diff --git a/src/cuchaz/enigma/Util.java b/src/cuchaz/enigma/Util.java
index c51eb62..84927fd 100644
--- a/src/cuchaz/enigma/Util.java
+++ b/src/cuchaz/enigma/Util.java
@@ -10,10 +10,17 @@
******************************************************************************/
package cuchaz.enigma;
+import java.awt.Desktop;
import java.io.Closeable;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.jar.JarFile;
+import com.google.common.io.CharStreams;
+
public class Util
{
@@ -62,4 +69,41 @@ public class Util
}
}
}
+
+ public static String readStreamToString( InputStream in )
+ throws IOException
+ {
+ return CharStreams.toString( new InputStreamReader( in, "UTF-8" ) );
+ }
+
+ public static String readResourceToString( String path )
+ throws IOException
+ {
+ InputStream in = Util.class.getResourceAsStream( path );
+ if( in == null )
+ {
+ throw new IllegalArgumentException( "Resource not found! " + path );
+ }
+ return readStreamToString( in );
+ }
+
+ public static void openUrl( String url )
+ {
+ if( Desktop.isDesktopSupported() )
+ {
+ Desktop desktop = Desktop.getDesktop();
+ try
+ {
+ desktop.browse( new URI( url ) );
+ }
+ catch( IOException ex )
+ {
+ throw new Error( ex );
+ }
+ catch( URISyntaxException ex )
+ {
+ throw new IllegalArgumentException( ex );
+ }
+ }
+ }
}
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 );
+ }
+}
diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java
index 2a539a3..631089c 100644
--- a/src/cuchaz/enigma/gui/Gui.java
+++ b/src/cuchaz/enigma/gui/Gui.java
@@ -30,6 +30,9 @@ import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
@@ -42,6 +45,7 @@ import javax.swing.text.BadLocationException;
import jsyntaxpane.DefaultSyntaxKit;
import jsyntaxpane.Token;
import cuchaz.enigma.ClassFile;
+import cuchaz.enigma.Constants;
import cuchaz.enigma.analysis.SourceIndex;
import cuchaz.enigma.mapping.ArgumentEntry;
import cuchaz.enigma.mapping.ClassEntry;
@@ -51,8 +55,6 @@ import cuchaz.enigma.mapping.MethodEntry;
public class Gui
{
- private static final String Name = "Enigma";
-
// controls
private JFrame m_frame;
private JList m_obfClasses;
@@ -74,7 +76,7 @@ public class Gui
public Gui( )
{
// init frame
- m_frame = new JFrame( Name );
+ m_frame = new JFrame( Constants.Name );
final Container pane = m_frame.getContentPane();
pane.setLayout( new BorderLayout() );
@@ -160,6 +162,24 @@ public class Gui
JSplitPane splitMain = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, true, splitLeft, rightPanel );
pane.add( splitMain, BorderLayout.CENTER );
+ // init menus
+ JMenuBar menuBar = new JMenuBar();
+ JMenu menu = new JMenu( "Help" );
+ menu.setMnemonic( 'h' );
+ JMenuItem item = new JMenuItem( "About" );
+ item.setMnemonic( 'a' );
+ item.addActionListener( new ActionListener( )
+ {
+ @Override
+ public void actionPerformed( ActionEvent event )
+ {
+ AboutDialog.show( m_frame );
+ }
+ } );
+ menu.add( item );
+ menuBar.add( menu );
+ m_frame.setJMenuBar( menuBar );
+
// show the frame
pane.doLayout();
m_frame.setSize( 800, 600 );
@@ -176,7 +196,7 @@ public class Gui
public void setTitle( String title )
{
- m_frame.setTitle( Name + " - " + title );
+ m_frame.setTitle( Constants.Name + " - " + title );
}
public void setObfClasses( List classes )
--
cgit v1.2.3