summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jeff2014-07-29 00:37:51 -0400
committerGravatar jeff2014-07-29 00:37:51 -0400
commit1318888e5b37a2d76270c5c330e63d4b5dcf779e (patch)
tree1a26f087424b310fa8c7bf06fcccfb1f92d5bdca /src
parentadded identifier renaming capability (diff)
downloadenigma-fork-1318888e5b37a2d76270c5c330e63d4b5dcf779e.tar.gz
enigma-fork-1318888e5b37a2d76270c5c330e63d4b5dcf779e.tar.xz
enigma-fork-1318888e5b37a2d76270c5c330e63d4b5dcf779e.zip
added start of menu bar
added about bow
Diffstat (limited to 'src')
-rw-r--r--src/cuchaz/enigma/Constants.java3
-rw-r--r--src/cuchaz/enigma/Util.java44
-rw-r--r--src/cuchaz/enigma/gui/AboutDialog.java86
-rw-r--r--src/cuchaz/enigma/gui/Gui.java28
4 files changed, 157 insertions, 4 deletions
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;
13 13
14public class Constants 14public class Constants
15{ 15{
16 public static final String Name = "Enigma";
17 public static final String Version = "0.1";
18 public static final String Url = "http://www.cuchazinteractive.com/enigma";
16 public static final int MiB = 1024*1024; // 1 mebibyte 19 public static final int MiB = 1024*1024; // 1 mebibyte
17 public static final int KiB = 1024; // 1 kebibyte 20 public static final int KiB = 1024; // 1 kebibyte
18} 21}
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 @@
10 ******************************************************************************/ 10 ******************************************************************************/
11package cuchaz.enigma; 11package cuchaz.enigma;
12 12
13import java.awt.Desktop;
13import java.io.Closeable; 14import java.io.Closeable;
14import java.io.IOException; 15import java.io.IOException;
16import java.io.InputStream;
17import java.io.InputStreamReader;
18import java.net.URI;
19import java.net.URISyntaxException;
15import java.util.jar.JarFile; 20import java.util.jar.JarFile;
16 21
22import com.google.common.io.CharStreams;
23
17 24
18public class Util 25public class Util
19{ 26{
@@ -62,4 +69,41 @@ public class Util
62 } 69 }
63 } 70 }
64 } 71 }
72
73 public static String readStreamToString( InputStream in )
74 throws IOException
75 {
76 return CharStreams.toString( new InputStreamReader( in, "UTF-8" ) );
77 }
78
79 public static String readResourceToString( String path )
80 throws IOException
81 {
82 InputStream in = Util.class.getResourceAsStream( path );
83 if( in == null )
84 {
85 throw new IllegalArgumentException( "Resource not found! " + path );
86 }
87 return readStreamToString( in );
88 }
89
90 public static void openUrl( String url )
91 {
92 if( Desktop.isDesktopSupported() )
93 {
94 Desktop desktop = Desktop.getDesktop();
95 try
96 {
97 desktop.browse( new URI( url ) );
98 }
99 catch( IOException ex )
100 {
101 throw new Error( ex );
102 }
103 catch( URISyntaxException ex )
104 {
105 throw new IllegalArgumentException( ex );
106 }
107 }
108 }
65} 109}
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 @@
1package cuchaz.enigma.gui;
2
3import java.awt.Color;
4import java.awt.Container;
5import java.awt.Cursor;
6import java.awt.FlowLayout;
7import java.awt.event.ActionEvent;
8import java.awt.event.ActionListener;
9import java.io.IOException;
10
11import javax.swing.Box;
12import javax.swing.BoxLayout;
13import javax.swing.JButton;
14import javax.swing.JFrame;
15import javax.swing.JLabel;
16import javax.swing.JPanel;
17import javax.swing.WindowConstants;
18
19import cuchaz.enigma.Constants;
20import cuchaz.enigma.Util;
21
22public 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}
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;
30import javax.swing.JFrame; 30import javax.swing.JFrame;
31import javax.swing.JLabel; 31import javax.swing.JLabel;
32import javax.swing.JList; 32import javax.swing.JList;
33import javax.swing.JMenu;
34import javax.swing.JMenuBar;
35import javax.swing.JMenuItem;
33import javax.swing.JPanel; 36import javax.swing.JPanel;
34import javax.swing.JScrollPane; 37import javax.swing.JScrollPane;
35import javax.swing.JSplitPane; 38import javax.swing.JSplitPane;
@@ -42,6 +45,7 @@ import javax.swing.text.BadLocationException;
42import jsyntaxpane.DefaultSyntaxKit; 45import jsyntaxpane.DefaultSyntaxKit;
43import jsyntaxpane.Token; 46import jsyntaxpane.Token;
44import cuchaz.enigma.ClassFile; 47import cuchaz.enigma.ClassFile;
48import cuchaz.enigma.Constants;
45import cuchaz.enigma.analysis.SourceIndex; 49import cuchaz.enigma.analysis.SourceIndex;
46import cuchaz.enigma.mapping.ArgumentEntry; 50import cuchaz.enigma.mapping.ArgumentEntry;
47import cuchaz.enigma.mapping.ClassEntry; 51import cuchaz.enigma.mapping.ClassEntry;
@@ -51,8 +55,6 @@ import cuchaz.enigma.mapping.MethodEntry;
51 55
52public class Gui 56public class Gui
53{ 57{
54 private static final String Name = "Enigma";
55
56 // controls 58 // controls
57 private JFrame m_frame; 59 private JFrame m_frame;
58 private JList<ClassFile> m_obfClasses; 60 private JList<ClassFile> m_obfClasses;
@@ -74,7 +76,7 @@ public class Gui
74 public Gui( ) 76 public Gui( )
75 { 77 {
76 // init frame 78 // init frame
77 m_frame = new JFrame( Name ); 79 m_frame = new JFrame( Constants.Name );
78 final Container pane = m_frame.getContentPane(); 80 final Container pane = m_frame.getContentPane();
79 pane.setLayout( new BorderLayout() ); 81 pane.setLayout( new BorderLayout() );
80 82
@@ -160,6 +162,24 @@ public class Gui
160 JSplitPane splitMain = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, true, splitLeft, rightPanel ); 162 JSplitPane splitMain = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, true, splitLeft, rightPanel );
161 pane.add( splitMain, BorderLayout.CENTER ); 163 pane.add( splitMain, BorderLayout.CENTER );
162 164
165 // init menus
166 JMenuBar menuBar = new JMenuBar();
167 JMenu menu = new JMenu( "Help" );
168 menu.setMnemonic( 'h' );
169 JMenuItem item = new JMenuItem( "About" );
170 item.setMnemonic( 'a' );
171 item.addActionListener( new ActionListener( )
172 {
173 @Override
174 public void actionPerformed( ActionEvent event )
175 {
176 AboutDialog.show( m_frame );
177 }
178 } );
179 menu.add( item );
180 menuBar.add( menu );
181 m_frame.setJMenuBar( menuBar );
182
163 // show the frame 183 // show the frame
164 pane.doLayout(); 184 pane.doLayout();
165 m_frame.setSize( 800, 600 ); 185 m_frame.setSize( 800, 600 );
@@ -176,7 +196,7 @@ public class Gui
176 196
177 public void setTitle( String title ) 197 public void setTitle( String title )
178 { 198 {
179 m_frame.setTitle( Name + " - " + title ); 199 m_frame.setTitle( Constants.Name + " - " + title );
180 } 200 }
181 201
182 public void setObfClasses( List<ClassFile> classes ) 202 public void setObfClasses( List<ClassFile> classes )