summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/Controller.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuchaz/enigma/Controller.java')
-rw-r--r--src/cuchaz/enigma/Controller.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/Controller.java b/src/cuchaz/enigma/Controller.java
new file mode 100644
index 00000000..debc5e38
--- /dev/null
+++ b/src/cuchaz/enigma/Controller.java
@@ -0,0 +1,83 @@
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 ******************************************************************************/
11package cuchaz.enigma;
12
13import javax.swing.event.CaretEvent;
14import javax.swing.event.CaretListener;
15
16import cuchaz.enigma.analysis.Analyzer;
17import cuchaz.enigma.analysis.SourceIndex;
18import cuchaz.enigma.gui.ClassSelectionListener;
19import cuchaz.enigma.gui.Gui;
20import cuchaz.enigma.gui.RenameListener;
21import cuchaz.enigma.mapping.Entry;
22
23public class Controller implements ClassSelectionListener, CaretListener, RenameListener
24{
25 private Deobfuscator m_deobfuscator;
26 private Gui m_gui;
27 private SourceIndex m_index;
28
29 public Controller( Deobfuscator deobfuscator, Gui gui )
30 {
31 m_deobfuscator = deobfuscator;
32 m_gui = gui;
33 m_index = null;
34
35 // update GUI
36 gui.setTitle( deobfuscator.getJarName() );
37 gui.setObfClasses( deobfuscator.getObfuscatedClasses() );
38
39 // handle events
40 gui.setClassSelectionListener( this );
41 gui.setCaretListener( this );
42 gui.setRenameListener( this );
43 }
44
45 @Override
46 public void classSelected( final ClassFile classFile )
47 {
48 m_gui.setSource( "(deobfuscating...)" );
49
50 // run the deobfuscator in a separate thread so we don't block the GUI event queue
51 new Thread( )
52 {
53 @Override
54 public void run( )
55 {
56 // deobfuscate the bytecode
57 String source = m_deobfuscator.getSource( classFile );
58 m_gui.setSource( source );
59
60 // index the source file
61 m_index = Analyzer.analyze( classFile.getName(), source );
62 m_gui.highlightTokens( m_index.tokens() );
63 }
64 }.start();
65 }
66
67 @Override
68 public void caretUpdate( CaretEvent event )
69 {
70 if( m_index != null )
71 {
72 int pos = event.getDot();
73 m_gui.showEntry( m_index.getEntry( pos ) );
74 }
75 }
76
77 @Override
78 public void rename( Entry entry, String newName )
79 {
80 // TEMP
81 System.out.println( "Rename " + entry + " to " + newName );
82 }
83}