diff options
| author | 2014-07-26 19:24:00 -0400 | |
|---|---|---|
| committer | 2014-07-26 19:24:00 -0400 | |
| commit | 295eceece371b516e771de93b6127bf728999483 (patch) | |
| tree | 20ff6a35de79997fc338d922cae934b8872b11a9 /src/cuchaz/enigma/gui/Gui.java | |
| download | enigma-fork-295eceece371b516e771de93b6127bf728999483.tar.gz enigma-fork-295eceece371b516e771de93b6127bf728999483.tar.xz enigma-fork-295eceece371b516e771de93b6127bf728999483.zip | |
initial commit
so far source analysis is working. =)
Diffstat (limited to 'src/cuchaz/enigma/gui/Gui.java')
| -rw-r--r-- | src/cuchaz/enigma/gui/Gui.java | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java new file mode 100644 index 0000000..e0d53d8 --- /dev/null +++ b/src/cuchaz/enigma/gui/Gui.java | |||
| @@ -0,0 +1,163 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.gui; | ||
| 12 | |||
| 13 | import java.awt.BorderLayout; | ||
| 14 | import java.awt.Container; | ||
| 15 | import java.awt.event.MouseAdapter; | ||
| 16 | import java.awt.event.MouseEvent; | ||
| 17 | import java.util.List; | ||
| 18 | import java.util.Vector; | ||
| 19 | |||
| 20 | import javax.swing.JEditorPane; | ||
| 21 | import javax.swing.JFrame; | ||
| 22 | import javax.swing.JLabel; | ||
| 23 | import javax.swing.JList; | ||
| 24 | import javax.swing.JPanel; | ||
| 25 | import javax.swing.JScrollPane; | ||
| 26 | import javax.swing.JSplitPane; | ||
| 27 | import javax.swing.ListSelectionModel; | ||
| 28 | import javax.swing.WindowConstants; | ||
| 29 | import javax.swing.text.BadLocationException; | ||
| 30 | |||
| 31 | import jsyntaxpane.DefaultSyntaxKit; | ||
| 32 | import jsyntaxpane.Token; | ||
| 33 | import cuchaz.enigma.ClassFile; | ||
| 34 | import cuchaz.enigma.analysis.SourceIndex; | ||
| 35 | |||
| 36 | public class Gui | ||
| 37 | { | ||
| 38 | private static final String Name = "Enigma"; | ||
| 39 | |||
| 40 | // controls | ||
| 41 | private JFrame m_frame; | ||
| 42 | private JList<ClassFile> m_obfClasses; | ||
| 43 | private JList<ClassFile> m_deobfClasses; | ||
| 44 | private JEditorPane m_editor; | ||
| 45 | |||
| 46 | // handlers | ||
| 47 | private ClassSelectionHandler m_classSelectionHandler; | ||
| 48 | |||
| 49 | private BoxHighlightPainter m_highlightPainter; | ||
| 50 | |||
| 51 | public Gui( ) | ||
| 52 | { | ||
| 53 | // init frame | ||
| 54 | m_frame = new JFrame( Name ); | ||
| 55 | final Container pane = m_frame.getContentPane(); | ||
| 56 | pane.setLayout( new BorderLayout() ); | ||
| 57 | |||
| 58 | // init obfuscated classes list | ||
| 59 | m_obfClasses = new JList<ClassFile>(); | ||
| 60 | m_obfClasses.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); | ||
| 61 | m_obfClasses.setLayoutOrientation( JList.VERTICAL ); | ||
| 62 | m_obfClasses.setCellRenderer( new ObfuscatedClassListCellRenderer() ); | ||
| 63 | m_obfClasses.addMouseListener( new MouseAdapter() | ||
| 64 | { | ||
| 65 | public void mouseClicked( MouseEvent event ) | ||
| 66 | { | ||
| 67 | if( event.getClickCount() == 2 ) | ||
| 68 | { | ||
| 69 | if( m_classSelectionHandler != null ) | ||
| 70 | { | ||
| 71 | ClassFile selected = m_obfClasses.getSelectedValue(); | ||
| 72 | if( selected != null ) | ||
| 73 | { | ||
| 74 | m_classSelectionHandler.classSelected( selected ); | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | } ); | ||
| 80 | JScrollPane obfScroller = new JScrollPane( m_obfClasses ); | ||
| 81 | JPanel obfPanel = new JPanel(); | ||
| 82 | obfPanel.setLayout( new BorderLayout() ); | ||
| 83 | obfPanel.add( new JLabel( "Obfuscated Classes" ), BorderLayout.NORTH ); | ||
| 84 | obfPanel.add( obfScroller, BorderLayout.CENTER ); | ||
| 85 | |||
| 86 | // init deobfuscated classes list | ||
| 87 | m_deobfClasses = new JList<ClassFile>(); | ||
| 88 | m_obfClasses.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); | ||
| 89 | m_obfClasses.setLayoutOrientation( JList.VERTICAL ); | ||
| 90 | JScrollPane deobfScroller = new JScrollPane( m_deobfClasses ); | ||
| 91 | JPanel deobfPanel = new JPanel(); | ||
| 92 | deobfPanel.setLayout( new BorderLayout() ); | ||
| 93 | deobfPanel.add( new JLabel( "De-obfuscated Classes" ), BorderLayout.NORTH ); | ||
| 94 | deobfPanel.add( deobfScroller, BorderLayout.CENTER ); | ||
| 95 | |||
| 96 | // init editor | ||
| 97 | DefaultSyntaxKit.initKit(); | ||
| 98 | m_editor = new JEditorPane(); | ||
| 99 | m_editor.setEditable( false ); | ||
| 100 | JScrollPane sourceScroller = new JScrollPane( m_editor ); | ||
| 101 | m_editor.setContentType( "text/java" ); | ||
| 102 | |||
| 103 | // layout controls | ||
| 104 | JSplitPane splitLeft = new JSplitPane( JSplitPane.VERTICAL_SPLIT, true, obfPanel, deobfPanel ); | ||
| 105 | JSplitPane splitMain = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, true, splitLeft, sourceScroller ); | ||
| 106 | pane.add( splitMain, BorderLayout.CENTER ); | ||
| 107 | |||
| 108 | // show the frame | ||
| 109 | pane.doLayout(); | ||
| 110 | m_frame.setSize( 800, 600 ); | ||
| 111 | m_frame.setVisible( true ); | ||
| 112 | m_frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE ); | ||
| 113 | |||
| 114 | // init handlers | ||
| 115 | m_classSelectionHandler = null; | ||
| 116 | |||
| 117 | m_highlightPainter = new BoxHighlightPainter(); | ||
| 118 | } | ||
| 119 | |||
| 120 | public void setTitle( String title ) | ||
| 121 | { | ||
| 122 | m_frame.setTitle( Name + " - " + title ); | ||
| 123 | } | ||
| 124 | |||
| 125 | public void setObfClasses( List<ClassFile> classes ) | ||
| 126 | { | ||
| 127 | m_obfClasses.setListData( new Vector<ClassFile>( classes ) ); | ||
| 128 | } | ||
| 129 | |||
| 130 | public void setSource( String source ) | ||
| 131 | { | ||
| 132 | setSource( source, null ); | ||
| 133 | } | ||
| 134 | |||
| 135 | public void setSource( String source, SourceIndex index ) | ||
| 136 | { | ||
| 137 | m_editor.setText( source ); | ||
| 138 | |||
| 139 | // remove any old highlighters | ||
| 140 | m_editor.getHighlighter().removeAllHighlights();; | ||
| 141 | |||
| 142 | if( index != null ) | ||
| 143 | { | ||
| 144 | // color things based on the index | ||
| 145 | for( Token token : index.tokens() ) | ||
| 146 | { | ||
| 147 | try | ||
| 148 | { | ||
| 149 | m_editor.getHighlighter().addHighlight( token.start, token.end(), m_highlightPainter ); | ||
| 150 | } | ||
| 151 | catch( BadLocationException ex ) | ||
| 152 | { | ||
| 153 | throw new Error( ex ); | ||
| 154 | } | ||
| 155 | } | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | public void setClassSelectionHandler( ClassSelectionHandler val ) | ||
| 160 | { | ||
| 161 | m_classSelectionHandler = val; | ||
| 162 | } | ||
| 163 | } | ||