summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/gui
diff options
context:
space:
mode:
authorGravatar jeff2014-08-06 00:22:25 -0400
committerGravatar jeff2014-08-06 00:22:25 -0400
commitd71c0af8ed298bfb4b35b4e3e61b5678bc1c7d9f (patch)
tree103fea72601d989d1a1bb503c6bcfe662c6dc541 /src/cuchaz/enigma/gui
parentstarted on inheritance viewer (diff)
downloadenigma-fork-d71c0af8ed298bfb4b35b4e3e61b5678bc1c7d9f.tar.gz
enigma-fork-d71c0af8ed298bfb4b35b4e3e61b5678bc1c7d9f.tar.xz
enigma-fork-d71c0af8ed298bfb4b35b4e3e61b5678bc1c7d9f.zip
added simple class inheritance browsing
Diffstat (limited to 'src/cuchaz/enigma/gui')
-rw-r--r--src/cuchaz/enigma/gui/ClassInheritanceTreeNode.java56
-rw-r--r--src/cuchaz/enigma/gui/Gui.java61
-rw-r--r--src/cuchaz/enigma/gui/GuiController.java22
3 files changed, 130 insertions, 9 deletions
diff --git a/src/cuchaz/enigma/gui/ClassInheritanceTreeNode.java b/src/cuchaz/enigma/gui/ClassInheritanceTreeNode.java
new file mode 100644
index 0000000..921a1e9
--- /dev/null
+++ b/src/cuchaz/enigma/gui/ClassInheritanceTreeNode.java
@@ -0,0 +1,56 @@
1package cuchaz.enigma.gui;
2
3import java.util.List;
4
5import javax.swing.tree.DefaultMutableTreeNode;
6
7import com.beust.jcommander.internal.Lists;
8
9import cuchaz.enigma.mapping.Ancestries;
10
11public class ClassInheritanceTreeNode extends DefaultMutableTreeNode
12{
13 private static final long serialVersionUID = 4432367405826178490L;
14
15 String m_className;
16
17 public ClassInheritanceTreeNode( String className )
18 {
19 m_className = className;
20 }
21
22 public String getClassName( )
23 {
24 return m_className;
25 }
26
27 @Override
28 public String toString( )
29 {
30 return m_className;
31 }
32
33 public void load( Ancestries ancestries, boolean recurse )
34 {
35 // get all the child nodes
36 List<ClassInheritanceTreeNode> nodes = Lists.newArrayList();
37 for( String subclassName : ancestries.getSubclasses( m_className ) )
38 {
39 nodes.add( new ClassInheritanceTreeNode( subclassName ) );
40 }
41
42 // add then to this node
43 for( ClassInheritanceTreeNode node : nodes )
44 {
45 this.add( node );
46 }
47
48 if( recurse )
49 {
50 for( ClassInheritanceTreeNode node : nodes )
51 {
52 node.load( ancestries, true );
53 }
54 }
55 }
56}
diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java
index f9afb64..2002a4d 100644
--- a/src/cuchaz/enigma/gui/Gui.java
+++ b/src/cuchaz/enigma/gui/Gui.java
@@ -49,12 +49,18 @@ import javax.swing.JScrollPane;
49import javax.swing.JSplitPane; 49import javax.swing.JSplitPane;
50import javax.swing.JTabbedPane; 50import javax.swing.JTabbedPane;
51import javax.swing.JTextField; 51import javax.swing.JTextField;
52import javax.swing.JTree;
52import javax.swing.ListSelectionModel; 53import javax.swing.ListSelectionModel;
53import javax.swing.WindowConstants; 54import javax.swing.WindowConstants;
54import javax.swing.event.CaretEvent; 55import javax.swing.event.CaretEvent;
55import javax.swing.event.CaretListener; 56import javax.swing.event.CaretListener;
56import javax.swing.text.BadLocationException; 57import javax.swing.text.BadLocationException;
57import javax.swing.text.Highlighter; 58import javax.swing.text.Highlighter;
59import javax.swing.tree.DefaultTreeModel;
60import javax.swing.tree.TreeNode;
61import javax.swing.tree.TreePath;
62
63import com.beust.jcommander.internal.Lists;
58 64
59import jsyntaxpane.DefaultSyntaxKit; 65import jsyntaxpane.DefaultSyntaxKit;
60import jsyntaxpane.SyntaxDocument; 66import jsyntaxpane.SyntaxDocument;
@@ -100,7 +106,7 @@ public class Gui
100 private JPanel m_infoPanel; 106 private JPanel m_infoPanel;
101 private BoxHighlightPainter m_obfuscatedHighlightPainter; 107 private BoxHighlightPainter m_obfuscatedHighlightPainter;
102 private BoxHighlightPainter m_deobfuscatedHighlightPainter; 108 private BoxHighlightPainter m_deobfuscatedHighlightPainter;
103 private JPanel m_inheritancePanel; 109 private JTree m_inheritanceTree;
104 110
105 // dynamic menu items 111 // dynamic menu items
106 private JMenuItem m_closeJarMenu; 112 private JMenuItem m_closeJarMenu;
@@ -136,6 +142,7 @@ public class Gui
136 m_obfClasses.setCellRenderer( new ObfuscatedClassListCellRenderer() ); 142 m_obfClasses.setCellRenderer( new ObfuscatedClassListCellRenderer() );
137 m_obfClasses.addMouseListener( new MouseAdapter() 143 m_obfClasses.addMouseListener( new MouseAdapter()
138 { 144 {
145 @Override
139 public void mouseClicked( MouseEvent event ) 146 public void mouseClicked( MouseEvent event )
140 { 147 {
141 if( event.getClickCount() == 2 ) 148 if( event.getClickCount() == 2 )
@@ -161,6 +168,7 @@ public class Gui
161 m_deobfClasses.setCellRenderer( new DeobfuscatedClassListCellRenderer() ); 168 m_deobfClasses.setCellRenderer( new DeobfuscatedClassListCellRenderer() );
162 m_deobfClasses.addMouseListener( new MouseAdapter() 169 m_deobfClasses.addMouseListener( new MouseAdapter()
163 { 170 {
171 @Override
164 public void mouseClicked( MouseEvent event ) 172 public void mouseClicked( MouseEvent event )
165 { 173 {
166 if( event.getClickCount() == 2 ) 174 if( event.getClickCount() == 2 )
@@ -252,7 +260,26 @@ public class Gui
252 } 260 }
253 261
254 // init inheritance panel 262 // init inheritance panel
255 m_inheritancePanel = new JPanel(); 263 m_inheritanceTree = new JTree();
264 m_inheritanceTree.setModel( null );
265 m_inheritanceTree.addMouseListener( new MouseAdapter( )
266 {
267 @Override
268 public void mouseClicked( MouseEvent event )
269 {
270 if( event.getClickCount() == 2 )
271 {
272 ClassInheritanceTreeNode node = (ClassInheritanceTreeNode)m_inheritanceTree.getSelectionPath().getLastPathComponent();
273 if( node != null )
274 {
275 m_controller.deobfuscateClass( new ClassFile( node.getClassName() ) );
276 }
277 }
278 }
279 } );
280 JPanel inheritancePanel = new JPanel();
281 inheritancePanel.setLayout( new BorderLayout() );
282 inheritancePanel.add( new JScrollPane( m_inheritanceTree ) );
256 283
257 // layout controls 284 // layout controls
258 JSplitPane splitLeft = new JSplitPane( JSplitPane.VERTICAL_SPLIT, true, obfPanel, deobfPanel ); 285 JSplitPane splitLeft = new JSplitPane( JSplitPane.VERTICAL_SPLIT, true, obfPanel, deobfPanel );
@@ -263,7 +290,7 @@ public class Gui
263 centerPanel.add( sourceScroller, BorderLayout.CENTER ); 290 centerPanel.add( sourceScroller, BorderLayout.CENTER );
264 JTabbedPane tabbedPane = new JTabbedPane(); 291 JTabbedPane tabbedPane = new JTabbedPane();
265 tabbedPane.setPreferredSize( new Dimension( 200, 0 ) ); 292 tabbedPane.setPreferredSize( new Dimension( 200, 0 ) );
266 tabbedPane.addTab( "Inheritance", m_inheritancePanel ); 293 tabbedPane.addTab( "Inheritance", inheritancePanel );
267 JSplitPane splitRight = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, true, centerPanel, tabbedPane ); 294 JSplitPane splitRight = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, true, centerPanel, tabbedPane );
268 splitRight.setResizeWeight( 1 ); // let the left side take all the slack 295 splitRight.setResizeWeight( 1 ); // let the left side take all the slack
269 splitRight.resetToPreferredSizes(); 296 splitRight.resetToPreferredSizes();
@@ -748,12 +775,28 @@ public class Gui
748 775
749 private void showInheritance( ) 776 private void showInheritance( )
750 { 777 {
751 m_inheritancePanel.removeAll(); 778 // get the current class
752 779 if( m_selectedEntryPair.obf instanceof ClassEntry )
753 // TEMP 780 {
754 m_inheritancePanel.add( new JLabel( m_selectedEntryPair.obf.getName() ) ); 781 ClassInheritanceTreeNode classNode = m_controller.getClassInheritance( (ClassEntry)m_selectedEntryPair.obf );
755 m_inheritancePanel.add( new JLabel( m_selectedEntryPair.deobf.getName() ) ); 782
756 783 // build the path from the root to the class node
784 List<TreeNode> nodes = Lists.newArrayList();
785 TreeNode node = classNode;
786 do
787 {
788 nodes.add( node );
789 node = node.getParent();
790 }
791 while( node != null );
792 Collections.reverse( nodes );
793 TreePath path = new TreePath( nodes.toArray() );
794
795 // show the tree at the root
796 m_inheritanceTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) );
797 m_inheritanceTree.expandPath( path );
798 m_inheritanceTree.setSelectionRow( m_inheritanceTree.getRowForPath( path ) );
799 }
757 redraw(); 800 redraw();
758 } 801 }
759 802
diff --git a/src/cuchaz/enigma/gui/GuiController.java b/src/cuchaz/enigma/gui/GuiController.java
index e1ba49a..452632f 100644
--- a/src/cuchaz/enigma/gui/GuiController.java
+++ b/src/cuchaz/enigma/gui/GuiController.java
@@ -26,6 +26,7 @@ import cuchaz.enigma.ClassFile;
26import cuchaz.enigma.Deobfuscator; 26import cuchaz.enigma.Deobfuscator;
27import cuchaz.enigma.analysis.Analyzer; 27import cuchaz.enigma.analysis.Analyzer;
28import cuchaz.enigma.analysis.SourceIndex; 28import cuchaz.enigma.analysis.SourceIndex;
29import cuchaz.enigma.mapping.ClassEntry;
29import cuchaz.enigma.mapping.Entry; 30import cuchaz.enigma.mapping.Entry;
30import cuchaz.enigma.mapping.EntryPair; 31import cuchaz.enigma.mapping.EntryPair;
31import cuchaz.enigma.mapping.MappingsReader; 32import cuchaz.enigma.mapping.MappingsReader;
@@ -129,6 +130,27 @@ public class GuiController
129 return m_deobfuscator.hasMapping( pair.obf ); 130 return m_deobfuscator.hasMapping( pair.obf );
130 } 131 }
131 132
133 public ClassInheritanceTreeNode getClassInheritance( ClassEntry classEntry )
134 {
135 // create a node for this class
136 ClassInheritanceTreeNode thisNode = new ClassInheritanceTreeNode( classEntry.getName() );
137
138 // expand all children recursively
139 thisNode.load( m_deobfuscator.getAncestries(), true );
140
141 // get the ancestors too
142 ClassInheritanceTreeNode node = thisNode;
143 for( String superclassName : m_deobfuscator.getAncestries().getAncestry( classEntry.getName() ) )
144 {
145 // add the parent node
146 ClassInheritanceTreeNode parentNode = new ClassInheritanceTreeNode( superclassName );
147 parentNode.add( node );
148 node = parentNode;
149 }
150
151 return thisNode;
152 }
153
132 public void rename( Entry obfsEntry, String newName, int lineNum ) 154 public void rename( Entry obfsEntry, String newName, int lineNum )
133 { 155 {
134 m_deobfuscator.rename( obfsEntry, newName ); 156 m_deobfuscator.rename( obfsEntry, newName );