diff options
| author | 2014-07-29 00:37:51 -0400 | |
|---|---|---|
| committer | 2014-07-29 00:37:51 -0400 | |
| commit | 1318888e5b37a2d76270c5c330e63d4b5dcf779e (patch) | |
| tree | 1a26f087424b310fa8c7bf06fcccfb1f92d5bdca /src | |
| parent | added identifier renaming capability (diff) | |
| download | enigma-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.java | 3 | ||||
| -rw-r--r-- | src/cuchaz/enigma/Util.java | 44 | ||||
| -rw-r--r-- | src/cuchaz/enigma/gui/AboutDialog.java | 86 | ||||
| -rw-r--r-- | src/cuchaz/enigma/gui/Gui.java | 28 |
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 | ||
| 14 | public class Constants | 14 | public 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 | ******************************************************************************/ |
| 11 | package cuchaz.enigma; | 11 | package cuchaz.enigma; |
| 12 | 12 | ||
| 13 | import java.awt.Desktop; | ||
| 13 | import java.io.Closeable; | 14 | import java.io.Closeable; |
| 14 | import java.io.IOException; | 15 | import java.io.IOException; |
| 16 | import java.io.InputStream; | ||
| 17 | import java.io.InputStreamReader; | ||
| 18 | import java.net.URI; | ||
| 19 | import java.net.URISyntaxException; | ||
| 15 | import java.util.jar.JarFile; | 20 | import java.util.jar.JarFile; |
| 16 | 21 | ||
| 22 | import com.google.common.io.CharStreams; | ||
| 23 | |||
| 17 | 24 | ||
| 18 | public class Util | 25 | public 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 @@ | |||
| 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 | } | ||
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; | |||
| 30 | import javax.swing.JFrame; | 30 | import javax.swing.JFrame; |
| 31 | import javax.swing.JLabel; | 31 | import javax.swing.JLabel; |
| 32 | import javax.swing.JList; | 32 | import javax.swing.JList; |
| 33 | import javax.swing.JMenu; | ||
| 34 | import javax.swing.JMenuBar; | ||
| 35 | import javax.swing.JMenuItem; | ||
| 33 | import javax.swing.JPanel; | 36 | import javax.swing.JPanel; |
| 34 | import javax.swing.JScrollPane; | 37 | import javax.swing.JScrollPane; |
| 35 | import javax.swing.JSplitPane; | 38 | import javax.swing.JSplitPane; |
| @@ -42,6 +45,7 @@ import javax.swing.text.BadLocationException; | |||
| 42 | import jsyntaxpane.DefaultSyntaxKit; | 45 | import jsyntaxpane.DefaultSyntaxKit; |
| 43 | import jsyntaxpane.Token; | 46 | import jsyntaxpane.Token; |
| 44 | import cuchaz.enigma.ClassFile; | 47 | import cuchaz.enigma.ClassFile; |
| 48 | import cuchaz.enigma.Constants; | ||
| 45 | import cuchaz.enigma.analysis.SourceIndex; | 49 | import cuchaz.enigma.analysis.SourceIndex; |
| 46 | import cuchaz.enigma.mapping.ArgumentEntry; | 50 | import cuchaz.enigma.mapping.ArgumentEntry; |
| 47 | import cuchaz.enigma.mapping.ClassEntry; | 51 | import cuchaz.enigma.mapping.ClassEntry; |
| @@ -51,8 +55,6 @@ import cuchaz.enigma.mapping.MethodEntry; | |||
| 51 | 55 | ||
| 52 | public class Gui | 56 | public 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 ) |