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 --- conf/about.html | 6 +++ 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 +++++++++-- 5 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 conf/about.html create mode 100644 src/cuchaz/enigma/gui/AboutDialog.java diff --git a/conf/about.html b/conf/about.html new file mode 100644 index 00000000..b75c1bf0 --- /dev/null +++ b/conf/about.html @@ -0,0 +1,6 @@ + +
A tool for debofuscation of Java code
++
Version: %s
+ \ No newline at end of file diff --git a/src/cuchaz/enigma/Constants.java b/src/cuchaz/enigma/Constants.java index 09787145..a8c4f44c 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 c51eb621..84927fd9 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 00000000..2584182f --- /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 2a539a3f..631089c4 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