diff options
Diffstat (limited to 'src/cuchaz/enigma/gui/Gui.java')
| -rw-r--r-- | src/cuchaz/enigma/gui/Gui.java | 61 |
1 files changed, 52 insertions, 9 deletions
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; | |||
| 49 | import javax.swing.JSplitPane; | 49 | import javax.swing.JSplitPane; |
| 50 | import javax.swing.JTabbedPane; | 50 | import javax.swing.JTabbedPane; |
| 51 | import javax.swing.JTextField; | 51 | import javax.swing.JTextField; |
| 52 | import javax.swing.JTree; | ||
| 52 | import javax.swing.ListSelectionModel; | 53 | import javax.swing.ListSelectionModel; |
| 53 | import javax.swing.WindowConstants; | 54 | import javax.swing.WindowConstants; |
| 54 | import javax.swing.event.CaretEvent; | 55 | import javax.swing.event.CaretEvent; |
| 55 | import javax.swing.event.CaretListener; | 56 | import javax.swing.event.CaretListener; |
| 56 | import javax.swing.text.BadLocationException; | 57 | import javax.swing.text.BadLocationException; |
| 57 | import javax.swing.text.Highlighter; | 58 | import javax.swing.text.Highlighter; |
| 59 | import javax.swing.tree.DefaultTreeModel; | ||
| 60 | import javax.swing.tree.TreeNode; | ||
| 61 | import javax.swing.tree.TreePath; | ||
| 62 | |||
| 63 | import com.beust.jcommander.internal.Lists; | ||
| 58 | 64 | ||
| 59 | import jsyntaxpane.DefaultSyntaxKit; | 65 | import jsyntaxpane.DefaultSyntaxKit; |
| 60 | import jsyntaxpane.SyntaxDocument; | 66 | import 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 | ||