diff options
| author | 2015-01-13 23:25:04 -0500 | |
|---|---|---|
| committer | 2015-01-13 23:25:04 -0500 | |
| commit | 959cb5fd4f9586ec3bd265b452fe25fe1db82e3f (patch) | |
| tree | bdd8a2c52c2fe053ba3460614bde8542e5378dbe /src/cuchaz/enigma/gui | |
| parent | got rid of gradle in favor of ivy+ssjb (diff) | |
| download | enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.tar.gz enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.tar.xz enigma-fork-959cb5fd4f9586ec3bd265b452fe25fe1db82e3f.zip | |
source format change
don't hate me too much if you were planning a big merge. =P
Diffstat (limited to 'src/cuchaz/enigma/gui')
19 files changed, 913 insertions, 1283 deletions
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; | |||
| 27 | import cuchaz.enigma.Constants; | 27 | import cuchaz.enigma.Constants; |
| 28 | import cuchaz.enigma.Util; | 28 | import cuchaz.enigma.Util; |
| 29 | 29 | ||
| 30 | public class AboutDialog | 30 | public class AboutDialog { |
| 31 | { | 31 | |
| 32 | public static void show( JFrame parent ) | 32 | public static void show(JFrame parent) { |
| 33 | { | ||
| 34 | // init frame | 33 | // init frame |
| 35 | final JFrame frame = new JFrame( Constants.Name + " - About" ); | 34 | final JFrame frame = new JFrame(Constants.Name + " - About"); |
| 36 | final Container pane = frame.getContentPane(); | 35 | final Container pane = frame.getContentPane(); |
| 37 | pane.setLayout( new FlowLayout() ); | 36 | pane.setLayout(new FlowLayout()); |
| 38 | 37 | ||
| 39 | // load the content | 38 | // load the content |
| 40 | try | 39 | try { |
| 41 | { | 40 | String html = Util.readResourceToString("/about.html"); |
| 42 | String html = Util.readResourceToString( "/about.html" ); | 41 | html = String.format(html, Constants.Name, Constants.Version); |
| 43 | html = String.format( html, Constants.Name, Constants.Version ); | 42 | JLabel label = new JLabel(html); |
| 44 | JLabel label = new JLabel( html ); | 43 | label.setHorizontalAlignment(JLabel.CENTER); |
| 45 | label.setHorizontalAlignment( JLabel.CENTER ); | 44 | pane.add(label); |
| 46 | pane.add( label ); | 45 | } catch (IOException ex) { |
| 47 | } | 46 | throw new Error(ex); |
| 48 | catch( IOException ex ) | ||
| 49 | { | ||
| 50 | throw new Error( ex ); | ||
| 51 | } | 47 | } |
| 52 | 48 | ||
| 53 | // show the link | 49 | // show the link |
| 54 | String html = "<html><a href=\"%s\">%s</a></html>"; | 50 | String html = "<html><a href=\"%s\">%s</a></html>"; |
| 55 | html = String.format( html, Constants.Url, Constants.Url ); | 51 | html = String.format(html, Constants.Url, Constants.Url); |
| 56 | JButton link = new JButton( html ); | 52 | JButton link = new JButton(html); |
| 57 | link.addActionListener( new ActionListener( ) | 53 | link.addActionListener(new ActionListener() { |
| 58 | { | ||
| 59 | @Override | 54 | @Override |
| 60 | public void actionPerformed( ActionEvent event ) | 55 | public void actionPerformed(ActionEvent event) { |
| 61 | { | 56 | Util.openUrl(Constants.Url); |
| 62 | Util.openUrl( Constants.Url ); | ||
| 63 | } | 57 | } |
| 64 | } ); | 58 | }); |
| 65 | link.setBorderPainted( false ); | 59 | link.setBorderPainted(false); |
| 66 | link.setOpaque( false ); | 60 | link.setOpaque(false); |
| 67 | link.setBackground( Color.WHITE ); | 61 | link.setBackground(Color.WHITE); |
| 68 | link.setCursor( new Cursor( Cursor.HAND_CURSOR ) ); | 62 | link.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
| 69 | link.setFocusable( false ); | 63 | link.setFocusable(false); |
| 70 | JPanel linkPanel = new JPanel(); | 64 | JPanel linkPanel = new JPanel(); |
| 71 | linkPanel.add( link ); | 65 | linkPanel.add(link); |
| 72 | pane.add( linkPanel ); | 66 | pane.add(linkPanel); |
| 73 | 67 | ||
| 74 | // show ok button | 68 | // show ok button |
| 75 | JButton okButton = new JButton( "Ok" ); | 69 | JButton okButton = new JButton("Ok"); |
| 76 | pane.add( okButton ); | 70 | pane.add(okButton); |
| 77 | okButton.addActionListener( new ActionListener( ) | 71 | okButton.addActionListener(new ActionListener() { |
| 78 | { | ||
| 79 | @Override | 72 | @Override |
| 80 | public void actionPerformed( ActionEvent arg0 ) | 73 | public void actionPerformed(ActionEvent arg0) { |
| 81 | { | ||
| 82 | frame.dispose(); | 74 | frame.dispose(); |
| 83 | } | 75 | } |
| 84 | } ); | 76 | }); |
| 85 | 77 | ||
| 86 | // show the frame | 78 | // show the frame |
| 87 | pane.doLayout(); | 79 | pane.doLayout(); |
| 88 | frame.setSize( 400, 220 ); | 80 | frame.setSize(400, 220); |
| 89 | frame.setResizable( false ); | 81 | frame.setResizable(false); |
| 90 | frame.setLocationRelativeTo( parent ); | 82 | frame.setLocationRelativeTo(parent); |
| 91 | frame.setVisible( true ); | 83 | frame.setVisible(true); |
| 92 | frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE ); | 84 | frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
| 93 | } | 85 | } |
| 94 | } | 86 | } |
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; | |||
| 19 | import javax.swing.text.Highlighter; | 19 | import javax.swing.text.Highlighter; |
| 20 | import javax.swing.text.JTextComponent; | 20 | import javax.swing.text.JTextComponent; |
| 21 | 21 | ||
| 22 | public abstract class BoxHighlightPainter implements Highlighter.HighlightPainter | 22 | public abstract class BoxHighlightPainter implements Highlighter.HighlightPainter { |
| 23 | { | 23 | |
| 24 | private Color m_fillColor; | 24 | private Color m_fillColor; |
| 25 | private Color m_borderColor; | 25 | private Color m_borderColor; |
| 26 | 26 | ||
| 27 | protected BoxHighlightPainter( Color fillColor, Color borderColor ) | 27 | protected BoxHighlightPainter(Color fillColor, Color borderColor) { |
| 28 | { | ||
| 29 | m_fillColor = fillColor; | 28 | m_fillColor = fillColor; |
| 30 | m_borderColor = borderColor; | 29 | m_borderColor = borderColor; |
| 31 | } | 30 | } |
| 32 | 31 | ||
| 33 | @Override | 32 | @Override |
| 34 | public void paint( Graphics g, int start, int end, Shape shape, JTextComponent text ) | 33 | public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) { |
| 35 | { | 34 | Rectangle bounds = getBounds(text, start, end); |
| 36 | Rectangle bounds = getBounds( text, start, end ); | ||
| 37 | 35 | ||
| 38 | // fill the area | 36 | // fill the area |
| 39 | if( m_fillColor != null ) | 37 | if (m_fillColor != null) { |
| 40 | { | 38 | g.setColor(m_fillColor); |
| 41 | g.setColor( m_fillColor ); | 39 | g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); |
| 42 | g.fillRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | ||
| 43 | } | 40 | } |
| 44 | 41 | ||
| 45 | // draw a box around the area | 42 | // draw a box around the area |
| 46 | g.setColor( m_borderColor ); | 43 | g.setColor(m_borderColor); |
| 47 | g.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | 44 | g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); |
| 48 | } | 45 | } |
| 49 | 46 | ||
| 50 | protected static Rectangle getBounds( JTextComponent text, int start, int end ) | 47 | protected static Rectangle getBounds(JTextComponent text, int start, int end) { |
| 51 | { | 48 | try { |
| 52 | try | ||
| 53 | { | ||
| 54 | // determine the bounds of the text | 49 | // determine the bounds of the text |
| 55 | Rectangle bounds = text.modelToView( start ).union( text.modelToView( end ) ); | 50 | Rectangle bounds = text.modelToView(start).union(text.modelToView(end)); |
| 56 | 51 | ||
| 57 | // adjust the box so it looks nice | 52 | // adjust the box so it looks nice |
| 58 | bounds.x -= 2; | 53 | bounds.x -= 2; |
| @@ -61,11 +56,9 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte | |||
| 61 | bounds.height -= 2; | 56 | bounds.height -= 2; |
| 62 | 57 | ||
| 63 | return bounds; | 58 | return bounds; |
| 64 | } | 59 | } catch (BadLocationException ex) { |
| 65 | catch( BadLocationException ex ) | ||
| 66 | { | ||
| 67 | // don't care... just return something | 60 | // don't care... just return something |
| 68 | return new Rectangle( 0, 0, 0, 0 ); | 61 | return new Rectangle(0, 0, 0, 0); |
| 69 | } | 62 | } |
| 70 | } | 63 | } |
| 71 | } | 64 | } |
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; | |||
| 17 | import javax.swing.text.Highlighter; | 17 | import javax.swing.text.Highlighter; |
| 18 | import javax.swing.text.JTextComponent; | 18 | import javax.swing.text.JTextComponent; |
| 19 | 19 | ||
| 20 | public class BrowserCaret extends DefaultCaret | 20 | public class BrowserCaret extends DefaultCaret { |
| 21 | { | 21 | |
| 22 | private static final long serialVersionUID = 1158977422507969940L; | 22 | private static final long serialVersionUID = 1158977422507969940L; |
| 23 | 23 | ||
| 24 | private static final Highlighter.HighlightPainter m_selectionPainter = new Highlighter.HighlightPainter( ) | 24 | private static final Highlighter.HighlightPainter m_selectionPainter = new Highlighter.HighlightPainter() { |
| 25 | { | ||
| 26 | @Override | 25 | @Override |
| 27 | public void paint( Graphics g, int p0, int p1, Shape bounds, JTextComponent c ) | 26 | public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) { |
| 28 | { | ||
| 29 | // don't paint anything | 27 | // don't paint anything |
| 30 | } | 28 | } |
| 31 | }; | 29 | }; |
| 32 | 30 | ||
| 33 | @Override | 31 | @Override |
| 34 | public boolean isSelectionVisible( ) | 32 | public boolean isSelectionVisible() { |
| 35 | { | ||
| 36 | return false; | 33 | return false; |
| 37 | } | 34 | } |
| 38 | 35 | ||
| 39 | @Override | 36 | @Override |
| 40 | public boolean isVisible( ) | 37 | public boolean isVisible() { |
| 41 | { | ||
| 42 | return true; | 38 | return true; |
| 43 | } | 39 | } |
| 44 | 40 | ||
| 45 | @Override | 41 | @Override |
| 46 | public Highlighter.HighlightPainter getSelectionPainter( ) | 42 | public Highlighter.HighlightPainter getSelectionPainter() { |
| 47 | { | ||
| 48 | return m_selectionPainter; | 43 | return m_selectionPainter; |
| 49 | } | 44 | } |
| 50 | } | 45 | } |
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; | |||
| 19 | import javax.swing.JList; | 19 | import javax.swing.JList; |
| 20 | import javax.swing.ListCellRenderer; | 20 | import javax.swing.ListCellRenderer; |
| 21 | 21 | ||
| 22 | public class ClassListCellRenderer implements ListCellRenderer<String> | 22 | public class ClassListCellRenderer implements ListCellRenderer<String> { |
| 23 | { | 23 | |
| 24 | private DefaultListCellRenderer m_defaultRenderer; | 24 | private DefaultListCellRenderer m_defaultRenderer; |
| 25 | 25 | ||
| 26 | public ClassListCellRenderer( ) | 26 | public ClassListCellRenderer() { |
| 27 | { | ||
| 28 | m_defaultRenderer = new DefaultListCellRenderer(); | 27 | m_defaultRenderer = new DefaultListCellRenderer(); |
| 29 | } | 28 | } |
| 30 | 29 | ||
| 31 | @Override | 30 | @Override |
| 32 | public Component getListCellRendererComponent( JList<? extends String> list, String className, int index, boolean isSelected, boolean hasFocus ) | 31 | public Component getListCellRendererComponent(JList<? extends String> list, String className, int index, boolean isSelected, boolean hasFocus) { |
| 33 | { | 32 | JLabel label = (JLabel)m_defaultRenderer.getListCellRendererComponent(list, className, index, isSelected, hasFocus); |
| 34 | JLabel label = (JLabel)m_defaultRenderer.getListCellRendererComponent( list, className, index, isSelected, hasFocus ); | 33 | label.setText(Descriptor.toJavaName(className)); |
| 35 | label.setText( Descriptor.toJavaName( className ) ); | ||
| 36 | return label; | 34 | return label; |
| 37 | } | 35 | } |
| 38 | } | 36 | } |
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; | |||
| 30 | 30 | ||
| 31 | import cuchaz.enigma.mapping.ClassEntry; | 31 | import cuchaz.enigma.mapping.ClassEntry; |
| 32 | 32 | ||
| 33 | public class ClassSelector extends JTree | 33 | public class ClassSelector extends JTree { |
| 34 | { | 34 | |
| 35 | private static final long serialVersionUID = -7632046902384775977L; | 35 | private static final long serialVersionUID = -7632046902384775977L; |
| 36 | 36 | ||
| 37 | public interface ClassSelectionListener | 37 | public interface ClassSelectionListener { |
| 38 | { | 38 | void onSelectClass(ClassEntry classEntry); |
| 39 | void onSelectClass( ClassEntry classEntry ); | ||
| 40 | } | 39 | } |
| 41 | 40 | ||
| 42 | public static Comparator<ClassEntry> ObfuscatedClassEntryComparator; | 41 | public static Comparator<ClassEntry> ObfuscatedClassEntryComparator; |
| 43 | public static Comparator<ClassEntry> DeobfuscatedClassEntryComparator; | 42 | public static Comparator<ClassEntry> DeobfuscatedClassEntryComparator; |
| 44 | 43 | ||
| 45 | static | 44 | static { |
| 46 | { | 45 | ObfuscatedClassEntryComparator = new Comparator<ClassEntry>() { |
| 47 | ObfuscatedClassEntryComparator = new Comparator<ClassEntry>( ) | ||
| 48 | { | ||
| 49 | @Override | 46 | @Override |
| 50 | public int compare( ClassEntry a, ClassEntry b ) | 47 | public int compare(ClassEntry a, ClassEntry b) { |
| 51 | { | 48 | if (a.getName().length() != b.getName().length()) { |
| 52 | if( a.getName().length() != b.getName().length() ) | ||
| 53 | { | ||
| 54 | return a.getName().length() - b.getName().length(); | 49 | return a.getName().length() - b.getName().length(); |
| 55 | } | 50 | } |
| 56 | return a.getName().compareTo( b.getName() ); | 51 | return a.getName().compareTo(b.getName()); |
| 57 | } | 52 | } |
| 58 | }; | 53 | }; |
| 59 | 54 | ||
| 60 | DeobfuscatedClassEntryComparator = new Comparator<ClassEntry>( ) | 55 | DeobfuscatedClassEntryComparator = new Comparator<ClassEntry>() { |
| 61 | { | ||
| 62 | @Override | 56 | @Override |
| 63 | public int compare( ClassEntry a, ClassEntry b ) | 57 | public int compare(ClassEntry a, ClassEntry b) { |
| 64 | { | 58 | return a.getName().compareTo(b.getName()); |
| 65 | return a.getName().compareTo( b.getName() ); | ||
| 66 | } | 59 | } |
| 67 | }; | 60 | }; |
| 68 | } | 61 | } |
| @@ -70,122 +63,102 @@ public class ClassSelector extends JTree | |||
| 70 | private ClassSelectionListener m_listener; | 63 | private ClassSelectionListener m_listener; |
| 71 | private Comparator<ClassEntry> m_comparator; | 64 | private Comparator<ClassEntry> m_comparator; |
| 72 | 65 | ||
| 73 | public ClassSelector( Comparator<ClassEntry> comparator ) | 66 | public ClassSelector(Comparator<ClassEntry> comparator) { |
| 74 | { | ||
| 75 | m_comparator = comparator; | 67 | m_comparator = comparator; |
| 76 | 68 | ||
| 77 | // configure the tree control | 69 | // configure the tree control |
| 78 | setRootVisible( false ); | 70 | setRootVisible(false); |
| 79 | setShowsRootHandles( false ); | 71 | setShowsRootHandles(false); |
| 80 | setModel( null ); | 72 | setModel(null); |
| 81 | 73 | ||
| 82 | // hook events | 74 | // hook events |
| 83 | addMouseListener( new MouseAdapter() | 75 | addMouseListener(new MouseAdapter() { |
| 84 | { | ||
| 85 | @Override | 76 | @Override |
| 86 | public void mouseClicked( MouseEvent event ) | 77 | public void mouseClicked(MouseEvent event) { |
| 87 | { | 78 | if (m_listener != null && event.getClickCount() == 2) { |
| 88 | if( m_listener != null && event.getClickCount() == 2 ) | ||
| 89 | { | ||
| 90 | // get the selected node | 79 | // get the selected node |
| 91 | TreePath path = getSelectionPath(); | 80 | TreePath path = getSelectionPath(); |
| 92 | if( path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode ) | 81 | if (path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode) { |
| 93 | { | ||
| 94 | ClassSelectorClassNode node = (ClassSelectorClassNode)path.getLastPathComponent(); | 82 | ClassSelectorClassNode node = (ClassSelectorClassNode)path.getLastPathComponent(); |
| 95 | m_listener.onSelectClass( node.getClassEntry() ); | 83 | m_listener.onSelectClass(node.getClassEntry()); |
| 96 | } | 84 | } |
| 97 | } | 85 | } |
| 98 | } | 86 | } |
| 99 | } ); | 87 | }); |
| 100 | 88 | ||
| 101 | // init defaults | 89 | // init defaults |
| 102 | m_listener = null; | 90 | m_listener = null; |
| 103 | } | 91 | } |
| 104 | 92 | ||
| 105 | public void setListener( ClassSelectionListener val ) | 93 | public void setListener(ClassSelectionListener val) { |
| 106 | { | ||
| 107 | m_listener = val; | 94 | m_listener = val; |
| 108 | } | 95 | } |
| 109 | 96 | ||
| 110 | public void setClasses( Collection<ClassEntry> classEntries ) | 97 | public void setClasses(Collection<ClassEntry> classEntries) { |
| 111 | { | 98 | if (classEntries == null) { |
| 112 | if( classEntries == null ) | 99 | setModel(null); |
| 113 | { | ||
| 114 | setModel( null ); | ||
| 115 | return; | 100 | return; |
| 116 | } | 101 | } |
| 117 | 102 | ||
| 118 | // build the package names | 103 | // build the package names |
| 119 | Map<String,ClassSelectorPackageNode> packages = Maps.newHashMap(); | 104 | Map<String,ClassSelectorPackageNode> packages = Maps.newHashMap(); |
| 120 | for( ClassEntry classEntry : classEntries ) | 105 | for (ClassEntry classEntry : classEntries) { |
| 121 | { | 106 | packages.put(classEntry.getPackageName(), null); |
| 122 | packages.put( classEntry.getPackageName(), null ); | ||
| 123 | } | 107 | } |
| 124 | 108 | ||
| 125 | // sort the packages | 109 | // sort the packages |
| 126 | List<String> sortedPackageNames = Lists.newArrayList( packages.keySet() ); | 110 | List<String> sortedPackageNames = Lists.newArrayList(packages.keySet()); |
| 127 | Collections.sort( sortedPackageNames, new Comparator<String>( ) | 111 | Collections.sort(sortedPackageNames, new Comparator<String>() { |
| 128 | { | ||
| 129 | @Override | 112 | @Override |
| 130 | public int compare( String a, String b ) | 113 | public int compare(String a, String b) { |
| 131 | { | ||
| 132 | // I can never keep this rule straight when writing these damn things... | 114 | // I can never keep this rule straight when writing these damn things... |
| 133 | // a < b => -1, a == b => 0, a > b => +1 | 115 | // a < b => -1, a == b => 0, a > b => +1 |
| 134 | 116 | ||
| 135 | String[] aparts = a.split( "/" ); | 117 | String[] aparts = a.split("/"); |
| 136 | String[] bparts = b.split( "/" ); | 118 | String[] bparts = b.split("/"); |
| 137 | for( int i=0; true; i++ ) | 119 | for (int i = 0; true; i++) { |
| 138 | { | 120 | if (i >= aparts.length) { |
| 139 | if( i >= aparts.length ) | ||
| 140 | { | ||
| 141 | return -1; | 121 | return -1; |
| 142 | } | 122 | } else if (i >= bparts.length) { |
| 143 | else if( i >= bparts.length ) | ||
| 144 | { | ||
| 145 | return 1; | 123 | return 1; |
| 146 | } | 124 | } |
| 147 | 125 | ||
| 148 | int result = aparts[i].compareTo( bparts[i] ); | 126 | int result = aparts[i].compareTo(bparts[i]); |
| 149 | if( result != 0 ) | 127 | if (result != 0) { |
| 150 | { | ||
| 151 | return result; | 128 | return result; |
| 152 | } | 129 | } |
| 153 | } | 130 | } |
| 154 | } | 131 | } |
| 155 | } ); | 132 | }); |
| 156 | 133 | ||
| 157 | // create the root node and the package nodes | 134 | // create the root node and the package nodes |
| 158 | DefaultMutableTreeNode root = new DefaultMutableTreeNode(); | 135 | DefaultMutableTreeNode root = new DefaultMutableTreeNode(); |
| 159 | for( String packageName : sortedPackageNames ) | 136 | for (String packageName : sortedPackageNames) { |
| 160 | { | 137 | ClassSelectorPackageNode node = new ClassSelectorPackageNode(packageName); |
| 161 | ClassSelectorPackageNode node = new ClassSelectorPackageNode( packageName ); | 138 | packages.put(packageName, node); |
| 162 | packages.put( packageName, node ); | 139 | root.add(node); |
| 163 | root.add( node ); | ||
| 164 | } | 140 | } |
| 165 | 141 | ||
| 166 | // put the classes into packages | 142 | // put the classes into packages |
| 167 | Multimap<String,ClassEntry> packagedClassEntries = ArrayListMultimap.create(); | 143 | Multimap<String,ClassEntry> packagedClassEntries = ArrayListMultimap.create(); |
| 168 | for( ClassEntry classEntry : classEntries ) | 144 | for (ClassEntry classEntry : classEntries) { |
| 169 | { | 145 | packagedClassEntries.put(classEntry.getPackageName(), classEntry); |
| 170 | packagedClassEntries.put( classEntry.getPackageName(), classEntry ); | ||
| 171 | } | 146 | } |
| 172 | 147 | ||
| 173 | // build the class nodes | 148 | // build the class nodes |
| 174 | for( String packageName : packagedClassEntries.keySet() ) | 149 | for (String packageName : packagedClassEntries.keySet()) { |
| 175 | { | ||
| 176 | // sort the class entries | 150 | // sort the class entries |
| 177 | List<ClassEntry> classEntriesInPackage = Lists.newArrayList( packagedClassEntries.get( packageName ) ); | 151 | List<ClassEntry> classEntriesInPackage = Lists.newArrayList(packagedClassEntries.get(packageName)); |
| 178 | Collections.sort( classEntriesInPackage, m_comparator ); | 152 | Collections.sort(classEntriesInPackage, m_comparator); |
| 179 | 153 | ||
| 180 | // create the nodes in order | 154 | // create the nodes in order |
| 181 | for( ClassEntry classEntry : classEntriesInPackage ) | 155 | for (ClassEntry classEntry : classEntriesInPackage) { |
| 182 | { | 156 | ClassSelectorPackageNode node = packages.get(packageName); |
| 183 | ClassSelectorPackageNode node = packages.get( packageName ); | 157 | node.add(new ClassSelectorClassNode(classEntry)); |
| 184 | node.add( new ClassSelectorClassNode( classEntry ) ); | ||
| 185 | } | 158 | } |
| 186 | } | 159 | } |
| 187 | 160 | ||
| 188 | // finally, update the tree control | 161 | // finally, update the tree control |
| 189 | setModel( new DefaultTreeModel( root ) ); | 162 | setModel(new DefaultTreeModel(root)); |
| 190 | } | 163 | } |
| 191 | } | 164 | } |
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; | |||
| 14 | 14 | ||
| 15 | import cuchaz.enigma.mapping.ClassEntry; | 15 | import cuchaz.enigma.mapping.ClassEntry; |
| 16 | 16 | ||
| 17 | public class ClassSelectorClassNode extends DefaultMutableTreeNode | 17 | public class ClassSelectorClassNode extends DefaultMutableTreeNode { |
| 18 | { | 18 | |
| 19 | private static final long serialVersionUID = -8956754339813257380L; | 19 | private static final long serialVersionUID = -8956754339813257380L; |
| 20 | 20 | ||
| 21 | private ClassEntry m_classEntry; | 21 | private ClassEntry m_classEntry; |
| 22 | 22 | ||
| 23 | public ClassSelectorClassNode( ClassEntry classEntry ) | 23 | public ClassSelectorClassNode(ClassEntry classEntry) { |
| 24 | { | ||
| 25 | m_classEntry = classEntry; | 24 | m_classEntry = classEntry; |
| 26 | } | 25 | } |
| 27 | 26 | ||
| 28 | public ClassEntry getClassEntry( ) | 27 | public ClassEntry getClassEntry() { |
| 29 | { | ||
| 30 | return m_classEntry; | 28 | return m_classEntry; |
| 31 | } | 29 | } |
| 32 | 30 | ||
| 33 | @Override | 31 | @Override |
| 34 | public String toString( ) | 32 | public String toString() { |
| 35 | { | ||
| 36 | return m_classEntry.getSimpleName(); | 33 | return m_classEntry.getSimpleName(); |
| 37 | } | 34 | } |
| 38 | } | 35 | } |
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; | |||
| 12 | 12 | ||
| 13 | import javax.swing.tree.DefaultMutableTreeNode; | 13 | import javax.swing.tree.DefaultMutableTreeNode; |
| 14 | 14 | ||
| 15 | public class ClassSelectorPackageNode extends DefaultMutableTreeNode | 15 | public class ClassSelectorPackageNode extends DefaultMutableTreeNode { |
| 16 | { | 16 | |
| 17 | private static final long serialVersionUID = -3730868701219548043L; | 17 | private static final long serialVersionUID = -3730868701219548043L; |
| 18 | 18 | ||
| 19 | private String m_packageName; | 19 | private String m_packageName; |
| 20 | 20 | ||
| 21 | public ClassSelectorPackageNode( String packageName ) | 21 | public ClassSelectorPackageNode(String packageName) { |
| 22 | { | ||
| 23 | m_packageName = packageName; | 22 | m_packageName = packageName; |
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | public String getPackageName( ) | 25 | public String getPackageName() { |
| 27 | { | ||
| 28 | return m_packageName; | 26 | return m_packageName; |
| 29 | } | 27 | } |
| 30 | 28 | ||
| 31 | @Override | 29 | @Override |
| 32 | public String toString( ) | 30 | public String toString() { |
| 33 | { | ||
| 34 | return m_packageName; | 31 | return m_packageName; |
| 35 | } | 32 | } |
| 36 | } | 33 | } |
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; | |||
| 29 | 29 | ||
| 30 | import cuchaz.enigma.Constants; | 30 | import cuchaz.enigma.Constants; |
| 31 | 31 | ||
| 32 | public class CrashDialog | 32 | public class CrashDialog { |
| 33 | { | 33 | |
| 34 | private static CrashDialog m_instance = null; | 34 | private static CrashDialog m_instance = null; |
| 35 | 35 | ||
| 36 | private JFrame m_frame; | 36 | private JFrame m_frame; |
| 37 | private JTextArea m_text; | 37 | private JTextArea m_text; |
| 38 | 38 | ||
| 39 | private CrashDialog( JFrame parent ) | 39 | private CrashDialog(JFrame parent) { |
| 40 | { | ||
| 41 | // init frame | 40 | // init frame |
| 42 | m_frame = new JFrame( Constants.Name + " - Crash Report" ); | 41 | m_frame = new JFrame(Constants.Name + " - Crash Report"); |
| 43 | final Container pane = m_frame.getContentPane(); | 42 | final Container pane = m_frame.getContentPane(); |
| 44 | pane.setLayout( new BorderLayout() ); | 43 | pane.setLayout(new BorderLayout()); |
| 45 | 44 | ||
| 46 | JLabel label = new JLabel( Constants.Name + " has crashed! =(" ); | 45 | JLabel label = new JLabel(Constants.Name + " has crashed! =("); |
| 47 | label.setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) ); | 46 | label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
| 48 | pane.add( label, BorderLayout.NORTH ); | 47 | pane.add(label, BorderLayout.NORTH); |
| 49 | 48 | ||
| 50 | // report panel | 49 | // report panel |
| 51 | m_text = new JTextArea(); | 50 | m_text = new JTextArea(); |
| 52 | m_text.setTabSize( 2 ); | 51 | m_text.setTabSize(2); |
| 53 | pane.add( new JScrollPane( m_text ), BorderLayout.CENTER ); | 52 | pane.add(new JScrollPane(m_text), BorderLayout.CENTER); |
| 54 | 53 | ||
| 55 | // buttons panel | 54 | // buttons panel |
| 56 | JPanel buttonsPanel = new JPanel(); | 55 | JPanel buttonsPanel = new JPanel(); |
| 57 | FlowLayout buttonsLayout = new FlowLayout(); | 56 | FlowLayout buttonsLayout = new FlowLayout(); |
| 58 | buttonsLayout.setAlignment( FlowLayout.RIGHT ); | 57 | buttonsLayout.setAlignment(FlowLayout.RIGHT); |
| 59 | buttonsPanel.setLayout( buttonsLayout ); | 58 | buttonsPanel.setLayout(buttonsLayout); |
| 60 | buttonsPanel.add( GuiTricks.unboldLabel( new JLabel( "If you choose exit, you will lose any unsaved work." ) ) ); | 59 | buttonsPanel.add(GuiTricks.unboldLabel(new JLabel("If you choose exit, you will lose any unsaved work."))); |
| 61 | JButton ignoreButton = new JButton( "Ignore" ); | 60 | JButton ignoreButton = new JButton("Ignore"); |
| 62 | ignoreButton.addActionListener( new ActionListener( ) | 61 | ignoreButton.addActionListener(new ActionListener() { |
| 63 | { | ||
| 64 | @Override | 62 | @Override |
| 65 | public void actionPerformed( ActionEvent event ) | 63 | public void actionPerformed(ActionEvent event) { |
| 66 | { | ||
| 67 | // close (hide) the dialog | 64 | // close (hide) the dialog |
| 68 | m_frame.setVisible( false ); | 65 | m_frame.setVisible(false); |
| 69 | } | 66 | } |
| 70 | } ); | 67 | }); |
| 71 | buttonsPanel.add( ignoreButton ); | 68 | buttonsPanel.add(ignoreButton); |
| 72 | JButton exitButton = new JButton( "Exit" ); | 69 | JButton exitButton = new JButton("Exit"); |
| 73 | exitButton.addActionListener( new ActionListener( ) | 70 | exitButton.addActionListener(new ActionListener() { |
| 74 | { | ||
| 75 | @Override | 71 | @Override |
| 76 | public void actionPerformed( ActionEvent event ) | 72 | public void actionPerformed(ActionEvent event) { |
| 77 | { | ||
| 78 | // exit enigma | 73 | // exit enigma |
| 79 | System.exit( 1 ); | 74 | System.exit(1); |
| 80 | } | 75 | } |
| 81 | } ); | 76 | }); |
| 82 | buttonsPanel.add( exitButton ); | 77 | buttonsPanel.add(exitButton); |
| 83 | pane.add( buttonsPanel, BorderLayout.SOUTH ); | 78 | pane.add(buttonsPanel, BorderLayout.SOUTH); |
| 84 | 79 | ||
| 85 | // show the frame | 80 | // show the frame |
| 86 | m_frame.setSize( 600, 400 ); | 81 | m_frame.setSize(600, 400); |
| 87 | m_frame.setLocationRelativeTo( parent ); | 82 | m_frame.setLocationRelativeTo(parent); |
| 88 | m_frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); | 83 | m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); |
| 89 | } | 84 | } |
| 90 | 85 | ||
| 91 | public static void init( JFrame parent ) | 86 | public static void init(JFrame parent) { |
| 92 | { | 87 | m_instance = new CrashDialog(parent); |
| 93 | m_instance = new CrashDialog( parent ); | ||
| 94 | } | 88 | } |
| 95 | 89 | ||
| 96 | public static void show( Throwable ex ) | 90 | public static void show(Throwable ex) { |
| 97 | { | ||
| 98 | // get the error report | 91 | // get the error report |
| 99 | StringWriter buf = new StringWriter(); | 92 | StringWriter buf = new StringWriter(); |
| 100 | ex.printStackTrace( new PrintWriter( buf ) ); | 93 | ex.printStackTrace(new PrintWriter(buf)); |
| 101 | String report = buf.toString(); | 94 | String report = buf.toString(); |
| 102 | 95 | ||
| 103 | // show it! | 96 | // show it! |
| 104 | m_instance.m_text.setText( report ); | 97 | m_instance.m_text.setText(report); |
| 105 | m_instance.m_frame.doLayout(); | 98 | m_instance.m_frame.doLayout(); |
| 106 | m_instance.m_frame.setVisible( true ); | 99 | m_instance.m_frame.setVisible(true); |
| 107 | } | 100 | } |
| 108 | } | 101 | } |
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; | |||
| 12 | 12 | ||
| 13 | import java.awt.Color; | 13 | import java.awt.Color; |
| 14 | 14 | ||
| 15 | public class DeobfuscatedHighlightPainter extends BoxHighlightPainter | 15 | public class DeobfuscatedHighlightPainter extends BoxHighlightPainter { |
| 16 | { | 16 | |
| 17 | public DeobfuscatedHighlightPainter( ) | 17 | public DeobfuscatedHighlightPainter() { |
| 18 | { | ||
| 19 | // green ish | 18 | // green ish |
| 20 | super( new Color( 220, 255, 220 ), new Color( 80, 160, 80 ) ); | 19 | super(new Color(220, 255, 220), new Color(80, 160, 80)); |
| 21 | } | 20 | } |
| 22 | } | 21 | } |
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; | |||
| 88 | import cuchaz.enigma.mapping.MappingParseException; | 88 | import cuchaz.enigma.mapping.MappingParseException; |
| 89 | import cuchaz.enigma.mapping.MethodEntry; | 89 | import cuchaz.enigma.mapping.MethodEntry; |
| 90 | 90 | ||
| 91 | public class Gui | 91 | public class Gui { |
| 92 | { | 92 | |
| 93 | private GuiController m_controller; | 93 | private GuiController m_controller; |
| 94 | 94 | ||
| 95 | // controls | 95 | // controls |
| @@ -133,81 +133,74 @@ public class Gui | |||
| 133 | private JFileChooser m_exportSourceFileChooser; | 133 | private JFileChooser m_exportSourceFileChooser; |
| 134 | private JFileChooser m_exportJarFileChooser; | 134 | private JFileChooser m_exportJarFileChooser; |
| 135 | 135 | ||
| 136 | public Gui( ) | 136 | public Gui() { |
| 137 | { | 137 | |
| 138 | // init frame | 138 | // init frame |
| 139 | m_frame = new JFrame( Constants.Name ); | 139 | m_frame = new JFrame(Constants.Name); |
| 140 | final Container pane = m_frame.getContentPane(); | 140 | final Container pane = m_frame.getContentPane(); |
| 141 | pane.setLayout( new BorderLayout() ); | 141 | pane.setLayout(new BorderLayout()); |
| 142 | 142 | ||
| 143 | if( Boolean.parseBoolean( System.getProperty( "enigma.catchExceptions", "true" ) ) ) | 143 | if (Boolean.parseBoolean(System.getProperty("enigma.catchExceptions", "true"))) { |
| 144 | { | ||
| 145 | // install a global exception handler to the event thread | 144 | // install a global exception handler to the event thread |
| 146 | CrashDialog.init( m_frame ); | 145 | CrashDialog.init(m_frame); |
| 147 | Thread.setDefaultUncaughtExceptionHandler( new UncaughtExceptionHandler( ) | 146 | Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { |
| 148 | { | ||
| 149 | @Override | 147 | @Override |
| 150 | public void uncaughtException( Thread thread, Throwable ex ) | 148 | public void uncaughtException(Thread thread, Throwable ex) { |
| 151 | { | 149 | ex.printStackTrace(System.err); |
| 152 | ex.printStackTrace( System.err ); | 150 | CrashDialog.show(ex); |
| 153 | CrashDialog.show( ex ); | ||
| 154 | } | 151 | } |
| 155 | } ); | 152 | }); |
| 156 | } | 153 | } |
| 157 | 154 | ||
| 158 | m_controller = new GuiController( this ); | 155 | m_controller = new GuiController(this); |
| 159 | 156 | ||
| 160 | // init file choosers | 157 | // init file choosers |
| 161 | m_jarFileChooser = new JFileChooser(); | 158 | m_jarFileChooser = new JFileChooser(); |
| 162 | m_mappingsFileChooser = new JFileChooser(); | 159 | m_mappingsFileChooser = new JFileChooser(); |
| 163 | m_exportSourceFileChooser = new JFileChooser(); | 160 | m_exportSourceFileChooser = new JFileChooser(); |
| 164 | m_exportSourceFileChooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ); | 161 | m_exportSourceFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
| 165 | m_exportJarFileChooser = new JFileChooser(); | 162 | m_exportJarFileChooser = new JFileChooser(); |
| 166 | 163 | ||
| 167 | // init obfuscated classes list | 164 | // init obfuscated classes list |
| 168 | m_obfClasses = new ClassSelector( ClassSelector.ObfuscatedClassEntryComparator ); | 165 | m_obfClasses = new ClassSelector(ClassSelector.ObfuscatedClassEntryComparator); |
| 169 | m_obfClasses.setListener( new ClassSelectionListener( ) | 166 | m_obfClasses.setListener(new ClassSelectionListener() { |
| 170 | { | ||
| 171 | @Override | 167 | @Override |
| 172 | public void onSelectClass( ClassEntry classEntry ) | 168 | public void onSelectClass(ClassEntry classEntry) { |
| 173 | { | 169 | navigateTo(classEntry); |
| 174 | navigateTo( classEntry ); | ||
| 175 | } | 170 | } |
| 176 | } ); | 171 | }); |
| 177 | JScrollPane obfScroller = new JScrollPane( m_obfClasses ); | 172 | JScrollPane obfScroller = new JScrollPane(m_obfClasses); |
| 178 | JPanel obfPanel = new JPanel(); | 173 | JPanel obfPanel = new JPanel(); |
| 179 | obfPanel.setLayout( new BorderLayout() ); | 174 | obfPanel.setLayout(new BorderLayout()); |
| 180 | obfPanel.add( new JLabel( "Obfuscated Classes" ), BorderLayout.NORTH ); | 175 | obfPanel.add(new JLabel("Obfuscated Classes"), BorderLayout.NORTH); |
| 181 | obfPanel.add( obfScroller, BorderLayout.CENTER ); | 176 | obfPanel.add(obfScroller, BorderLayout.CENTER); |
| 182 | 177 | ||
| 183 | // init deobfuscated classes list | 178 | // init deobfuscated classes list |
| 184 | m_deobfClasses = new ClassSelector( ClassSelector.DeobfuscatedClassEntryComparator ); | 179 | m_deobfClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); |
| 185 | m_deobfClasses.setListener( new ClassSelectionListener( ) | 180 | m_deobfClasses.setListener(new ClassSelectionListener() { |
| 186 | { | ||
| 187 | @Override | 181 | @Override |
| 188 | public void onSelectClass( ClassEntry classEntry ) | 182 | public void onSelectClass(ClassEntry classEntry) { |
| 189 | { | 183 | navigateTo(classEntry); |
| 190 | navigateTo( classEntry ); | ||
| 191 | } | 184 | } |
| 192 | } ); | 185 | }); |
| 193 | JScrollPane deobfScroller = new JScrollPane( m_deobfClasses ); | 186 | JScrollPane deobfScroller = new JScrollPane(m_deobfClasses); |
| 194 | JPanel deobfPanel = new JPanel(); | 187 | JPanel deobfPanel = new JPanel(); |
| 195 | deobfPanel.setLayout( new BorderLayout() ); | 188 | deobfPanel.setLayout(new BorderLayout()); |
| 196 | deobfPanel.add( new JLabel( "De-obfuscated Classes" ), BorderLayout.NORTH ); | 189 | deobfPanel.add(new JLabel("De-obfuscated Classes"), BorderLayout.NORTH); |
| 197 | deobfPanel.add( deobfScroller, BorderLayout.CENTER ); | 190 | deobfPanel.add(deobfScroller, BorderLayout.CENTER); |
| 198 | 191 | ||
| 199 | // set up classes panel (don't add the splitter yet) | 192 | // set up classes panel (don't add the splitter yet) |
| 200 | m_splitClasses = new JSplitPane( JSplitPane.VERTICAL_SPLIT, true, obfPanel, deobfPanel ); | 193 | m_splitClasses = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, obfPanel, deobfPanel); |
| 201 | m_splitClasses.setResizeWeight( 0.3 ); | 194 | m_splitClasses.setResizeWeight(0.3); |
| 202 | m_classesPanel = new JPanel(); | 195 | m_classesPanel = new JPanel(); |
| 203 | m_classesPanel.setLayout( new BorderLayout() ); | 196 | m_classesPanel.setLayout(new BorderLayout()); |
| 204 | m_classesPanel.setPreferredSize( new Dimension( 250, 0 ) ); | 197 | m_classesPanel.setPreferredSize(new Dimension(250, 0)); |
| 205 | 198 | ||
| 206 | // init info panel | 199 | // init info panel |
| 207 | m_infoPanel = new JPanel(); | 200 | m_infoPanel = new JPanel(); |
| 208 | m_infoPanel.setLayout( new GridLayout( 4, 1, 0, 0 ) ); | 201 | m_infoPanel.setLayout(new GridLayout(4, 1, 0, 0)); |
| 209 | m_infoPanel.setPreferredSize( new Dimension( 0, 100 ) ); | 202 | m_infoPanel.setPreferredSize(new Dimension(0, 100)); |
| 210 | m_infoPanel.setBorder( BorderFactory.createTitledBorder( "Identifier Info" ) ); | 203 | m_infoPanel.setBorder(BorderFactory.createTitledBorder("Identifier Info")); |
| 211 | clearReference(); | 204 | clearReference(); |
| 212 | 205 | ||
| 213 | // init editor | 206 | // init editor |
| @@ -217,25 +210,20 @@ public class Gui | |||
| 217 | m_otherHighlightPainter = new OtherHighlightPainter(); | 210 | m_otherHighlightPainter = new OtherHighlightPainter(); |
| 218 | m_selectionHighlightPainter = new SelectionHighlightPainter(); | 211 | m_selectionHighlightPainter = new SelectionHighlightPainter(); |
| 219 | m_editor = new JEditorPane(); | 212 | m_editor = new JEditorPane(); |
| 220 | m_editor.setEditable( false ); | 213 | m_editor.setEditable(false); |
| 221 | m_editor.setCaret( new BrowserCaret() ); | 214 | m_editor.setCaret(new BrowserCaret()); |
| 222 | JScrollPane sourceScroller = new JScrollPane( m_editor ); | 215 | JScrollPane sourceScroller = new JScrollPane(m_editor); |
| 223 | m_editor.setContentType( "text/java" ); | 216 | m_editor.setContentType("text/java"); |
| 224 | m_editor.addCaretListener( new CaretListener( ) | 217 | m_editor.addCaretListener(new CaretListener() { |
| 225 | { | ||
| 226 | @Override | 218 | @Override |
| 227 | public void caretUpdate( CaretEvent event ) | 219 | public void caretUpdate(CaretEvent event) { |
| 228 | { | 220 | onCaretMove(event.getDot()); |
| 229 | onCaretMove( event.getDot() ); | ||
| 230 | } | 221 | } |
| 231 | } ); | 222 | }); |
| 232 | m_editor.addKeyListener( new KeyAdapter( ) | 223 | m_editor.addKeyListener(new KeyAdapter() { |
| 233 | { | ||
| 234 | @Override | 224 | @Override |
| 235 | public void keyPressed( KeyEvent event ) | 225 | public void keyPressed(KeyEvent event) { |
| 236 | { | 226 | switch (event.getKeyCode()) { |
| 237 | switch( event.getKeyCode() ) | ||
| 238 | { | ||
| 239 | case KeyEvent.VK_R: | 227 | case KeyEvent.VK_R: |
| 240 | m_renameMenu.doClick(); | 228 | m_renameMenu.doClick(); |
| 241 | break; | 229 | break; |
| @@ -265,713 +253,594 @@ public class Gui | |||
| 265 | break; | 253 | break; |
| 266 | } | 254 | } |
| 267 | } | 255 | } |
| 268 | } ); | 256 | }); |
| 269 | 257 | ||
| 270 | // turn off token highlighting (it's wrong most of the time anyway...) | 258 | // turn off token highlighting (it's wrong most of the time anyway...) |
| 271 | DefaultSyntaxKit kit = (DefaultSyntaxKit)m_editor.getEditorKit(); | 259 | DefaultSyntaxKit kit = (DefaultSyntaxKit)m_editor.getEditorKit(); |
| 272 | kit.toggleComponent( m_editor, "jsyntaxpane.components.TokenMarker" ); | 260 | kit.toggleComponent(m_editor, "jsyntaxpane.components.TokenMarker"); |
| 273 | 261 | ||
| 274 | // init editor popup menu | 262 | // init editor popup menu |
| 275 | JPopupMenu popupMenu = new JPopupMenu(); | 263 | JPopupMenu popupMenu = new JPopupMenu(); |
| 276 | m_editor.setComponentPopupMenu( popupMenu ); | 264 | m_editor.setComponentPopupMenu(popupMenu); |
| 277 | { | 265 | { |
| 278 | JMenuItem menu = new JMenuItem( "Rename" ); | 266 | JMenuItem menu = new JMenuItem("Rename"); |
| 279 | menu.addActionListener( new ActionListener( ) | 267 | menu.addActionListener(new ActionListener() { |
| 280 | { | ||
| 281 | @Override | 268 | @Override |
| 282 | public void actionPerformed( ActionEvent event ) | 269 | public void actionPerformed(ActionEvent event) { |
| 283 | { | ||
| 284 | startRename(); | 270 | startRename(); |
| 285 | } | 271 | } |
| 286 | } ); | 272 | }); |
| 287 | menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_R, 0 ) ); | 273 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, 0)); |
| 288 | menu.setEnabled( false ); | 274 | menu.setEnabled(false); |
| 289 | popupMenu.add( menu ); | 275 | popupMenu.add(menu); |
| 290 | m_renameMenu = menu; | 276 | m_renameMenu = menu; |
| 291 | } | 277 | } |
| 292 | { | 278 | { |
| 293 | JMenuItem menu = new JMenuItem( "Show Inheritance" ); | 279 | JMenuItem menu = new JMenuItem("Show Inheritance"); |
| 294 | menu.addActionListener( new ActionListener( ) | 280 | menu.addActionListener(new ActionListener() { |
| 295 | { | ||
| 296 | @Override | 281 | @Override |
| 297 | public void actionPerformed( ActionEvent event ) | 282 | public void actionPerformed(ActionEvent event) { |
| 298 | { | ||
| 299 | showInheritance(); | 283 | showInheritance(); |
| 300 | } | 284 | } |
| 301 | } ); | 285 | }); |
| 302 | menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_I, 0 ) ); | 286 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, 0)); |
| 303 | menu.setEnabled( false ); | 287 | menu.setEnabled(false); |
| 304 | popupMenu.add( menu ); | 288 | popupMenu.add(menu); |
| 305 | m_showInheritanceMenu = menu; | 289 | m_showInheritanceMenu = menu; |
| 306 | } | 290 | } |
| 307 | { | 291 | { |
| 308 | JMenuItem menu = new JMenuItem( "Show Implementations" ); | 292 | JMenuItem menu = new JMenuItem("Show Implementations"); |
| 309 | menu.addActionListener( new ActionListener( ) | 293 | menu.addActionListener(new ActionListener() { |
| 310 | { | ||
| 311 | @Override | 294 | @Override |
| 312 | public void actionPerformed( ActionEvent event ) | 295 | public void actionPerformed(ActionEvent event) { |
| 313 | { | ||
| 314 | showImplementations(); | 296 | showImplementations(); |
| 315 | } | 297 | } |
| 316 | } ); | 298 | }); |
| 317 | menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_M, 0 ) ); | 299 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, 0)); |
| 318 | menu.setEnabled( false ); | 300 | menu.setEnabled(false); |
| 319 | popupMenu.add( menu ); | 301 | popupMenu.add(menu); |
| 320 | m_showImplementationsMenu = menu; | 302 | m_showImplementationsMenu = menu; |
| 321 | } | 303 | } |
| 322 | { | 304 | { |
| 323 | JMenuItem menu = new JMenuItem( "Show Calls" ); | 305 | JMenuItem menu = new JMenuItem("Show Calls"); |
| 324 | menu.addActionListener( new ActionListener( ) | 306 | menu.addActionListener(new ActionListener() { |
| 325 | { | ||
| 326 | @Override | 307 | @Override |
| 327 | public void actionPerformed( ActionEvent event ) | 308 | public void actionPerformed(ActionEvent event) { |
| 328 | { | ||
| 329 | showCalls(); | 309 | showCalls(); |
| 330 | } | 310 | } |
| 331 | } ); | 311 | }); |
| 332 | menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_C, 0 ) ); | 312 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 0)); |
| 333 | menu.setEnabled( false ); | 313 | menu.setEnabled(false); |
| 334 | popupMenu.add( menu ); | 314 | popupMenu.add(menu); |
| 335 | m_showCallsMenu = menu; | 315 | m_showCallsMenu = menu; |
| 336 | } | 316 | } |
| 337 | { | 317 | { |
| 338 | JMenuItem menu = new JMenuItem( "Go to Declaration" ); | 318 | JMenuItem menu = new JMenuItem("Go to Declaration"); |
| 339 | menu.addActionListener( new ActionListener( ) | 319 | menu.addActionListener(new ActionListener() { |
| 340 | { | ||
| 341 | @Override | 320 | @Override |
| 342 | public void actionPerformed( ActionEvent event ) | 321 | public void actionPerformed(ActionEvent event) { |
| 343 | { | 322 | navigateTo(m_reference.entry); |
| 344 | navigateTo( m_reference.entry ); | ||
| 345 | } | 323 | } |
| 346 | } ); | 324 | }); |
| 347 | menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_N, 0 ) ); | 325 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 0)); |
| 348 | menu.setEnabled( false ); | 326 | menu.setEnabled(false); |
| 349 | popupMenu.add( menu ); | 327 | popupMenu.add(menu); |
| 350 | m_openEntryMenu = menu; | 328 | m_openEntryMenu = menu; |
| 351 | } | 329 | } |
| 352 | { | 330 | { |
| 353 | JMenuItem menu = new JMenuItem( "Go to previous" ); | 331 | JMenuItem menu = new JMenuItem("Go to previous"); |
| 354 | menu.addActionListener( new ActionListener( ) | 332 | menu.addActionListener(new ActionListener() { |
| 355 | { | ||
| 356 | @Override | 333 | @Override |
| 357 | public void actionPerformed( ActionEvent event ) | 334 | public void actionPerformed(ActionEvent event) { |
| 358 | { | ||
| 359 | m_controller.openPreviousReference(); | 335 | m_controller.openPreviousReference(); |
| 360 | } | 336 | } |
| 361 | } ); | 337 | }); |
| 362 | menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_P, 0 ) ); | 338 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, 0)); |
| 363 | menu.setEnabled( false ); | 339 | menu.setEnabled(false); |
| 364 | popupMenu.add( menu ); | 340 | popupMenu.add(menu); |
| 365 | m_openPreviousMenu = menu; | 341 | m_openPreviousMenu = menu; |
| 366 | } | 342 | } |
| 367 | { | 343 | { |
| 368 | JMenuItem menu = new JMenuItem( "Mark as deobfuscated" ); | 344 | JMenuItem menu = new JMenuItem("Mark as deobfuscated"); |
| 369 | menu.addActionListener( new ActionListener( ) | 345 | menu.addActionListener(new ActionListener() { |
| 370 | { | ||
| 371 | @Override | 346 | @Override |
| 372 | public void actionPerformed( ActionEvent event ) | 347 | public void actionPerformed(ActionEvent event) { |
| 373 | { | ||
| 374 | toggleMapping(); | 348 | toggleMapping(); |
| 375 | } | 349 | } |
| 376 | } ); | 350 | }); |
| 377 | menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_T, 0 ) ); | 351 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, 0)); |
| 378 | menu.setEnabled( false ); | 352 | menu.setEnabled(false); |
| 379 | popupMenu.add( menu ); | 353 | popupMenu.add(menu); |
| 380 | m_toggleMappingMenu = menu; | 354 | m_toggleMappingMenu = menu; |
| 381 | } | 355 | } |
| 382 | 356 | ||
| 383 | // init inheritance panel | 357 | // init inheritance panel |
| 384 | m_inheritanceTree = new JTree(); | 358 | m_inheritanceTree = new JTree(); |
| 385 | m_inheritanceTree.setModel( null ); | 359 | m_inheritanceTree.setModel(null); |
| 386 | m_inheritanceTree.addMouseListener( new MouseAdapter( ) | 360 | m_inheritanceTree.addMouseListener(new MouseAdapter() { |
| 387 | { | ||
| 388 | @Override | 361 | @Override |
| 389 | public void mouseClicked( MouseEvent event ) | 362 | public void mouseClicked(MouseEvent event) { |
| 390 | { | 363 | if (event.getClickCount() == 2) { |
| 391 | if( event.getClickCount() == 2 ) | ||
| 392 | { | ||
| 393 | // get the selected node | 364 | // get the selected node |
| 394 | TreePath path = m_inheritanceTree.getSelectionPath(); | 365 | TreePath path = m_inheritanceTree.getSelectionPath(); |
| 395 | if( path == null ) | 366 | if (path == null) { |
| 396 | { | ||
| 397 | return; | 367 | return; |
| 398 | } | 368 | } |
| 399 | 369 | ||
| 400 | Object node = path.getLastPathComponent(); | 370 | Object node = path.getLastPathComponent(); |
| 401 | if( node instanceof ClassInheritanceTreeNode ) | 371 | if (node instanceof ClassInheritanceTreeNode) { |
| 402 | { | ||
| 403 | ClassInheritanceTreeNode classNode = (ClassInheritanceTreeNode)node; | 372 | ClassInheritanceTreeNode classNode = (ClassInheritanceTreeNode)node; |
| 404 | navigateTo( new ClassEntry( classNode.getObfClassName() ) ); | 373 | navigateTo(new ClassEntry(classNode.getObfClassName())); |
| 405 | } | 374 | } else if (node instanceof MethodInheritanceTreeNode) { |
| 406 | else if( node instanceof MethodInheritanceTreeNode ) | ||
| 407 | { | ||
| 408 | MethodInheritanceTreeNode methodNode = (MethodInheritanceTreeNode)node; | 375 | MethodInheritanceTreeNode methodNode = (MethodInheritanceTreeNode)node; |
| 409 | if( methodNode.isImplemented() ) | 376 | if (methodNode.isImplemented()) { |
| 410 | { | 377 | navigateTo(methodNode.getMethodEntry()); |
| 411 | navigateTo( methodNode.getMethodEntry() ); | ||
| 412 | } | 378 | } |
| 413 | } | 379 | } |
| 414 | } | 380 | } |
| 415 | } | 381 | } |
| 416 | } ); | 382 | }); |
| 417 | JPanel inheritancePanel = new JPanel(); | 383 | JPanel inheritancePanel = new JPanel(); |
| 418 | inheritancePanel.setLayout( new BorderLayout() ); | 384 | inheritancePanel.setLayout(new BorderLayout()); |
| 419 | inheritancePanel.add( new JScrollPane( m_inheritanceTree ) ); | 385 | inheritancePanel.add(new JScrollPane(m_inheritanceTree)); |
| 420 | 386 | ||
| 421 | // init implementations panel | 387 | // init implementations panel |
| 422 | m_implementationsTree = new JTree(); | 388 | m_implementationsTree = new JTree(); |
| 423 | m_implementationsTree.setModel( null ); | 389 | m_implementationsTree.setModel(null); |
| 424 | m_implementationsTree.addMouseListener( new MouseAdapter( ) | 390 | m_implementationsTree.addMouseListener(new MouseAdapter() { |
| 425 | { | ||
| 426 | @Override | 391 | @Override |
| 427 | public void mouseClicked( MouseEvent event ) | 392 | public void mouseClicked(MouseEvent event) { |
| 428 | { | 393 | if (event.getClickCount() == 2) { |
| 429 | if( event.getClickCount() == 2 ) | ||
| 430 | { | ||
| 431 | // get the selected node | 394 | // get the selected node |
| 432 | TreePath path = m_implementationsTree.getSelectionPath(); | 395 | TreePath path = m_implementationsTree.getSelectionPath(); |
| 433 | if( path == null ) | 396 | if (path == null) { |
| 434 | { | ||
| 435 | return; | 397 | return; |
| 436 | } | 398 | } |
| 437 | 399 | ||
| 438 | Object node = path.getLastPathComponent(); | 400 | Object node = path.getLastPathComponent(); |
| 439 | if( node instanceof ClassImplementationsTreeNode ) | 401 | if (node instanceof ClassImplementationsTreeNode) { |
| 440 | { | ||
| 441 | ClassImplementationsTreeNode classNode = (ClassImplementationsTreeNode)node; | 402 | ClassImplementationsTreeNode classNode = (ClassImplementationsTreeNode)node; |
| 442 | navigateTo( classNode.getClassEntry() ); | 403 | navigateTo(classNode.getClassEntry()); |
| 443 | } | 404 | } else if (node instanceof MethodImplementationsTreeNode) { |
| 444 | else if( node instanceof MethodImplementationsTreeNode ) | ||
| 445 | { | ||
| 446 | MethodImplementationsTreeNode methodNode = (MethodImplementationsTreeNode)node; | 405 | MethodImplementationsTreeNode methodNode = (MethodImplementationsTreeNode)node; |
| 447 | navigateTo( methodNode.getMethodEntry() ); | 406 | navigateTo(methodNode.getMethodEntry()); |
| 448 | } | 407 | } |
| 449 | } | 408 | } |
| 450 | } | 409 | } |
| 451 | } ); | 410 | }); |
| 452 | JPanel implementationsPanel = new JPanel(); | 411 | JPanel implementationsPanel = new JPanel(); |
| 453 | implementationsPanel.setLayout( new BorderLayout() ); | 412 | implementationsPanel.setLayout(new BorderLayout()); |
| 454 | implementationsPanel.add( new JScrollPane( m_implementationsTree ) ); | 413 | implementationsPanel.add(new JScrollPane(m_implementationsTree)); |
| 455 | 414 | ||
| 456 | // init call panel | 415 | // init call panel |
| 457 | m_callsTree = new JTree(); | 416 | m_callsTree = new JTree(); |
| 458 | m_callsTree.setModel( null ); | 417 | m_callsTree.setModel(null); |
| 459 | m_callsTree.addMouseListener( new MouseAdapter( ) | 418 | m_callsTree.addMouseListener(new MouseAdapter() { |
| 460 | { | 419 | @SuppressWarnings("unchecked") |
| 461 | @SuppressWarnings( "unchecked" ) | ||
| 462 | @Override | 420 | @Override |
| 463 | public void mouseClicked( MouseEvent event ) | 421 | public void mouseClicked(MouseEvent event) { |
| 464 | { | 422 | if (event.getClickCount() == 2) { |
| 465 | if( event.getClickCount() == 2 ) | ||
| 466 | { | ||
| 467 | // get the selected node | 423 | // get the selected node |
| 468 | TreePath path = m_callsTree.getSelectionPath(); | 424 | TreePath path = m_callsTree.getSelectionPath(); |
| 469 | if( path == null ) | 425 | if (path == null) { |
| 470 | { | ||
| 471 | return; | 426 | return; |
| 472 | } | 427 | } |
| 473 | 428 | ||
| 474 | Object node = path.getLastPathComponent(); | 429 | Object node = path.getLastPathComponent(); |
| 475 | if( node instanceof ReferenceTreeNode ) | 430 | if (node instanceof ReferenceTreeNode) { |
| 476 | { | ||
| 477 | ReferenceTreeNode<Entry,Entry> referenceNode = ((ReferenceTreeNode<Entry,Entry>)node); | 431 | ReferenceTreeNode<Entry,Entry> referenceNode = ((ReferenceTreeNode<Entry,Entry>)node); |
| 478 | if( referenceNode.getReference() != null ) | 432 | if (referenceNode.getReference() != null) { |
| 479 | { | 433 | navigateTo(referenceNode.getReference()); |
| 480 | navigateTo( referenceNode.getReference() ); | 434 | } else { |
| 481 | } | 435 | navigateTo(referenceNode.getEntry()); |
| 482 | else | ||
| 483 | { | ||
| 484 | navigateTo( referenceNode.getEntry() ); | ||
| 485 | } | 436 | } |
| 486 | } | 437 | } |
| 487 | } | 438 | } |
| 488 | } | 439 | } |
| 489 | } ); | 440 | }); |
| 490 | m_tokens = new JList<Token>(); | 441 | m_tokens = new JList<Token>(); |
| 491 | m_tokens.setCellRenderer( new TokenListCellRenderer( m_controller ) ); | 442 | m_tokens.setCellRenderer(new TokenListCellRenderer(m_controller)); |
| 492 | m_tokens.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); | 443 | m_tokens.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
| 493 | m_tokens.setLayoutOrientation( JList.VERTICAL ); | 444 | m_tokens.setLayoutOrientation(JList.VERTICAL); |
| 494 | m_tokens.addMouseListener( new MouseAdapter() | 445 | m_tokens.addMouseListener(new MouseAdapter() { |
| 495 | { | ||
| 496 | @Override | 446 | @Override |
| 497 | public void mouseClicked( MouseEvent event ) | 447 | public void mouseClicked(MouseEvent event) { |
| 498 | { | 448 | if (event.getClickCount() == 2) { |
| 499 | if( event.getClickCount() == 2 ) | ||
| 500 | { | ||
| 501 | Token selected = m_tokens.getSelectedValue(); | 449 | Token selected = m_tokens.getSelectedValue(); |
| 502 | if( selected != null ) | 450 | if (selected != null) { |
| 503 | { | 451 | showToken(selected); |
| 504 | showToken( selected ); | ||
| 505 | } | 452 | } |
| 506 | } | 453 | } |
| 507 | } | 454 | } |
| 508 | } ); | 455 | }); |
| 509 | m_tokens.setPreferredSize( new Dimension( 0, 200 ) ); | 456 | m_tokens.setPreferredSize(new Dimension(0, 200)); |
| 510 | m_tokens.setMinimumSize( new Dimension( 0, 200 ) ); | 457 | m_tokens.setMinimumSize(new Dimension(0, 200)); |
| 511 | JSplitPane callPanel = new JSplitPane( JSplitPane.VERTICAL_SPLIT, true, new JScrollPane( m_callsTree ), new JScrollPane( m_tokens ) ); | 458 | JSplitPane callPanel = new JSplitPane( |
| 512 | callPanel.setResizeWeight( 1 ); // let the top side take all the slack | 459 | JSplitPane.VERTICAL_SPLIT, |
| 460 | true, | ||
| 461 | new JScrollPane(m_callsTree), | ||
| 462 | new JScrollPane(m_tokens) | ||
| 463 | ); | ||
| 464 | callPanel.setResizeWeight(1); // let the top side take all the slack | ||
| 513 | callPanel.resetToPreferredSizes(); | 465 | callPanel.resetToPreferredSizes(); |
| 514 | 466 | ||
| 515 | // layout controls | 467 | // layout controls |
| 516 | JPanel centerPanel = new JPanel(); | 468 | JPanel centerPanel = new JPanel(); |
| 517 | centerPanel.setLayout( new BorderLayout() ); | 469 | centerPanel.setLayout(new BorderLayout()); |
| 518 | centerPanel.add( m_infoPanel, BorderLayout.NORTH ); | 470 | centerPanel.add(m_infoPanel, BorderLayout.NORTH); |
| 519 | centerPanel.add( sourceScroller, BorderLayout.CENTER ); | 471 | centerPanel.add(sourceScroller, BorderLayout.CENTER); |
| 520 | m_tabs = new JTabbedPane(); | 472 | m_tabs = new JTabbedPane(); |
| 521 | m_tabs.setPreferredSize( new Dimension( 250, 0 ) ); | 473 | m_tabs.setPreferredSize(new Dimension(250, 0)); |
| 522 | m_tabs.addTab( "Inheritance", inheritancePanel ); | 474 | m_tabs.addTab("Inheritance", inheritancePanel); |
| 523 | m_tabs.addTab( "Implementations", implementationsPanel ); | 475 | m_tabs.addTab("Implementations", implementationsPanel); |
| 524 | m_tabs.addTab( "Call Graph", callPanel ); | 476 | m_tabs.addTab("Call Graph", callPanel); |
| 525 | JSplitPane splitRight = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, true, centerPanel, m_tabs ); | 477 | JSplitPane splitRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, centerPanel, m_tabs); |
| 526 | splitRight.setResizeWeight( 1 ); // let the left side take all the slack | 478 | splitRight.setResizeWeight(1); // let the left side take all the slack |
| 527 | splitRight.resetToPreferredSizes(); | 479 | splitRight.resetToPreferredSizes(); |
| 528 | JSplitPane splitCenter = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, true, m_classesPanel, splitRight ); | 480 | JSplitPane splitCenter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, m_classesPanel, splitRight); |
| 529 | splitCenter.setResizeWeight( 0 ); // let the right side take all the slack | 481 | splitCenter.setResizeWeight(0); // let the right side take all the slack |
| 530 | pane.add( splitCenter, BorderLayout.CENTER ); | 482 | pane.add(splitCenter, BorderLayout.CENTER); |
| 531 | 483 | ||
| 532 | // init menus | 484 | // init menus |
| 533 | JMenuBar menuBar = new JMenuBar(); | 485 | JMenuBar menuBar = new JMenuBar(); |
| 534 | m_frame.setJMenuBar( menuBar ); | 486 | m_frame.setJMenuBar(menuBar); |
| 535 | { | 487 | { |
| 536 | JMenu menu = new JMenu( "File" ); | 488 | JMenu menu = new JMenu("File"); |
| 537 | menuBar.add( menu ); | 489 | menuBar.add(menu); |
| 538 | { | 490 | { |
| 539 | JMenuItem item = new JMenuItem( "Open Jar..." ); | 491 | JMenuItem item = new JMenuItem("Open Jar..."); |
| 540 | menu.add( item ); | 492 | menu.add(item); |
| 541 | item.addActionListener( new ActionListener( ) | 493 | item.addActionListener(new ActionListener() { |
| 542 | { | ||
| 543 | @Override | 494 | @Override |
| 544 | public void actionPerformed( ActionEvent event ) | 495 | public void actionPerformed(ActionEvent event) { |
| 545 | { | 496 | if (m_jarFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { |
| 546 | if( m_jarFileChooser.showOpenDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) | ||
| 547 | { | ||
| 548 | // load the jar in a separate thread | 497 | // load the jar in a separate thread |
| 549 | new Thread( ) | 498 | new Thread() { |
| 550 | { | ||
| 551 | @Override | 499 | @Override |
| 552 | public void run( ) | 500 | public void run() { |
| 553 | { | 501 | try { |
| 554 | try | 502 | m_controller.openJar(m_jarFileChooser.getSelectedFile()); |
| 555 | { | 503 | } catch (IOException ex) { |
| 556 | m_controller.openJar( m_jarFileChooser.getSelectedFile() ); | 504 | throw new Error(ex); |
| 557 | } | ||
| 558 | catch( IOException ex ) | ||
| 559 | { | ||
| 560 | throw new Error( ex ); | ||
| 561 | } | 505 | } |
| 562 | } | 506 | } |
| 563 | }.start(); | 507 | }.start(); |
| 564 | } | 508 | } |
| 565 | } | 509 | } |
| 566 | } ); | 510 | }); |
| 567 | } | 511 | } |
| 568 | { | 512 | { |
| 569 | JMenuItem item = new JMenuItem( "Close Jar" ); | 513 | JMenuItem item = new JMenuItem("Close Jar"); |
| 570 | menu.add( item ); | 514 | menu.add(item); |
| 571 | item.addActionListener( new ActionListener( ) | 515 | item.addActionListener(new ActionListener() { |
| 572 | { | ||
| 573 | @Override | 516 | @Override |
| 574 | public void actionPerformed( ActionEvent event ) | 517 | public void actionPerformed(ActionEvent event) { |
| 575 | { | ||
| 576 | m_controller.closeJar(); | 518 | m_controller.closeJar(); |
| 577 | } | 519 | } |
| 578 | } ); | 520 | }); |
| 579 | m_closeJarMenu = item; | 521 | m_closeJarMenu = item; |
| 580 | } | 522 | } |
| 581 | menu.addSeparator(); | 523 | menu.addSeparator(); |
| 582 | { | 524 | { |
| 583 | JMenuItem item = new JMenuItem( "Open Mappings..." ); | 525 | JMenuItem item = new JMenuItem("Open Mappings..."); |
| 584 | menu.add( item ); | 526 | menu.add(item); |
| 585 | item.addActionListener( new ActionListener( ) | 527 | item.addActionListener(new ActionListener() { |
| 586 | { | ||
| 587 | @Override | 528 | @Override |
| 588 | public void actionPerformed( ActionEvent event ) | 529 | public void actionPerformed(ActionEvent event) { |
| 589 | { | 530 | if (m_mappingsFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { |
| 590 | if( m_mappingsFileChooser.showOpenDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) | 531 | try { |
| 591 | { | 532 | m_controller.openMappings(m_mappingsFileChooser.getSelectedFile()); |
| 592 | try | 533 | } catch (IOException ex) { |
| 593 | { | 534 | throw new Error(ex); |
| 594 | m_controller.openMappings( m_mappingsFileChooser.getSelectedFile() ); | 535 | } catch (MappingParseException ex) { |
| 595 | } | 536 | JOptionPane.showMessageDialog(m_frame, ex.getMessage()); |
| 596 | catch( IOException ex ) | ||
| 597 | { | ||
| 598 | throw new Error( ex ); | ||
| 599 | } | ||
| 600 | catch( MappingParseException ex ) | ||
| 601 | { | ||
| 602 | JOptionPane.showMessageDialog( m_frame, ex.getMessage() ); | ||
| 603 | } | 537 | } |
| 604 | } | 538 | } |
| 605 | } | 539 | } |
| 606 | } ); | 540 | }); |
| 607 | m_openMappingsMenu = item; | 541 | m_openMappingsMenu = item; |
| 608 | } | 542 | } |
| 609 | { | 543 | { |
| 610 | JMenuItem item = new JMenuItem( "Save Mappings" ); | 544 | JMenuItem item = new JMenuItem("Save Mappings"); |
| 611 | menu.add( item ); | 545 | menu.add(item); |
| 612 | item.addActionListener( new ActionListener( ) | 546 | item.addActionListener(new ActionListener() { |
| 613 | { | ||
| 614 | @Override | 547 | @Override |
| 615 | public void actionPerformed( ActionEvent event ) | 548 | public void actionPerformed(ActionEvent event) { |
| 616 | { | 549 | try { |
| 617 | try | 550 | m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); |
| 618 | { | 551 | } catch (IOException ex) { |
| 619 | m_controller.saveMappings( m_mappingsFileChooser.getSelectedFile() ); | 552 | throw new Error(ex); |
| 620 | } | ||
| 621 | catch( IOException ex ) | ||
| 622 | { | ||
| 623 | throw new Error( ex ); | ||
| 624 | } | 553 | } |
| 625 | } | 554 | } |
| 626 | } ); | 555 | }); |
| 627 | item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK ) ); | 556 | item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); |
| 628 | m_saveMappingsMenu = item; | 557 | m_saveMappingsMenu = item; |
| 629 | } | 558 | } |
| 630 | { | 559 | { |
| 631 | JMenuItem item = new JMenuItem( "Save Mappings As..." ); | 560 | JMenuItem item = new JMenuItem("Save Mappings As..."); |
| 632 | menu.add( item ); | 561 | menu.add(item); |
| 633 | item.addActionListener( new ActionListener( ) | 562 | item.addActionListener(new ActionListener() { |
| 634 | { | ||
| 635 | @Override | 563 | @Override |
| 636 | public void actionPerformed( ActionEvent event ) | 564 | public void actionPerformed(ActionEvent event) { |
| 637 | { | 565 | if (m_mappingsFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { |
| 638 | if( m_mappingsFileChooser.showSaveDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) | 566 | try { |
| 639 | { | 567 | m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); |
| 640 | try | 568 | m_saveMappingsMenu.setEnabled(true); |
| 641 | { | 569 | } catch (IOException ex) { |
| 642 | m_controller.saveMappings( m_mappingsFileChooser.getSelectedFile() ); | 570 | throw new Error(ex); |
| 643 | m_saveMappingsMenu.setEnabled( true ); | ||
| 644 | } | ||
| 645 | catch( IOException ex ) | ||
| 646 | { | ||
| 647 | throw new Error( ex ); | ||
| 648 | } | 571 | } |
| 649 | } | 572 | } |
| 650 | } | 573 | } |
| 651 | } ); | 574 | }); |
| 652 | item.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK ) ); | 575 | item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); |
| 653 | m_saveMappingsAsMenu = item; | 576 | m_saveMappingsAsMenu = item; |
| 654 | } | 577 | } |
| 655 | { | 578 | { |
| 656 | JMenuItem item = new JMenuItem( "Close Mappings" ); | 579 | JMenuItem item = new JMenuItem("Close Mappings"); |
| 657 | menu.add( item ); | 580 | menu.add(item); |
| 658 | item.addActionListener( new ActionListener( ) | 581 | item.addActionListener(new ActionListener() { |
| 659 | { | ||
| 660 | @Override | 582 | @Override |
| 661 | public void actionPerformed( ActionEvent event ) | 583 | public void actionPerformed(ActionEvent event) { |
| 662 | { | ||
| 663 | m_controller.closeMappings(); | 584 | m_controller.closeMappings(); |
| 664 | } | 585 | } |
| 665 | } ); | 586 | }); |
| 666 | m_closeMappingsMenu = item; | 587 | m_closeMappingsMenu = item; |
| 667 | } | 588 | } |
| 668 | menu.addSeparator(); | 589 | menu.addSeparator(); |
| 669 | { | 590 | { |
| 670 | JMenuItem item = new JMenuItem( "Export Source..." ); | 591 | JMenuItem item = new JMenuItem("Export Source..."); |
| 671 | menu.add( item ); | 592 | menu.add(item); |
| 672 | item.addActionListener( new ActionListener( ) | 593 | item.addActionListener(new ActionListener() { |
| 673 | { | ||
| 674 | @Override | 594 | @Override |
| 675 | public void actionPerformed( ActionEvent event ) | 595 | public void actionPerformed(ActionEvent event) { |
| 676 | { | 596 | if (m_exportSourceFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { |
| 677 | if( m_exportSourceFileChooser.showSaveDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) | 597 | m_controller.exportSource(m_exportSourceFileChooser.getSelectedFile()); |
| 678 | { | ||
| 679 | m_controller.exportSource( m_exportSourceFileChooser.getSelectedFile() ); | ||
| 680 | } | 598 | } |
| 681 | } | 599 | } |
| 682 | } ); | 600 | }); |
| 683 | m_exportSourceMenu = item; | 601 | m_exportSourceMenu = item; |
| 684 | } | 602 | } |
| 685 | { | 603 | { |
| 686 | JMenuItem item = new JMenuItem( "Export Jar..." ); | 604 | JMenuItem item = new JMenuItem("Export Jar..."); |
| 687 | menu.add( item ); | 605 | menu.add(item); |
| 688 | item.addActionListener( new ActionListener( ) | 606 | item.addActionListener(new ActionListener() { |
| 689 | { | ||
| 690 | @Override | 607 | @Override |
| 691 | public void actionPerformed( ActionEvent event ) | 608 | public void actionPerformed(ActionEvent event) { |
| 692 | { | 609 | if (m_exportJarFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { |
| 693 | if( m_exportJarFileChooser.showSaveDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) | 610 | m_controller.exportJar(m_exportJarFileChooser.getSelectedFile()); |
| 694 | { | ||
| 695 | m_controller.exportJar( m_exportJarFileChooser.getSelectedFile() ); | ||
| 696 | } | 611 | } |
| 697 | } | 612 | } |
| 698 | } ); | 613 | }); |
| 699 | m_exportJarMenu = item; | 614 | m_exportJarMenu = item; |
| 700 | } | 615 | } |
| 701 | menu.addSeparator(); | 616 | menu.addSeparator(); |
| 702 | { | 617 | { |
| 703 | JMenuItem item = new JMenuItem( "Exit" ); | 618 | JMenuItem item = new JMenuItem("Exit"); |
| 704 | menu.add( item ); | 619 | menu.add(item); |
| 705 | item.addActionListener( new ActionListener( ) | 620 | item.addActionListener(new ActionListener() { |
| 706 | { | ||
| 707 | @Override | 621 | @Override |
| 708 | public void actionPerformed( ActionEvent event ) | 622 | public void actionPerformed(ActionEvent event) { |
| 709 | { | ||
| 710 | close(); | 623 | close(); |
| 711 | } | 624 | } |
| 712 | } ); | 625 | }); |
| 713 | } | 626 | } |
| 714 | } | 627 | } |
| 715 | { | 628 | { |
| 716 | JMenu menu = new JMenu( "Help" ); | 629 | JMenu menu = new JMenu("Help"); |
| 717 | menuBar.add( menu ); | 630 | menuBar.add(menu); |
| 718 | { | 631 | { |
| 719 | JMenuItem item = new JMenuItem( "About" ); | 632 | JMenuItem item = new JMenuItem("About"); |
| 720 | menu.add( item ); | 633 | menu.add(item); |
| 721 | item.addActionListener( new ActionListener( ) | 634 | item.addActionListener(new ActionListener() { |
| 722 | { | ||
| 723 | @Override | 635 | @Override |
| 724 | public void actionPerformed( ActionEvent event ) | 636 | public void actionPerformed(ActionEvent event) { |
| 725 | { | 637 | AboutDialog.show(m_frame); |
| 726 | AboutDialog.show( m_frame ); | ||
| 727 | } | 638 | } |
| 728 | } ); | 639 | }); |
| 729 | } | 640 | } |
| 730 | } | 641 | } |
| 731 | 642 | ||
| 732 | // init state | 643 | // init state |
| 733 | onCloseJar(); | 644 | onCloseJar(); |
| 734 | 645 | ||
| 735 | m_frame.addWindowListener( new WindowAdapter( ) | 646 | m_frame.addWindowListener(new WindowAdapter() { |
| 736 | { | ||
| 737 | @Override | 647 | @Override |
| 738 | public void windowClosing( WindowEvent event ) | 648 | public void windowClosing(WindowEvent event) { |
| 739 | { | ||
| 740 | close(); | 649 | close(); |
| 741 | } | 650 | } |
| 742 | } ); | 651 | }); |
| 743 | 652 | ||
| 744 | // show the frame | 653 | // show the frame |
| 745 | pane.doLayout(); | 654 | pane.doLayout(); |
| 746 | m_frame.setSize( 1024, 576 ); | 655 | m_frame.setSize(1024, 576); |
| 747 | m_frame.setMinimumSize( new Dimension( 640, 480 ) ); | 656 | m_frame.setMinimumSize(new Dimension(640, 480)); |
| 748 | m_frame.setVisible( true ); | 657 | m_frame.setVisible(true); |
| 749 | m_frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); | 658 | m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); |
| 750 | } | 659 | } |
| 751 | 660 | ||
| 752 | public JFrame getFrame( ) | 661 | public JFrame getFrame() { |
| 753 | { | ||
| 754 | return m_frame; | 662 | return m_frame; |
| 755 | } | 663 | } |
| 756 | 664 | ||
| 757 | public GuiController getController( ) | 665 | public GuiController getController() { |
| 758 | { | ||
| 759 | return m_controller; | 666 | return m_controller; |
| 760 | } | 667 | } |
| 761 | 668 | ||
| 762 | public void onStartOpenJar( ) | 669 | public void onStartOpenJar() { |
| 763 | { | ||
| 764 | m_classesPanel.removeAll(); | 670 | m_classesPanel.removeAll(); |
| 765 | JPanel panel = new JPanel(); | 671 | JPanel panel = new JPanel(); |
| 766 | panel.setLayout( new FlowLayout() ); | 672 | panel.setLayout(new FlowLayout()); |
| 767 | panel.add( new JLabel( "Loading..." ) ); | 673 | panel.add(new JLabel("Loading...")); |
| 768 | m_classesPanel.add( panel ); | 674 | m_classesPanel.add(panel); |
| 769 | redraw(); | 675 | redraw(); |
| 770 | } | 676 | } |
| 771 | 677 | ||
| 772 | public void onFinishOpenJar( String jarName ) | 678 | public void onFinishOpenJar(String jarName) { |
| 773 | { | ||
| 774 | // update gui | 679 | // update gui |
| 775 | m_frame.setTitle( Constants.Name + " - " + jarName ); | 680 | m_frame.setTitle(Constants.Name + " - " + jarName); |
| 776 | m_classesPanel.removeAll(); | 681 | m_classesPanel.removeAll(); |
| 777 | m_classesPanel.add( m_splitClasses ); | 682 | m_classesPanel.add(m_splitClasses); |
| 778 | setSource( null ); | 683 | setSource(null); |
| 779 | 684 | ||
| 780 | // update menu | 685 | // update menu |
| 781 | m_closeJarMenu.setEnabled( true ); | 686 | m_closeJarMenu.setEnabled(true); |
| 782 | m_openMappingsMenu.setEnabled( true ); | 687 | m_openMappingsMenu.setEnabled(true); |
| 783 | m_saveMappingsMenu.setEnabled( false ); | 688 | m_saveMappingsMenu.setEnabled(false); |
| 784 | m_saveMappingsAsMenu.setEnabled( true ); | 689 | m_saveMappingsAsMenu.setEnabled(true); |
| 785 | m_closeMappingsMenu.setEnabled( true ); | 690 | m_closeMappingsMenu.setEnabled(true); |
| 786 | m_exportSourceMenu.setEnabled( true ); | 691 | m_exportSourceMenu.setEnabled(true); |
| 787 | m_exportJarMenu.setEnabled( true ); | 692 | m_exportJarMenu.setEnabled(true); |
| 788 | 693 | ||
| 789 | redraw(); | 694 | redraw(); |
| 790 | } | 695 | } |
| 791 | 696 | ||
| 792 | public void onCloseJar( ) | 697 | public void onCloseJar() { |
| 793 | { | ||
| 794 | // update gui | 698 | // update gui |
| 795 | m_frame.setTitle( Constants.Name ); | 699 | m_frame.setTitle(Constants.Name); |
| 796 | setObfClasses( null ); | 700 | setObfClasses(null); |
| 797 | setDeobfClasses( null ); | 701 | setDeobfClasses(null); |
| 798 | setSource( null ); | 702 | setSource(null); |
| 799 | m_classesPanel.removeAll(); | 703 | m_classesPanel.removeAll(); |
| 800 | 704 | ||
| 801 | // update menu | 705 | // update menu |
| 802 | m_closeJarMenu.setEnabled( false ); | 706 | m_closeJarMenu.setEnabled(false); |
| 803 | m_openMappingsMenu.setEnabled( false ); | 707 | m_openMappingsMenu.setEnabled(false); |
| 804 | m_saveMappingsMenu.setEnabled( false ); | 708 | m_saveMappingsMenu.setEnabled(false); |
| 805 | m_saveMappingsAsMenu.setEnabled( false ); | 709 | m_saveMappingsAsMenu.setEnabled(false); |
| 806 | m_closeMappingsMenu.setEnabled( false ); | 710 | m_closeMappingsMenu.setEnabled(false); |
| 807 | m_exportSourceMenu.setEnabled( false ); | 711 | m_exportSourceMenu.setEnabled(false); |
| 808 | m_exportJarMenu.setEnabled( false ); | 712 | m_exportJarMenu.setEnabled(false); |
| 809 | 713 | ||
| 810 | redraw(); | 714 | redraw(); |
| 811 | } | 715 | } |
| 812 | 716 | ||
| 813 | public void setObfClasses( Collection<ClassEntry> obfClasses ) | 717 | public void setObfClasses(Collection<ClassEntry> obfClasses) { |
| 814 | { | 718 | m_obfClasses.setClasses(obfClasses); |
| 815 | m_obfClasses.setClasses( obfClasses ); | ||
| 816 | } | 719 | } |
| 817 | 720 | ||
| 818 | public void setDeobfClasses( Collection<ClassEntry> deobfClasses ) | 721 | public void setDeobfClasses(Collection<ClassEntry> deobfClasses) { |
| 819 | { | 722 | m_deobfClasses.setClasses(deobfClasses); |
| 820 | m_deobfClasses.setClasses( deobfClasses ); | ||
| 821 | } | 723 | } |
| 822 | 724 | ||
| 823 | public void setMappingsFile( File file ) | 725 | public void setMappingsFile(File file) { |
| 824 | { | 726 | m_mappingsFileChooser.setSelectedFile(file); |
| 825 | m_mappingsFileChooser.setSelectedFile( file ); | 727 | m_saveMappingsMenu.setEnabled(file != null); |
| 826 | m_saveMappingsMenu.setEnabled( file != null ); | ||
| 827 | } | 728 | } |
| 828 | 729 | ||
| 829 | public void setSource( String source ) | 730 | public void setSource(String source) { |
| 830 | { | ||
| 831 | m_editor.getHighlighter().removeAllHighlights(); | 731 | m_editor.getHighlighter().removeAllHighlights(); |
| 832 | m_editor.setText( source ); | 732 | m_editor.setText(source); |
| 833 | } | 733 | } |
| 834 | 734 | ||
| 835 | public void showToken( final Token token ) | 735 | public void showToken(final Token token) { |
| 836 | { | 736 | if (token == null) { |
| 837 | if( token == null ) | 737 | throw new IllegalArgumentException("Token cannot be null!"); |
| 838 | { | ||
| 839 | throw new IllegalArgumentException( "Token cannot be null!" ); | ||
| 840 | } | 738 | } |
| 841 | 739 | ||
| 842 | // set the caret position to the token | 740 | // set the caret position to the token |
| 843 | m_editor.setCaretPosition( token.start ); | 741 | m_editor.setCaretPosition(token.start); |
| 844 | m_editor.grabFocus(); | 742 | m_editor.grabFocus(); |
| 845 | 743 | ||
| 846 | try | 744 | try { |
| 847 | { | ||
| 848 | // make sure the token is visible in the scroll window | 745 | // make sure the token is visible in the scroll window |
| 849 | Rectangle start = m_editor.modelToView( token.start ); | 746 | Rectangle start = m_editor.modelToView(token.start); |
| 850 | Rectangle end = m_editor.modelToView( token.end ); | 747 | Rectangle end = m_editor.modelToView(token.end); |
| 851 | final Rectangle show = start.union( end ); | 748 | final Rectangle show = start.union(end); |
| 852 | show.grow( start.width*10, start.height*6 ); | 749 | show.grow(start.width * 10, start.height * 6); |
| 853 | SwingUtilities.invokeLater( new Runnable( ) | 750 | SwingUtilities.invokeLater(new Runnable() { |
| 854 | { | ||
| 855 | @Override | 751 | @Override |
| 856 | public void run( ) | 752 | public void run() { |
| 857 | { | 753 | m_editor.scrollRectToVisible(show); |
| 858 | m_editor.scrollRectToVisible( show ); | ||
| 859 | } | 754 | } |
| 860 | } ); | 755 | }); |
| 861 | } | 756 | } catch (BadLocationException ex) { |
| 862 | catch( BadLocationException ex ) | 757 | throw new Error(ex); |
| 863 | { | ||
| 864 | throw new Error( ex ); | ||
| 865 | } | 758 | } |
| 866 | 759 | ||
| 867 | // highlight the token momentarily | 760 | // highlight the token momentarily |
| 868 | final Timer timer = new Timer( 200, new ActionListener( ) | 761 | final Timer timer = new Timer(200, new ActionListener() { |
| 869 | { | ||
| 870 | private int m_counter = 0; | 762 | private int m_counter = 0; |
| 871 | private Object m_highlight = null; | 763 | private Object m_highlight = null; |
| 872 | 764 | ||
| 873 | @Override | 765 | @Override |
| 874 | public void actionPerformed( ActionEvent event ) | 766 | public void actionPerformed(ActionEvent event) { |
| 875 | { | 767 | if (m_counter % 2 == 0) { |
| 876 | if( m_counter % 2 == 0 ) | 768 | try { |
| 877 | { | 769 | m_highlight = m_editor.getHighlighter().addHighlight(token.start, token.end, m_selectionHighlightPainter); |
| 878 | try | 770 | } catch (BadLocationException ex) { |
| 879 | { | ||
| 880 | m_highlight = m_editor.getHighlighter().addHighlight( token.start, token.end, m_selectionHighlightPainter ); | ||
| 881 | } | ||
| 882 | catch( BadLocationException ex ) | ||
| 883 | { | ||
| 884 | // don't care | 771 | // don't care |
| 885 | } | 772 | } |
| 886 | } | 773 | } else if (m_highlight != null) { |
| 887 | else if( m_highlight != null ) | 774 | m_editor.getHighlighter().removeHighlight(m_highlight); |
| 888 | { | ||
| 889 | m_editor.getHighlighter().removeHighlight( m_highlight ); | ||
| 890 | } | 775 | } |
| 891 | 776 | ||
| 892 | if( m_counter++ > 6 ) | 777 | if (m_counter++ > 6) { |
| 893 | { | ||
| 894 | Timer timer = (Timer)event.getSource(); | 778 | Timer timer = (Timer)event.getSource(); |
| 895 | timer.stop(); | 779 | timer.stop(); |
| 896 | } | 780 | } |
| 897 | } | 781 | } |
| 898 | } ); | 782 | }); |
| 899 | timer.start(); | 783 | timer.start(); |
| 900 | 784 | ||
| 901 | redraw(); | 785 | redraw(); |
| 902 | } | 786 | } |
| 903 | 787 | ||
| 904 | public void showTokens( Collection<Token> tokens ) | 788 | public void showTokens(Collection<Token> tokens) { |
| 905 | { | 789 | Vector<Token> sortedTokens = new Vector<Token>(tokens); |
| 906 | Vector<Token> sortedTokens = new Vector<Token>( tokens ); | 790 | Collections.sort(sortedTokens); |
| 907 | Collections.sort( sortedTokens ); | 791 | if (sortedTokens.size() > 1) { |
| 908 | if( sortedTokens.size() > 1 ) | ||
| 909 | { | ||
| 910 | // sort the tokens and update the tokens panel | 792 | // sort the tokens and update the tokens panel |
| 911 | m_tokens.setListData( sortedTokens ); | 793 | m_tokens.setListData(sortedTokens); |
| 912 | m_tokens.setSelectedIndex( 0 ); | 794 | m_tokens.setSelectedIndex(0); |
| 913 | } | 795 | } else { |
| 914 | else | 796 | m_tokens.setListData(new Vector<Token>()); |
| 915 | { | ||
| 916 | m_tokens.setListData( new Vector<Token>() ); | ||
| 917 | } | 797 | } |
| 918 | 798 | ||
| 919 | // show the first token | 799 | // show the first token |
| 920 | showToken( sortedTokens.get( 0 ) ); | 800 | showToken(sortedTokens.get(0)); |
| 921 | } | 801 | } |
| 922 | 802 | ||
| 923 | public void setHighlightedTokens( Iterable<Token> obfuscatedTokens, Iterable<Token> deobfuscatedTokens, Iterable<Token> otherTokens ) | 803 | public void setHighlightedTokens(Iterable<Token> obfuscatedTokens, Iterable<Token> deobfuscatedTokens, Iterable<Token> otherTokens) { |
| 924 | { | 804 | |
| 925 | // remove any old highlighters | 805 | // remove any old highlighters |
| 926 | m_editor.getHighlighter().removeAllHighlights(); | 806 | m_editor.getHighlighter().removeAllHighlights(); |
| 927 | 807 | ||
| 928 | // color things based on the index | 808 | // color things based on the index |
| 929 | if( obfuscatedTokens != null ) | 809 | if (obfuscatedTokens != null) { |
| 930 | { | 810 | setHighlightedTokens(obfuscatedTokens, m_obfuscatedHighlightPainter); |
| 931 | setHighlightedTokens( obfuscatedTokens, m_obfuscatedHighlightPainter ); | ||
| 932 | } | 811 | } |
| 933 | if( deobfuscatedTokens != null ) | 812 | if (deobfuscatedTokens != null) { |
| 934 | { | 813 | setHighlightedTokens(deobfuscatedTokens, m_deobfuscatedHighlightPainter); |
| 935 | setHighlightedTokens( deobfuscatedTokens, m_deobfuscatedHighlightPainter ); | ||
| 936 | } | 814 | } |
| 937 | if( otherTokens != null ) | 815 | if (otherTokens != null) { |
| 938 | { | 816 | setHighlightedTokens(otherTokens, m_otherHighlightPainter); |
| 939 | setHighlightedTokens( otherTokens, m_otherHighlightPainter ); | ||
| 940 | } | 817 | } |
| 941 | 818 | ||
| 942 | redraw(); | 819 | redraw(); |
| 943 | } | 820 | } |
| 944 | 821 | ||
| 945 | private void setHighlightedTokens( Iterable<Token> tokens, Highlighter.HighlightPainter painter ) | 822 | private void setHighlightedTokens(Iterable<Token> tokens, Highlighter.HighlightPainter painter) { |
| 946 | { | 823 | for (Token token : tokens) { |
| 947 | for( Token token : tokens ) | 824 | try { |
| 948 | { | 825 | m_editor.getHighlighter().addHighlight(token.start, token.end, painter); |
| 949 | try | 826 | } catch (BadLocationException ex) { |
| 950 | { | 827 | throw new IllegalArgumentException(ex); |
| 951 | m_editor.getHighlighter().addHighlight( token.start, token.end, painter ); | ||
| 952 | } | ||
| 953 | catch( BadLocationException ex ) | ||
| 954 | { | ||
| 955 | throw new IllegalArgumentException( ex ); | ||
| 956 | } | 828 | } |
| 957 | } | 829 | } |
| 958 | } | 830 | } |
| 959 | 831 | ||
| 960 | private void clearReference( ) | 832 | private void clearReference() { |
| 961 | { | ||
| 962 | m_infoPanel.removeAll(); | 833 | m_infoPanel.removeAll(); |
| 963 | JLabel label = new JLabel( "No identifier selected" ); | 834 | JLabel label = new JLabel("No identifier selected"); |
| 964 | GuiTricks.unboldLabel( label ); | 835 | GuiTricks.unboldLabel(label); |
| 965 | label.setHorizontalAlignment( JLabel.CENTER ); | 836 | label.setHorizontalAlignment(JLabel.CENTER); |
| 966 | m_infoPanel.add( label ); | 837 | m_infoPanel.add(label); |
| 967 | 838 | ||
| 968 | redraw(); | 839 | redraw(); |
| 969 | } | 840 | } |
| 970 | 841 | ||
| 971 | private void showReference( EntryReference<Entry,Entry> reference ) | 842 | private void showReference(EntryReference<Entry,Entry> reference) { |
| 972 | { | 843 | if (reference == null) { |
| 973 | if( reference == null ) | ||
| 974 | { | ||
| 975 | clearReference(); | 844 | clearReference(); |
| 976 | return; | 845 | return; |
| 977 | } | 846 | } |
| @@ -979,383 +848,300 @@ public class Gui | |||
| 979 | m_reference = reference; | 848 | m_reference = reference; |
| 980 | 849 | ||
| 981 | m_infoPanel.removeAll(); | 850 | m_infoPanel.removeAll(); |
| 982 | if( reference.entry instanceof ClassEntry ) | 851 | if (reference.entry instanceof ClassEntry) { |
| 983 | { | 852 | showClassEntry((ClassEntry)m_reference.entry); |
| 984 | showClassEntry( (ClassEntry)m_reference.entry ); | 853 | } else if (m_reference.entry instanceof FieldEntry) { |
| 985 | } | 854 | showFieldEntry((FieldEntry)m_reference.entry); |
| 986 | else if( m_reference.entry instanceof FieldEntry ) | 855 | } else if (m_reference.entry instanceof MethodEntry) { |
| 987 | { | 856 | showMethodEntry((MethodEntry)m_reference.entry); |
| 988 | showFieldEntry( (FieldEntry)m_reference.entry ); | 857 | } else if (m_reference.entry instanceof ConstructorEntry) { |
| 989 | } | 858 | showConstructorEntry((ConstructorEntry)m_reference.entry); |
| 990 | else if( m_reference.entry instanceof MethodEntry ) | 859 | } else if (m_reference.entry instanceof ArgumentEntry) { |
| 991 | { | 860 | showArgumentEntry((ArgumentEntry)m_reference.entry); |
| 992 | showMethodEntry( (MethodEntry)m_reference.entry ); | 861 | } else { |
| 993 | } | 862 | throw new Error("Unknown entry type: " + m_reference.entry.getClass().getName()); |
| 994 | else if( m_reference.entry instanceof ConstructorEntry ) | ||
| 995 | { | ||
| 996 | showConstructorEntry( (ConstructorEntry)m_reference.entry ); | ||
| 997 | } | ||
| 998 | else if( m_reference.entry instanceof ArgumentEntry ) | ||
| 999 | { | ||
| 1000 | showArgumentEntry( (ArgumentEntry)m_reference.entry ); | ||
| 1001 | } | ||
| 1002 | else | ||
| 1003 | { | ||
| 1004 | throw new Error( "Unknown entry type: " + m_reference.entry.getClass().getName() ); | ||
| 1005 | } | 863 | } |
| 1006 | 864 | ||
| 1007 | redraw(); | 865 | redraw(); |
| 1008 | } | 866 | } |
| 1009 | 867 | ||
| 1010 | private void showClassEntry( ClassEntry entry ) | 868 | private void showClassEntry(ClassEntry entry) { |
| 1011 | { | 869 | addNameValue(m_infoPanel, "Class", entry.getName()); |
| 1012 | addNameValue( m_infoPanel, "Class", entry.getName() ); | ||
| 1013 | } | 870 | } |
| 1014 | 871 | ||
| 1015 | private void showFieldEntry( FieldEntry entry ) | 872 | private void showFieldEntry(FieldEntry entry) { |
| 1016 | { | 873 | addNameValue(m_infoPanel, "Field", entry.getName()); |
| 1017 | addNameValue( m_infoPanel, "Field", entry.getName() ); | 874 | addNameValue(m_infoPanel, "Class", entry.getClassEntry().getName()); |
| 1018 | addNameValue( m_infoPanel, "Class", entry.getClassEntry().getName() ); | ||
| 1019 | } | 875 | } |
| 1020 | 876 | ||
| 1021 | private void showMethodEntry( MethodEntry entry ) | 877 | private void showMethodEntry(MethodEntry entry) { |
| 1022 | { | 878 | addNameValue(m_infoPanel, "Method", entry.getName()); |
| 1023 | addNameValue( m_infoPanel, "Method", entry.getName() ); | 879 | addNameValue(m_infoPanel, "Class", entry.getClassEntry().getName()); |
| 1024 | addNameValue( m_infoPanel, "Class", entry.getClassEntry().getName() ); | 880 | addNameValue(m_infoPanel, "Signature", entry.getSignature()); |
| 1025 | addNameValue( m_infoPanel, "Signature", entry.getSignature() ); | ||
| 1026 | } | 881 | } |
| 1027 | 882 | ||
| 1028 | private void showConstructorEntry( ConstructorEntry entry ) | 883 | private void showConstructorEntry(ConstructorEntry entry) { |
| 1029 | { | 884 | addNameValue(m_infoPanel, "Constructor", entry.getClassEntry().getName()); |
| 1030 | addNameValue( m_infoPanel, "Constructor", entry.getClassEntry().getName() ); | 885 | addNameValue(m_infoPanel, "Signature", entry.getSignature()); |
| 1031 | addNameValue( m_infoPanel, "Signature", entry.getSignature() ); | ||
| 1032 | } | 886 | } |
| 1033 | 887 | ||
| 1034 | private void showArgumentEntry( ArgumentEntry entry ) | 888 | private void showArgumentEntry(ArgumentEntry entry) { |
| 1035 | { | 889 | addNameValue(m_infoPanel, "Argument", entry.getName()); |
| 1036 | addNameValue( m_infoPanel, "Argument", entry.getName() ); | 890 | addNameValue(m_infoPanel, "Class", entry.getClassEntry().getName()); |
| 1037 | addNameValue( m_infoPanel, "Class", entry.getClassEntry().getName() ); | 891 | addNameValue(m_infoPanel, "Method", entry.getBehaviorEntry().getName()); |
| 1038 | addNameValue( m_infoPanel, "Method", entry.getBehaviorEntry().getName() ); | 892 | addNameValue(m_infoPanel, "Index", Integer.toString(entry.getIndex())); |
| 1039 | addNameValue( m_infoPanel, "Index", Integer.toString( entry.getIndex() ) ); | ||
| 1040 | } | 893 | } |
| 1041 | 894 | ||
| 1042 | private void addNameValue( JPanel container, String name, String value ) | 895 | private void addNameValue(JPanel container, String name, String value) { |
| 1043 | { | ||
| 1044 | JPanel panel = new JPanel(); | 896 | JPanel panel = new JPanel(); |
| 1045 | panel.setLayout( new FlowLayout( FlowLayout.LEFT, 6, 0 ) ); | 897 | panel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0)); |
| 1046 | container.add( panel ); | 898 | container.add(panel); |
| 1047 | 899 | ||
| 1048 | JLabel label = new JLabel( name + ":", JLabel.RIGHT ); | 900 | JLabel label = new JLabel(name + ":", JLabel.RIGHT); |
| 1049 | label.setPreferredSize( new Dimension( 100, label.getPreferredSize().height ) ); | 901 | label.setPreferredSize(new Dimension(100, label.getPreferredSize().height)); |
| 1050 | panel.add( label ); | 902 | panel.add(label); |
| 1051 | 903 | ||
| 1052 | panel.add( GuiTricks.unboldLabel( new JLabel( value, JLabel.LEFT ) ) ); | 904 | panel.add(GuiTricks.unboldLabel(new JLabel(value, JLabel.LEFT))); |
| 1053 | } | 905 | } |
| 1054 | 906 | ||
| 1055 | private void onCaretMove( int pos ) | 907 | private void onCaretMove(int pos) { |
| 1056 | { | 908 | |
| 1057 | Token token = m_controller.getToken( pos ); | 909 | Token token = m_controller.getToken(pos); |
| 1058 | boolean isToken = token != null; | 910 | boolean isToken = token != null; |
| 1059 | 911 | ||
| 1060 | m_reference = m_controller.getDeobfReference( token ); | 912 | m_reference = m_controller.getDeobfReference(token); |
| 1061 | boolean isClassEntry = isToken && m_reference.entry instanceof ClassEntry; | 913 | boolean isClassEntry = isToken && m_reference.entry instanceof ClassEntry; |
| 1062 | boolean isFieldEntry = isToken && m_reference.entry instanceof FieldEntry; | 914 | boolean isFieldEntry = isToken && m_reference.entry instanceof FieldEntry; |
| 1063 | boolean isMethodEntry = isToken && m_reference.entry instanceof MethodEntry; | 915 | boolean isMethodEntry = isToken && m_reference.entry instanceof MethodEntry; |
| 1064 | boolean isConstructorEntry = isToken && m_reference.entry instanceof ConstructorEntry; | 916 | boolean isConstructorEntry = isToken && m_reference.entry instanceof ConstructorEntry; |
| 1065 | boolean isInJar = isToken && m_controller.entryIsInJar( m_reference.entry ); | 917 | boolean isInJar = isToken && m_controller.entryIsInJar(m_reference.entry); |
| 1066 | boolean isRenameable = isToken && m_controller.referenceIsRenameable( m_reference ); | 918 | boolean isRenameable = isToken && m_controller.referenceIsRenameable(m_reference); |
| 1067 | 919 | ||
| 1068 | if( isToken ) | 920 | if (isToken) { |
| 1069 | { | 921 | showReference(m_reference); |
| 1070 | showReference( m_reference ); | 922 | } else { |
| 1071 | } | ||
| 1072 | else | ||
| 1073 | { | ||
| 1074 | clearReference(); | 923 | clearReference(); |
| 1075 | } | 924 | } |
| 1076 | 925 | ||
| 1077 | m_renameMenu.setEnabled( isRenameable && isToken ); | 926 | m_renameMenu.setEnabled(isRenameable && isToken); |
| 1078 | m_showInheritanceMenu.setEnabled( isClassEntry || isMethodEntry || isConstructorEntry ); | 927 | m_showInheritanceMenu.setEnabled(isClassEntry || isMethodEntry || isConstructorEntry); |
| 1079 | m_showImplementationsMenu.setEnabled( isClassEntry || isMethodEntry ); | 928 | m_showImplementationsMenu.setEnabled(isClassEntry || isMethodEntry); |
| 1080 | m_showCallsMenu.setEnabled( isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry ); | 929 | m_showCallsMenu.setEnabled(isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry); |
| 1081 | m_openEntryMenu.setEnabled( isInJar && ( isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry ) ); | 930 | m_openEntryMenu.setEnabled(isInJar && (isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry)); |
| 1082 | m_openPreviousMenu.setEnabled( m_controller.hasPreviousLocation() ); | 931 | m_openPreviousMenu.setEnabled(m_controller.hasPreviousLocation()); |
| 1083 | m_toggleMappingMenu.setEnabled( isRenameable && isToken ); | 932 | m_toggleMappingMenu.setEnabled(isRenameable && isToken); |
| 1084 | 933 | ||
| 1085 | if( isToken && m_controller.entryHasDeobfuscatedName( m_reference.entry ) ) | 934 | if (isToken && m_controller.entryHasDeobfuscatedName(m_reference.entry)) { |
| 1086 | { | 935 | m_toggleMappingMenu.setText("Reset to obfuscated"); |
| 1087 | m_toggleMappingMenu.setText( "Reset to obfuscated" ); | 936 | } else { |
| 1088 | } | 937 | m_toggleMappingMenu.setText("Mark as deobfuscated"); |
| 1089 | else | ||
| 1090 | { | ||
| 1091 | m_toggleMappingMenu.setText( "Mark as deobfuscated" ); | ||
| 1092 | } | 938 | } |
| 1093 | } | 939 | } |
| 1094 | 940 | ||
| 1095 | private void navigateTo( Entry entry ) | 941 | private void navigateTo(Entry entry) { |
| 1096 | { | 942 | if (!m_controller.entryIsInJar(entry)) { |
| 1097 | if( !m_controller.entryIsInJar( entry ) ) | ||
| 1098 | { | ||
| 1099 | // entry is not in the jar. Ignore it | 943 | // entry is not in the jar. Ignore it |
| 1100 | return; | 944 | return; |
| 1101 | } | 945 | } |
| 1102 | if( m_reference != null ) | 946 | if (m_reference != null) { |
| 1103 | { | 947 | m_controller.savePreviousReference(m_reference); |
| 1104 | m_controller.savePreviousReference( m_reference ); | ||
| 1105 | } | 948 | } |
| 1106 | m_controller.openDeclaration( entry ); | 949 | m_controller.openDeclaration(entry); |
| 1107 | } | 950 | } |
| 1108 | 951 | ||
| 1109 | private void navigateTo( EntryReference<Entry,Entry> reference ) | 952 | private void navigateTo(EntryReference<Entry,Entry> reference) { |
| 1110 | { | 953 | if (!m_controller.entryIsInJar(reference.getLocationClassEntry())) { |
| 1111 | if( !m_controller.entryIsInJar( reference.getLocationClassEntry() ) ) | ||
| 1112 | { | ||
| 1113 | // reference is not in the jar. Ignore it | 954 | // reference is not in the jar. Ignore it |
| 1114 | return; | 955 | return; |
| 1115 | } | 956 | } |
| 1116 | if( m_reference != null ) | 957 | if (m_reference != null) { |
| 1117 | { | 958 | m_controller.savePreviousReference(m_reference); |
| 1118 | m_controller.savePreviousReference( m_reference ); | ||
| 1119 | } | 959 | } |
| 1120 | m_controller.openReference( reference ); | 960 | m_controller.openReference(reference); |
| 1121 | } | 961 | } |
| 1122 | 962 | ||
| 1123 | private void startRename( ) | 963 | private void startRename() { |
| 1124 | { | 964 | |
| 1125 | // init the text box | 965 | // init the text box |
| 1126 | final JTextField text = new JTextField(); | 966 | final JTextField text = new JTextField(); |
| 1127 | text.setText( m_reference.getNamableName() ); | 967 | text.setText(m_reference.getNamableName()); |
| 1128 | text.setPreferredSize( new Dimension( 360, text.getPreferredSize().height ) ); | 968 | text.setPreferredSize(new Dimension(360, text.getPreferredSize().height)); |
| 1129 | text.addKeyListener( new KeyAdapter( ) | 969 | text.addKeyListener(new KeyAdapter() { |
| 1130 | { | ||
| 1131 | @Override | 970 | @Override |
| 1132 | public void keyPressed( KeyEvent event ) | 971 | public void keyPressed(KeyEvent event) { |
| 1133 | { | 972 | switch (event.getKeyCode()) { |
| 1134 | switch( event.getKeyCode() ) | ||
| 1135 | { | ||
| 1136 | case KeyEvent.VK_ENTER: | 973 | case KeyEvent.VK_ENTER: |
| 1137 | finishRename( text, true ); | 974 | finishRename(text, true); |
| 1138 | break; | 975 | break; |
| 1139 | 976 | ||
| 1140 | case KeyEvent.VK_ESCAPE: | 977 | case KeyEvent.VK_ESCAPE: |
| 1141 | finishRename( text, false ); | 978 | finishRename(text, false); |
| 1142 | break; | 979 | break; |
| 1143 | } | 980 | } |
| 1144 | } | 981 | } |
| 1145 | } ); | 982 | }); |
| 1146 | 983 | ||
| 1147 | // find the label with the name and replace it with the text box | 984 | // find the label with the name and replace it with the text box |
| 1148 | JPanel panel = (JPanel)m_infoPanel.getComponent( 0 ); | 985 | JPanel panel = (JPanel)m_infoPanel.getComponent(0); |
| 1149 | panel.remove( panel.getComponentCount() - 1 ); | 986 | panel.remove(panel.getComponentCount() - 1); |
| 1150 | panel.add( text ); | 987 | panel.add(text); |
| 1151 | text.grabFocus(); | 988 | text.grabFocus(); |
| 1152 | text.selectAll(); | 989 | text.selectAll(); |
| 1153 | 990 | ||
| 1154 | redraw(); | 991 | redraw(); |
| 1155 | } | 992 | } |
| 1156 | 993 | ||
| 1157 | private void finishRename( JTextField text, boolean saveName ) | 994 | private void finishRename(JTextField text, boolean saveName) { |
| 1158 | { | ||
| 1159 | String newName = text.getText(); | 995 | String newName = text.getText(); |
| 1160 | if( saveName && newName != null && newName.length() > 0 ) | 996 | if (saveName && newName != null && newName.length() > 0) { |
| 1161 | { | 997 | try { |
| 1162 | try | 998 | m_controller.rename(m_reference, newName); |
| 1163 | { | 999 | } catch (IllegalNameException ex) { |
| 1164 | m_controller.rename( m_reference, newName ); | 1000 | text.setBorder(BorderFactory.createLineBorder(Color.red, 1)); |
| 1165 | } | 1001 | text.setToolTipText(ex.getReason()); |
| 1166 | catch( IllegalNameException ex ) | 1002 | GuiTricks.showToolTipNow(text); |
| 1167 | { | ||
| 1168 | text.setBorder( BorderFactory.createLineBorder( Color.red, 1 ) ); | ||
| 1169 | text.setToolTipText( ex.getReason() ); | ||
| 1170 | GuiTricks.showToolTipNow( text ); | ||
| 1171 | } | 1003 | } |
| 1172 | return; | 1004 | return; |
| 1173 | } | 1005 | } |
| 1174 | 1006 | ||
| 1175 | // abort the rename | 1007 | // abort the rename |
| 1176 | JPanel panel = (JPanel)m_infoPanel.getComponent( 0 ); | 1008 | JPanel panel = (JPanel)m_infoPanel.getComponent(0); |
| 1177 | panel.remove( panel.getComponentCount() - 1 ); | 1009 | panel.remove(panel.getComponentCount() - 1); |
| 1178 | panel.add( GuiTricks.unboldLabel( new JLabel( m_reference.getNamableName(), JLabel.LEFT ) ) ); | 1010 | panel.add(GuiTricks.unboldLabel(new JLabel(m_reference.getNamableName(), JLabel.LEFT))); |
| 1179 | 1011 | ||
| 1180 | m_editor.grabFocus(); | 1012 | m_editor.grabFocus(); |
| 1181 | 1013 | ||
| 1182 | redraw(); | 1014 | redraw(); |
| 1183 | } | 1015 | } |
| 1184 | 1016 | ||
| 1185 | private void showInheritance( ) | 1017 | private void showInheritance() { |
| 1186 | { | 1018 | |
| 1187 | if( m_reference == null ) | 1019 | if (m_reference == null) { |
| 1188 | { | ||
| 1189 | return; | 1020 | return; |
| 1190 | } | 1021 | } |
| 1191 | 1022 | ||
| 1192 | m_inheritanceTree.setModel( null ); | 1023 | m_inheritanceTree.setModel(null); |
| 1193 | 1024 | ||
| 1194 | if( m_reference.entry instanceof ClassEntry ) | 1025 | if (m_reference.entry instanceof ClassEntry) { |
| 1195 | { | ||
| 1196 | // get the class inheritance | 1026 | // get the class inheritance |
| 1197 | ClassInheritanceTreeNode classNode = m_controller.getClassInheritance( (ClassEntry)m_reference.entry ); | 1027 | ClassInheritanceTreeNode classNode = m_controller.getClassInheritance((ClassEntry)m_reference.entry); |
| 1198 | 1028 | ||
| 1199 | // show the tree at the root | 1029 | // show the tree at the root |
| 1200 | TreePath path = getPathToRoot( classNode ); | 1030 | TreePath path = getPathToRoot(classNode); |
| 1201 | m_inheritanceTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) ); | 1031 | m_inheritanceTree.setModel(new DefaultTreeModel((TreeNode)path.getPathComponent(0))); |
| 1202 | m_inheritanceTree.expandPath( path ); | 1032 | m_inheritanceTree.expandPath(path); |
| 1203 | m_inheritanceTree.setSelectionRow( m_inheritanceTree.getRowForPath( path ) ); | 1033 | m_inheritanceTree.setSelectionRow(m_inheritanceTree.getRowForPath(path)); |
| 1204 | } | 1034 | } else if (m_reference.entry instanceof MethodEntry) { |
| 1205 | else if( m_reference.entry instanceof MethodEntry ) | ||
| 1206 | { | ||
| 1207 | // get the method inheritance | 1035 | // get the method inheritance |
| 1208 | MethodInheritanceTreeNode classNode = m_controller.getMethodInheritance( (MethodEntry)m_reference.entry ); | 1036 | MethodInheritanceTreeNode classNode = m_controller.getMethodInheritance((MethodEntry)m_reference.entry); |
| 1209 | 1037 | ||
| 1210 | // show the tree at the root | 1038 | // show the tree at the root |
| 1211 | TreePath path = getPathToRoot( classNode ); | 1039 | TreePath path = getPathToRoot(classNode); |
| 1212 | m_inheritanceTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) ); | 1040 | m_inheritanceTree.setModel(new DefaultTreeModel((TreeNode)path.getPathComponent(0))); |
| 1213 | m_inheritanceTree.expandPath( path ); | 1041 | m_inheritanceTree.expandPath(path); |
| 1214 | m_inheritanceTree.setSelectionRow( m_inheritanceTree.getRowForPath( path ) ); | 1042 | m_inheritanceTree.setSelectionRow(m_inheritanceTree.getRowForPath(path)); |
| 1215 | } | 1043 | } |
| 1216 | 1044 | ||
| 1217 | m_tabs.setSelectedIndex( 0 ); | 1045 | m_tabs.setSelectedIndex(0); |
| 1218 | redraw(); | 1046 | redraw(); |
| 1219 | } | 1047 | } |
| 1220 | 1048 | ||
| 1221 | private void showImplementations( ) | 1049 | private void showImplementations() { |
| 1222 | { | 1050 | |
| 1223 | if( m_reference == null ) | 1051 | if (m_reference == null) { |
| 1224 | { | ||
| 1225 | return; | 1052 | return; |
| 1226 | } | 1053 | } |
| 1227 | 1054 | ||
| 1228 | m_implementationsTree.setModel( null ); | 1055 | m_implementationsTree.setModel(null); |
| 1229 | 1056 | ||
| 1230 | if( m_reference.entry instanceof ClassEntry ) | 1057 | if (m_reference.entry instanceof ClassEntry) { |
| 1231 | { | ||
| 1232 | // get the class implementations | 1058 | // get the class implementations |
| 1233 | ClassImplementationsTreeNode node = m_controller.getClassImplementations( (ClassEntry)m_reference.entry ); | 1059 | ClassImplementationsTreeNode node = m_controller.getClassImplementations((ClassEntry)m_reference.entry); |
| 1234 | if( node != null ) | 1060 | if (node != null) { |
| 1235 | { | ||
| 1236 | // show the tree at the root | 1061 | // show the tree at the root |
| 1237 | TreePath path = getPathToRoot( node ); | 1062 | TreePath path = getPathToRoot(node); |
| 1238 | m_implementationsTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) ); | 1063 | m_implementationsTree.setModel(new DefaultTreeModel((TreeNode)path.getPathComponent(0))); |
| 1239 | m_implementationsTree.expandPath( path ); | 1064 | m_implementationsTree.expandPath(path); |
| 1240 | m_implementationsTree.setSelectionRow( m_implementationsTree.getRowForPath( path ) ); | 1065 | m_implementationsTree.setSelectionRow(m_implementationsTree.getRowForPath(path)); |
| 1241 | } | 1066 | } |
| 1242 | } | 1067 | } else if (m_reference.entry instanceof MethodEntry) { |
| 1243 | else if( m_reference.entry instanceof MethodEntry ) | ||
| 1244 | { | ||
| 1245 | // get the method implementations | 1068 | // get the method implementations |
| 1246 | MethodImplementationsTreeNode node = m_controller.getMethodImplementations( (MethodEntry)m_reference.entry ); | 1069 | MethodImplementationsTreeNode node = m_controller.getMethodImplementations((MethodEntry)m_reference.entry); |
| 1247 | if( node != null ) | 1070 | if (node != null) { |
| 1248 | { | ||
| 1249 | // show the tree at the root | 1071 | // show the tree at the root |
| 1250 | TreePath path = getPathToRoot( node ); | 1072 | TreePath path = getPathToRoot(node); |
| 1251 | m_implementationsTree.setModel( new DefaultTreeModel( (TreeNode)path.getPathComponent( 0 ) ) ); | 1073 | m_implementationsTree.setModel(new DefaultTreeModel((TreeNode)path.getPathComponent(0))); |
| 1252 | m_implementationsTree.expandPath( path ); | 1074 | m_implementationsTree.expandPath(path); |
| 1253 | m_implementationsTree.setSelectionRow( m_implementationsTree.getRowForPath( path ) ); | 1075 | m_implementationsTree.setSelectionRow(m_implementationsTree.getRowForPath(path)); |
| 1254 | } | 1076 | } |
| 1255 | } | 1077 | } |
| 1256 | 1078 | ||
| 1257 | m_tabs.setSelectedIndex( 1 ); | 1079 | m_tabs.setSelectedIndex(1); |
| 1258 | redraw(); | 1080 | redraw(); |
| 1259 | } | 1081 | } |
| 1260 | 1082 | ||
| 1261 | private void showCalls( ) | 1083 | private void showCalls() { |
| 1262 | { | 1084 | |
| 1263 | if( m_reference == null ) | 1085 | if (m_reference == null) { |
| 1264 | { | ||
| 1265 | return; | 1086 | return; |
| 1266 | } | 1087 | } |
| 1267 | 1088 | ||
| 1268 | if( m_reference.entry instanceof ClassEntry ) | 1089 | if (m_reference.entry instanceof ClassEntry) { |
| 1269 | { | ||
| 1270 | // look for calls to the default constructor | 1090 | // look for calls to the default constructor |
| 1271 | // TODO: get a list of all the constructors and find calls to all of them | 1091 | // TODO: get a list of all the constructors and find calls to all of them |
| 1272 | BehaviorReferenceTreeNode node = m_controller.getMethodReferences( new ConstructorEntry( (ClassEntry)m_reference.entry, "()V" ) ); | 1092 | BehaviorReferenceTreeNode node = m_controller.getMethodReferences(new ConstructorEntry((ClassEntry)m_reference.entry, "()V")); |
| 1273 | m_callsTree.setModel( new DefaultTreeModel( node ) ); | 1093 | m_callsTree.setModel(new DefaultTreeModel(node)); |
| 1274 | } | 1094 | } else if (m_reference.entry instanceof FieldEntry) { |
| 1275 | else if( m_reference.entry instanceof FieldEntry ) | 1095 | FieldReferenceTreeNode node = m_controller.getFieldReferences((FieldEntry)m_reference.entry); |
| 1276 | { | 1096 | m_callsTree.setModel(new DefaultTreeModel(node)); |
| 1277 | FieldReferenceTreeNode node = m_controller.getFieldReferences( (FieldEntry)m_reference.entry ); | 1097 | } else if (m_reference.entry instanceof MethodEntry) { |
| 1278 | m_callsTree.setModel( new DefaultTreeModel( node ) ); | 1098 | BehaviorReferenceTreeNode node = m_controller.getMethodReferences((MethodEntry)m_reference.entry); |
| 1279 | } | 1099 | m_callsTree.setModel(new DefaultTreeModel(node)); |
| 1280 | else if( m_reference.entry instanceof MethodEntry ) | 1100 | } else if (m_reference.entry instanceof ConstructorEntry) { |
| 1281 | { | 1101 | BehaviorReferenceTreeNode node = m_controller.getMethodReferences((ConstructorEntry)m_reference.entry); |
| 1282 | BehaviorReferenceTreeNode node = m_controller.getMethodReferences( (MethodEntry)m_reference.entry ); | 1102 | m_callsTree.setModel(new DefaultTreeModel(node)); |
| 1283 | m_callsTree.setModel( new DefaultTreeModel( node ) ); | ||
| 1284 | } | ||
| 1285 | else if( m_reference.entry instanceof ConstructorEntry ) | ||
| 1286 | { | ||
| 1287 | BehaviorReferenceTreeNode node = m_controller.getMethodReferences( (ConstructorEntry)m_reference.entry ); | ||
| 1288 | m_callsTree.setModel( new DefaultTreeModel( node ) ); | ||
| 1289 | } | 1103 | } |
| 1290 | 1104 | ||
| 1291 | m_tabs.setSelectedIndex( 2 ); | 1105 | m_tabs.setSelectedIndex(2); |
| 1292 | redraw(); | 1106 | redraw(); |
| 1293 | } | 1107 | } |
| 1294 | 1108 | ||
| 1295 | private void toggleMapping() | 1109 | private void toggleMapping() { |
| 1296 | { | 1110 | if (m_controller.entryHasDeobfuscatedName(m_reference.entry)) { |
| 1297 | if( m_controller.entryHasDeobfuscatedName( m_reference.entry ) ) | 1111 | m_controller.removeMapping(m_reference); |
| 1298 | { | 1112 | } else { |
| 1299 | m_controller.removeMapping( m_reference ); | 1113 | m_controller.markAsDeobfuscated(m_reference); |
| 1300 | } | ||
| 1301 | else | ||
| 1302 | { | ||
| 1303 | m_controller.markAsDeobfuscated( m_reference ); | ||
| 1304 | } | 1114 | } |
| 1305 | } | 1115 | } |
| 1306 | 1116 | ||
| 1307 | private TreePath getPathToRoot( TreeNode node ) | 1117 | private TreePath getPathToRoot(TreeNode node) { |
| 1308 | { | ||
| 1309 | List<TreeNode> nodes = Lists.newArrayList(); | 1118 | List<TreeNode> nodes = Lists.newArrayList(); |
| 1310 | TreeNode n = node; | 1119 | TreeNode n = node; |
| 1311 | do | 1120 | do { |
| 1312 | { | 1121 | nodes.add(n); |
| 1313 | nodes.add( n ); | ||
| 1314 | n = n.getParent(); | 1122 | n = n.getParent(); |
| 1315 | } | 1123 | } while (n != null); |
| 1316 | while( n != null ); | 1124 | Collections.reverse(nodes); |
| 1317 | Collections.reverse( nodes ); | 1125 | return new TreePath(nodes.toArray()); |
| 1318 | return new TreePath( nodes.toArray() ); | ||
| 1319 | } | 1126 | } |
| 1320 | 1127 | ||
| 1321 | private void close( ) | 1128 | private void close() { |
| 1322 | { | 1129 | if (!m_controller.isDirty()) { |
| 1323 | if( !m_controller.isDirty() ) | ||
| 1324 | { | ||
| 1325 | // everything is saved, we can exit safely | 1130 | // everything is saved, we can exit safely |
| 1326 | m_frame.dispose(); | 1131 | m_frame.dispose(); |
| 1327 | } | 1132 | } else { |
| 1328 | else | ||
| 1329 | { | ||
| 1330 | // ask to save before closing | 1133 | // ask to save before closing |
| 1331 | String[] options = { | 1134 | String[] options = { "Save and exit", "Discard changes", "Cancel" }; |
| 1332 | "Save and exit", | 1135 | 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, |
| 1333 | "Discard changes", | 1136 | JOptionPane.QUESTION_MESSAGE, null, options, options[2]); |
| 1334 | "Cancel" | 1137 | switch (response) { |
| 1335 | }; | ||
| 1336 | int response = JOptionPane.showOptionDialog( | ||
| 1337 | m_frame, | ||
| 1338 | "Your mappings have not been saved yet. Do you want to save?", | ||
| 1339 | "Save your changes?", | ||
| 1340 | JOptionPane.YES_NO_CANCEL_OPTION, | ||
| 1341 | JOptionPane.QUESTION_MESSAGE, | ||
| 1342 | null, | ||
| 1343 | options, | ||
| 1344 | options[2] | ||
| 1345 | ); | ||
| 1346 | switch( response ) | ||
| 1347 | { | ||
| 1348 | case JOptionPane.YES_OPTION: // save and exit | 1138 | case JOptionPane.YES_OPTION: // save and exit |
| 1349 | if( m_mappingsFileChooser.getSelectedFile() != null || m_mappingsFileChooser.showSaveDialog( m_frame ) == JFileChooser.APPROVE_OPTION ) | 1139 | if (m_mappingsFileChooser.getSelectedFile() != null || m_mappingsFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { |
| 1350 | { | 1140 | try { |
| 1351 | try | 1141 | m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); |
| 1352 | { | ||
| 1353 | m_controller.saveMappings( m_mappingsFileChooser.getSelectedFile() ); | ||
| 1354 | m_frame.dispose(); | 1142 | m_frame.dispose(); |
| 1355 | } | 1143 | } catch (IOException ex) { |
| 1356 | catch( IOException ex ) | 1144 | throw new Error(ex); |
| 1357 | { | ||
| 1358 | throw new Error( ex ); | ||
| 1359 | } | 1145 | } |
| 1360 | } | 1146 | } |
| 1361 | break; | 1147 | break; |
| @@ -1364,14 +1150,13 @@ public class Gui | |||
| 1364 | // don't save, exit | 1150 | // don't save, exit |
| 1365 | m_frame.dispose(); | 1151 | m_frame.dispose(); |
| 1366 | break; | 1152 | break; |
| 1367 | 1153 | ||
| 1368 | // cancel means do nothing | 1154 | // cancel means do nothing |
| 1369 | } | 1155 | } |
| 1370 | } | 1156 | } |
| 1371 | } | 1157 | } |
| 1372 | 1158 | ||
| 1373 | private void redraw( ) | 1159 | private void redraw() { |
| 1374 | { | ||
| 1375 | m_frame.validate(); | 1160 | m_frame.validate(); |
| 1376 | m_frame.repaint(); | 1161 | m_frame.repaint(); |
| 1377 | } | 1162 | } |
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; | |||
| 44 | import cuchaz.enigma.mapping.MethodEntry; | 44 | import cuchaz.enigma.mapping.MethodEntry; |
| 45 | import cuchaz.enigma.mapping.TranslationDirection; | 45 | import cuchaz.enigma.mapping.TranslationDirection; |
| 46 | 46 | ||
| 47 | public class GuiController | 47 | public class GuiController { |
| 48 | { | 48 | |
| 49 | private Deobfuscator m_deobfuscator; | 49 | private Deobfuscator m_deobfuscator; |
| 50 | private Gui m_gui; | 50 | private Gui m_gui; |
| 51 | private SourceIndex m_index; | 51 | private SourceIndex m_index; |
| @@ -53,8 +53,7 @@ public class GuiController | |||
| 53 | private boolean m_isDirty; | 53 | private boolean m_isDirty; |
| 54 | private Deque<EntryReference<Entry,Entry>> m_referenceStack; | 54 | private Deque<EntryReference<Entry,Entry>> m_referenceStack; |
| 55 | 55 | ||
| 56 | public GuiController( Gui gui ) | 56 | public GuiController(Gui gui) { |
| 57 | { | ||
| 58 | m_gui = gui; | 57 | m_gui = gui; |
| 59 | m_deobfuscator = null; | 58 | m_deobfuscator = null; |
| 60 | m_index = null; | 59 | m_index = null; |
| @@ -63,358 +62,292 @@ public class GuiController | |||
| 63 | m_referenceStack = Queues.newArrayDeque(); | 62 | m_referenceStack = Queues.newArrayDeque(); |
| 64 | } | 63 | } |
| 65 | 64 | ||
| 66 | public boolean isDirty( ) | 65 | public boolean isDirty() { |
| 67 | { | ||
| 68 | return m_isDirty; | 66 | return m_isDirty; |
| 69 | } | 67 | } |
| 70 | 68 | ||
| 71 | public void openJar( final File file ) | 69 | public void openJar(final File file) throws IOException { |
| 72 | throws IOException | ||
| 73 | { | ||
| 74 | m_gui.onStartOpenJar(); | 70 | m_gui.onStartOpenJar(); |
| 75 | m_deobfuscator = new Deobfuscator( file ); | 71 | m_deobfuscator = new Deobfuscator(file); |
| 76 | m_gui.onFinishOpenJar( m_deobfuscator.getJarName() ); | 72 | m_gui.onFinishOpenJar(m_deobfuscator.getJarName()); |
| 77 | refreshClasses(); | 73 | refreshClasses(); |
| 78 | } | 74 | } |
| 79 | 75 | ||
| 80 | public void closeJar( ) | 76 | public void closeJar() { |
| 81 | { | ||
| 82 | m_deobfuscator = null; | 77 | m_deobfuscator = null; |
| 83 | m_gui.onCloseJar(); | 78 | m_gui.onCloseJar(); |
| 84 | } | 79 | } |
| 85 | 80 | ||
| 86 | public void openMappings( File file ) | 81 | public void openMappings(File file) throws IOException, MappingParseException { |
| 87 | throws IOException, MappingParseException | 82 | FileReader in = new FileReader(file); |
| 88 | { | 83 | m_deobfuscator.setMappings(new MappingsReader().read(in)); |
| 89 | FileReader in = new FileReader( file ); | ||
| 90 | m_deobfuscator.setMappings( new MappingsReader().read( in ) ); | ||
| 91 | in.close(); | 84 | in.close(); |
| 92 | m_isDirty = false; | 85 | m_isDirty = false; |
| 93 | m_gui.setMappingsFile( file ); | 86 | m_gui.setMappingsFile(file); |
| 94 | refreshClasses(); | 87 | refreshClasses(); |
| 95 | refreshCurrentClass(); | 88 | refreshCurrentClass(); |
| 96 | } | 89 | } |
| 97 | 90 | ||
| 98 | public void saveMappings( File file ) | 91 | public void saveMappings(File file) throws IOException { |
| 99 | throws IOException | 92 | FileWriter out = new FileWriter(file); |
| 100 | { | 93 | new MappingsWriter().write(out, m_deobfuscator.getMappings()); |
| 101 | FileWriter out = new FileWriter( file ); | ||
| 102 | new MappingsWriter().write( out, m_deobfuscator.getMappings() ); | ||
| 103 | out.close(); | 94 | out.close(); |
| 104 | m_isDirty = false; | 95 | m_isDirty = false; |
| 105 | } | 96 | } |
| 106 | 97 | ||
| 107 | public void closeMappings( ) | 98 | public void closeMappings() { |
| 108 | { | 99 | m_deobfuscator.setMappings(null); |
| 109 | m_deobfuscator.setMappings( null ); | 100 | m_gui.setMappingsFile(null); |
| 110 | m_gui.setMappingsFile( null ); | ||
| 111 | refreshClasses(); | 101 | refreshClasses(); |
| 112 | refreshCurrentClass(); | 102 | refreshCurrentClass(); |
| 113 | } | 103 | } |
| 114 | 104 | ||
| 115 | public void exportSource( final File dirOut ) | 105 | public void exportSource(final File dirOut) { |
| 116 | { | 106 | ProgressDialog.runInThread(m_gui.getFrame(), new ProgressRunnable() { |
| 117 | ProgressDialog.runInThread( m_gui.getFrame(), new ProgressRunnable( ) | ||
| 118 | { | ||
| 119 | @Override | 107 | @Override |
| 120 | public void run( ProgressListener progress ) | 108 | public void run(ProgressListener progress) throws Exception { |
| 121 | throws Exception | 109 | m_deobfuscator.writeSources(dirOut, progress); |
| 122 | { | ||
| 123 | m_deobfuscator.writeSources( dirOut, progress ); | ||
| 124 | } | 110 | } |
| 125 | } ); | 111 | }); |
| 126 | } | 112 | } |
| 127 | 113 | ||
| 128 | public void exportJar( final File fileOut ) | 114 | public void exportJar(final File fileOut) { |
| 129 | { | 115 | ProgressDialog.runInThread(m_gui.getFrame(), new ProgressRunnable() { |
| 130 | ProgressDialog.runInThread( m_gui.getFrame(), new ProgressRunnable( ) | ||
| 131 | { | ||
| 132 | @Override | 116 | @Override |
| 133 | public void run( ProgressListener progress ) | 117 | public void run(ProgressListener progress) { |
| 134 | { | 118 | m_deobfuscator.writeJar(fileOut, progress); |
| 135 | m_deobfuscator.writeJar( fileOut, progress ); | ||
| 136 | } | 119 | } |
| 137 | } ); | 120 | }); |
| 138 | } | 121 | } |
| 139 | 122 | ||
| 140 | public Token getToken( int pos ) | 123 | public Token getToken(int pos) { |
| 141 | { | 124 | if (m_index == null) { |
| 142 | if( m_index == null ) | ||
| 143 | { | ||
| 144 | return null; | 125 | return null; |
| 145 | } | 126 | } |
| 146 | return m_index.getReferenceToken( pos ); | 127 | return m_index.getReferenceToken(pos); |
| 147 | } | 128 | } |
| 148 | 129 | ||
| 149 | public EntryReference<Entry,Entry> getDeobfReference( Token token ) | 130 | public EntryReference<Entry,Entry> getDeobfReference(Token token) { |
| 150 | { | 131 | if (m_index == null) { |
| 151 | if( m_index == null ) | ||
| 152 | { | ||
| 153 | return null; | 132 | return null; |
| 154 | } | 133 | } |
| 155 | return m_index.getDeobfReference( token ); | 134 | return m_index.getDeobfReference(token); |
| 156 | } | 135 | } |
| 157 | 136 | ||
| 158 | public ReadableToken getReadableToken( Token token ) | 137 | public ReadableToken getReadableToken(Token token) { |
| 159 | { | 138 | if (m_index == null) { |
| 160 | if( m_index == null ) | ||
| 161 | { | ||
| 162 | return null; | 139 | return null; |
| 163 | } | 140 | } |
| 164 | return new ReadableToken( | 141 | return new ReadableToken( |
| 165 | m_index.getLineNumber( token.start ), | 142 | m_index.getLineNumber(token.start), |
| 166 | m_index.getColumnNumber( token.start ), | 143 | m_index.getColumnNumber(token.start), |
| 167 | m_index.getColumnNumber( token.end ) | 144 | m_index.getColumnNumber(token.end) |
| 168 | ); | 145 | ); |
| 169 | } | 146 | } |
| 170 | 147 | ||
| 171 | public boolean entryHasDeobfuscatedName( Entry deobfEntry ) | 148 | public boolean entryHasDeobfuscatedName(Entry deobfEntry) { |
| 172 | { | 149 | return m_deobfuscator.hasDeobfuscatedName(m_deobfuscator.obfuscateEntry(deobfEntry)); |
| 173 | return m_deobfuscator.hasDeobfuscatedName( m_deobfuscator.obfuscateEntry( deobfEntry ) ); | ||
| 174 | } | 150 | } |
| 175 | 151 | ||
| 176 | public boolean entryIsInJar( Entry deobfEntry ) | 152 | public boolean entryIsInJar(Entry deobfEntry) { |
| 177 | { | 153 | return m_deobfuscator.isObfuscatedIdentifier(m_deobfuscator.obfuscateEntry(deobfEntry)); |
| 178 | return m_deobfuscator.isObfuscatedIdentifier( m_deobfuscator.obfuscateEntry( deobfEntry ) ); | ||
| 179 | } | 154 | } |
| 180 | 155 | ||
| 181 | public boolean referenceIsRenameable( EntryReference<Entry,Entry> deobfReference ) | 156 | public boolean referenceIsRenameable(EntryReference<Entry,Entry> deobfReference) { |
| 182 | { | 157 | return m_deobfuscator.isRenameable(m_deobfuscator.obfuscateReference(deobfReference)); |
| 183 | return m_deobfuscator.isRenameable( m_deobfuscator.obfuscateReference( deobfReference ) ); | ||
| 184 | } | 158 | } |
| 185 | 159 | ||
| 186 | public ClassInheritanceTreeNode getClassInheritance( ClassEntry deobfClassEntry ) | 160 | public ClassInheritanceTreeNode getClassInheritance(ClassEntry deobfClassEntry) { |
| 187 | { | 161 | ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry(deobfClassEntry); |
| 188 | ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry( deobfClassEntry ); | ||
| 189 | ClassInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getClassInheritance( | 162 | ClassInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getClassInheritance( |
| 190 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), | 163 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), |
| 191 | obfClassEntry | 164 | obfClassEntry |
| 192 | ); | 165 | ); |
| 193 | return ClassInheritanceTreeNode.findNode( rootNode, obfClassEntry ); | 166 | return ClassInheritanceTreeNode.findNode(rootNode, obfClassEntry); |
| 194 | } | 167 | } |
| 195 | 168 | ||
| 196 | public ClassImplementationsTreeNode getClassImplementations( ClassEntry deobfClassEntry ) | 169 | public ClassImplementationsTreeNode getClassImplementations(ClassEntry deobfClassEntry) { |
| 197 | { | 170 | ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry(deobfClassEntry); |
| 198 | ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry( deobfClassEntry ); | ||
| 199 | return m_deobfuscator.getJarIndex().getClassImplementations( | 171 | return m_deobfuscator.getJarIndex().getClassImplementations( |
| 200 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), | 172 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), |
| 201 | obfClassEntry | 173 | obfClassEntry |
| 202 | ); | 174 | ); |
| 203 | } | 175 | } |
| 204 | 176 | ||
| 205 | public MethodInheritanceTreeNode getMethodInheritance( MethodEntry deobfMethodEntry ) | 177 | public MethodInheritanceTreeNode getMethodInheritance(MethodEntry deobfMethodEntry) { |
| 206 | { | 178 | MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry(deobfMethodEntry); |
| 207 | MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry( deobfMethodEntry ); | ||
| 208 | MethodInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getMethodInheritance( | 179 | MethodInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getMethodInheritance( |
| 209 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), | 180 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), |
| 210 | obfMethodEntry | 181 | obfMethodEntry |
| 211 | ); | 182 | ); |
| 212 | return MethodInheritanceTreeNode.findNode( rootNode, obfMethodEntry ); | 183 | return MethodInheritanceTreeNode.findNode(rootNode, obfMethodEntry); |
| 213 | } | 184 | } |
| 214 | 185 | ||
| 215 | public MethodImplementationsTreeNode getMethodImplementations( MethodEntry deobfMethodEntry ) | 186 | public MethodImplementationsTreeNode getMethodImplementations(MethodEntry deobfMethodEntry) { |
| 216 | { | 187 | MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry(deobfMethodEntry); |
| 217 | MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry( deobfMethodEntry ); | ||
| 218 | MethodImplementationsTreeNode rootNode = m_deobfuscator.getJarIndex().getMethodImplementations( | 188 | MethodImplementationsTreeNode rootNode = m_deobfuscator.getJarIndex().getMethodImplementations( |
| 219 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), | 189 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), |
| 220 | obfMethodEntry | 190 | obfMethodEntry |
| 221 | ); | 191 | ); |
| 222 | if( rootNode == null ) | 192 | if (rootNode == null) { |
| 223 | { | ||
| 224 | return null; | 193 | return null; |
| 225 | } | 194 | } |
| 226 | return MethodImplementationsTreeNode.findNode( rootNode, obfMethodEntry ); | 195 | return MethodImplementationsTreeNode.findNode(rootNode, obfMethodEntry); |
| 227 | } | 196 | } |
| 228 | 197 | ||
| 229 | public FieldReferenceTreeNode getFieldReferences( FieldEntry deobfFieldEntry ) | 198 | public FieldReferenceTreeNode getFieldReferences(FieldEntry deobfFieldEntry) { |
| 230 | { | 199 | FieldEntry obfFieldEntry = m_deobfuscator.obfuscateEntry(deobfFieldEntry); |
| 231 | FieldEntry obfFieldEntry = m_deobfuscator.obfuscateEntry( deobfFieldEntry ); | ||
| 232 | FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode( | 200 | FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode( |
| 233 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), | 201 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), |
| 234 | obfFieldEntry | 202 | obfFieldEntry |
| 235 | ); | 203 | ); |
| 236 | rootNode.load( m_deobfuscator.getJarIndex(), true ); | 204 | rootNode.load(m_deobfuscator.getJarIndex(), true); |
| 237 | return rootNode; | 205 | return rootNode; |
| 238 | } | 206 | } |
| 239 | 207 | ||
| 240 | public BehaviorReferenceTreeNode getMethodReferences( BehaviorEntry deobfBehaviorEntry ) | 208 | public BehaviorReferenceTreeNode getMethodReferences(BehaviorEntry deobfBehaviorEntry) { |
| 241 | { | 209 | BehaviorEntry obfBehaviorEntry = m_deobfuscator.obfuscateEntry(deobfBehaviorEntry); |
| 242 | BehaviorEntry obfBehaviorEntry = m_deobfuscator.obfuscateEntry( deobfBehaviorEntry ); | ||
| 243 | BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode( | 210 | BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode( |
| 244 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), | 211 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), |
| 245 | obfBehaviorEntry | 212 | obfBehaviorEntry |
| 246 | ); | 213 | ); |
| 247 | rootNode.load( m_deobfuscator.getJarIndex(), true ); | 214 | rootNode.load(m_deobfuscator.getJarIndex(), true); |
| 248 | return rootNode; | 215 | return rootNode; |
| 249 | } | 216 | } |
| 250 | 217 | ||
| 251 | public void rename( EntryReference<Entry,Entry> deobfReference, String newName ) | 218 | public void rename(EntryReference<Entry,Entry> deobfReference, String newName) { |
| 252 | { | 219 | EntryReference<Entry,Entry> obfReference = m_deobfuscator.obfuscateReference(deobfReference); |
| 253 | EntryReference<Entry,Entry> obfReference = m_deobfuscator.obfuscateReference( deobfReference ); | 220 | m_deobfuscator.rename(obfReference.getNameableEntry(), newName); |
| 254 | m_deobfuscator.rename( obfReference.getNameableEntry(), newName ); | ||
| 255 | m_isDirty = true; | 221 | m_isDirty = true; |
| 256 | refreshClasses(); | 222 | refreshClasses(); |
| 257 | refreshCurrentClass( obfReference ); | 223 | refreshCurrentClass(obfReference); |
| 258 | } | 224 | } |
| 259 | 225 | ||
| 260 | public void removeMapping( EntryReference<Entry,Entry> deobfReference ) | 226 | public void removeMapping(EntryReference<Entry,Entry> deobfReference) { |
| 261 | { | 227 | EntryReference<Entry,Entry> obfReference = m_deobfuscator.obfuscateReference(deobfReference); |
| 262 | EntryReference<Entry,Entry> obfReference = m_deobfuscator.obfuscateReference( deobfReference ); | 228 | m_deobfuscator.removeMapping(obfReference.getNameableEntry()); |
| 263 | m_deobfuscator.removeMapping( obfReference.getNameableEntry() ); | ||
| 264 | m_isDirty = true; | 229 | m_isDirty = true; |
| 265 | refreshClasses(); | 230 | refreshClasses(); |
| 266 | refreshCurrentClass( obfReference ); | 231 | refreshCurrentClass(obfReference); |
| 267 | } | 232 | } |
| 268 | 233 | ||
| 269 | public void markAsDeobfuscated( EntryReference<Entry,Entry> deobfReference ) | 234 | public void markAsDeobfuscated(EntryReference<Entry,Entry> deobfReference) { |
| 270 | { | 235 | EntryReference<Entry,Entry> obfReference = m_deobfuscator.obfuscateReference(deobfReference); |
| 271 | EntryReference<Entry,Entry> obfReference = m_deobfuscator.obfuscateReference( deobfReference ); | 236 | m_deobfuscator.markAsDeobfuscated(obfReference.getNameableEntry()); |
| 272 | m_deobfuscator.markAsDeobfuscated( obfReference.getNameableEntry() ); | ||
| 273 | m_isDirty = true; | 237 | m_isDirty = true; |
| 274 | refreshClasses(); | 238 | refreshClasses(); |
| 275 | refreshCurrentClass( obfReference ); | 239 | refreshCurrentClass(obfReference); |
| 276 | } | 240 | } |
| 277 | 241 | ||
| 278 | public void openDeclaration( Entry deobfEntry ) | 242 | public void openDeclaration(Entry deobfEntry) { |
| 279 | { | 243 | if (deobfEntry == null) { |
| 280 | if( deobfEntry == null ) | 244 | throw new IllegalArgumentException("Entry cannot be null!"); |
| 281 | { | ||
| 282 | throw new IllegalArgumentException( "Entry cannot be null!" ); | ||
| 283 | } | 245 | } |
| 284 | openReference( new EntryReference<Entry,Entry>( deobfEntry, deobfEntry.getName() ) ); | 246 | openReference(new EntryReference<Entry,Entry>(deobfEntry, deobfEntry.getName())); |
| 285 | } | 247 | } |
| 286 | 248 | ||
| 287 | public void openReference( EntryReference<Entry,Entry> deobfReference ) | 249 | public void openReference(EntryReference<Entry,Entry> deobfReference) { |
| 288 | { | 250 | if (deobfReference == null) { |
| 289 | if( deobfReference == null ) | 251 | throw new IllegalArgumentException("Reference cannot be null!"); |
| 290 | { | ||
| 291 | throw new IllegalArgumentException( "Reference cannot be null!" ); | ||
| 292 | } | 252 | } |
| 293 | 253 | ||
| 294 | // get the reference target class | 254 | // get the reference target class |
| 295 | EntryReference<Entry,Entry> obfReference = m_deobfuscator.obfuscateReference( deobfReference ); | 255 | EntryReference<Entry,Entry> obfReference = m_deobfuscator.obfuscateReference(deobfReference); |
| 296 | ClassEntry obfClassEntry = obfReference.getLocationClassEntry().getOuterClassEntry(); | 256 | ClassEntry obfClassEntry = obfReference.getLocationClassEntry().getOuterClassEntry(); |
| 297 | if( !m_deobfuscator.isObfuscatedIdentifier( obfClassEntry ) ) | 257 | if (!m_deobfuscator.isObfuscatedIdentifier(obfClassEntry)) { |
| 298 | { | 258 | throw new IllegalArgumentException("Obfuscated class " + obfClassEntry + " was not found in the jar!"); |
| 299 | throw new IllegalArgumentException( "Obfuscated class " + obfClassEntry + " was not found in the jar!" ); | ||
| 300 | } | 259 | } |
| 301 | if( m_currentObfClass == null || !m_currentObfClass.equals( obfClassEntry ) ) | 260 | if (m_currentObfClass == null || !m_currentObfClass.equals(obfClassEntry)) { |
| 302 | { | ||
| 303 | // deobfuscate the class, then navigate to the reference | 261 | // deobfuscate the class, then navigate to the reference |
| 304 | m_currentObfClass = obfClassEntry; | 262 | m_currentObfClass = obfClassEntry; |
| 305 | deobfuscate( m_currentObfClass, obfReference ); | 263 | deobfuscate(m_currentObfClass, obfReference); |
| 306 | } | 264 | } else { |
| 307 | else | 265 | showReference(obfReference); |
| 308 | { | ||
| 309 | showReference( obfReference ); | ||
| 310 | } | 266 | } |
| 311 | } | 267 | } |
| 312 | 268 | ||
| 313 | private void showReference( EntryReference<Entry,Entry> obfReference ) | 269 | private void showReference(EntryReference<Entry,Entry> obfReference) { |
| 314 | { | 270 | EntryReference<Entry,Entry> deobfReference = m_deobfuscator.deobfuscateReference(obfReference); |
| 315 | EntryReference<Entry,Entry> deobfReference = m_deobfuscator.deobfuscateReference( obfReference ); | 271 | Collection<Token> tokens = m_index.getReferenceTokens(deobfReference); |
| 316 | Collection<Token> tokens = m_index.getReferenceTokens( deobfReference ); | 272 | if (tokens.isEmpty()) { |
| 317 | if( tokens.isEmpty() ) | ||
| 318 | { | ||
| 319 | // DEBUG | 273 | // DEBUG |
| 320 | System.err.println( String.format( "WARNING: no tokens found for %s in %s", deobfReference, m_currentObfClass ) ); | 274 | System.err.println(String.format("WARNING: no tokens found for %s in %s", deobfReference, m_currentObfClass)); |
| 321 | } | 275 | } else { |
| 322 | else | 276 | m_gui.showTokens(tokens); |
| 323 | { | ||
| 324 | m_gui.showTokens( tokens ); | ||
| 325 | } | 277 | } |
| 326 | } | 278 | } |
| 327 | 279 | ||
| 328 | public void savePreviousReference( EntryReference<Entry,Entry> deobfReference ) | 280 | public void savePreviousReference(EntryReference<Entry,Entry> deobfReference) { |
| 329 | { | 281 | m_referenceStack.push(m_deobfuscator.obfuscateReference(deobfReference)); |
| 330 | m_referenceStack.push( m_deobfuscator.obfuscateReference( deobfReference ) ); | ||
| 331 | } | 282 | } |
| 332 | 283 | ||
| 333 | public void openPreviousReference( ) | 284 | public void openPreviousReference() { |
| 334 | { | 285 | if (hasPreviousLocation()) { |
| 335 | if( hasPreviousLocation() ) | 286 | openReference(m_deobfuscator.deobfuscateReference(m_referenceStack.pop())); |
| 336 | { | ||
| 337 | openReference( m_deobfuscator.deobfuscateReference( m_referenceStack.pop() ) ); | ||
| 338 | } | 287 | } |
| 339 | } | 288 | } |
| 340 | 289 | ||
| 341 | public boolean hasPreviousLocation( ) | 290 | public boolean hasPreviousLocation() { |
| 342 | { | ||
| 343 | return !m_referenceStack.isEmpty(); | 291 | return !m_referenceStack.isEmpty(); |
| 344 | } | 292 | } |
| 345 | 293 | ||
| 346 | private void refreshClasses( ) | 294 | private void refreshClasses() { |
| 347 | { | ||
| 348 | List<ClassEntry> obfClasses = Lists.newArrayList(); | 295 | List<ClassEntry> obfClasses = Lists.newArrayList(); |
| 349 | List<ClassEntry> deobfClasses = Lists.newArrayList(); | 296 | List<ClassEntry> deobfClasses = Lists.newArrayList(); |
| 350 | m_deobfuscator.getSeparatedClasses( obfClasses, deobfClasses ); | 297 | m_deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); |
| 351 | m_gui.setObfClasses( obfClasses ); | 298 | m_gui.setObfClasses(obfClasses); |
| 352 | m_gui.setDeobfClasses( deobfClasses ); | 299 | m_gui.setDeobfClasses(deobfClasses); |
| 353 | } | 300 | } |
| 354 | 301 | ||
| 355 | private void refreshCurrentClass( ) | 302 | private void refreshCurrentClass() { |
| 356 | { | 303 | refreshCurrentClass(null); |
| 357 | refreshCurrentClass( null ); | ||
| 358 | } | 304 | } |
| 359 | 305 | ||
| 360 | private void refreshCurrentClass( EntryReference<Entry,Entry> obfReference ) | 306 | private void refreshCurrentClass(EntryReference<Entry,Entry> obfReference) { |
| 361 | { | 307 | if (m_currentObfClass != null) { |
| 362 | if( m_currentObfClass != null ) | 308 | deobfuscate(m_currentObfClass, obfReference); |
| 363 | { | ||
| 364 | deobfuscate( m_currentObfClass, obfReference ); | ||
| 365 | } | 309 | } |
| 366 | } | 310 | } |
| 367 | 311 | ||
| 368 | private void deobfuscate( final ClassEntry classEntry, final EntryReference<Entry,Entry> obfReference ) | 312 | private void deobfuscate(final ClassEntry classEntry, final EntryReference<Entry,Entry> obfReference) { |
| 369 | { | 313 | |
| 370 | m_gui.setSource( "(deobfuscating...)" ); | 314 | m_gui.setSource("(deobfuscating...)"); |
| 371 | 315 | ||
| 372 | // run the deobfuscator in a separate thread so we don't block the GUI event queue | 316 | // run the deobfuscator in a separate thread so we don't block the GUI event queue |
| 373 | new Thread( ) | 317 | new Thread() { |
| 374 | { | ||
| 375 | @Override | 318 | @Override |
| 376 | public void run( ) | 319 | public void run() { |
| 377 | { | ||
| 378 | // decompile,deobfuscate the bytecode | 320 | // decompile,deobfuscate the bytecode |
| 379 | CompilationUnit sourceTree = m_deobfuscator.getSourceTree( classEntry.getClassName() ); | 321 | CompilationUnit sourceTree = m_deobfuscator.getSourceTree(classEntry.getClassName()); |
| 380 | if( sourceTree == null ) | 322 | if (sourceTree == null) { |
| 381 | { | ||
| 382 | // decompilation of this class is not supported | 323 | // decompilation of this class is not supported |
| 383 | m_gui.setSource("Unable to find class: " + classEntry); | 324 | m_gui.setSource("Unable to find class: " + classEntry); |
| 384 | return; | 325 | return; |
| 385 | } | 326 | } |
| 386 | String source = m_deobfuscator.getSource( sourceTree ); | 327 | String source = m_deobfuscator.getSource(sourceTree); |
| 387 | m_index = m_deobfuscator.getSourceIndex( sourceTree, source ); | 328 | m_index = m_deobfuscator.getSourceIndex(sourceTree, source); |
| 388 | m_gui.setSource( m_index.getSource() ); | 329 | m_gui.setSource(m_index.getSource()); |
| 389 | if( obfReference != null ) | 330 | if (obfReference != null) { |
| 390 | { | 331 | showReference(obfReference); |
| 391 | showReference( obfReference ); | ||
| 392 | } | 332 | } |
| 393 | 333 | ||
| 394 | // set the highlighted tokens | 334 | // set the highlighted tokens |
| 395 | List<Token> obfuscatedTokens = Lists.newArrayList(); | 335 | List<Token> obfuscatedTokens = Lists.newArrayList(); |
| 396 | List<Token> deobfuscatedTokens = Lists.newArrayList(); | 336 | List<Token> deobfuscatedTokens = Lists.newArrayList(); |
| 397 | List<Token> otherTokens = Lists.newArrayList(); | 337 | List<Token> otherTokens = Lists.newArrayList(); |
| 398 | for( Token token : m_index.referenceTokens() ) | 338 | for (Token token : m_index.referenceTokens()) { |
| 399 | { | 339 | EntryReference<Entry,Entry> reference = m_index.getDeobfReference(token); |
| 400 | EntryReference<Entry,Entry> reference = m_index.getDeobfReference( token ); | 340 | if (referenceIsRenameable(reference)) { |
| 401 | if( referenceIsRenameable( reference ) ) | 341 | if (entryHasDeobfuscatedName(reference.getNameableEntry())) { |
| 402 | { | 342 | deobfuscatedTokens.add(token); |
| 403 | if( entryHasDeobfuscatedName( reference.getNameableEntry() ) ) | 343 | } else { |
| 404 | { | 344 | obfuscatedTokens.add(token); |
| 405 | deobfuscatedTokens.add( token ); | ||
| 406 | } | 345 | } |
| 407 | else | 346 | } else { |
| 408 | { | 347 | otherTokens.add(token); |
| 409 | obfuscatedTokens.add( token ); | ||
| 410 | } | ||
| 411 | } | ||
| 412 | else | ||
| 413 | { | ||
| 414 | otherTokens.add( token ); | ||
| 415 | } | 348 | } |
| 416 | } | 349 | } |
| 417 | m_gui.setHighlightedTokens( obfuscatedTokens, deobfuscatedTokens, otherTokens ); | 350 | m_gui.setHighlightedTokens(obfuscatedTokens, deobfuscatedTokens, otherTokens); |
| 418 | } | 351 | } |
| 419 | }.start(); | 352 | }.start(); |
| 420 | } | 353 | } |
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; | |||
| 17 | import javax.swing.JLabel; | 17 | import javax.swing.JLabel; |
| 18 | import javax.swing.ToolTipManager; | 18 | import javax.swing.ToolTipManager; |
| 19 | 19 | ||
| 20 | public class GuiTricks | 20 | public class GuiTricks { |
| 21 | { | 21 | |
| 22 | public static JLabel unboldLabel( JLabel label ) | 22 | public static JLabel unboldLabel(JLabel label) { |
| 23 | { | ||
| 24 | Font font = label.getFont(); | 23 | Font font = label.getFont(); |
| 25 | label.setFont( font.deriveFont( font.getStyle() & ~Font.BOLD ) ); | 24 | label.setFont(font.deriveFont(font.getStyle() & ~Font.BOLD)); |
| 26 | return label; | 25 | return label; |
| 27 | } | 26 | } |
| 28 | 27 | ||
| 29 | public static void showToolTipNow( JComponent component ) | 28 | public static void showToolTipNow(JComponent component) { |
| 30 | { | ||
| 31 | // HACKHACK: trick the tooltip manager into showing the tooltip right now | 29 | // HACKHACK: trick the tooltip manager into showing the tooltip right now |
| 32 | ToolTipManager manager = ToolTipManager.sharedInstance(); | 30 | ToolTipManager manager = ToolTipManager.sharedInstance(); |
| 33 | int oldDelay = manager.getInitialDelay(); | 31 | int oldDelay = manager.getInitialDelay(); |
| 34 | manager.setInitialDelay( 0 ); | 32 | manager.setInitialDelay(0); |
| 35 | manager.mouseMoved( new MouseEvent( | 33 | manager.mouseMoved(new MouseEvent(component, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, 0, 0, 0, false)); |
| 36 | component, | 34 | manager.setInitialDelay(oldDelay); |
| 37 | MouseEvent.MOUSE_MOVED, | ||
| 38 | System.currentTimeMillis(), | ||
| 39 | 0, 0, 0, 0, false | ||
| 40 | ) ); | ||
| 41 | manager.setInitialDelay( oldDelay ); | ||
| 42 | } | 35 | } |
| 43 | } | 36 | } |
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; | |||
| 12 | 12 | ||
| 13 | import java.awt.Color; | 13 | import java.awt.Color; |
| 14 | 14 | ||
| 15 | public class ObfuscatedHighlightPainter extends BoxHighlightPainter | 15 | public class ObfuscatedHighlightPainter extends BoxHighlightPainter { |
| 16 | { | 16 | |
| 17 | public ObfuscatedHighlightPainter( ) | 17 | public ObfuscatedHighlightPainter() { |
| 18 | { | ||
| 19 | // red ish | 18 | // red ish |
| 20 | super( new Color( 255, 220, 220 ), new Color( 160, 80, 80 ) ); | 19 | super(new Color(255, 220, 220), new Color(160, 80, 80)); |
| 21 | } | 20 | } |
| 22 | } | 21 | } |
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; | |||
| 12 | 12 | ||
| 13 | import java.awt.Color; | 13 | import java.awt.Color; |
| 14 | 14 | ||
| 15 | public class OtherHighlightPainter extends BoxHighlightPainter | 15 | public class OtherHighlightPainter extends BoxHighlightPainter { |
| 16 | { | 16 | |
| 17 | public OtherHighlightPainter( ) | 17 | public OtherHighlightPainter() { |
| 18 | { | ||
| 19 | // grey | 18 | // grey |
| 20 | super( null, new Color( 180, 180, 180 ) ); | 19 | super(null, new Color(180, 180, 180)); |
| 21 | } | 20 | } |
| 22 | } | 21 | } |
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; | |||
| 25 | import cuchaz.enigma.Constants; | 25 | import cuchaz.enigma.Constants; |
| 26 | import cuchaz.enigma.Deobfuscator.ProgressListener; | 26 | import cuchaz.enigma.Deobfuscator.ProgressListener; |
| 27 | 27 | ||
| 28 | public class ProgressDialog implements ProgressListener, AutoCloseable | 28 | public class ProgressDialog implements ProgressListener, AutoCloseable { |
| 29 | { | 29 | |
| 30 | private JFrame m_frame; | 30 | private JFrame m_frame; |
| 31 | private JLabel m_title; | 31 | private JLabel m_title; |
| 32 | private JLabel m_text; | 32 | private JLabel m_text; |
| 33 | private JProgressBar m_progress; | 33 | private JProgressBar m_progress; |
| 34 | 34 | ||
| 35 | public ProgressDialog( JFrame parent ) | 35 | public ProgressDialog(JFrame parent) { |
| 36 | { | 36 | |
| 37 | // init frame | 37 | // init frame |
| 38 | m_frame = new JFrame( Constants.Name + " - Operation in progress" ); | 38 | m_frame = new JFrame(Constants.Name + " - Operation in progress"); |
| 39 | final Container pane = m_frame.getContentPane(); | 39 | final Container pane = m_frame.getContentPane(); |
| 40 | FlowLayout layout = new FlowLayout(); | 40 | FlowLayout layout = new FlowLayout(); |
| 41 | layout.setAlignment( FlowLayout.LEFT ); | 41 | layout.setAlignment(FlowLayout.LEFT); |
| 42 | pane.setLayout( layout ); | 42 | pane.setLayout(layout); |
| 43 | 43 | ||
| 44 | m_title = new JLabel(); | 44 | m_title = new JLabel(); |
| 45 | pane.add( m_title ); | 45 | pane.add(m_title); |
| 46 | 46 | ||
| 47 | // set up the progress bar | 47 | // set up the progress bar |
| 48 | JPanel panel = new JPanel(); | 48 | JPanel panel = new JPanel(); |
| 49 | pane.add( panel ); | 49 | pane.add(panel); |
| 50 | panel.setLayout( new BorderLayout() ); | 50 | panel.setLayout(new BorderLayout()); |
| 51 | m_text = GuiTricks.unboldLabel( new JLabel() ); | 51 | m_text = GuiTricks.unboldLabel(new JLabel()); |
| 52 | m_progress = new JProgressBar(); | 52 | m_progress = new JProgressBar(); |
| 53 | m_text.setBorder( BorderFactory.createEmptyBorder( 0, 0, 10, 0 ) ); | 53 | m_text.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); |
| 54 | panel.add( m_text, BorderLayout.NORTH ); | 54 | panel.add(m_text, BorderLayout.NORTH); |
| 55 | panel.add( m_progress, BorderLayout.CENTER ); | 55 | panel.add(m_progress, BorderLayout.CENTER); |
| 56 | panel.setPreferredSize( new Dimension( 360, 50 ) ); | 56 | panel.setPreferredSize(new Dimension(360, 50)); |
| 57 | 57 | ||
| 58 | // show the frame | 58 | // show the frame |
| 59 | pane.doLayout(); | 59 | pane.doLayout(); |
| 60 | m_frame.setSize( 400, 120 ); | 60 | m_frame.setSize(400, 120); |
| 61 | m_frame.setResizable( false ); | 61 | m_frame.setResizable(false); |
| 62 | m_frame.setLocationRelativeTo( parent ); | 62 | m_frame.setLocationRelativeTo(parent); |
| 63 | m_frame.setVisible( true ); | 63 | m_frame.setVisible(true); |
| 64 | m_frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE ); | 64 | m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | public void close( ) | 67 | public void close() { |
| 68 | { | ||
| 69 | m_frame.dispose(); | 68 | m_frame.dispose(); |
| 70 | } | 69 | } |
| 71 | 70 | ||
| 72 | @Override | 71 | @Override |
| 73 | public void init( int totalWork, String title ) | 72 | public void init(int totalWork, String title) { |
| 74 | { | 73 | m_title.setText(title); |
| 75 | m_title.setText( title ); | 74 | m_progress.setMinimum(0); |
| 76 | m_progress.setMinimum( 0 ); | 75 | m_progress.setMaximum(totalWork); |
| 77 | m_progress.setMaximum( totalWork ); | 76 | m_progress.setValue(0); |
| 78 | m_progress.setValue( 0 ); | ||
| 79 | } | 77 | } |
| 80 | 78 | ||
| 81 | @Override | 79 | @Override |
| 82 | public void onProgress( int numDone, String message ) | 80 | public void onProgress(int numDone, String message) { |
| 83 | { | 81 | m_text.setText(message); |
| 84 | m_text.setText( message ); | 82 | m_progress.setValue(numDone); |
| 85 | m_progress.setValue( numDone ); | ||
| 86 | 83 | ||
| 87 | // update the frame | 84 | // update the frame |
| 88 | m_frame.validate(); | 85 | m_frame.validate(); |
| 89 | m_frame.repaint(); | 86 | m_frame.repaint(); |
| 90 | } | 87 | } |
| 91 | 88 | ||
| 92 | public static interface ProgressRunnable | 89 | public static interface ProgressRunnable { |
| 93 | { | 90 | void run(ProgressListener listener) throws Exception; |
| 94 | void run( ProgressListener listener ) throws Exception; | ||
| 95 | } | 91 | } |
| 96 | 92 | ||
| 97 | public static void runInThread( final JFrame parent, final ProgressRunnable runnable ) | 93 | public static void runInThread(final JFrame parent, final ProgressRunnable runnable) { |
| 98 | { | 94 | new Thread() { |
| 99 | new Thread( ) | ||
| 100 | { | ||
| 101 | @Override | 95 | @Override |
| 102 | public void run( ) | 96 | public void run() { |
| 103 | { | 97 | try (ProgressDialog progress = new ProgressDialog(parent)) { |
| 104 | try( ProgressDialog progress = new ProgressDialog( parent ) ) | 98 | runnable.run(progress); |
| 105 | { | 99 | } catch (Exception ex) { |
| 106 | runnable.run( progress ); | 100 | throw new Error(ex); |
| 107 | } | ||
| 108 | catch( Exception ex ) | ||
| 109 | { | ||
| 110 | throw new Error( ex ); | ||
| 111 | } | 101 | } |
| 112 | } | 102 | } |
| 113 | }.start(); | 103 | }.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 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.gui; | 11 | package cuchaz.enigma.gui; |
| 12 | 12 | ||
| 13 | public class ReadableToken | 13 | public class ReadableToken { |
| 14 | { | 14 | |
| 15 | public int line; | 15 | public int line; |
| 16 | public int startColumn; | 16 | public int startColumn; |
| 17 | public int endColumn; | 17 | public int endColumn; |
| 18 | 18 | ||
| 19 | public ReadableToken( int line, int startColumn, int endColumn ) | 19 | public ReadableToken(int line, int startColumn, int endColumn) { |
| 20 | { | ||
| 21 | this.line = line; | 20 | this.line = line; |
| 22 | this.startColumn = startColumn; | 21 | this.startColumn = startColumn; |
| 23 | this.endColumn = endColumn; | 22 | this.endColumn = endColumn; |
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | @Override | 25 | @Override |
| 27 | public String toString( ) | 26 | public String toString() { |
| 28 | { | ||
| 29 | StringBuilder buf = new StringBuilder(); | 27 | StringBuilder buf = new StringBuilder(); |
| 30 | buf.append( "line " ); | 28 | buf.append("line "); |
| 31 | buf.append( line ); | 29 | buf.append(line); |
| 32 | buf.append( " columns " ); | 30 | buf.append(" columns "); |
| 33 | buf.append( startColumn ); | 31 | buf.append(startColumn); |
| 34 | buf.append( "-" ); | 32 | buf.append("-"); |
| 35 | buf.append( endColumn ); | 33 | buf.append(endColumn); |
| 36 | return buf.toString(); | 34 | return buf.toString(); |
| 37 | } | 35 | } |
| 38 | } | 36 | } |
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; | |||
| 12 | 12 | ||
| 13 | import cuchaz.enigma.mapping.Entry; | 13 | import cuchaz.enigma.mapping.Entry; |
| 14 | 14 | ||
| 15 | public interface RenameListener | 15 | public interface RenameListener { |
| 16 | { | 16 | void rename(Entry obfEntry, String newName); |
| 17 | void rename( Entry obfEntry, String newName ); | ||
| 18 | } | 17 | } |
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; | |||
| 20 | import javax.swing.text.Highlighter; | 20 | import javax.swing.text.Highlighter; |
| 21 | import javax.swing.text.JTextComponent; | 21 | import javax.swing.text.JTextComponent; |
| 22 | 22 | ||
| 23 | public class SelectionHighlightPainter implements Highlighter.HighlightPainter | 23 | public class SelectionHighlightPainter implements Highlighter.HighlightPainter { |
| 24 | { | 24 | |
| 25 | @Override | 25 | @Override |
| 26 | public void paint( Graphics g, int start, int end, Shape shape, JTextComponent text ) | 26 | public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) { |
| 27 | { | ||
| 28 | // draw a thick border | 27 | // draw a thick border |
| 29 | Graphics2D g2d = (Graphics2D)g; | 28 | Graphics2D g2d = (Graphics2D)g; |
| 30 | Rectangle bounds = BoxHighlightPainter.getBounds( text, start, end ); | 29 | Rectangle bounds = BoxHighlightPainter.getBounds(text, start, end); |
| 31 | g2d.setColor( Color.black ); | 30 | g2d.setColor(Color.black); |
| 32 | g2d.setStroke( new BasicStroke( 2.0f ) ); | 31 | g2d.setStroke(new BasicStroke(2.0f)); |
| 33 | g2d.drawRoundRect( bounds.x, bounds.y, bounds.width, bounds.height, 4, 4 ); | 32 | g2d.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); |
| 34 | } | 33 | } |
| 35 | } | 34 | } |
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; | |||
| 19 | 19 | ||
| 20 | import cuchaz.enigma.analysis.Token; | 20 | import cuchaz.enigma.analysis.Token; |
| 21 | 21 | ||
| 22 | public class TokenListCellRenderer implements ListCellRenderer<Token> | 22 | public class TokenListCellRenderer implements ListCellRenderer<Token> { |
| 23 | { | 23 | |
| 24 | private GuiController m_controller; | 24 | private GuiController m_controller; |
| 25 | private DefaultListCellRenderer m_defaultRenderer; | 25 | private DefaultListCellRenderer m_defaultRenderer; |
| 26 | 26 | ||
| 27 | public TokenListCellRenderer( GuiController controller ) | 27 | public TokenListCellRenderer(GuiController controller) { |
| 28 | { | ||
| 29 | m_controller = controller; | 28 | m_controller = controller; |
| 30 | m_defaultRenderer = new DefaultListCellRenderer(); | 29 | m_defaultRenderer = new DefaultListCellRenderer(); |
| 31 | } | 30 | } |
| 32 | 31 | ||
| 33 | @Override | 32 | @Override |
| 34 | public Component getListCellRendererComponent( JList<? extends Token> list, Token token, int index, boolean isSelected, boolean hasFocus ) | 33 | public Component getListCellRendererComponent(JList<? extends Token> list, Token token, int index, boolean isSelected, boolean hasFocus) { |
| 35 | { | 34 | JLabel label = (JLabel)m_defaultRenderer.getListCellRendererComponent(list, token, index, isSelected, hasFocus); |
| 36 | JLabel label = (JLabel)m_defaultRenderer.getListCellRendererComponent( list, token, index, isSelected, hasFocus ); | 35 | label.setText(m_controller.getReadableToken(token).toString()); |
| 37 | label.setText( m_controller.getReadableToken( token ).toString() ); | ||
| 38 | return label; | 36 | return label; |
| 39 | } | 37 | } |
| 40 | } | 38 | } |