From 959cb5fd4f9586ec3bd265b452fe25fe1db82e3f Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 13 Jan 2015 23:25:04 -0500 Subject: source format change don't hate me too much if you were planning a big merge. =P --- src/cuchaz/enigma/gui/AboutDialog.java | 80 +- src/cuchaz/enigma/gui/BoxHighlightPainter.java | 37 +- src/cuchaz/enigma/gui/BrowserCaret.java | 21 +- src/cuchaz/enigma/gui/ClassListCellRenderer.java | 14 +- src/cuchaz/enigma/gui/ClassSelector.java | 131 +- src/cuchaz/enigma/gui/ClassSelectorClassNode.java | 13 +- .../enigma/gui/ClassSelectorPackageNode.java | 13 +- src/cuchaz/enigma/gui/CrashDialog.java | 77 +- .../enigma/gui/DeobfuscatedHighlightPainter.java | 9 +- src/cuchaz/enigma/gui/Gui.java | 1265 ++++++++------------ src/cuchaz/enigma/gui/GuiController.java | 349 +++--- src/cuchaz/enigma/gui/GuiTricks.java | 23 +- .../enigma/gui/ObfuscatedHighlightPainter.java | 9 +- src/cuchaz/enigma/gui/OtherHighlightPainter.java | 9 +- src/cuchaz/enigma/gui/ProgressDialog.java | 90 +- src/cuchaz/enigma/gui/ReadableToken.java | 22 +- src/cuchaz/enigma/gui/RenameListener.java | 5 +- .../enigma/gui/SelectionHighlightPainter.java | 15 +- src/cuchaz/enigma/gui/TokenListCellRenderer.java | 14 +- 19 files changed, 913 insertions(+), 1283 deletions(-) (limited to 'src/cuchaz/enigma/gui') diff --git a/src/cuchaz/enigma/gui/AboutDialog.java b/src/cuchaz/enigma/gui/AboutDialog.java index a245956..2476b56 100644 --- a/src/cuchaz/enigma/gui/AboutDialog.java +++ b/src/cuchaz/enigma/gui/AboutDialog.java @@ -27,68 +27,60 @@ import javax.swing.WindowConstants; import cuchaz.enigma.Constants; import cuchaz.enigma.Util; -public class AboutDialog -{ - public static void show( JFrame parent ) - { +public class AboutDialog { + + public static void show(JFrame parent) { // init frame - final JFrame frame = new JFrame( Constants.Name + " - About" ); + final JFrame frame = new JFrame(Constants.Name + " - About"); final Container pane = frame.getContentPane(); - pane.setLayout( new FlowLayout() ); + pane.setLayout(new FlowLayout()); // load the content - try - { - String html = Util.readResourceToString( "/about.html" ); - html = String.format( html, Constants.Name, Constants.Version ); - JLabel label = new JLabel( html ); - label.setHorizontalAlignment( JLabel.CENTER ); - pane.add( label ); - } - catch( IOException ex ) - { - throw new Error( ex ); + try { + String html = Util.readResourceToString("/about.html"); + html = String.format(html, Constants.Name, Constants.Version); + JLabel label = new JLabel(html); + label.setHorizontalAlignment(JLabel.CENTER); + pane.add(label); + } catch (IOException ex) { + throw new Error(ex); } // show the link String html = "%s"; - html = String.format( html, Constants.Url, Constants.Url ); - JButton link = new JButton( html ); - link.addActionListener( new ActionListener( ) - { + html = String.format(html, Constants.Url, Constants.Url); + JButton link = new JButton(html); + link.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { - Util.openUrl( Constants.Url ); + public void actionPerformed(ActionEvent event) { + Util.openUrl(Constants.Url); } - } ); - link.setBorderPainted( false ); - link.setOpaque( false ); - link.setBackground( Color.WHITE ); - link.setCursor( new Cursor( Cursor.HAND_CURSOR ) ); - link.setFocusable( false ); + }); + link.setBorderPainted(false); + link.setOpaque(false); + link.setBackground(Color.WHITE); + link.setCursor(new Cursor(Cursor.HAND_CURSOR)); + link.setFocusable(false); JPanel linkPanel = new JPanel(); - linkPanel.add( link ); - pane.add( linkPanel ); + linkPanel.add(link); + pane.add(linkPanel); // show ok button - JButton okButton = new JButton( "Ok" ); - pane.add( okButton ); - okButton.addActionListener( new ActionListener( ) - { + JButton okButton = new JButton("Ok"); + pane.add(okButton); + okButton.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent arg0 ) - { + public void actionPerformed(ActionEvent arg0) { frame.dispose(); } - } ); + }); // show the frame pane.doLayout(); - frame.setSize( 400, 220 ); - frame.setResizable( false ); - frame.setLocationRelativeTo( parent ); - frame.setVisible( true ); - frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); + frame.setSize(400, 220); + frame.setResizable(false); + frame.setLocationRelativeTo(parent); + frame.setVisible(true); + frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); } } diff --git a/src/cuchaz/enigma/gui/BoxHighlightPainter.java b/src/cuchaz/enigma/gui/BoxHighlightPainter.java index df63f5a..db7c85b 100644 --- a/src/cuchaz/enigma/gui/BoxHighlightPainter.java +++ b/src/cuchaz/enigma/gui/BoxHighlightPainter.java @@ -19,40 +19,35 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Highlighter; import javax.swing.text.JTextComponent; -public abstract class BoxHighlightPainter implements Highlighter.HighlightPainter -{ +public abstract class BoxHighlightPainter implements Highlighter.HighlightPainter { + private Color m_fillColor; private Color m_borderColor; - protected BoxHighlightPainter( Color fillColor, Color borderColor ) - { + protected BoxHighlightPainter(Color fillColor, Color borderColor) { m_fillColor = fillColor; m_borderColor = borderColor; } @Override - public void paint( Graphics g, int start, int end, Shape shape, JTextComponent text ) - { - Rectangle bounds = getBounds( text, start, end ); + public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) { + Rectangle bounds = getBounds(text, start, end); // fill the area - if( m_fillColor != null ) - { - g.setColor( m_fillColor ); - g.fillRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); + if (m_fillColor != null) { + g.setColor(m_fillColor); + g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); } // draw a box around the area - g.setColor( m_borderColor ); - g.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); + g.setColor(m_borderColor); + g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); } - protected static Rectangle getBounds( JTextComponent text, int start, int end ) - { - try - { + protected static Rectangle getBounds(JTextComponent text, int start, int end) { + try { // determine the bounds of the text - Rectangle bounds = text.modelToView( start ).union( text.modelToView( end ) ); + Rectangle bounds = text.modelToView(start).union(text.modelToView(end)); // adjust the box so it looks nice bounds.x -= 2; @@ -61,11 +56,9 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte bounds.height -= 2; return bounds; - } - catch( BadLocationException ex ) - { + } catch (BadLocationException ex) { // don't care... just return something - return new Rectangle( 0, 0, 0, 0 ); + return new Rectangle(0, 0, 0, 0); } } } diff --git a/src/cuchaz/enigma/gui/BrowserCaret.java b/src/cuchaz/enigma/gui/BrowserCaret.java index f7e608b..acee483 100644 --- a/src/cuchaz/enigma/gui/BrowserCaret.java +++ b/src/cuchaz/enigma/gui/BrowserCaret.java @@ -17,34 +17,29 @@ import javax.swing.text.DefaultCaret; import javax.swing.text.Highlighter; import javax.swing.text.JTextComponent; -public class BrowserCaret extends DefaultCaret -{ +public class BrowserCaret extends DefaultCaret { + private static final long serialVersionUID = 1158977422507969940L; - private static final Highlighter.HighlightPainter m_selectionPainter = new Highlighter.HighlightPainter( ) - { + private static final Highlighter.HighlightPainter m_selectionPainter = new Highlighter.HighlightPainter() { @Override - public void paint( Graphics g, int p0, int p1, Shape bounds, JTextComponent c ) - { + public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) { // don't paint anything } }; @Override - public boolean isSelectionVisible( ) - { + public boolean isSelectionVisible() { return false; } - + @Override - public boolean isVisible( ) - { + public boolean isVisible() { return true; } @Override - public Highlighter.HighlightPainter getSelectionPainter( ) - { + public Highlighter.HighlightPainter getSelectionPainter() { return m_selectionPainter; } } diff --git a/src/cuchaz/enigma/gui/ClassListCellRenderer.java b/src/cuchaz/enigma/gui/ClassListCellRenderer.java index d9d6578..d0f01e6 100644 --- a/src/cuchaz/enigma/gui/ClassListCellRenderer.java +++ b/src/cuchaz/enigma/gui/ClassListCellRenderer.java @@ -19,20 +19,18 @@ import javax.swing.JLabel; import javax.swing.JList; import javax.swing.ListCellRenderer; -public class ClassListCellRenderer implements ListCellRenderer -{ +public class ClassListCellRenderer implements ListCellRenderer { + private DefaultListCellRenderer m_defaultRenderer; - public ClassListCellRenderer( ) - { + public ClassListCellRenderer() { m_defaultRenderer = new DefaultListCellRenderer(); } @Override - public Component getListCellRendererComponent( JList list, String className, int index, boolean isSelected, boolean hasFocus ) - { - JLabel label = (JLabel)m_defaultRenderer.getListCellRendererComponent( list, className, index, isSelected, hasFocus ); - label.setText( Descriptor.toJavaName( className ) ); + public Component getListCellRendererComponent(JList list, String className, int index, boolean isSelected, boolean hasFocus) { + JLabel label = (JLabel)m_defaultRenderer.getListCellRendererComponent(list, className, index, isSelected, hasFocus); + label.setText(Descriptor.toJavaName(className)); return label; } } diff --git a/src/cuchaz/enigma/gui/ClassSelector.java b/src/cuchaz/enigma/gui/ClassSelector.java index 8365def..654bfbe 100644 --- a/src/cuchaz/enigma/gui/ClassSelector.java +++ b/src/cuchaz/enigma/gui/ClassSelector.java @@ -30,39 +30,32 @@ import com.google.common.collect.Multimap; import cuchaz.enigma.mapping.ClassEntry; -public class ClassSelector extends JTree -{ +public class ClassSelector extends JTree { + private static final long serialVersionUID = -7632046902384775977L; - public interface ClassSelectionListener - { - void onSelectClass( ClassEntry classEntry ); + public interface ClassSelectionListener { + void onSelectClass(ClassEntry classEntry); } public static Comparator ObfuscatedClassEntryComparator; public static Comparator DeobfuscatedClassEntryComparator; - static - { - ObfuscatedClassEntryComparator = new Comparator( ) - { + static { + ObfuscatedClassEntryComparator = new Comparator() { @Override - public int compare( ClassEntry a, ClassEntry b ) - { - if( a.getName().length() != b.getName().length() ) - { + public int compare(ClassEntry a, ClassEntry b) { + if (a.getName().length() != b.getName().length()) { return a.getName().length() - b.getName().length(); } - return a.getName().compareTo( b.getName() ); + return a.getName().compareTo(b.getName()); } }; - DeobfuscatedClassEntryComparator = new Comparator( ) - { + DeobfuscatedClassEntryComparator = new Comparator() { @Override - public int compare( ClassEntry a, ClassEntry b ) - { - return a.getName().compareTo( b.getName() ); + public int compare(ClassEntry a, ClassEntry b) { + return a.getName().compareTo(b.getName()); } }; } @@ -70,122 +63,102 @@ public class ClassSelector extends JTree private ClassSelectionListener m_listener; private Comparator m_comparator; - public ClassSelector( Comparator comparator ) - { + public ClassSelector(Comparator comparator) { m_comparator = comparator; // configure the tree control - setRootVisible( false ); - setShowsRootHandles( false ); - setModel( null ); + setRootVisible(false); + setShowsRootHandles(false); + setModel(null); // hook events - addMouseListener( new MouseAdapter() - { + addMouseListener(new MouseAdapter() { @Override - public void mouseClicked( MouseEvent event ) - { - if( m_listener != null && event.getClickCount() == 2 ) - { + public void mouseClicked(MouseEvent event) { + if (m_listener != null && event.getClickCount() == 2) { // get the selected node TreePath path = getSelectionPath(); - if( path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode ) - { + if (path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode) { ClassSelectorClassNode node = (ClassSelectorClassNode)path.getLastPathComponent(); - m_listener.onSelectClass( node.getClassEntry() ); + m_listener.onSelectClass(node.getClassEntry()); } } } - } ); + }); // init defaults m_listener = null; } - public void setListener( ClassSelectionListener val ) - { + public void setListener(ClassSelectionListener val) { m_listener = val; } - public void setClasses( Collection classEntries ) - { - if( classEntries == null ) - { - setModel( null ); + public void setClasses(Collection classEntries) { + if (classEntries == null) { + setModel(null); return; } // build the package names Map packages = Maps.newHashMap(); - for( ClassEntry classEntry : classEntries ) - { - packages.put( classEntry.getPackageName(), null ); + for (ClassEntry classEntry : classEntries) { + packages.put(classEntry.getPackageName(), null); } // sort the packages - List sortedPackageNames = Lists.newArrayList( packages.keySet() ); - Collections.sort( sortedPackageNames, new Comparator( ) - { + List sortedPackageNames = Lists.newArrayList(packages.keySet()); + Collections.sort(sortedPackageNames, new Comparator() { @Override - public int compare( String a, String b ) - { + public int compare(String a, String b) { // I can never keep this rule straight when writing these damn things... // a < b => -1, a == b => 0, a > b => +1 - String[] aparts = a.split( "/" ); - String[] bparts = b.split( "/" ); - for( int i=0; true; i++ ) - { - if( i >= aparts.length ) - { + String[] aparts = a.split("/"); + String[] bparts = b.split("/"); + for (int i = 0; true; i++) { + if (i >= aparts.length) { return -1; - } - else if( i >= bparts.length ) - { + } else if (i >= bparts.length) { return 1; } - int result = aparts[i].compareTo( bparts[i] ); - if( result != 0 ) - { + int result = aparts[i].compareTo(bparts[i]); + if (result != 0) { return result; } } } - } ); + }); // create the root node and the package nodes DefaultMutableTreeNode root = new DefaultMutableTreeNode(); - for( String packageName : sortedPackageNames ) - { - ClassSelectorPackageNode node = new ClassSelectorPackageNode( packageName ); - packages.put( packageName, node ); - root.add( node ); + for (String packageName : sortedPackageNames) { + ClassSelectorPackageNode node = new ClassSelectorPackageNode(packageName); + packages.put(packageName, node); + root.add(node); } // put the classes into packages Multimap packagedClassEntries = ArrayListMultimap.create(); - for( ClassEntry classEntry : classEntries ) - { - packagedClassEntries.put( classEntry.getPackageName(), classEntry ); + for (ClassEntry classEntry : classEntries) { + packagedClassEntries.put(classEntry.getPackageName(), classEntry); } // build the class nodes - for( String packageName : packagedClassEntries.keySet() ) - { + for (String packageName : packagedClassEntries.keySet()) { // sort the class entries - List classEntriesInPackage = Lists.newArrayList( packagedClassEntries.get( packageName ) ); - Collections.sort( classEntriesInPackage, m_comparator ); + List classEntriesInPackage = Lists.newArrayList(packagedClassEntries.get(packageName)); + Collections.sort(classEntriesInPackage, m_comparator); // create the nodes in order - for( ClassEntry classEntry : classEntriesInPackage ) - { - ClassSelectorPackageNode node = packages.get( packageName ); - node.add( new ClassSelectorClassNode( classEntry ) ); + for (ClassEntry classEntry : classEntriesInPackage) { + ClassSelectorPackageNode node = packages.get(packageName); + node.add(new ClassSelectorClassNode(classEntry)); } } // finally, update the tree control - setModel( new DefaultTreeModel( root ) ); + setModel(new DefaultTreeModel(root)); } } diff --git a/src/cuchaz/enigma/gui/ClassSelectorClassNode.java b/src/cuchaz/enigma/gui/ClassSelectorClassNode.java index cffa795..66e931b 100644 --- a/src/cuchaz/enigma/gui/ClassSelectorClassNode.java +++ b/src/cuchaz/enigma/gui/ClassSelectorClassNode.java @@ -14,25 +14,22 @@ import javax.swing.tree.DefaultMutableTreeNode; import cuchaz.enigma.mapping.ClassEntry; -public class ClassSelectorClassNode extends DefaultMutableTreeNode -{ +public class ClassSelectorClassNode extends DefaultMutableTreeNode { + private static final long serialVersionUID = -8956754339813257380L; private ClassEntry m_classEntry; - public ClassSelectorClassNode( ClassEntry classEntry ) - { + public ClassSelectorClassNode(ClassEntry classEntry) { m_classEntry = classEntry; } - public ClassEntry getClassEntry( ) - { + public ClassEntry getClassEntry() { return m_classEntry; } @Override - public String toString( ) - { + public String toString() { return m_classEntry.getSimpleName(); } } diff --git a/src/cuchaz/enigma/gui/ClassSelectorPackageNode.java b/src/cuchaz/enigma/gui/ClassSelectorPackageNode.java index ad88fb4..451d380 100644 --- a/src/cuchaz/enigma/gui/ClassSelectorPackageNode.java +++ b/src/cuchaz/enigma/gui/ClassSelectorPackageNode.java @@ -12,25 +12,22 @@ package cuchaz.enigma.gui; import javax.swing.tree.DefaultMutableTreeNode; -public class ClassSelectorPackageNode extends DefaultMutableTreeNode -{ +public class ClassSelectorPackageNode extends DefaultMutableTreeNode { + private static final long serialVersionUID = -3730868701219548043L; private String m_packageName; - public ClassSelectorPackageNode( String packageName ) - { + public ClassSelectorPackageNode(String packageName) { m_packageName = packageName; } - public String getPackageName( ) - { + public String getPackageName() { return m_packageName; } @Override - public String toString( ) - { + public String toString() { return m_packageName; } } diff --git a/src/cuchaz/enigma/gui/CrashDialog.java b/src/cuchaz/enigma/gui/CrashDialog.java index 0eb9830..360091a 100644 --- a/src/cuchaz/enigma/gui/CrashDialog.java +++ b/src/cuchaz/enigma/gui/CrashDialog.java @@ -29,80 +29,73 @@ import javax.swing.WindowConstants; import cuchaz.enigma.Constants; -public class CrashDialog -{ +public class CrashDialog { + private static CrashDialog m_instance = null; private JFrame m_frame; private JTextArea m_text; - private CrashDialog( JFrame parent ) - { + private CrashDialog(JFrame parent) { // init frame - m_frame = new JFrame( Constants.Name + " - Crash Report" ); + m_frame = new JFrame(Constants.Name + " - Crash Report"); final Container pane = m_frame.getContentPane(); - pane.setLayout( new BorderLayout() ); + pane.setLayout(new BorderLayout()); - JLabel label = new JLabel( Constants.Name + " has crashed! =(" ); - label.setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) ); - pane.add( label, BorderLayout.NORTH ); + JLabel label = new JLabel(Constants.Name + " has crashed! =("); + label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + pane.add(label, BorderLayout.NORTH); // report panel m_text = new JTextArea(); - m_text.setTabSize( 2 ); - pane.add( new JScrollPane( m_text ), BorderLayout.CENTER ); + m_text.setTabSize(2); + pane.add(new JScrollPane(m_text), BorderLayout.CENTER); // buttons panel JPanel buttonsPanel = new JPanel(); FlowLayout buttonsLayout = new FlowLayout(); - buttonsLayout.setAlignment( FlowLayout.RIGHT ); - buttonsPanel.setLayout( buttonsLayout ); - buttonsPanel.add( GuiTricks.unboldLabel( new JLabel( "If you choose exit, you will lose any unsaved work." ) ) ); - JButton ignoreButton = new JButton( "Ignore" ); - ignoreButton.addActionListener( new ActionListener( ) - { + buttonsLayout.setAlignment(FlowLayout.RIGHT); + buttonsPanel.setLayout(buttonsLayout); + buttonsPanel.add(GuiTricks.unboldLabel(new JLabel("If you choose exit, you will lose any unsaved work."))); + JButton ignoreButton = new JButton("Ignore"); + ignoreButton.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { + public void actionPerformed(ActionEvent event) { // close (hide) the dialog - m_frame.setVisible( false ); + m_frame.setVisible(false); } - } ); - buttonsPanel.add( ignoreButton ); - JButton exitButton = new JButton( "Exit" ); - exitButton.addActionListener( new ActionListener( ) - { + }); + buttonsPanel.add(ignoreButton); + JButton exitButton = new JButton("Exit"); + exitButton.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { + public void actionPerformed(ActionEvent event) { // exit enigma - System.exit( 1 ); + System.exit(1); } - } ); - buttonsPanel.add( exitButton ); - pane.add( buttonsPanel, BorderLayout.SOUTH ); + }); + buttonsPanel.add(exitButton); + pane.add(buttonsPanel, BorderLayout.SOUTH); // show the frame - m_frame.setSize( 600, 400 ); - m_frame.setLocationRelativeTo( parent ); - m_frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); + m_frame.setSize(600, 400); + m_frame.setLocationRelativeTo(parent); + m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); } - public static void init( JFrame parent ) - { - m_instance = new CrashDialog( parent ); + public static void init(JFrame parent) { + m_instance = new CrashDialog(parent); } - public static void show( Throwable ex ) - { + public static void show(Throwable ex) { // get the error report StringWriter buf = new StringWriter(); - ex.printStackTrace( new PrintWriter( buf ) ); + ex.printStackTrace(new PrintWriter(buf)); String report = buf.toString(); // show it! - m_instance.m_text.setText( report ); + m_instance.m_text.setText(report); m_instance.m_frame.doLayout(); - m_instance.m_frame.setVisible( true ); + m_instance.m_frame.setVisible(true); } } diff --git a/src/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java b/src/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java index 6a42884..26a3163 100644 --- a/src/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java +++ b/src/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java @@ -12,11 +12,10 @@ package cuchaz.enigma.gui; import java.awt.Color; -public class DeobfuscatedHighlightPainter extends BoxHighlightPainter -{ - public DeobfuscatedHighlightPainter( ) - { +public class DeobfuscatedHighlightPainter extends BoxHighlightPainter { + + public DeobfuscatedHighlightPainter() { // green ish - super( new Color( 220, 255, 220 ), new Color( 80, 160, 80 ) ); + super(new Color(220, 255, 220), new Color(80, 160, 80)); } } diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java index faa9b7b..86ba93b 100644 --- a/src/cuchaz/enigma/gui/Gui.java +++ b/src/cuchaz/enigma/gui/Gui.java @@ -88,8 +88,8 @@ import cuchaz.enigma.mapping.IllegalNameException; import cuchaz.enigma.mapping.MappingParseException; import cuchaz.enigma.mapping.MethodEntry; -public class Gui -{ +public class Gui { + private GuiController m_controller; // controls @@ -133,81 +133,74 @@ public class Gui private JFileChooser m_exportSourceFileChooser; private JFileChooser m_exportJarFileChooser; - public Gui( ) - { + public Gui() { + // init frame - m_frame = new JFrame( Constants.Name ); + m_frame = new JFrame(Constants.Name); final Container pane = m_frame.getContentPane(); - pane.setLayout( new BorderLayout() ); + pane.setLayout(new BorderLayout()); - if( Boolean.parseBoolean( System.getProperty( "enigma.catchExceptions", "true" ) ) ) - { + if (Boolean.parseBoolean(System.getProperty("enigma.catchExceptions", "true"))) { // install a global exception handler to the event thread - CrashDialog.init( m_frame ); - Thread.setDefaultUncaughtExceptionHandler( new UncaughtExceptionHandler( ) - { + CrashDialog.init(m_frame); + Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override - public void uncaughtException( Thread thread, Throwable ex ) - { - ex.printStackTrace( System.err ); - CrashDialog.show( ex ); + public void uncaughtException(Thread thread, Throwable ex) { + ex.printStackTrace(System.err); + CrashDialog.show(ex); } - } ); + }); } - m_controller = new GuiController( this ); + m_controller = new GuiController(this); // init file choosers m_jarFileChooser = new JFileChooser(); m_mappingsFileChooser = new JFileChooser(); m_exportSourceFileChooser = new JFileChooser(); - m_exportSourceFileChooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ); + m_exportSourceFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); m_exportJarFileChooser = new JFileChooser(); // init obfuscated classes list - m_obfClasses = new ClassSelector( ClassSelector.ObfuscatedClassEntryComparator ); - m_obfClasses.setListener( new ClassSelectionListener( ) - { + m_obfClasses = new ClassSelector(ClassSelector.ObfuscatedClassEntryComparator); + m_obfClasses.setListener(new ClassSelectionListener() { @Override - public void onSelectClass( ClassEntry classEntry ) - { - navigateTo( classEntry ); + public void onSelectClass(ClassEntry classEntry) { + navigateTo(classEntry); } - } ); - JScrollPane obfScroller = new JScrollPane( m_obfClasses ); + }); + JScrollPane obfScroller = new JScrollPane(m_obfClasses); JPanel obfPanel = new JPanel(); - obfPanel.setLayout( new BorderLayout() ); - obfPanel.add( new JLabel( "Obfuscated Classes" ), BorderLayout.NORTH ); - obfPanel.add( obfScroller, BorderLayout.CENTER ); + obfPanel.setLayout(new BorderLayout()); + obfPanel.add(new JLabel("Obfuscated Classes"), BorderLayout.NORTH); + obfPanel.add(obfScroller, BorderLayout.CENTER); // init deobfuscated classes list - m_deobfClasses = new ClassSelector( ClassSelector.DeobfuscatedClassEntryComparator ); - m_deobfClasses.setListener( new ClassSelectionListener( ) - { + m_deobfClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); + m_deobfClasses.setListener(new ClassSelectionListener() { @Override - public void onSelectClass( ClassEntry classEntry ) - { - navigateTo( classEntry ); + public void onSelectClass(ClassEntry classEntry) { + navigateTo(classEntry); } - } ); - JScrollPane deobfScroller = new JScrollPane( m_deobfClasses ); + }); + JScrollPane deobfScroller = new JScrollPane(m_deobfClasses); JPanel deobfPanel = new JPanel(); - deobfPanel.setLayout( new BorderLayout() ); - deobfPanel.add( new JLabel( "De-obfuscated Classes" ), BorderLayout.NORTH ); - deobfPanel.add( deobfScroller, BorderLayout.CENTER ); + deobfPanel.setLayout(new BorderLayout()); + deobfPanel.add(new JLabel("De-obfuscated Classes"), BorderLayout.NORTH); + deobfPanel.add(deobfScroller, BorderLayout.CENTER); // set up classes panel (don't add the splitter yet) - m_splitClasses = new JSplitPane( JSplitPane.VERTICAL_SPLIT, true, obfPanel, deobfPanel ); - m_splitClasses.setResizeWeight( 0.3 ); + m_splitClasses = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, obfPanel, deobfPanel); + m_splitClasses.setResizeWeight(0.3); m_classesPanel = new JPanel(); - m_classesPanel.setLayout( new BorderLayout() ); - m_classesPanel.setPreferredSize( new Dimension( 250, 0 ) ); + m_classesPanel.setLayout(new BorderLayout()); + m_classesPanel.setPreferredSize(new Dimension(250, 0)); // init info panel m_infoPanel = new JPanel(); - m_infoPanel.setLayout( new GridLayout( 4, 1, 0, 0 ) ); - m_infoPanel.setPreferredSize( new Dimension( 0, 100 ) ); - m_infoPanel.setBorder( BorderFactory.createTitledBorder( "Identifier Info" ) ); + m_infoPanel.setLayout(new GridLayout(4, 1, 0, 0)); + m_infoPanel.setPreferredSize(new Dimension(0, 100)); + m_infoPanel.setBorder(BorderFactory.createTitledBorder("Identifier Info")); clearReference(); // init editor @@ -217,25 +210,20 @@ public class Gui m_otherHighlightPainter = new OtherHighlightPainter(); m_selectionHighlightPainter = new SelectionHighlightPainter(); m_editor = new JEditorPane(); - m_editor.setEditable( false ); - m_editor.setCaret( new BrowserCaret() ); - JScrollPane sourceScroller = new JScrollPane( m_editor ); - m_editor.setContentType( "text/java" ); - m_editor.addCaretListener( new CaretListener( ) - { + m_editor.setEditable(false); + m_editor.setCaret(new BrowserCaret()); + JScrollPane sourceScroller = new JScrollPane(m_editor); + m_editor.setContentType("text/java"); + m_editor.addCaretListener(new CaretListener() { @Override - public void caretUpdate( CaretEvent event ) - { - onCaretMove( event.getDot() ); + public void caretUpdate(CaretEvent event) { + onCaretMove(event.getDot()); } - } ); - m_editor.addKeyListener( new KeyAdapter( ) - { + }); + m_editor.addKeyListener(new KeyAdapter() { @Override - public void keyPressed( KeyEvent event ) - { - switch( event.getKeyCode() ) - { + public void keyPressed(KeyEvent event) { + switch (event.getKeyCode()) { case KeyEvent.VK_R: m_renameMenu.doClick(); break; @@ -265,713 +253,594 @@ public class Gui break; } } - } ); + }); // turn off token highlighting (it's wrong most of the time anyway...) DefaultSyntaxKit kit = (DefaultSyntaxKit)m_editor.getEditorKit(); - kit.toggleComponent( m_editor, "jsyntaxpane.components.TokenMarker" ); + kit.toggleComponent(m_editor, "jsyntaxpane.components.TokenMarker"); // init editor popup menu JPopupMenu popupMenu = new JPopupMenu(); - m_editor.setComponentPopupMenu( popupMenu ); + m_editor.setComponentPopupMenu(popupMenu); { - JMenuItem menu = new JMenuItem( "Rename" ); - menu.addActionListener( new ActionListener( ) - { + JMenuItem menu = new JMenuItem("Rename"); + menu.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { + public void actionPerformed(ActionEvent event) { startRename(); } - } ); - menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_R, 0 ) ); - menu.setEnabled( false ); - popupMenu.add( menu ); + }); + menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, 0)); + menu.setEnabled(false); + popupMenu.add(menu); m_renameMenu = menu; } { - JMenuItem menu = new JMenuItem( "Show Inheritance" ); - menu.addActionListener( new ActionListener( ) - { + JMenuItem menu = new JMenuItem("Show Inheritance"); + menu.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { + public void actionPerformed(ActionEvent event) { showInheritance(); } - } ); - menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_I, 0 ) ); - menu.setEnabled( false ); - popupMenu.add( menu ); + }); + menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, 0)); + menu.setEnabled(false); + popupMenu.add(menu); m_showInheritanceMenu = menu; } { - JMenuItem menu = new JMenuItem( "Show Implementations" ); - menu.addActionListener( new ActionListener( ) - { + JMenuItem menu = new JMenuItem("Show Implementations"); + menu.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { + public void actionPerformed(ActionEvent event) { showImplementations(); } - } ); - menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_M, 0 ) ); - menu.setEnabled( false ); - popupMenu.add( menu ); + }); + menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, 0)); + menu.setEnabled(false); + popupMenu.add(menu); m_showImplementationsMenu = menu; } { - JMenuItem menu = new JMenuItem( "Show Calls" ); - menu.addActionListener( new ActionListener( ) - { + JMenuItem menu = new JMenuItem("Show Calls"); + menu.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { + public void actionPerformed(ActionEvent event) { showCalls(); } - } ); - menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_C, 0 ) ); - menu.setEnabled( false ); - popupMenu.add( menu ); + }); + menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 0)); + menu.setEnabled(false); + popupMenu.add(menu); m_showCallsMenu = menu; } { - JMenuItem menu = new JMenuItem( "Go to Declaration" ); - menu.addActionListener( new ActionListener( ) - { + JMenuItem menu = new JMenuItem("Go to Declaration"); + menu.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { - navigateTo( m_reference.entry ); + public void actionPerformed(ActionEvent event) { + navigateTo(m_reference.entry); } - } ); - menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_N, 0 ) ); - menu.setEnabled( false ); - popupMenu.add( menu ); + }); + menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 0)); + menu.setEnabled(false); + popupMenu.add(menu); m_openEntryMenu = menu; } { - JMenuItem menu = new JMenuItem( "Go to previous" ); - menu.addActionListener( new ActionListener( ) - { + JMenuItem menu = new JMenuItem("Go to previous"); + menu.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { + public void actionPerformed(ActionEvent event) { m_controller.openPreviousReference(); } - } ); - menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_P, 0 ) ); - menu.setEnabled( false ); - popupMenu.add( menu ); + }); + menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, 0)); + menu.setEnabled(false); + popupMenu.add(menu); m_openPreviousMenu = menu; } { - JMenuItem menu = new JMenuItem( "Mark as deobfuscated" ); - menu.addActionListener( new ActionListener( ) - { + JMenuItem menu = new JMenuItem("Mark as deobfuscated"); + menu.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { + public void actionPerformed(ActionEvent event) { toggleMapping(); } - } ); - menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_T, 0 ) ); - menu.setEnabled( false ); - popupMenu.add( menu ); + }); + menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, 0)); + menu.setEnabled(false); + popupMenu.add(menu); m_toggleMappingMenu = menu; } // init inheritance panel m_inheritanceTree = new JTree(); - m_inheritanceTree.setModel( null ); - m_inheritanceTree.addMouseListener( new MouseAdapter( ) - { + m_inheritanceTree.setModel(null); + m_inheritanceTree.addMouseListener(new MouseAdapter() { @Override - public void mouseClicked( MouseEvent event ) - { - if( event.getClickCount() == 2 ) - { + public void mouseClicked(MouseEvent event) { + if (event.getClickCount() == 2) { // get the selected node TreePath path = m_inheritanceTree.getSelectionPath(); - if( path == null ) - { + if (path == null) { return; } Object node = path.getLastPathComponent(); - if( node instanceof ClassInheritanceTreeNode ) - { + if (node instanceof ClassInheritanceTreeNode) { ClassInheritanceTreeNode classNode = (ClassInheritanceTreeNode)node; - navigateTo( new ClassEntry( classNode.getObfClassName() ) ); - } - else if( node instanceof MethodInheritanceTreeNode ) - { + navigateTo(new ClassEntry(classNode.getObfClassName())); + } else if (node instanceof MethodInheritanceTreeNode) { MethodInheritanceTreeNode methodNode = (MethodInheritanceTreeNode)node; - if( methodNode.isImplemented() ) - { - navigateTo( methodNode.getMethodEntry() ); + if (methodNode.isImplemented()) { + navigateTo(methodNode.getMethodEntry()); } } } } - } ); + }); JPanel inheritancePanel = new JPanel(); - inheritancePanel.setLayout( new BorderLayout() ); - inheritancePanel.add( new JScrollPane( m_inheritanceTree ) ); + inheritancePanel.setLayout(new BorderLayout()); + inheritancePanel.add(new JScrollPane(m_inheritanceTree)); // init implementations panel m_implementationsTree = new JTree(); - m_implementationsTree.setModel( null ); - m_implementationsTree.addMouseListener( new MouseAdapter( ) - { + m_implementationsTree.setModel(null); + m_implementationsTree.addMouseListener(new MouseAdapter() { @Override - public void mouseClicked( MouseEvent event ) - { - if( event.getClickCount() == 2 ) - { + public void mouseClicked(MouseEvent event) { + if (event.getClickCount() == 2) { // get the selected node TreePath path = m_implementationsTree.getSelectionPath(); - if( path == null ) - { + if (path == null) { return; } Object node = path.getLastPathComponent(); - if( node instanceof ClassImplementationsTreeNode ) - { + if (node instanceof ClassImplementationsTreeNode) { ClassImplementationsTreeNode classNode = (ClassImplementationsTreeNode)node; - navigateTo( classNode.getClassEntry() ); - } - else if( node instanceof MethodImplementationsTreeNode ) - { + navigateTo(classNode.getClassEntry()); + } else if (node instanceof MethodImplementationsTreeNode) { MethodImplementationsTreeNode methodNode = (MethodImplementationsTreeNode)node; - navigateTo( methodNode.getMethodEntry() ); + navigateTo(methodNode.getMethodEntry()); } } } - } ); + }); JPanel implementationsPanel = new JPanel(); - implementationsPanel.setLayout( new BorderLayout() ); - implementationsPanel.add( new JScrollPane( m_implementationsTree ) ); + implementationsPanel.setLayout(new BorderLayout()); + implementationsPanel.add(new JScrollPane(m_implementationsTree)); // init call panel m_callsTree = new JTree(); - m_callsTree.setModel( null ); - m_callsTree.addMouseListener( new MouseAdapter( ) - { - @SuppressWarnings( "unchecked" ) + m_callsTree.setModel(null); + m_callsTree.addMouseListener(new MouseAdapter() { + @SuppressWarnings("unchecked") @Override - public void mouseClicked( MouseEvent event ) - { - if( event.getClickCount() == 2 ) - { + public void mouseClicked(MouseEvent event) { + if (event.getClickCount() == 2) { // get the selected node TreePath path = m_callsTree.getSelectionPath(); - if( path == null ) - { + if (path == null) { return; } Object node = path.getLastPathComponent(); - if( node instanceof ReferenceTreeNode ) - { + if (node instanceof ReferenceTreeNode) { ReferenceTreeNode referenceNode = ((ReferenceTreeNode)node); - if( referenceNode.getReference() != null ) - { - navigateTo( referenceNode.getReference() ); - } - else - { - navigateTo( referenceNode.getEntry() ); + if (referenceNode.getReference() != null) { + navigateTo(referenceNode.getReference()); + } else { + navigateTo(referenceNode.getEntry()); } } } } - } ); + }); m_tokens = new JList(); - m_tokens.setCellRenderer( new TokenListCellRenderer( m_controller ) ); - m_tokens.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); - m_tokens.setLayoutOrientation( JList.VERTICAL ); - m_tokens.addMouseListener( new MouseAdapter() - { + m_tokens.setCellRenderer(new TokenListCellRenderer(m_controller)); + m_tokens.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + m_tokens.setLayoutOrientation(JList.VERTICAL); + m_tokens.addMouseListener(new MouseAdapter() { @Override - public void mouseClicked( MouseEvent event ) - { - if( event.getClickCount() == 2 ) - { + public void mouseClicked(MouseEvent event) { + if (event.getClickCount() == 2) { Token selected = m_tokens.getSelectedValue(); - if( selected != null ) - { - showToken( selected ); + if (selected != null) { + showToken(selected); } } } - } ); - m_tokens.setPreferredSize( new Dimension( 0, 200 ) ); - m_tokens.setMinimumSize( new Dimension( 0, 200 ) ); - JSplitPane callPanel = new JSplitPane( JSplitPane.VERTICAL_SPLIT, true, new JScrollPane( m_callsTree ), new JScrollPane( m_tokens ) ); - callPanel.setResizeWeight( 1 ); // let the top side take all the slack + }); + m_tokens.setPreferredSize(new Dimension(0, 200)); + m_tokens.setMinimumSize(new Dimension(0, 200)); + JSplitPane callPanel = new JSplitPane( + JSplitPane.VERTICAL_SPLIT, + true, + new JScrollPane(m_callsTree), + new JScrollPane(m_tokens) + ); + callPanel.setResizeWeight(1); // let the top side take all the slack callPanel.resetToPreferredSizes(); // layout controls JPanel centerPanel = new JPanel(); - centerPanel.setLayout( new BorderLayout() ); - centerPanel.add( m_infoPanel, BorderLayout.NORTH ); - centerPanel.add( sourceScroller, BorderLayout.CENTER ); + centerPanel.setLayout(new BorderLayout()); + centerPanel.add(m_infoPanel, BorderLayout.NORTH); + centerPanel.add(sourceScroller, BorderLayout.CENTER); m_tabs = new JTabbedPane(); - m_tabs.setPreferredSize( new Dimension( 250, 0 ) ); - m_tabs.addTab( "Inheritance", inheritancePanel ); - m_tabs.addTab( "Implementations", implementationsPanel ); - m_tabs.addTab( "Call Graph", callPanel ); - JSplitPane splitRight = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, true, centerPanel, m_tabs ); - splitRight.setResizeWeight( 1 ); // let the left side take all the slack + m_tabs.setPreferredSize(new Dimension(250, 0)); + m_tabs.addTab("Inheritance", inheritancePanel); + m_tabs.addTab("Implementations", implementationsPanel); + m_tabs.addTab("Call Graph", callPanel); + JSplitPane splitRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, centerPanel, m_tabs); + splitRight.setResizeWeight(1); // let the left side take all the slack splitRight.resetToPreferredSizes(); - JSplitPane splitCenter = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, true, m_classesPanel, splitRight ); - splitCenter.setResizeWeight( 0 ); // let the right side take all the slack - pane.add( splitCenter, BorderLayout.CENTER ); + JSplitPane splitCenter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, m_classesPanel, splitRight); + splitCenter.setResizeWeight(0); // let the right side take all the slack + pane.add(splitCenter, BorderLayout.CENTER); // init menus JMenuBar menuBar = new JMenuBar(); - m_frame.setJMenuBar( menuBar ); + m_frame.setJMenuBar(menuBar); { - JMenu menu = new JMenu( "File" ); - menuBar.add( menu ); + JMenu menu = new JMenu("File"); + menuBar.add(menu); { - JMenuItem item = new JMenuItem( "Open Jar..." ); - menu.add( item ); - item.addActionListener( new ActionListener( ) - { + JMenuItem item = new JMenuItem("Open Jar..."); + menu.add(item); + item.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { - if( m_jarFileChooser.showOpenDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) - { + public void actionPerformed(ActionEvent event) { + if (m_jarFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { // load the jar in a separate thread - new Thread( ) - { + new Thread() { @Override - public void run( ) - { - try - { - m_controller.openJar( m_jarFileChooser.getSelectedFile() ); - } - catch( IOException ex ) - { - throw new Error( ex ); + public void run() { + try { + m_controller.openJar(m_jarFileChooser.getSelectedFile()); + } catch (IOException ex) { + throw new Error(ex); } } }.start(); } } - } ); + }); } { - JMenuItem item = new JMenuItem( "Close Jar" ); - menu.add( item ); - item.addActionListener( new ActionListener( ) - { + JMenuItem item = new JMenuItem("Close Jar"); + menu.add(item); + item.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { + public void actionPerformed(ActionEvent event) { m_controller.closeJar(); } - } ); + }); m_closeJarMenu = item; } menu.addSeparator(); { - JMenuItem item = new JMenuItem( "Open Mappings..." ); - menu.add( item ); - item.addActionListener( new ActionListener( ) - { + JMenuItem item = new JMenuItem("Open Mappings..."); + menu.add(item); + item.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { - if( m_mappingsFileChooser.showOpenDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) - { - try - { - m_controller.openMappings( m_mappingsFileChooser.getSelectedFile() ); - } - catch( IOException ex ) - { - throw new Error( ex ); - } - catch( MappingParseException ex ) - { - JOptionPane.showMessageDialog( m_frame, ex.getMessage() ); + public void actionPerformed(ActionEvent event) { + if (m_mappingsFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { + try { + m_controller.openMappings(m_mappingsFileChooser.getSelectedFile()); + } catch (IOException ex) { + throw new Error(ex); + } catch (MappingParseException ex) { + JOptionPane.showMessageDialog(m_frame, ex.getMessage()); } } } - } ); + }); m_openMappingsMenu = item; } { - JMenuItem item = new JMenuItem( "Save Mappings" ); - menu.add( item ); - item.addActionListener( new ActionListener( ) - { + JMenuItem item = new JMenuItem("Save Mappings"); + menu.add(item); + item.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { - try - { - m_controller.saveMappings( m_mappingsFileChooser.getSelectedFile() ); - } - catch( IOException ex ) - { - throw new Error( ex ); + public void actionPerformed(ActionEvent event) { + try { + m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); + } catch (IOException ex) { + throw new Error(ex); } } - } ); - item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK ) ); + }); + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); m_saveMappingsMenu = item; } { - JMenuItem item = new JMenuItem( "Save Mappings As..." ); - menu.add( item ); - item.addActionListener( new ActionListener( ) - { + JMenuItem item = new JMenuItem("Save Mappings As..."); + menu.add(item); + item.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { - if( m_mappingsFileChooser.showSaveDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) - { - try - { - m_controller.saveMappings( m_mappingsFileChooser.getSelectedFile() ); - m_saveMappingsMenu.setEnabled( true ); - } - catch( IOException ex ) - { - throw new Error( ex ); + public void actionPerformed(ActionEvent event) { + if (m_mappingsFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { + try { + m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); + m_saveMappingsMenu.setEnabled(true); + } catch (IOException ex) { + throw new Error(ex); } } } - } ); - item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK ) ); + }); + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); m_saveMappingsAsMenu = item; } { - JMenuItem item = new JMenuItem( "Close Mappings" ); - menu.add( item ); - item.addActionListener( new ActionListener( ) - { + JMenuItem item = new JMenuItem("Close Mappings"); + menu.add(item); + item.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { + public void actionPerformed(ActionEvent event) { m_controller.closeMappings(); } - } ); + }); m_closeMappingsMenu = item; } menu.addSeparator(); { - JMenuItem item = new JMenuItem( "Export Source..." ); - menu.add( item ); - item.addActionListener( new ActionListener( ) - { + JMenuItem item = new JMenuItem("Export Source..."); + menu.add(item); + item.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { - if( m_exportSourceFileChooser.showSaveDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) - { - m_controller.exportSource( m_exportSourceFileChooser.getSelectedFile() ); + public void actionPerformed(ActionEvent event) { + if (m_exportSourceFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { + m_controller.exportSource(m_exportSourceFileChooser.getSelectedFile()); } } - } ); + }); m_exportSourceMenu = item; } { - JMenuItem item = new JMenuItem( "Export Jar..." ); - menu.add( item ); - item.addActionListener( new ActionListener( ) - { + JMenuItem item = new JMenuItem("Export Jar..."); + menu.add(item); + item.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { - if( m_exportJarFileChooser.showSaveDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) - { - m_controller.exportJar( m_exportJarFileChooser.getSelectedFile() ); + public void actionPerformed(ActionEvent event) { + if (m_exportJarFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { + m_controller.exportJar(m_exportJarFileChooser.getSelectedFile()); } } - } ); + }); m_exportJarMenu = item; } menu.addSeparator(); { - JMenuItem item = new JMenuItem( "Exit" ); - menu.add( item ); - item.addActionListener( new ActionListener( ) - { + JMenuItem item = new JMenuItem("Exit"); + menu.add(item); + item.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { + public void actionPerformed(ActionEvent event) { close(); } - } ); + }); } } { - JMenu menu = new JMenu( "Help" ); - menuBar.add( menu ); + JMenu menu = new JMenu("Help"); + menuBar.add(menu); { - JMenuItem item = new JMenuItem( "About" ); - menu.add( item ); - item.addActionListener( new ActionListener( ) - { + JMenuItem item = new JMenuItem("About"); + menu.add(item); + item.addActionListener(new ActionListener() { @Override - public void actionPerformed( ActionEvent event ) - { - AboutDialog.show( m_frame ); + public void actionPerformed(ActionEvent event) { + AboutDialog.show(m_frame); } - } ); + }); } } // init state onCloseJar(); - m_frame.addWindowListener( new WindowAdapter( ) - { + m_frame.addWindowListener(new WindowAdapter() { @Override - public void windowClosing( WindowEvent event ) - { + public void windowClosing(WindowEvent event) { close(); } - } ); + }); // show the frame pane.doLayout(); - m_frame.setSize( 1024, 576 ); - m_frame.setMinimumSize( new Dimension( 640, 480 ) ); - m_frame.setVisible( true ); - m_frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); + m_frame.setSize(1024, 576); + m_frame.setMinimumSize(new Dimension(640, 480)); + m_frame.setVisible(true); + m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); } - public JFrame getFrame( ) - { + public JFrame getFrame() { return m_frame; } - public GuiController getController( ) - { + public GuiController getController() { return m_controller; } - public void onStartOpenJar( ) - { + public void onStartOpenJar() { m_classesPanel.removeAll(); JPanel panel = new JPanel(); - panel.setLayout( new FlowLayout() ); - panel.add( new JLabel( "Loading..." ) ); - m_classesPanel.add( panel ); + panel.setLayout(new FlowLayout()); + panel.add(new JLabel("Loading...")); + m_classesPanel.add(panel); redraw(); } - public void onFinishOpenJar( String jarName ) - { + public void onFinishOpenJar(String jarName) { // update gui - m_frame.setTitle( Constants.Name + " - " + jarName ); + m_frame.setTitle(Constants.Name + " - " + jarName); m_classesPanel.removeAll(); - m_classesPanel.add( m_splitClasses ); - setSource( null ); + m_classesPanel.add(m_splitClasses); + setSource(null); // update menu - m_closeJarMenu.setEnabled( true ); - m_openMappingsMenu.setEnabled( true ); - m_saveMappingsMenu.setEnabled( false ); - m_saveMappingsAsMenu.setEnabled( true ); - m_closeMappingsMenu.setEnabled( true ); - m_exportSourceMenu.setEnabled( true ); - m_exportJarMenu.setEnabled( true ); + m_closeJarMenu.setEnabled(true); + m_openMappingsMenu.setEnabled(true); + m_saveMappingsMenu.setEnabled(false); + m_saveMappingsAsMenu.setEnabled(true); + m_closeMappingsMenu.setEnabled(true); + m_exportSourceMenu.setEnabled(true); + m_exportJarMenu.setEnabled(true); redraw(); } - public void onCloseJar( ) - { + public void onCloseJar() { // update gui - m_frame.setTitle( Constants.Name ); - setObfClasses( null ); - setDeobfClasses( null ); - setSource( null ); + m_frame.setTitle(Constants.Name); + setObfClasses(null); + setDeobfClasses(null); + setSource(null); m_classesPanel.removeAll(); // update menu - m_closeJarMenu.setEnabled( false ); - m_openMappingsMenu.setEnabled( false ); - m_saveMappingsMenu.setEnabled( false ); - m_saveMappingsAsMenu.setEnabled( false ); - m_closeMappingsMenu.setEnabled( false ); - m_exportSourceMenu.setEnabled( false ); - m_exportJarMenu.setEnabled( false ); + m_closeJarMenu.setEnabled(false); + m_openMappingsMenu.setEnabled(false); + m_saveMappingsMenu.setEnabled(false); + m_saveMappingsAsMenu.setEnabled(false); + m_closeMappingsMenu.setEnabled(false); + m_exportSourceMenu.setEnabled(false); + m_exportJarMenu.setEnabled(false); redraw(); } - public void setObfClasses( Collection obfClasses ) - { - m_obfClasses.setClasses( obfClasses ); + public void setObfClasses(Collection obfClasses) { + m_obfClasses.setClasses(obfClasses); } - public void setDeobfClasses( Collection deobfClasses ) - { - m_deobfClasses.setClasses( deobfClasses ); + public void setDeobfClasses(Collection deobfClasses) { + m_deobfClasses.setClasses(deobfClasses); } - public void setMappingsFile( File file ) - { - m_mappingsFileChooser.setSelectedFile( file ); - m_saveMappingsMenu.setEnabled( file != null ); + public void setMappingsFile(File file) { + m_mappingsFileChooser.setSelectedFile(file); + m_saveMappingsMenu.setEnabled(file != null); } - public void setSource( String source ) - { + public void setSource(String source) { m_editor.getHighlighter().removeAllHighlights(); - m_editor.setText( source ); + m_editor.setText(source); } - public void showToken( final Token token ) - { - if( token == null ) - { - throw new IllegalArgumentException( "Token cannot be null!" ); + public void showToken(final Token token) { + if (token == null) { + throw new IllegalArgumentException("Token cannot be null!"); } // set the caret position to the token - m_editor.setCaretPosition( token.start ); + m_editor.setCaretPosition(token.start); m_editor.grabFocus(); - try - { + try { // make sure the token is visible in the scroll window - Rectangle start = m_editor.modelToView( token.start ); - Rectangle end = m_editor.modelToView( token.end ); - final Rectangle show = start.union( end ); - show.grow( start.width*10, start.height*6 ); - SwingUtilities.invokeLater( new Runnable( ) - { + Rectangle start = m_editor.modelToView(token.start); + Rectangle end = m_editor.modelToView(token.end); + final Rectangle show = start.union(end); + show.grow(start.width * 10, start.height * 6); + SwingUtilities.invokeLater(new Runnable() { @Override - public void run( ) - { - m_editor.scrollRectToVisible( show ); + public void run() { + m_editor.scrollRectToVisible(show); } - } ); - } - catch( BadLocationException ex ) - { - throw new Error( ex ); + }); + } catch (BadLocationException ex) { + throw new Error(ex); } // highlight the token momentarily - final Timer timer = new Timer( 200, new ActionListener( ) - { + final Timer timer = new Timer(200, new ActionListener() { private int m_counter = 0; private Object m_highlight = null; @Override - public void actionPerformed( ActionEvent event ) - { - if( m_counter % 2 == 0 ) - { - try - { - m_highlight = m_editor.getHighlighter().addHighlight( token.start, token.end, m_selectionHighlightPainter ); - } - catch( BadLocationException ex ) - { + public void actionPerformed(ActionEvent event) { + if (m_counter % 2 == 0) { + try { + m_highlight = m_editor.getHighlighter().addHighlight(token.start, token.end, m_selectionHighlightPainter); + } catch (BadLocationException ex) { // don't care } - } - else if( m_highlight != null ) - { - m_editor.getHighlighter().removeHighlight( m_highlight ); + } else if (m_highlight != null) { + m_editor.getHighlighter().removeHighlight(m_highlight); } - if( m_counter++ > 6 ) - { + if (m_counter++ > 6) { Timer timer = (Timer)event.getSource(); timer.stop(); } } - } ); + }); timer.start(); redraw(); } - public void showTokens( Collection tokens ) - { - Vector sortedTokens = new Vector( tokens ); - Collections.sort( sortedTokens ); - if( sortedTokens.size() > 1 ) - { + public void showTokens(Collection tokens) { + Vector sortedTokens = new Vector(tokens); + Collections.sort(sortedTokens); + if (sortedTokens.size() > 1) { // sort the tokens and update the tokens panel - m_tokens.setListData( sortedTokens ); - m_tokens.setSelectedIndex( 0 ); - } - else - { - m_tokens.setListData( new Vector() ); + m_tokens.setListData(sortedTokens); + m_tokens.setSelectedIndex(0); + } else { + m_tokens.setListData(new Vector()); } // show the first token - showToken( sortedTokens.get( 0 ) ); + showToken(sortedTokens.get(0)); } - public void setHighlightedTokens( Iterable obfuscatedTokens, Iterable deobfuscatedTokens, Iterable otherTokens ) - { + public void setHighlightedTokens(Iterable obfuscatedTokens, Iterable deobfuscatedTokens, Iterable otherTokens) { + // remove any old highlighters m_editor.getHighlighter().removeAllHighlights(); // color things based on the index - if( obfuscatedTokens != null ) - { - setHighlightedTokens( obfuscatedTokens, m_obfuscatedHighlightPainter ); + if (obfuscatedTokens != null) { + setHighlightedTokens(obfuscatedTokens, m_obfuscatedHighlightPainter); } - if( deobfuscatedTokens != null ) - { - setHighlightedTokens( deobfuscatedTokens, m_deobfuscatedHighlightPainter ); + if (deobfuscatedTokens != null) { + setHighlightedTokens(deobfuscatedTokens, m_deobfuscatedHighlightPainter); } - if( otherTokens != null ) - { - setHighlightedTokens( otherTokens, m_otherHighlightPainter ); + if (otherTokens != null) { + setHighlightedTokens(otherTokens, m_otherHighlightPainter); } redraw(); } - private void setHighlightedTokens( Iterable tokens, Highlighter.HighlightPainter painter ) - { - for( Token token : tokens ) - { - try - { - m_editor.getHighlighter().addHighlight( token.start, token.end, painter ); - } - catch( BadLocationException ex ) - { - throw new IllegalArgumentException( ex ); + private void setHighlightedTokens(Iterable tokens, Highlighter.HighlightPainter painter) { + for (Token token : tokens) { + try { + m_editor.getHighlighter().addHighlight(token.start, token.end, painter); + } catch (BadLocationException ex) { + throw new IllegalArgumentException(ex); } } } - private void clearReference( ) - { + private void clearReference() { m_infoPanel.removeAll(); - JLabel label = new JLabel( "No identifier selected" ); - GuiTricks.unboldLabel( label ); - label.setHorizontalAlignment( JLabel.CENTER ); - m_infoPanel.add( label ); + JLabel label = new JLabel("No identifier selected"); + GuiTricks.unboldLabel(label); + label.setHorizontalAlignment(JLabel.CENTER); + m_infoPanel.add(label); redraw(); } - private void showReference( EntryReference reference ) - { - if( reference == null ) - { + private void showReference(EntryReference reference) { + if (reference == null) { clearReference(); return; } @@ -979,383 +848,300 @@ public class Gui m_reference = reference; m_infoPanel.removeAll(); - if( reference.entry instanceof ClassEntry ) - { - showClassEntry( (ClassEntry)m_reference.entry ); - } - else if( m_reference.entry instanceof FieldEntry ) - { - showFieldEntry( (FieldEntry)m_reference.entry ); - } - else if( m_reference.entry instanceof MethodEntry ) - { - showMethodEntry( (MethodEntry)m_reference.entry ); - } - else if( m_reference.entry instanceof ConstructorEntry ) - { - showConstructorEntry( (ConstructorEntry)m_reference.entry ); - } - else if( m_reference.entry instanceof ArgumentEntry ) - { - showArgumentEntry( (ArgumentEntry)m_reference.entry ); - } - else - { - throw new Error( "Unknown entry type: " + m_reference.entry.getClass().getName() ); + if (reference.entry instanceof ClassEntry) { + showClassEntry((ClassEntry)m_reference.entry); + } else if (m_reference.entry instanceof FieldEntry) { + showFieldEntry((FieldEntry)m_reference.entry); + } else if (m_reference.entry instanceof MethodEntry) { + showMethodEntry((MethodEntry)m_reference.entry); + } else if (m_reference.entry instanceof ConstructorEntry) { + showConstructorEntry((ConstructorEntry)m_reference.entry); + } else if (m_reference.entry instanceof ArgumentEntry) { + showArgumentEntry((ArgumentEntry)m_reference.entry); + } else { + throw new Error("Unknown entry type: " + m_reference.entry.getClass().getName()); } redraw(); } - private void showClassEntry( ClassEntry entry ) - { - addNameValue( m_infoPanel, "Class", entry.getName() ); + private void showClassEntry(ClassEntry entry) { + addNameValue(m_infoPanel, "Class", entry.getName()); } - private void showFieldEntry( FieldEntry entry ) - { - addNameValue( m_infoPanel, "Field", entry.getName() ); - addNameValue( m_infoPanel, "Class", entry.getClassEntry().getName() ); + private void showFieldEntry(FieldEntry entry) { + addNameValue(m_infoPanel, "Field", entry.getName()); + addNameValue(m_infoPanel, "Class", entry.getClassEntry().getName()); } - private void showMethodEntry( MethodEntry entry ) - { - addNameValue( m_infoPanel, "Method", entry.getName() ); - addNameValue( m_infoPanel, "Class", entry.getClassEntry().getName() ); - addNameValue( m_infoPanel, "Signature", entry.getSignature() ); + private void showMethodEntry(MethodEntry entry) { + addNameValue(m_infoPanel, "Method", entry.getName()); + addNameValue(m_infoPanel, "Class", entry.getClassEntry().getName()); + addNameValue(m_infoPanel, "Signature", entry.getSignature()); } - private void showConstructorEntry( ConstructorEntry entry ) - { - addNameValue( m_infoPanel, "Constructor", entry.getClassEntry().getName() ); - addNameValue( m_infoPanel, "Signature", entry.getSignature() ); + private void showConstructorEntry(ConstructorEntry entry) { + addNameValue(m_infoPanel, "Constructor", entry.getClassEntry().getName()); + addNameValue(m_infoPanel, "Signature", entry.getSignature()); } - private void showArgumentEntry( ArgumentEntry entry ) - { - addNameValue( m_infoPanel, "Argument", entry.getName() ); - addNameValue( m_infoPanel, "Class", entry.getClassEntry().getName() ); - addNameValue( m_infoPanel, "Method", entry.getBehaviorEntry().getName() ); - addNameValue( m_infoPanel, "Index", Integer.toString( entry.getIndex() ) ); + private void showArgumentEntry(ArgumentEntry entry) { + addNameValue(m_infoPanel, "Argument", entry.getName()); + addNameValue(m_infoPanel, "Class", entry.getClassEntry().getName()); + addNameValue(m_infoPanel, "Method", entry.getBehaviorEntry().getName()); + addNameValue(m_infoPanel, "Index", Integer.toString(entry.getIndex())); } - private void addNameValue( JPanel container, String name, String value ) - { + private void addNameValue(JPanel container, String name, String value) { JPanel panel = new JPanel(); - panel.setLayout( new FlowLayout( FlowLayout.LEFT, 6, 0 ) ); - container.add( panel ); + panel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0)); + container.add(panel); - JLabel label = new JLabel( name + ":", JLabel.RIGHT ); - label.setPreferredSize( new Dimension( 100, label.getPreferredSize().height ) ); - panel.add( label ); + JLabel label = new JLabel(name + ":", JLabel.RIGHT); + label.setPreferredSize(new Dimension(100, label.getPreferredSize().height)); + panel.add(label); - panel.add( GuiTricks.unboldLabel( new JLabel( value, JLabel.LEFT ) ) ); + panel.add(GuiTricks.unboldLabel(new JLabel(value, JLabel.LEFT))); } - private void onCaretMove( int pos ) - { - Token token = m_controller.getToken( pos ); + private void onCaretMove(int pos) { + + Token token = m_controller.getToken(pos); boolean isToken = token != null; - m_reference = m_controller.getDeobfReference( token ); + m_reference = m_controller.getDeobfReference(token); boolean isClassEntry = isToken && m_reference.entry instanceof ClassEntry; boolean isFieldEntry = isToken && m_reference.entry instanceof FieldEntry; boolean isMethodEntry = isToken && m_reference.entry instanceof MethodEntry; boolean isConstructorEntry = isToken && m_reference.entry instanceof ConstructorEntry; - boolean isInJar = isToken && m_controller.entryIsInJar( m_reference.entry ); - boolean isRenameable = isToken && m_controller.referenceIsRenameable( m_reference ); + boolean isInJar = isToken && m_controller.entryIsInJar(m_reference.entry); + boolean isRenameable = isToken && m_controller.referenceIsRenameable(m_reference); - if( isToken ) - { - showReference( m_reference ); - } - else - { + if (isToken) { + showReference(m_reference); + } else { clearReference(); } - m_renameMenu.setEnabled( isRenameable && isToken ); - m_showInheritanceMenu.setEnabled( isClassEntry || isMethodEntry || isConstructorEntry ); - m_showImplementationsMenu.setEnabled( isClassEntry || isMethodEntry ); - m_showCallsMenu.setEnabled( isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry ); - m_openEntryMenu.setEnabled( isInJar && ( isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry ) ); - m_openPreviousMenu.setEnabled( m_controller.hasPreviousLocation() ); - m_toggleMappingMenu.setEnabled( isRenameable && isToken ); + m_renameMenu.setEnabled(isRenameable && isToken); + m_showInheritanceMenu.setEnabled(isClassEntry || isMethodEntry || isConstructorEntry); + m_showImplementationsMenu.setEnabled(isClassEntry || isMethodEntry); + m_showCallsMenu.setEnabled(isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry); + m_openEntryMenu.setEnabled(isInJar && (isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry)); + m_openPreviousMenu.setEnabled(m_controller.hasPreviousLocation()); + m_toggleMappingMenu.setEnabled(isRenameable && isToken); - if( isToken && m_controller.entryHasDeobfuscatedName( m_reference.entry ) ) - { - m_toggleMappingMenu.setText( "Reset to obfuscated" ); - } - else - { - m_toggleMappingMenu.setText( "Mark as deobfuscated" ); + if (isToken && m_controller.entryHasDeobfuscatedName(m_reference.entry)) { + m_toggleMappingMenu.setText("Reset to obfuscated"); + } else { + m_toggleMappingMenu.setText("Mark as deobfuscated"); } } - private void navigateTo( Entry entry ) - { - if( !m_controller.entryIsInJar( entry ) ) - { + private void navigateTo(Entry entry) { + if (!m_controller.entryIsInJar(entry)) { // entry is not in the jar. Ignore it return; } - if( m_reference != null ) - { - m_controller.savePreviousReference( m_reference ); + if (m_reference != null) { + m_controller.savePreviousReference(m_reference); } - m_controller.openDeclaration( entry ); + m_controller.openDeclaration(entry); } - private void navigateTo( EntryReference reference ) - { - if( !m_controller.entryIsInJar( reference.getLocationClassEntry() ) ) - { + private void navigateTo(EntryReference reference) { + if (!m_controller.entryIsInJar(reference.getLocationClassEntry())) { // reference is not in the jar. Ignore it return; } - if( m_reference != null ) - { - m_controller.savePreviousReference( m_reference ); + if (m_reference != null) { + m_controller.savePreviousReference(m_reference); } - m_controller.openReference( reference ); + m_controller.openReference(reference); } - private void startRename( ) - { + private void startRename() { + // init the text box final JTextField text = new JTextField(); - text.setText( m_reference.getNamableName() ); - text.setPreferredSize( new Dimension( 360, text.getPreferredSize().height ) ); - text.addKeyListener( new KeyAdapter( ) - { + text.setText(m_reference.getNamableName()); + text.setPreferredSize(new Dimension(360, text.getPreferredSize().height)); + text.addKeyListener(new KeyAdapter() { @Override - public void keyPressed( KeyEvent event ) - { - switch( event.getKeyCode() ) - { + public void keyPressed(KeyEvent event) { + switch (event.getKeyCode()) { case KeyEvent.VK_ENTER: - finishRename( text, true ); + finishRename(text, true); break; case KeyEvent.VK_ESCAPE: - finishRename( text, false ); + finishRename(text, false); break; } } - } ); + }); // find the label with the name and replace it with the text box - JPanel panel = (JPanel)m_infoPanel.getComponent( 0 ); - panel.remove( panel.getComponentCount() - 1 ); - panel.add( text ); + JPanel panel = (JPanel)m_infoPanel.getComponent(0); + panel.remove(panel.getComponentCount() - 1); + panel.add(text); text.grabFocus(); text.selectAll(); redraw(); } - private void finishRename( JTextField text, boolean saveName ) - { + private void finishRename(JTextField text, boolean saveName) { String newName = text.getText(); - if( saveName && newName != null && newName.length() > 0 ) - { - try - { - m_controller.rename( m_reference, newName ); - } - catch( IllegalNameException ex ) - { - text.setBorder( BorderFactory.createLineBorder( Color.red, 1 ) ); - text.setToolTipText( ex.getReason() ); - GuiTricks.showToolTipNow( text ); + if (saveName && newName != null && newName.length() > 0) { + try { + m_controller.rename(m_reference, newName); + } catch (IllegalNameException ex) { + text.setBorder(BorderFactory.createLineBorder(Color.red, 1)); + text.setToolTipText(ex.getReason()); + GuiTricks.showToolTipNow(text); } return; } // abort the rename - JPanel panel = (JPanel)m_infoPanel.getComponent( 0 ); - panel.remove( panel.getComponentCount() - 1 ); - panel.add( GuiTricks.unboldLabel( new JLabel( m_reference.getNamableName(), JLabel.LEFT ) ) ); + JPanel panel = (JPanel)m_infoPanel.getComponent(0); + panel.remove(panel.getComponentCount() - 1); + panel.add(GuiTricks.unboldLabel(new JLabel(m_reference.getNamableName(), JLabel.LEFT))); m_editor.grabFocus(); redraw(); } - private void showInheritance( ) - { - if( m_reference == null ) - { + private void showInheritance() { + + if (m_reference == null) { return; } - m_inheritanceTree.setModel( null ); + m_inheritanceTree.setModel(null); - if( m_reference.entry instanceof ClassEntry ) - { + if (m_reference.entry instanceof ClassEntry) { // get the class inheritance - ClassInheritanceTreeNode classNode = m_controller.getClassInheritance( (ClassEntry)m_reference.entry ); + ClassInheritanceTreeNode classNode = m_controller.getClassInheritance((ClassEntry)m_reference.entry); // show the tree at the root - TreePath path = getPathToRoot( classNode ); - m_inheritanceTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) ); - m_inheritanceTree.expandPath( path ); - m_inheritanceTree.setSelectionRow( m_inheritanceTree.getRowForPath( path ) ); - } - else if( m_reference.entry instanceof MethodEntry ) - { + TreePath path = getPathToRoot(classNode); + m_inheritanceTree.setModel(new DefaultTreeModel((TreeNode)path.getPathComponent(0))); + m_inheritanceTree.expandPath(path); + m_inheritanceTree.setSelectionRow(m_inheritanceTree.getRowForPath(path)); + } else if (m_reference.entry instanceof MethodEntry) { // get the method inheritance - MethodInheritanceTreeNode classNode = m_controller.getMethodInheritance( (MethodEntry)m_reference.entry ); + MethodInheritanceTreeNode classNode = m_controller.getMethodInheritance((MethodEntry)m_reference.entry); // show the tree at the root - TreePath path = getPathToRoot( classNode ); - m_inheritanceTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) ); - m_inheritanceTree.expandPath( path ); - m_inheritanceTree.setSelectionRow( m_inheritanceTree.getRowForPath( path ) ); + TreePath path = getPathToRoot(classNode); + m_inheritanceTree.setModel(new DefaultTreeModel((TreeNode)path.getPathComponent(0))); + m_inheritanceTree.expandPath(path); + m_inheritanceTree.setSelectionRow(m_inheritanceTree.getRowForPath(path)); } - m_tabs.setSelectedIndex( 0 ); + m_tabs.setSelectedIndex(0); redraw(); } - private void showImplementations( ) - { - if( m_reference == null ) - { + private void showImplementations() { + + if (m_reference == null) { return; } - m_implementationsTree.setModel( null ); + m_implementationsTree.setModel(null); - if( m_reference.entry instanceof ClassEntry ) - { + if (m_reference.entry instanceof ClassEntry) { // get the class implementations - ClassImplementationsTreeNode node = m_controller.getClassImplementations( (ClassEntry)m_reference.entry ); - if( node != null ) - { + ClassImplementationsTreeNode node = m_controller.getClassImplementations((ClassEntry)m_reference.entry); + if (node != null) { // show the tree at the root - TreePath path = getPathToRoot( node ); - m_implementationsTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) ); - m_implementationsTree.expandPath( path ); - m_implementationsTree.setSelectionRow( m_implementationsTree.getRowForPath( path ) ); + TreePath path = getPathToRoot(node); + m_implementationsTree.setModel(new DefaultTreeModel((TreeNode)path.getPathComponent(0))); + m_implementationsTree.expandPath(path); + m_implementationsTree.setSelectionRow(m_implementationsTree.getRowForPath(path)); } - } - else if( m_reference.entry instanceof MethodEntry ) - { + } else if (m_reference.entry instanceof MethodEntry) { // get the method implementations - MethodImplementationsTreeNode node = m_controller.getMethodImplementations( (MethodEntry)m_reference.entry ); - if( node != null ) - { + MethodImplementationsTreeNode node = m_controller.getMethodImplementations((MethodEntry)m_reference.entry); + if (node != null) { // show the tree at the root - TreePath path = getPathToRoot( node ); - m_implementationsTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) ); - m_implementationsTree.expandPath( path ); - m_implementationsTree.setSelectionRow( m_implementationsTree.getRowForPath( path ) ); + TreePath path = getPathToRoot(node); + m_implementationsTree.setModel(new DefaultTreeModel((TreeNode)path.getPathComponent(0))); + m_implementationsTree.expandPath(path); + m_implementationsTree.setSelectionRow(m_implementationsTree.getRowForPath(path)); } } - m_tabs.setSelectedIndex( 1 ); + m_tabs.setSelectedIndex(1); redraw(); } - private void showCalls( ) - { - if( m_reference == null ) - { + private void showCalls() { + + if (m_reference == null) { return; } - if( m_reference.entry instanceof ClassEntry ) - { + if (m_reference.entry instanceof ClassEntry) { // look for calls to the default constructor // TODO: get a list of all the constructors and find calls to all of them - BehaviorReferenceTreeNode node = m_controller.getMethodReferences( new ConstructorEntry( (ClassEntry)m_reference.entry, "()V" ) ); - m_callsTree.setModel( new DefaultTreeModel( node ) ); - } - else if( m_reference.entry instanceof FieldEntry ) - { - FieldReferenceTreeNode node = m_controller.getFieldReferences( (FieldEntry)m_reference.entry ); - m_callsTree.setModel( new DefaultTreeModel( node ) ); - } - else if( m_reference.entry instanceof MethodEntry ) - { - BehaviorReferenceTreeNode node = m_controller.getMethodReferences( (MethodEntry)m_reference.entry ); - m_callsTree.setModel( new DefaultTreeModel( node ) ); - } - else if( m_reference.entry instanceof ConstructorEntry ) - { - BehaviorReferenceTreeNode node = m_controller.getMethodReferences( (ConstructorEntry)m_reference.entry ); - m_callsTree.setModel( new DefaultTreeModel( node ) ); + BehaviorReferenceTreeNode node = m_controller.getMethodReferences(new ConstructorEntry((ClassEntry)m_reference.entry, "()V")); + m_callsTree.setModel(new DefaultTreeModel(node)); + } else if (m_reference.entry instanceof FieldEntry) { + FieldReferenceTreeNode node = m_controller.getFieldReferences((FieldEntry)m_reference.entry); + m_callsTree.setModel(new DefaultTreeModel(node)); + } else if (m_reference.entry instanceof MethodEntry) { + BehaviorReferenceTreeNode node = m_controller.getMethodReferences((MethodEntry)m_reference.entry); + m_callsTree.setModel(new DefaultTreeModel(node)); + } else if (m_reference.entry instanceof ConstructorEntry) { + BehaviorReferenceTreeNode node = m_controller.getMethodReferences((ConstructorEntry)m_reference.entry); + m_callsTree.setModel(new DefaultTreeModel(node)); } - m_tabs.setSelectedIndex( 2 ); + m_tabs.setSelectedIndex(2); redraw(); } - private void toggleMapping() - { - if( m_controller.entryHasDeobfuscatedName( m_reference.entry ) ) - { - m_controller.removeMapping( m_reference ); - } - else - { - m_controller.markAsDeobfuscated( m_reference ); + private void toggleMapping() { + if (m_controller.entryHasDeobfuscatedName(m_reference.entry)) { + m_controller.removeMapping(m_reference); + } else { + m_controller.markAsDeobfuscated(m_reference); } } - private TreePath getPathToRoot( TreeNode node ) - { + private TreePath getPathToRoot(TreeNode node) { List nodes = Lists.newArrayList(); TreeNode n = node; - do - { - nodes.add( n ); + do { + nodes.add(n); n = n.getParent(); - } - while( n != null ); - Collections.reverse( nodes ); - return new TreePath( nodes.toArray() ); + } while (n != null); + Collections.reverse(nodes); + return new TreePath(nodes.toArray()); } - private void close( ) - { - if( !m_controller.isDirty() ) - { + private void close() { + if (!m_controller.isDirty()) { // everything is saved, we can exit safely m_frame.dispose(); - } - else - { + } else { // ask to save before closing - String[] options = { - "Save and exit", - "Discard changes", - "Cancel" - }; - int response = JOptionPane.showOptionDialog( - m_frame, - "Your mappings have not been saved yet. Do you want to save?", - "Save your changes?", - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, - null, - options, - options[2] - ); - switch( response ) - { + String[] options = { "Save and exit", "Discard changes", "Cancel" }; + int response = JOptionPane.showOptionDialog(m_frame, "Your mappings have not been saved yet. Do you want to save?", "Save your changes?", JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE, null, options, options[2]); + switch (response) { case JOptionPane.YES_OPTION: // save and exit - if( m_mappingsFileChooser.getSelectedFile() != null || m_mappingsFileChooser.showSaveDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) - { - try - { - m_controller.saveMappings( m_mappingsFileChooser.getSelectedFile() ); + if (m_mappingsFileChooser.getSelectedFile() != null || m_mappingsFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { + try { + m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); m_frame.dispose(); - } - catch( IOException ex ) - { - throw new Error( ex ); + } catch (IOException ex) { + throw new Error(ex); } } break; @@ -1364,14 +1150,13 @@ public class Gui // don't save, exit m_frame.dispose(); break; - + // cancel means do nothing } } } - - private void redraw( ) - { + + private void redraw() { m_frame.validate(); m_frame.repaint(); } diff --git a/src/cuchaz/enigma/gui/GuiController.java b/src/cuchaz/enigma/gui/GuiController.java index 2862ebe..908c16f 100644 --- a/src/cuchaz/enigma/gui/GuiController.java +++ b/src/cuchaz/enigma/gui/GuiController.java @@ -44,8 +44,8 @@ import cuchaz.enigma.mapping.MappingsWriter; import cuchaz.enigma.mapping.MethodEntry; import cuchaz.enigma.mapping.TranslationDirection; -public class GuiController -{ +public class GuiController { + private Deobfuscator m_deobfuscator; private Gui m_gui; private SourceIndex m_index; @@ -53,8 +53,7 @@ public class GuiController private boolean m_isDirty; private Deque> m_referenceStack; - public GuiController( Gui gui ) - { + public GuiController(Gui gui) { m_gui = gui; m_deobfuscator = null; m_index = null; @@ -63,358 +62,292 @@ public class GuiController m_referenceStack = Queues.newArrayDeque(); } - public boolean isDirty( ) - { + public boolean isDirty() { return m_isDirty; } - public void openJar( final File file ) - throws IOException - { + public void openJar(final File file) throws IOException { m_gui.onStartOpenJar(); - m_deobfuscator = new Deobfuscator( file ); - m_gui.onFinishOpenJar( m_deobfuscator.getJarName() ); + m_deobfuscator = new Deobfuscator(file); + m_gui.onFinishOpenJar(m_deobfuscator.getJarName()); refreshClasses(); } - public void closeJar( ) - { + public void closeJar() { m_deobfuscator = null; m_gui.onCloseJar(); } - public void openMappings( File file ) - throws IOException, MappingParseException - { - FileReader in = new FileReader( file ); - m_deobfuscator.setMappings( new MappingsReader().read( in ) ); + public void openMappings(File file) throws IOException, MappingParseException { + FileReader in = new FileReader(file); + m_deobfuscator.setMappings(new MappingsReader().read(in)); in.close(); m_isDirty = false; - m_gui.setMappingsFile( file ); + m_gui.setMappingsFile(file); refreshClasses(); refreshCurrentClass(); } - - public void saveMappings( File file ) - throws IOException - { - FileWriter out = new FileWriter( file ); - new MappingsWriter().write( out, m_deobfuscator.getMappings() ); + + public void saveMappings(File file) throws IOException { + FileWriter out = new FileWriter(file); + new MappingsWriter().write(out, m_deobfuscator.getMappings()); out.close(); m_isDirty = false; } - - public void closeMappings( ) - { - m_deobfuscator.setMappings( null ); - m_gui.setMappingsFile( null ); + + public void closeMappings() { + m_deobfuscator.setMappings(null); + m_gui.setMappingsFile(null); refreshClasses(); refreshCurrentClass(); } - public void exportSource( final File dirOut ) - { - ProgressDialog.runInThread( m_gui.getFrame(), new ProgressRunnable( ) - { + public void exportSource(final File dirOut) { + ProgressDialog.runInThread(m_gui.getFrame(), new ProgressRunnable() { @Override - public void run( ProgressListener progress ) - throws Exception - { - m_deobfuscator.writeSources( dirOut, progress ); + public void run(ProgressListener progress) throws Exception { + m_deobfuscator.writeSources(dirOut, progress); } - } ); + }); } - public void exportJar( final File fileOut ) - { - ProgressDialog.runInThread( m_gui.getFrame(), new ProgressRunnable( ) - { + public void exportJar(final File fileOut) { + ProgressDialog.runInThread(m_gui.getFrame(), new ProgressRunnable() { @Override - public void run( ProgressListener progress ) - { - m_deobfuscator.writeJar( fileOut, progress ); + public void run(ProgressListener progress) { + m_deobfuscator.writeJar(fileOut, progress); } - } ); + }); } - public Token getToken( int pos ) - { - if( m_index == null ) - { + public Token getToken(int pos) { + if (m_index == null) { return null; } - return m_index.getReferenceToken( pos ); + return m_index.getReferenceToken(pos); } - public EntryReference getDeobfReference( Token token ) - { - if( m_index == null ) - { + public EntryReference getDeobfReference(Token token) { + if (m_index == null) { return null; } - return m_index.getDeobfReference( token ); + return m_index.getDeobfReference(token); } - public ReadableToken getReadableToken( Token token ) - { - if( m_index == null ) - { + public ReadableToken getReadableToken(Token token) { + if (m_index == null) { return null; } return new ReadableToken( - m_index.getLineNumber( token.start ), - m_index.getColumnNumber( token.start ), - m_index.getColumnNumber( token.end ) + m_index.getLineNumber(token.start), + m_index.getColumnNumber(token.start), + m_index.getColumnNumber(token.end) ); } - public boolean entryHasDeobfuscatedName( Entry deobfEntry ) - { - return m_deobfuscator.hasDeobfuscatedName( m_deobfuscator.obfuscateEntry( deobfEntry ) ); + public boolean entryHasDeobfuscatedName(Entry deobfEntry) { + return m_deobfuscator.hasDeobfuscatedName(m_deobfuscator.obfuscateEntry(deobfEntry)); } - public boolean entryIsInJar( Entry deobfEntry ) - { - return m_deobfuscator.isObfuscatedIdentifier( m_deobfuscator.obfuscateEntry( deobfEntry ) ); + public boolean entryIsInJar(Entry deobfEntry) { + return m_deobfuscator.isObfuscatedIdentifier(m_deobfuscator.obfuscateEntry(deobfEntry)); } - public boolean referenceIsRenameable( EntryReference deobfReference ) - { - return m_deobfuscator.isRenameable( m_deobfuscator.obfuscateReference( deobfReference ) ); + public boolean referenceIsRenameable(EntryReference deobfReference) { + return m_deobfuscator.isRenameable(m_deobfuscator.obfuscateReference(deobfReference)); } - public ClassInheritanceTreeNode getClassInheritance( ClassEntry deobfClassEntry ) - { - ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry( deobfClassEntry ); + public ClassInheritanceTreeNode getClassInheritance(ClassEntry deobfClassEntry) { + ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry(deobfClassEntry); ClassInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getClassInheritance( - m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), + m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry ); - return ClassInheritanceTreeNode.findNode( rootNode, obfClassEntry ); + return ClassInheritanceTreeNode.findNode(rootNode, obfClassEntry); } - public ClassImplementationsTreeNode getClassImplementations( ClassEntry deobfClassEntry ) - { - ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry( deobfClassEntry ); + public ClassImplementationsTreeNode getClassImplementations(ClassEntry deobfClassEntry) { + ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry(deobfClassEntry); return m_deobfuscator.getJarIndex().getClassImplementations( - m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), + m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry ); } - public MethodInheritanceTreeNode getMethodInheritance( MethodEntry deobfMethodEntry ) - { - MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry( deobfMethodEntry ); + public MethodInheritanceTreeNode getMethodInheritance(MethodEntry deobfMethodEntry) { + MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry(deobfMethodEntry); MethodInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getMethodInheritance( - m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), + m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry ); - return MethodInheritanceTreeNode.findNode( rootNode, obfMethodEntry ); + return MethodInheritanceTreeNode.findNode(rootNode, obfMethodEntry); } - public MethodImplementationsTreeNode getMethodImplementations( MethodEntry deobfMethodEntry ) - { - MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry( deobfMethodEntry ); + public MethodImplementationsTreeNode getMethodImplementations(MethodEntry deobfMethodEntry) { + MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry(deobfMethodEntry); MethodImplementationsTreeNode rootNode = m_deobfuscator.getJarIndex().getMethodImplementations( - m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), + m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry ); - if( rootNode == null ) - { + if (rootNode == null) { return null; } - return MethodImplementationsTreeNode.findNode( rootNode, obfMethodEntry ); + return MethodImplementationsTreeNode.findNode(rootNode, obfMethodEntry); } - public FieldReferenceTreeNode getFieldReferences( FieldEntry deobfFieldEntry ) - { - FieldEntry obfFieldEntry = m_deobfuscator.obfuscateEntry( deobfFieldEntry ); + public FieldReferenceTreeNode getFieldReferences(FieldEntry deobfFieldEntry) { + FieldEntry obfFieldEntry = m_deobfuscator.obfuscateEntry(deobfFieldEntry); FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode( - m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), + m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfFieldEntry ); - rootNode.load( m_deobfuscator.getJarIndex(), true ); + rootNode.load(m_deobfuscator.getJarIndex(), true); return rootNode; } - public BehaviorReferenceTreeNode getMethodReferences( BehaviorEntry deobfBehaviorEntry ) - { - BehaviorEntry obfBehaviorEntry = m_deobfuscator.obfuscateEntry( deobfBehaviorEntry ); + public BehaviorReferenceTreeNode getMethodReferences(BehaviorEntry deobfBehaviorEntry) { + BehaviorEntry obfBehaviorEntry = m_deobfuscator.obfuscateEntry(deobfBehaviorEntry); BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode( - m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), + m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfBehaviorEntry ); - rootNode.load( m_deobfuscator.getJarIndex(), true ); + rootNode.load(m_deobfuscator.getJarIndex(), true); return rootNode; } - public void rename( EntryReference deobfReference, String newName ) - { - EntryReference obfReference = m_deobfuscator.obfuscateReference( deobfReference ); - m_deobfuscator.rename( obfReference.getNameableEntry(), newName ); + public void rename(EntryReference deobfReference, String newName) { + EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); + m_deobfuscator.rename(obfReference.getNameableEntry(), newName); m_isDirty = true; refreshClasses(); - refreshCurrentClass( obfReference ); + refreshCurrentClass(obfReference); } - public void removeMapping( EntryReference deobfReference ) - { - EntryReference obfReference = m_deobfuscator.obfuscateReference( deobfReference ); - m_deobfuscator.removeMapping( obfReference.getNameableEntry() ); + public void removeMapping(EntryReference deobfReference) { + EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); + m_deobfuscator.removeMapping(obfReference.getNameableEntry()); m_isDirty = true; refreshClasses(); - refreshCurrentClass( obfReference ); + refreshCurrentClass(obfReference); } - public void markAsDeobfuscated( EntryReference deobfReference ) - { - EntryReference obfReference = m_deobfuscator.obfuscateReference( deobfReference ); - m_deobfuscator.markAsDeobfuscated( obfReference.getNameableEntry() ); + public void markAsDeobfuscated(EntryReference deobfReference) { + EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); + m_deobfuscator.markAsDeobfuscated(obfReference.getNameableEntry()); m_isDirty = true; refreshClasses(); - refreshCurrentClass( obfReference ); + refreshCurrentClass(obfReference); } - public void openDeclaration( Entry deobfEntry ) - { - if( deobfEntry == null ) - { - throw new IllegalArgumentException( "Entry cannot be null!" ); + public void openDeclaration(Entry deobfEntry) { + if (deobfEntry == null) { + throw new IllegalArgumentException("Entry cannot be null!"); } - openReference( new EntryReference( deobfEntry, deobfEntry.getName() ) ); + openReference(new EntryReference(deobfEntry, deobfEntry.getName())); } - public void openReference( EntryReference deobfReference ) - { - if( deobfReference == null ) - { - throw new IllegalArgumentException( "Reference cannot be null!" ); + public void openReference(EntryReference deobfReference) { + if (deobfReference == null) { + throw new IllegalArgumentException("Reference cannot be null!"); } // get the reference target class - EntryReference obfReference = m_deobfuscator.obfuscateReference( deobfReference ); + EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); ClassEntry obfClassEntry = obfReference.getLocationClassEntry().getOuterClassEntry(); - if( !m_deobfuscator.isObfuscatedIdentifier( obfClassEntry ) ) - { - throw new IllegalArgumentException( "Obfuscated class " + obfClassEntry + " was not found in the jar!" ); + if (!m_deobfuscator.isObfuscatedIdentifier(obfClassEntry)) { + throw new IllegalArgumentException("Obfuscated class " + obfClassEntry + " was not found in the jar!"); } - if( m_currentObfClass == null || !m_currentObfClass.equals( obfClassEntry ) ) - { + if (m_currentObfClass == null || !m_currentObfClass.equals(obfClassEntry)) { // deobfuscate the class, then navigate to the reference m_currentObfClass = obfClassEntry; - deobfuscate( m_currentObfClass, obfReference ); - } - else - { - showReference( obfReference ); + deobfuscate(m_currentObfClass, obfReference); + } else { + showReference(obfReference); } } - private void showReference( EntryReference obfReference ) - { - EntryReference deobfReference = m_deobfuscator.deobfuscateReference( obfReference ); - Collection tokens = m_index.getReferenceTokens( deobfReference ); - if( tokens.isEmpty() ) - { + private void showReference(EntryReference obfReference) { + EntryReference deobfReference = m_deobfuscator.deobfuscateReference(obfReference); + Collection tokens = m_index.getReferenceTokens(deobfReference); + if (tokens.isEmpty()) { // DEBUG - System.err.println( String.format( "WARNING: no tokens found for %s in %s", deobfReference, m_currentObfClass ) ); - } - else - { - m_gui.showTokens( tokens ); + System.err.println(String.format("WARNING: no tokens found for %s in %s", deobfReference, m_currentObfClass)); + } else { + m_gui.showTokens(tokens); } } - public void savePreviousReference( EntryReference deobfReference ) - { - m_referenceStack.push( m_deobfuscator.obfuscateReference( deobfReference ) ); + public void savePreviousReference(EntryReference deobfReference) { + m_referenceStack.push(m_deobfuscator.obfuscateReference(deobfReference)); } - public void openPreviousReference( ) - { - if( hasPreviousLocation() ) - { - openReference( m_deobfuscator.deobfuscateReference( m_referenceStack.pop() ) ); + public void openPreviousReference() { + if (hasPreviousLocation()) { + openReference(m_deobfuscator.deobfuscateReference(m_referenceStack.pop())); } } - public boolean hasPreviousLocation( ) - { + public boolean hasPreviousLocation() { return !m_referenceStack.isEmpty(); } - private void refreshClasses( ) - { + private void refreshClasses() { List obfClasses = Lists.newArrayList(); List deobfClasses = Lists.newArrayList(); - m_deobfuscator.getSeparatedClasses( obfClasses, deobfClasses ); - m_gui.setObfClasses( obfClasses ); - m_gui.setDeobfClasses( deobfClasses ); + m_deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); + m_gui.setObfClasses(obfClasses); + m_gui.setDeobfClasses(deobfClasses); } - private void refreshCurrentClass( ) - { - refreshCurrentClass( null ); + private void refreshCurrentClass() { + refreshCurrentClass(null); } - private void refreshCurrentClass( EntryReference obfReference ) - { - if( m_currentObfClass != null ) - { - deobfuscate( m_currentObfClass, obfReference ); + private void refreshCurrentClass(EntryReference obfReference) { + if (m_currentObfClass != null) { + deobfuscate(m_currentObfClass, obfReference); } } - private void deobfuscate( final ClassEntry classEntry, final EntryReference obfReference ) - { - m_gui.setSource( "(deobfuscating...)" ); + private void deobfuscate(final ClassEntry classEntry, final EntryReference obfReference) { + + m_gui.setSource("(deobfuscating...)"); // run the deobfuscator in a separate thread so we don't block the GUI event queue - new Thread( ) - { + new Thread() { @Override - public void run( ) - { + public void run() { // decompile,deobfuscate the bytecode - CompilationUnit sourceTree = m_deobfuscator.getSourceTree( classEntry.getClassName() ); - if( sourceTree == null ) - { + CompilationUnit sourceTree = m_deobfuscator.getSourceTree(classEntry.getClassName()); + if (sourceTree == null) { // decompilation of this class is not supported m_gui.setSource("Unable to find class: " + classEntry); return; } - String source = m_deobfuscator.getSource( sourceTree ); - m_index = m_deobfuscator.getSourceIndex( sourceTree, source ); - m_gui.setSource( m_index.getSource() ); - if( obfReference != null ) - { - showReference( obfReference ); + String source = m_deobfuscator.getSource(sourceTree); + m_index = m_deobfuscator.getSourceIndex(sourceTree, source); + m_gui.setSource(m_index.getSource()); + if (obfReference != null) { + showReference(obfReference); } // set the highlighted tokens List obfuscatedTokens = Lists.newArrayList(); List deobfuscatedTokens = Lists.newArrayList(); List otherTokens = Lists.newArrayList(); - for( Token token : m_index.referenceTokens() ) - { - EntryReference reference = m_index.getDeobfReference( token ); - if( referenceIsRenameable( reference ) ) - { - if( entryHasDeobfuscatedName( reference.getNameableEntry() ) ) - { - deobfuscatedTokens.add( token ); + for (Token token : m_index.referenceTokens()) { + EntryReference reference = m_index.getDeobfReference(token); + if (referenceIsRenameable(reference)) { + if (entryHasDeobfuscatedName(reference.getNameableEntry())) { + deobfuscatedTokens.add(token); + } else { + obfuscatedTokens.add(token); } - else - { - obfuscatedTokens.add( token ); - } - } - else - { - otherTokens.add( token ); + } else { + otherTokens.add(token); } } - m_gui.setHighlightedTokens( obfuscatedTokens, deobfuscatedTokens, otherTokens ); + m_gui.setHighlightedTokens(obfuscatedTokens, deobfuscatedTokens, otherTokens); } }.start(); } diff --git a/src/cuchaz/enigma/gui/GuiTricks.java b/src/cuchaz/enigma/gui/GuiTricks.java index 9b889ef..df9e221 100644 --- a/src/cuchaz/enigma/gui/GuiTricks.java +++ b/src/cuchaz/enigma/gui/GuiTricks.java @@ -17,27 +17,20 @@ import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.ToolTipManager; -public class GuiTricks -{ - public static JLabel unboldLabel( JLabel label ) - { +public class GuiTricks { + + public static JLabel unboldLabel(JLabel label) { Font font = label.getFont(); - label.setFont( font.deriveFont( font.getStyle() & ~Font.BOLD ) ); + label.setFont(font.deriveFont(font.getStyle() & ~Font.BOLD)); return label; } - public static void showToolTipNow( JComponent component ) - { + public static void showToolTipNow(JComponent component) { // HACKHACK: trick the tooltip manager into showing the tooltip right now ToolTipManager manager = ToolTipManager.sharedInstance(); int oldDelay = manager.getInitialDelay(); - manager.setInitialDelay( 0 ); - manager.mouseMoved( new MouseEvent( - component, - MouseEvent.MOUSE_MOVED, - System.currentTimeMillis(), - 0, 0, 0, 0, false - ) ); - manager.setInitialDelay( oldDelay ); + manager.setInitialDelay(0); + manager.mouseMoved(new MouseEvent(component, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, 0, 0, 0, false)); + manager.setInitialDelay(oldDelay); } } diff --git a/src/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java b/src/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java index 724be34..177835f 100644 --- a/src/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java +++ b/src/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java @@ -12,11 +12,10 @@ package cuchaz.enigma.gui; import java.awt.Color; -public class ObfuscatedHighlightPainter extends BoxHighlightPainter -{ - public ObfuscatedHighlightPainter( ) - { +public class ObfuscatedHighlightPainter extends BoxHighlightPainter { + + public ObfuscatedHighlightPainter() { // red ish - super( new Color( 255, 220, 220 ), new Color( 160, 80, 80 ) ); + super(new Color(255, 220, 220), new Color(160, 80, 80)); } } diff --git a/src/cuchaz/enigma/gui/OtherHighlightPainter.java b/src/cuchaz/enigma/gui/OtherHighlightPainter.java index 78de732..4e9c870 100644 --- a/src/cuchaz/enigma/gui/OtherHighlightPainter.java +++ b/src/cuchaz/enigma/gui/OtherHighlightPainter.java @@ -12,11 +12,10 @@ package cuchaz.enigma.gui; import java.awt.Color; -public class OtherHighlightPainter extends BoxHighlightPainter -{ - public OtherHighlightPainter( ) - { +public class OtherHighlightPainter extends BoxHighlightPainter { + + public OtherHighlightPainter() { // grey - super( null, new Color( 180, 180, 180 ) ); + super(null, new Color(180, 180, 180)); } } diff --git a/src/cuchaz/enigma/gui/ProgressDialog.java b/src/cuchaz/enigma/gui/ProgressDialog.java index 7f95431..b864fdb 100644 --- a/src/cuchaz/enigma/gui/ProgressDialog.java +++ b/src/cuchaz/enigma/gui/ProgressDialog.java @@ -25,89 +25,79 @@ import javax.swing.WindowConstants; import cuchaz.enigma.Constants; import cuchaz.enigma.Deobfuscator.ProgressListener; -public class ProgressDialog implements ProgressListener, AutoCloseable -{ +public class ProgressDialog implements ProgressListener, AutoCloseable { + private JFrame m_frame; private JLabel m_title; private JLabel m_text; private JProgressBar m_progress; - public ProgressDialog( JFrame parent ) - { + public ProgressDialog(JFrame parent) { + // init frame - m_frame = new JFrame( Constants.Name + " - Operation in progress" ); + m_frame = new JFrame(Constants.Name + " - Operation in progress"); final Container pane = m_frame.getContentPane(); FlowLayout layout = new FlowLayout(); - layout.setAlignment( FlowLayout.LEFT ); - pane.setLayout( layout ); + layout.setAlignment(FlowLayout.LEFT); + pane.setLayout(layout); m_title = new JLabel(); - pane.add( m_title ); + pane.add(m_title); // set up the progress bar JPanel panel = new JPanel(); - pane.add( panel ); - panel.setLayout( new BorderLayout() ); - m_text = GuiTricks.unboldLabel( new JLabel() ); + pane.add(panel); + panel.setLayout(new BorderLayout()); + m_text = GuiTricks.unboldLabel(new JLabel()); m_progress = new JProgressBar(); - m_text.setBorder( BorderFactory.createEmptyBorder( 0, 0, 10, 0 ) ); - panel.add( m_text, BorderLayout.NORTH ); - panel.add( m_progress, BorderLayout.CENTER ); - panel.setPreferredSize( new Dimension( 360, 50 ) ); + m_text.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); + panel.add(m_text, BorderLayout.NORTH); + panel.add(m_progress, BorderLayout.CENTER); + panel.setPreferredSize(new Dimension(360, 50)); // show the frame pane.doLayout(); - m_frame.setSize( 400, 120 ); - m_frame.setResizable( false ); - m_frame.setLocationRelativeTo( parent ); - m_frame.setVisible( true ); - m_frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); + m_frame.setSize(400, 120); + m_frame.setResizable(false); + m_frame.setLocationRelativeTo(parent); + m_frame.setVisible(true); + m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); } - public void close( ) - { + public void close() { m_frame.dispose(); } - + @Override - public void init( int totalWork, String title ) - { - m_title.setText( title ); - m_progress.setMinimum( 0 ); - m_progress.setMaximum( totalWork ); - m_progress.setValue( 0 ); + public void init(int totalWork, String title) { + m_title.setText(title); + m_progress.setMinimum(0); + m_progress.setMaximum(totalWork); + m_progress.setValue(0); } - + @Override - public void onProgress( int numDone, String message ) - { - m_text.setText( message ); - m_progress.setValue( numDone ); + public void onProgress(int numDone, String message) { + m_text.setText(message); + m_progress.setValue(numDone); // update the frame m_frame.validate(); m_frame.repaint(); } - public static interface ProgressRunnable - { - void run( ProgressListener listener ) throws Exception; + public static interface ProgressRunnable { + void run(ProgressListener listener) throws Exception; } - public static void runInThread( final JFrame parent, final ProgressRunnable runnable ) - { - new Thread( ) - { + public static void runInThread(final JFrame parent, final ProgressRunnable runnable) { + new Thread() { @Override - public void run( ) - { - try( ProgressDialog progress = new ProgressDialog( parent ) ) - { - runnable.run( progress ); - } - catch( Exception ex ) - { - throw new Error( ex ); + public void run() { + try (ProgressDialog progress = new ProgressDialog(parent)) { + runnable.run(progress); + } catch (Exception ex) { + throw new Error(ex); } } }.start(); diff --git a/src/cuchaz/enigma/gui/ReadableToken.java b/src/cuchaz/enigma/gui/ReadableToken.java index 3f43045..66bcbc2 100644 --- a/src/cuchaz/enigma/gui/ReadableToken.java +++ b/src/cuchaz/enigma/gui/ReadableToken.java @@ -10,29 +10,27 @@ ******************************************************************************/ package cuchaz.enigma.gui; -public class ReadableToken -{ +public class ReadableToken { + public int line; public int startColumn; public int endColumn; - public ReadableToken( int line, int startColumn, int endColumn ) - { + public ReadableToken(int line, int startColumn, int endColumn) { this.line = line; this.startColumn = startColumn; this.endColumn = endColumn; } @Override - public String toString( ) - { + public String toString() { StringBuilder buf = new StringBuilder(); - buf.append( "line " ); - buf.append( line ); - buf.append( " columns " ); - buf.append( startColumn ); - buf.append( "-" ); - buf.append( endColumn ); + buf.append("line "); + buf.append(line); + buf.append(" columns "); + buf.append(startColumn); + buf.append("-"); + buf.append(endColumn); return buf.toString(); } } diff --git a/src/cuchaz/enigma/gui/RenameListener.java b/src/cuchaz/enigma/gui/RenameListener.java index 7d45505..abeda0c 100644 --- a/src/cuchaz/enigma/gui/RenameListener.java +++ b/src/cuchaz/enigma/gui/RenameListener.java @@ -12,7 +12,6 @@ package cuchaz.enigma.gui; import cuchaz.enigma.mapping.Entry; -public interface RenameListener -{ - void rename( Entry obfEntry, String newName ); +public interface RenameListener { + void rename(Entry obfEntry, String newName); } diff --git a/src/cuchaz/enigma/gui/SelectionHighlightPainter.java b/src/cuchaz/enigma/gui/SelectionHighlightPainter.java index 35f9451..5e189d2 100644 --- a/src/cuchaz/enigma/gui/SelectionHighlightPainter.java +++ b/src/cuchaz/enigma/gui/SelectionHighlightPainter.java @@ -20,16 +20,15 @@ import java.awt.Shape; import javax.swing.text.Highlighter; import javax.swing.text.JTextComponent; -public class SelectionHighlightPainter implements Highlighter.HighlightPainter -{ +public class SelectionHighlightPainter implements Highlighter.HighlightPainter { + @Override - public void paint( Graphics g, int start, int end, Shape shape, JTextComponent text ) - { + public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) { // draw a thick border Graphics2D g2d = (Graphics2D)g; - Rectangle bounds = BoxHighlightPainter.getBounds( text, start, end ); - g2d.setColor( Color.black ); - g2d.setStroke( new BasicStroke( 2.0f ) ); - g2d.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); + Rectangle bounds = BoxHighlightPainter.getBounds(text, start, end); + g2d.setColor(Color.black); + g2d.setStroke(new BasicStroke(2.0f)); + g2d.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); } } diff --git a/src/cuchaz/enigma/gui/TokenListCellRenderer.java b/src/cuchaz/enigma/gui/TokenListCellRenderer.java index 9247c06..a49be37 100644 --- a/src/cuchaz/enigma/gui/TokenListCellRenderer.java +++ b/src/cuchaz/enigma/gui/TokenListCellRenderer.java @@ -19,22 +19,20 @@ import javax.swing.ListCellRenderer; import cuchaz.enigma.analysis.Token; -public class TokenListCellRenderer implements ListCellRenderer -{ +public class TokenListCellRenderer implements ListCellRenderer { + private GuiController m_controller; private DefaultListCellRenderer m_defaultRenderer; - public TokenListCellRenderer( GuiController controller ) - { + public TokenListCellRenderer(GuiController controller) { m_controller = controller; m_defaultRenderer = new DefaultListCellRenderer(); } @Override - public Component getListCellRendererComponent( JList list, Token token, int index, boolean isSelected, boolean hasFocus ) - { - JLabel label = (JLabel)m_defaultRenderer.getListCellRendererComponent( list, token, index, isSelected, hasFocus ); - label.setText( m_controller.getReadableToken( token ).toString() ); + public Component getListCellRendererComponent(JList list, Token token, int index, boolean isSelected, boolean hasFocus) { + JLabel label = (JLabel)m_defaultRenderer.getListCellRendererComponent(list, token, index, isSelected, hasFocus); + label.setText(m_controller.getReadableToken(token).toString()); return label; } } -- cgit v1.2.3