diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui')
21 files changed, 402 insertions, 686 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/AboutDialog.java b/src/main/java/cuchaz/enigma/gui/AboutDialog.java index a874399..bb12466 100644 --- a/src/main/java/cuchaz/enigma/gui/AboutDialog.java +++ b/src/main/java/cuchaz/enigma/gui/AboutDialog.java | |||
| @@ -25,14 +25,14 @@ public class AboutDialog { | |||
| 25 | 25 | ||
| 26 | public static void show(JFrame parent) { | 26 | public static void show(JFrame parent) { |
| 27 | // init frame | 27 | // init frame |
| 28 | final JFrame frame = new JFrame(Constants.Name + " - About"); | 28 | final JFrame frame = new JFrame(Constants.NAME + " - About"); |
| 29 | final Container pane = frame.getContentPane(); | 29 | final Container pane = frame.getContentPane(); |
| 30 | pane.setLayout(new FlowLayout()); | 30 | pane.setLayout(new FlowLayout()); |
| 31 | 31 | ||
| 32 | // load the content | 32 | // load the content |
| 33 | try { | 33 | try { |
| 34 | String html = Util.readResourceToString("/about.html"); | 34 | String html = Util.readResourceToString("/about.html"); |
| 35 | html = String.format(html, Constants.Name, Constants.Version); | 35 | html = String.format(html, Constants.NAME, Constants.VERSION); |
| 36 | JLabel label = new JLabel(html); | 36 | JLabel label = new JLabel(html); |
| 37 | label.setHorizontalAlignment(JLabel.CENTER); | 37 | label.setHorizontalAlignment(JLabel.CENTER); |
| 38 | pane.add(label); | 38 | pane.add(label); |
| @@ -42,9 +42,9 @@ public class AboutDialog { | |||
| 42 | 42 | ||
| 43 | // show the link | 43 | // show the link |
| 44 | String html = "<html><a href=\"%s\">%s</a></html>"; | 44 | String html = "<html><a href=\"%s\">%s</a></html>"; |
| 45 | html = String.format(html, Constants.Url, Constants.Url); | 45 | html = String.format(html, Constants.URL, Constants.URL); |
| 46 | JButton link = new JButton(html); | 46 | JButton link = new JButton(html); |
| 47 | link.addActionListener(event -> Util.openUrl(Constants.Url)); | 47 | link.addActionListener(event -> Util.openUrl(Constants.URL)); |
| 48 | link.setBorderPainted(false); | 48 | link.setBorderPainted(false); |
| 49 | link.setOpaque(false); | 49 | link.setOpaque(false); |
| 50 | link.setBackground(Color.WHITE); | 50 | link.setBackground(Color.WHITE); |
diff --git a/src/main/java/cuchaz/enigma/gui/BoxHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/BoxHighlightPainter.java index efe6b50..b66d13d 100644 --- a/src/main/java/cuchaz/enigma/gui/BoxHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/BoxHighlightPainter.java | |||
| @@ -21,12 +21,12 @@ 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 fillColor; |
| 25 | private Color m_borderColor; | 25 | private Color borderColor; |
| 26 | 26 | ||
| 27 | protected BoxHighlightPainter(Color fillColor, Color borderColor) { | 27 | protected BoxHighlightPainter(Color fillColor, Color borderColor) { |
| 28 | m_fillColor = fillColor; | 28 | this.fillColor = fillColor; |
| 29 | m_borderColor = borderColor; | 29 | this.borderColor = borderColor; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | @Override | 32 | @Override |
| @@ -34,17 +34,17 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte | |||
| 34 | Rectangle bounds = getBounds(text, start, end); | 34 | Rectangle bounds = getBounds(text, start, end); |
| 35 | 35 | ||
| 36 | // fill the area | 36 | // fill the area |
| 37 | if (m_fillColor != null) { | 37 | if (this.fillColor != null) { |
| 38 | g.setColor(m_fillColor); | 38 | g.setColor(this.fillColor); |
| 39 | g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); | 39 | g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | // draw a box around the area | 42 | // draw a box around the area |
| 43 | g.setColor(m_borderColor); | 43 | g.setColor(this.borderColor); |
| 44 | 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); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | protected static Rectangle getBounds(JTextComponent text, int start, int end) { | 47 | public static Rectangle getBounds(JTextComponent text, int start, int end) { |
| 48 | try { | 48 | try { |
| 49 | // determine the bounds of the text | 49 | // determine the bounds of the text |
| 50 | Rectangle bounds = text.modelToView(start).union(text.modelToView(end)); | 50 | Rectangle bounds = text.modelToView(start).union(text.modelToView(end)); |
diff --git a/src/main/java/cuchaz/enigma/gui/BrowserCaret.java b/src/main/java/cuchaz/enigma/gui/BrowserCaret.java index b4acbce..094b69b 100644 --- a/src/main/java/cuchaz/enigma/gui/BrowserCaret.java +++ b/src/main/java/cuchaz/enigma/gui/BrowserCaret.java | |||
| @@ -17,8 +17,7 @@ public class BrowserCaret extends DefaultCaret { | |||
| 17 | 17 | ||
| 18 | private static final long serialVersionUID = 1158977422507969940L; | 18 | private static final long serialVersionUID = 1158977422507969940L; |
| 19 | 19 | ||
| 20 | private static final Highlighter.HighlightPainter m_selectionPainter = (g, p0, p1, bounds, c) -> { | 20 | private static final Highlighter.HighlightPainter selectionPainter = (g, p0, p1, bounds, c) -> { |
| 21 | // don't paint anything | ||
| 22 | }; | 21 | }; |
| 23 | 22 | ||
| 24 | @Override | 23 | @Override |
| @@ -33,6 +32,6 @@ public class BrowserCaret extends DefaultCaret { | |||
| 33 | 32 | ||
| 34 | @Override | 33 | @Override |
| 35 | public Highlighter.HighlightPainter getSelectionPainter() { | 34 | public Highlighter.HighlightPainter getSelectionPainter() { |
| 36 | return m_selectionPainter; | 35 | return this.selectionPainter; |
| 37 | } | 36 | } |
| 38 | } | 37 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/ClassListCellRenderer.java b/src/main/java/cuchaz/enigma/gui/ClassListCellRenderer.java deleted file mode 100644 index 89b9bdd..0000000 --- a/src/main/java/cuchaz/enigma/gui/ClassListCellRenderer.java +++ /dev/null | |||
| @@ -1,36 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.gui; | ||
| 12 | |||
| 13 | import java.awt.Component; | ||
| 14 | |||
| 15 | import javax.swing.DefaultListCellRenderer; | ||
| 16 | import javax.swing.JLabel; | ||
| 17 | import javax.swing.JList; | ||
| 18 | import javax.swing.ListCellRenderer; | ||
| 19 | |||
| 20 | import javassist.bytecode.Descriptor; | ||
| 21 | |||
| 22 | public class ClassListCellRenderer implements ListCellRenderer<String> { | ||
| 23 | |||
| 24 | private DefaultListCellRenderer m_defaultRenderer; | ||
| 25 | |||
| 26 | public ClassListCellRenderer() { | ||
| 27 | m_defaultRenderer = new DefaultListCellRenderer(); | ||
| 28 | } | ||
| 29 | |||
| 30 | @Override | ||
| 31 | public Component getListCellRendererComponent(JList<? extends String> list, String className, int index, boolean isSelected, boolean hasFocus) { | ||
| 32 | JLabel label = (JLabel) m_defaultRenderer.getListCellRendererComponent(list, className, index, isSelected, hasFocus); | ||
| 33 | label.setText(Descriptor.toJavaName(className)); | ||
| 34 | return label; | ||
| 35 | } | ||
| 36 | } | ||
diff --git a/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java b/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java index 440565c..a069bca 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java +++ b/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java | |||
| @@ -77,35 +77,35 @@ public class ClassMatchingGui { | |||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | // controls | 79 | // controls |
| 80 | private JFrame m_frame; | 80 | private JFrame frame; |
| 81 | private ClassSelector m_sourceClasses; | 81 | private ClassSelector sourceClasses; |
| 82 | private ClassSelector m_destClasses; | 82 | private ClassSelector destClasses; |
| 83 | private CodeReader m_sourceReader; | 83 | private CodeReader sourceReader; |
| 84 | private CodeReader m_destReader; | 84 | private CodeReader destReader; |
| 85 | private JLabel m_sourceClassLabel; | 85 | private JLabel sourceClassLabel; |
| 86 | private JLabel m_destClassLabel; | 86 | private JLabel destClassLabel; |
| 87 | private JButton m_matchButton; | 87 | private JButton matchButton; |
| 88 | private Map<SourceType, JRadioButton> m_sourceTypeButtons; | 88 | private Map<SourceType, JRadioButton> sourceTypeButtons; |
| 89 | private JCheckBox m_advanceCheck; | 89 | private JCheckBox advanceCheck; |
| 90 | private JCheckBox m_top10Matches; | 90 | private JCheckBox top10Matches; |
| 91 | 91 | ||
| 92 | private ClassMatches m_classMatches; | 92 | private ClassMatches classMatches; |
| 93 | private Deobfuscator m_sourceDeobfuscator; | 93 | private Deobfuscator sourceDeobfuscator; |
| 94 | private Deobfuscator m_destDeobfuscator; | 94 | private Deobfuscator destDeobfuscator; |
| 95 | private ClassEntry m_sourceClass; | 95 | private ClassEntry sourceClass; |
| 96 | private ClassEntry m_destClass; | 96 | private ClassEntry destClass; |
| 97 | private SourceType m_sourceType; | 97 | private SourceType sourceType; |
| 98 | private SaveListener m_saveListener; | 98 | private SaveListener saveListener; |
| 99 | 99 | ||
| 100 | public ClassMatchingGui(ClassMatches matches, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) { | 100 | public ClassMatchingGui(ClassMatches matches, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) { |
| 101 | 101 | ||
| 102 | m_classMatches = matches; | 102 | this.classMatches = matches; |
| 103 | m_sourceDeobfuscator = sourceDeobfuscator; | 103 | this.sourceDeobfuscator = sourceDeobfuscator; |
| 104 | m_destDeobfuscator = destDeobfuscator; | 104 | this.destDeobfuscator = destDeobfuscator; |
| 105 | 105 | ||
| 106 | // init frame | 106 | // init frame |
| 107 | m_frame = new JFrame(Constants.Name + " - Class Matcher"); | 107 | this.frame = new JFrame(Constants.NAME + " - Class Matcher"); |
| 108 | final Container pane = m_frame.getContentPane(); | 108 | final Container pane = this.frame.getContentPane(); |
| 109 | pane.setLayout(new BorderLayout()); | 109 | pane.setLayout(new BorderLayout()); |
| 110 | 110 | ||
| 111 | // init source side | 111 | // init source side |
| @@ -121,16 +121,16 @@ public class ClassMatchingGui { | |||
| 121 | sourceTypePanel.setLayout(new BoxLayout(sourceTypePanel, BoxLayout.PAGE_AXIS)); | 121 | sourceTypePanel.setLayout(new BoxLayout(sourceTypePanel, BoxLayout.PAGE_AXIS)); |
| 122 | ActionListener sourceTypeListener = event -> setSourceType(SourceType.valueOf(event.getActionCommand())); | 122 | ActionListener sourceTypeListener = event -> setSourceType(SourceType.valueOf(event.getActionCommand())); |
| 123 | ButtonGroup sourceTypeButtons = new ButtonGroup(); | 123 | ButtonGroup sourceTypeButtons = new ButtonGroup(); |
| 124 | m_sourceTypeButtons = Maps.newHashMap(); | 124 | this.sourceTypeButtons = Maps.newHashMap(); |
| 125 | for (SourceType sourceType : SourceType.values()) { | 125 | for (SourceType sourceType : SourceType.values()) { |
| 126 | JRadioButton button = sourceType.newRadio(sourceTypeListener, sourceTypeButtons); | 126 | JRadioButton button = sourceType.newRadio(sourceTypeListener, sourceTypeButtons); |
| 127 | m_sourceTypeButtons.put(sourceType, button); | 127 | this.sourceTypeButtons.put(sourceType, button); |
| 128 | sourceTypePanel.add(button); | 128 | sourceTypePanel.add(button); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | m_sourceClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); | 131 | this.sourceClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); |
| 132 | m_sourceClasses.setListener(classEntry -> setSourceClass(classEntry)); | 132 | this.sourceClasses.setListener(this::setSourceClass); |
| 133 | JScrollPane sourceScroller = new JScrollPane(m_sourceClasses); | 133 | JScrollPane sourceScroller = new JScrollPane(this.sourceClasses); |
| 134 | sourcePanel.add(sourceScroller); | 134 | sourcePanel.add(sourceScroller); |
| 135 | 135 | ||
| 136 | // init dest side | 136 | // init dest side |
| @@ -140,13 +140,13 @@ public class ClassMatchingGui { | |||
| 140 | pane.add(destPanel, BorderLayout.WEST); | 140 | pane.add(destPanel, BorderLayout.WEST); |
| 141 | destPanel.add(new JLabel("Destination Classes")); | 141 | destPanel.add(new JLabel("Destination Classes")); |
| 142 | 142 | ||
| 143 | m_top10Matches = new JCheckBox("Show only top 10 matches"); | 143 | this.top10Matches = new JCheckBox("Show only top 10 matches"); |
| 144 | destPanel.add(m_top10Matches); | 144 | destPanel.add(this.top10Matches); |
| 145 | m_top10Matches.addActionListener(event -> toggleTop10Matches()); | 145 | this.top10Matches.addActionListener(event -> toggleTop10Matches()); |
| 146 | 146 | ||
| 147 | m_destClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); | 147 | this.destClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); |
| 148 | m_destClasses.setListener(this::setDestClass); | 148 | this.destClasses.setListener(this::setDestClass); |
| 149 | JScrollPane destScroller = new JScrollPane(m_destClasses); | 149 | JScrollPane destScroller = new JScrollPane(this.destClasses); |
| 150 | destPanel.add(destScroller); | 150 | destPanel.add(destScroller); |
| 151 | 151 | ||
| 152 | JButton autoMatchButton = new JButton("AutoMatch"); | 152 | JButton autoMatchButton = new JButton("AutoMatch"); |
| @@ -155,13 +155,13 @@ public class ClassMatchingGui { | |||
| 155 | 155 | ||
| 156 | // init source panels | 156 | // init source panels |
| 157 | DefaultSyntaxKit.initKit(); | 157 | DefaultSyntaxKit.initKit(); |
| 158 | m_sourceReader = new CodeReader(); | 158 | this.sourceReader = new CodeReader(); |
| 159 | m_destReader = new CodeReader(); | 159 | this.destReader = new CodeReader(); |
| 160 | 160 | ||
| 161 | // init all the splits | 161 | // init all the splits |
| 162 | JSplitPane splitLeft = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, sourcePanel, new JScrollPane(m_sourceReader)); | 162 | JSplitPane splitLeft = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, sourcePanel, new JScrollPane(this.sourceReader)); |
| 163 | splitLeft.setResizeWeight(0); // let the right side take all the slack | 163 | splitLeft.setResizeWeight(0); // let the right side take all the slack |
| 164 | JSplitPane splitRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, new JScrollPane(m_destReader), destPanel); | 164 | JSplitPane splitRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, new JScrollPane(this.destReader), destPanel); |
| 165 | splitRight.setResizeWeight(1); // let the left side take all the slack | 165 | splitRight.setResizeWeight(1); // let the left side take all the slack |
| 166 | JSplitPane splitCenter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, splitLeft, splitRight); | 166 | JSplitPane splitCenter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, splitLeft, splitRight); |
| 167 | splitCenter.setResizeWeight(0.5); // resize 50:50 | 167 | splitCenter.setResizeWeight(0.5); // resize 50:50 |
| @@ -172,81 +172,75 @@ public class ClassMatchingGui { | |||
| 172 | JPanel bottomPanel = new JPanel(); | 172 | JPanel bottomPanel = new JPanel(); |
| 173 | bottomPanel.setLayout(new FlowLayout()); | 173 | bottomPanel.setLayout(new FlowLayout()); |
| 174 | 174 | ||
| 175 | m_sourceClassLabel = new JLabel(); | 175 | this.sourceClassLabel = new JLabel(); |
| 176 | m_sourceClassLabel.setHorizontalAlignment(SwingConstants.RIGHT); | 176 | this.sourceClassLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
| 177 | m_destClassLabel = new JLabel(); | 177 | this.destClassLabel = new JLabel(); |
| 178 | m_destClassLabel.setHorizontalAlignment(SwingConstants.LEFT); | 178 | this.destClassLabel.setHorizontalAlignment(SwingConstants.LEFT); |
| 179 | 179 | ||
| 180 | m_matchButton = new JButton(); | 180 | this.matchButton = new JButton(); |
| 181 | 181 | ||
| 182 | m_advanceCheck = new JCheckBox("Advance to next likely match"); | 182 | this.advanceCheck = new JCheckBox("Advance to next likely match"); |
| 183 | m_advanceCheck.addActionListener(event -> { | 183 | this.advanceCheck.addActionListener(event -> { |
| 184 | if (m_advanceCheck.isSelected()) { | 184 | if (this.advanceCheck.isSelected()) { |
| 185 | advance(); | 185 | advance(); |
| 186 | } | 186 | } |
| 187 | }); | 187 | }); |
| 188 | 188 | ||
| 189 | bottomPanel.add(m_sourceClassLabel); | 189 | bottomPanel.add(this.sourceClassLabel); |
| 190 | bottomPanel.add(m_matchButton); | 190 | bottomPanel.add(this.matchButton); |
| 191 | bottomPanel.add(m_destClassLabel); | 191 | bottomPanel.add(this.destClassLabel); |
| 192 | bottomPanel.add(m_advanceCheck); | 192 | bottomPanel.add(this.advanceCheck); |
| 193 | pane.add(bottomPanel, BorderLayout.SOUTH); | 193 | pane.add(bottomPanel, BorderLayout.SOUTH); |
| 194 | 194 | ||
| 195 | // show the frame | 195 | // show the frame |
| 196 | pane.doLayout(); | 196 | pane.doLayout(); |
| 197 | m_frame.setSize(1024, 576); | 197 | this.frame.setSize(1024, 576); |
| 198 | m_frame.setMinimumSize(new Dimension(640, 480)); | 198 | this.frame.setMinimumSize(new Dimension(640, 480)); |
| 199 | m_frame.setVisible(true); | 199 | this.frame.setVisible(true); |
| 200 | m_frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); | 200 | this.frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
| 201 | 201 | ||
| 202 | // init state | 202 | // init state |
| 203 | updateDestMappings(); | 203 | updateDestMappings(); |
| 204 | setSourceType(SourceType.getDefault()); | 204 | setSourceType(SourceType.getDefault()); |
| 205 | updateMatchButton(); | 205 | updateMatchButton(); |
| 206 | m_saveListener = null; | 206 | this.saveListener = null; |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | public void setSaveListener(SaveListener val) { | 209 | public void setSaveListener(SaveListener val) { |
| 210 | m_saveListener = val; | 210 | this.saveListener = val; |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | private void updateDestMappings() { | 213 | private void updateDestMappings() { |
| 214 | 214 | ||
| 215 | Mappings newMappings = MappingsConverter.newMappings( | 215 | Mappings newMappings = MappingsConverter.newMappings(this.classMatches, this.sourceDeobfuscator.getMappings(), this.sourceDeobfuscator, this.destDeobfuscator); |
| 216 | m_classMatches, | ||
| 217 | m_sourceDeobfuscator.getMappings(), | ||
| 218 | m_sourceDeobfuscator, | ||
| 219 | m_destDeobfuscator | ||
| 220 | ); | ||
| 221 | 216 | ||
| 222 | // look for dropped mappings | 217 | // look for dropped mappings |
| 223 | MappingsChecker checker = new MappingsChecker(m_destDeobfuscator.getJarIndex()); | 218 | MappingsChecker checker = new MappingsChecker(this.destDeobfuscator.getJarIndex()); |
| 224 | checker.dropBrokenMappings(newMappings); | 219 | checker.dropBrokenMappings(newMappings); |
| 225 | 220 | ||
| 226 | // count them | 221 | // count them |
| 227 | int numDroppedFields = checker.getDroppedFieldMappings().size(); | 222 | int numDroppedFields = checker.getDroppedFieldMappings().size(); |
| 228 | int numDroppedMethods = checker.getDroppedMethodMappings().size(); | 223 | int numDroppedMethods = checker.getDroppedMethodMappings().size(); |
| 229 | System.out.println(String.format( | 224 | System.out.println(String.format("%d mappings from matched classes don't match the dest jar:\n\t%5d fields\n\t%5d methods", |
| 230 | "%d mappings from matched classes don't match the dest jar:\n\t%5d fields\n\t%5d methods", | ||
| 231 | numDroppedFields + numDroppedMethods, | 225 | numDroppedFields + numDroppedMethods, |
| 232 | numDroppedFields, | 226 | numDroppedFields, |
| 233 | numDroppedMethods | 227 | numDroppedMethods |
| 234 | )); | 228 | )); |
| 235 | 229 | ||
| 236 | m_destDeobfuscator.setMappings(newMappings); | 230 | this.destDeobfuscator.setMappings(newMappings); |
| 237 | } | 231 | } |
| 238 | 232 | ||
| 239 | protected void setSourceType(SourceType val) { | 233 | protected void setSourceType(SourceType val) { |
| 240 | 234 | ||
| 241 | // show the source classes | 235 | // show the source classes |
| 242 | m_sourceType = val; | 236 | this.sourceType = val; |
| 243 | m_sourceClasses.setClasses(deobfuscateClasses(m_sourceType.getSourceClasses(m_classMatches), m_sourceDeobfuscator)); | 237 | this.sourceClasses.setClasses(deobfuscateClasses(this.sourceType.getSourceClasses(this.classMatches), this.sourceDeobfuscator)); |
| 244 | 238 | ||
| 245 | // update counts | 239 | // update counts |
| 246 | for (SourceType sourceType : SourceType.values()) { | 240 | for (SourceType sourceType : SourceType.values()) { |
| 247 | m_sourceTypeButtons.get(sourceType).setText(String.format("%s (%d)", | 241 | this.sourceTypeButtons.get(sourceType).setText(String.format("%s (%d)", |
| 248 | sourceType.name(), | 242 | sourceType.name(), |
| 249 | sourceType.getSourceClasses(m_classMatches).size() | 243 | sourceType.getSourceClasses(this.classMatches).size() |
| 250 | )); | 244 | )); |
| 251 | } | 245 | } |
| 252 | } | 246 | } |
| @@ -270,7 +264,7 @@ public class ClassMatchingGui { | |||
| 270 | protected void setSourceClass(ClassEntry classEntry) { | 264 | protected void setSourceClass(ClassEntry classEntry) { |
| 271 | 265 | ||
| 272 | Runnable onGetDestClasses = null; | 266 | Runnable onGetDestClasses = null; |
| 273 | if (m_advanceCheck.isSelected()) { | 267 | if (this.advanceCheck.isSelected()) { |
| 274 | onGetDestClasses = this::pickBestDestClass; | 268 | onGetDestClasses = this::pickBestDestClass; |
| 275 | } | 269 | } |
| 276 | 270 | ||
| @@ -280,24 +274,24 @@ public class ClassMatchingGui { | |||
| 280 | protected void setSourceClass(ClassEntry classEntry, final Runnable onGetDestClasses) { | 274 | protected void setSourceClass(ClassEntry classEntry, final Runnable onGetDestClasses) { |
| 281 | 275 | ||
| 282 | // update the current source class | 276 | // update the current source class |
| 283 | m_sourceClass = classEntry; | 277 | this.sourceClass = classEntry; |
| 284 | m_sourceClassLabel.setText(m_sourceClass != null ? m_sourceClass.getName() : ""); | 278 | this.sourceClassLabel.setText(this.sourceClass != null ? this.sourceClass.getName() : ""); |
| 285 | 279 | ||
| 286 | if (m_sourceClass != null) { | 280 | if (this.sourceClass != null) { |
| 287 | 281 | ||
| 288 | // show the dest class(es) | 282 | // show the dest class(es) |
| 289 | ClassMatch match = m_classMatches.getMatchBySource(m_sourceDeobfuscator.obfuscateEntry(m_sourceClass)); | 283 | ClassMatch match = this.classMatches.getMatchBySource(this.sourceDeobfuscator.obfuscateEntry(this.sourceClass)); |
| 290 | assert (match != null); | 284 | assert (match != null); |
| 291 | if (match.destClasses.isEmpty()) { | 285 | if (match.destClasses.isEmpty()) { |
| 292 | 286 | ||
| 293 | m_destClasses.setClasses(null); | 287 | this.destClasses.setClasses(null); |
| 294 | 288 | ||
| 295 | // run in a separate thread to keep ui responsive | 289 | // run in a separate thread to keep ui responsive |
| 296 | new Thread() { | 290 | new Thread() { |
| 297 | @Override | 291 | @Override |
| 298 | public void run() { | 292 | public void run() { |
| 299 | m_destClasses.setClasses(deobfuscateClasses(getLikelyMatches(m_sourceClass), m_destDeobfuscator)); | 293 | destClasses.setClasses(deobfuscateClasses(getLikelyMatches(sourceClass), destDeobfuscator)); |
| 300 | m_destClasses.expandAll(); | 294 | destClasses.expandAll(); |
| 301 | 295 | ||
| 302 | if (onGetDestClasses != null) { | 296 | if (onGetDestClasses != null) { |
| 303 | onGetDestClasses.run(); | 297 | onGetDestClasses.run(); |
| @@ -307,8 +301,8 @@ public class ClassMatchingGui { | |||
| 307 | 301 | ||
| 308 | } else { | 302 | } else { |
| 309 | 303 | ||
| 310 | m_destClasses.setClasses(deobfuscateClasses(match.destClasses, m_destDeobfuscator)); | 304 | this.destClasses.setClasses(deobfuscateClasses(match.destClasses, this.destDeobfuscator)); |
| 311 | m_destClasses.expandAll(); | 305 | this.destClasses.expandAll(); |
| 312 | 306 | ||
| 313 | if (onGetDestClasses != null) { | 307 | if (onGetDestClasses != null) { |
| 314 | onGetDestClasses.run(); | 308 | onGetDestClasses.run(); |
| @@ -317,39 +311,33 @@ public class ClassMatchingGui { | |||
| 317 | } | 311 | } |
| 318 | 312 | ||
| 319 | setDestClass(null); | 313 | setDestClass(null); |
| 320 | m_sourceReader.decompileClass(m_sourceClass, m_sourceDeobfuscator, () -> m_sourceReader.navigateToClassDeclaration(m_sourceClass)); | 314 | this.sourceReader.decompileClass(this.sourceClass, this.sourceDeobfuscator, () -> this.sourceReader.navigateToClassDeclaration(this.sourceClass)); |
| 321 | 315 | ||
| 322 | updateMatchButton(); | 316 | updateMatchButton(); |
| 323 | } | 317 | } |
| 324 | 318 | ||
| 325 | private Collection<ClassEntry> getLikelyMatches(ClassEntry sourceClass) { | 319 | private Collection<ClassEntry> getLikelyMatches(ClassEntry sourceClass) { |
| 326 | 320 | ||
| 327 | ClassEntry obfSourceClass = m_sourceDeobfuscator.obfuscateEntry(sourceClass); | 321 | ClassEntry obfSourceClass = this.sourceDeobfuscator.obfuscateEntry(sourceClass); |
| 328 | 322 | ||
| 329 | // set up identifiers | 323 | // set up identifiers |
| 330 | ClassNamer namer = new ClassNamer(m_classMatches.getUniqueMatches()); | 324 | ClassNamer namer = new ClassNamer(this.classMatches.getUniqueMatches()); |
| 331 | ClassIdentifier sourceIdentifier = new ClassIdentifier( | 325 | ClassIdentifier sourceIdentifier = new ClassIdentifier(this.sourceDeobfuscator.getJar(), this.sourceDeobfuscator.getJarIndex(), namer.getSourceNamer(), true); |
| 332 | m_sourceDeobfuscator.getJar(), m_sourceDeobfuscator.getJarIndex(), | 326 | ClassIdentifier destIdentifier = new ClassIdentifier(this.destDeobfuscator.getJar(), this.destDeobfuscator.getJarIndex(), namer.getDestNamer(), true); |
| 333 | namer.getSourceNamer(), true | ||
| 334 | ); | ||
| 335 | ClassIdentifier destIdentifier = new ClassIdentifier( | ||
| 336 | m_destDeobfuscator.getJar(), m_destDeobfuscator.getJarIndex(), | ||
| 337 | namer.getDestNamer(), true | ||
| 338 | ); | ||
| 339 | 327 | ||
| 340 | try { | 328 | try { |
| 341 | 329 | ||
| 342 | // rank all the unmatched dest classes against the source class | 330 | // rank all the unmatched dest classes against the source class |
| 343 | ClassIdentity sourceIdentity = sourceIdentifier.identify(obfSourceClass); | 331 | ClassIdentity sourceIdentity = sourceIdentifier.identify(obfSourceClass); |
| 344 | List<ClassEntry> scoredDestClasses = Lists.newArrayList(); | 332 | List<ClassEntry> scoredDestClasses = Lists.newArrayList(); |
| 345 | for (ClassEntry unmatchedDestClass : m_classMatches.getUnmatchedDestClasses()) { | 333 | for (ClassEntry unmatchedDestClass : this.classMatches.getUnmatchedDestClasses()) { |
| 346 | ClassIdentity destIdentity = destIdentifier.identify(unmatchedDestClass); | 334 | ClassIdentity destIdentity = destIdentifier.identify(unmatchedDestClass); |
| 347 | float score = 100.0f * (sourceIdentity.getMatchScore(destIdentity) + destIdentity.getMatchScore(sourceIdentity)) | 335 | float score = 100.0f * (sourceIdentity.getMatchScore(destIdentity) + destIdentity.getMatchScore(sourceIdentity)) |
| 348 | / (sourceIdentity.getMaxMatchScore() + destIdentity.getMaxMatchScore()); | 336 | / (sourceIdentity.getMaxMatchScore() + destIdentity.getMaxMatchScore()); |
| 349 | scoredDestClasses.add(new ScoredClassEntry(unmatchedDestClass, score)); | 337 | scoredDestClasses.add(new ScoredClassEntry(unmatchedDestClass, score)); |
| 350 | } | 338 | } |
| 351 | 339 | ||
| 352 | if (m_top10Matches.isSelected() && scoredDestClasses.size() > 10) { | 340 | if (this.top10Matches.isSelected() && scoredDestClasses.size() > 10) { |
| 353 | Collections.sort(scoredDestClasses, (a, b) -> { | 341 | Collections.sort(scoredDestClasses, (a, b) -> { |
| 354 | ScoredClassEntry sa = (ScoredClassEntry) a; | 342 | ScoredClassEntry sa = (ScoredClassEntry) a; |
| 355 | ScoredClassEntry sb = (ScoredClassEntry) b; | 343 | ScoredClassEntry sb = (ScoredClassEntry) b; |
| @@ -368,30 +356,30 @@ public class ClassMatchingGui { | |||
| 368 | protected void setDestClass(ClassEntry classEntry) { | 356 | protected void setDestClass(ClassEntry classEntry) { |
| 369 | 357 | ||
| 370 | // update the current source class | 358 | // update the current source class |
| 371 | m_destClass = classEntry; | 359 | this.destClass = classEntry; |
| 372 | m_destClassLabel.setText(m_destClass != null ? m_destClass.getName() : ""); | 360 | this.destClassLabel.setText(this.destClass != null ? this.destClass.getName() : ""); |
| 373 | 361 | ||
| 374 | m_destReader.decompileClass(m_destClass, m_destDeobfuscator, () -> m_destReader.navigateToClassDeclaration(m_destClass)); | 362 | this.destReader.decompileClass(this.destClass, this.destDeobfuscator, () -> this.destReader.navigateToClassDeclaration(this.destClass)); |
| 375 | 363 | ||
| 376 | updateMatchButton(); | 364 | updateMatchButton(); |
| 377 | } | 365 | } |
| 378 | 366 | ||
| 379 | private void updateMatchButton() { | 367 | private void updateMatchButton() { |
| 380 | 368 | ||
| 381 | ClassEntry obfSource = m_sourceDeobfuscator.obfuscateEntry(m_sourceClass); | 369 | ClassEntry obfSource = this.sourceDeobfuscator.obfuscateEntry(this.sourceClass); |
| 382 | ClassEntry obfDest = m_destDeobfuscator.obfuscateEntry(m_destClass); | 370 | ClassEntry obfDest = this.destDeobfuscator.obfuscateEntry(this.destClass); |
| 383 | 371 | ||
| 384 | BiMap<ClassEntry, ClassEntry> uniqueMatches = m_classMatches.getUniqueMatches(); | 372 | BiMap<ClassEntry, ClassEntry> uniqueMatches = this.classMatches.getUniqueMatches(); |
| 385 | boolean twoSelected = m_sourceClass != null && m_destClass != null; | 373 | boolean twoSelected = this.sourceClass != null && this.destClass != null; |
| 386 | boolean isMatched = uniqueMatches.containsKey(obfSource) && uniqueMatches.containsValue(obfDest); | 374 | boolean isMatched = uniqueMatches.containsKey(obfSource) && uniqueMatches.containsValue(obfDest); |
| 387 | boolean canMatch = !uniqueMatches.containsKey(obfSource) && !uniqueMatches.containsValue(obfDest); | 375 | boolean canMatch = !uniqueMatches.containsKey(obfSource) && !uniqueMatches.containsValue(obfDest); |
| 388 | 376 | ||
| 389 | GuiTricks.deactivateButton(m_matchButton); | 377 | GuiTricks.deactivateButton(this.matchButton); |
| 390 | if (twoSelected) { | 378 | if (twoSelected) { |
| 391 | if (isMatched) { | 379 | if (isMatched) { |
| 392 | GuiTricks.activateButton(m_matchButton, "Unmatch", event -> onUnmatchClick()); | 380 | GuiTricks.activateButton(this.matchButton, "Unmatch", event -> onUnmatchClick()); |
| 393 | } else if (canMatch) { | 381 | } else if (canMatch) { |
| 394 | GuiTricks.activateButton(m_matchButton, "Match", event -> onMatchClick()); | 382 | GuiTricks.activateButton(this.matchButton, "Match", event -> onMatchClick()); |
| 395 | } | 383 | } |
| 396 | } | 384 | } |
| 397 | } | 385 | } |
| @@ -399,19 +387,19 @@ public class ClassMatchingGui { | |||
| 399 | private void onMatchClick() { | 387 | private void onMatchClick() { |
| 400 | // precondition: source and dest classes are set correctly | 388 | // precondition: source and dest classes are set correctly |
| 401 | 389 | ||
| 402 | ClassEntry obfSource = m_sourceDeobfuscator.obfuscateEntry(m_sourceClass); | 390 | ClassEntry obfSource = this.sourceDeobfuscator.obfuscateEntry(this.sourceClass); |
| 403 | ClassEntry obfDest = m_destDeobfuscator.obfuscateEntry(m_destClass); | 391 | ClassEntry obfDest = this.destDeobfuscator.obfuscateEntry(this.destClass); |
| 404 | 392 | ||
| 405 | // remove the classes from their match | 393 | // remove the classes from their match |
| 406 | m_classMatches.removeSource(obfSource); | 394 | this.classMatches.removeSource(obfSource); |
| 407 | m_classMatches.removeDest(obfDest); | 395 | this.classMatches.removeDest(obfDest); |
| 408 | 396 | ||
| 409 | // add them as matched classes | 397 | // add them as matched classes |
| 410 | m_classMatches.add(new ClassMatch(obfSource, obfDest)); | 398 | this.classMatches.add(new ClassMatch(obfSource, obfDest)); |
| 411 | 399 | ||
| 412 | ClassEntry nextClass = null; | 400 | ClassEntry nextClass = null; |
| 413 | if (m_advanceCheck.isSelected()) { | 401 | if (this.advanceCheck.isSelected()) { |
| 414 | nextClass = m_sourceClasses.getNextClass(m_sourceClass); | 402 | nextClass = this.sourceClasses.getNextClass(this.sourceClass); |
| 415 | } | 403 | } |
| 416 | 404 | ||
| 417 | save(); | 405 | save(); |
| @@ -425,11 +413,11 @@ public class ClassMatchingGui { | |||
| 425 | private void onUnmatchClick() { | 413 | private void onUnmatchClick() { |
| 426 | // precondition: source and dest classes are set to a unique match | 414 | // precondition: source and dest classes are set to a unique match |
| 427 | 415 | ||
| 428 | ClassEntry obfSource = m_sourceDeobfuscator.obfuscateEntry(m_sourceClass); | 416 | ClassEntry obfSource = this.sourceDeobfuscator.obfuscateEntry(this.sourceClass); |
| 429 | 417 | ||
| 430 | // remove the source to break the match, then add the source back as unmatched | 418 | // remove the source to break the match, then add the source back as unmatched |
| 431 | m_classMatches.removeSource(obfSource); | 419 | this.classMatches.removeSource(obfSource); |
| 432 | m_classMatches.add(new ClassMatch(obfSource, null)); | 420 | this.classMatches.add(new ClassMatch(obfSource, null)); |
| 433 | 421 | ||
| 434 | save(); | 422 | save(); |
| 435 | updateMatches(); | 423 | updateMatches(); |
| @@ -438,20 +426,20 @@ public class ClassMatchingGui { | |||
| 438 | private void updateMatches() { | 426 | private void updateMatches() { |
| 439 | updateDestMappings(); | 427 | updateDestMappings(); |
| 440 | setDestClass(null); | 428 | setDestClass(null); |
| 441 | m_destClasses.setClasses(null); | 429 | this.destClasses.setClasses(null); |
| 442 | updateMatchButton(); | 430 | updateMatchButton(); |
| 443 | 431 | ||
| 444 | // remember where we were in the source tree | 432 | // remember where we were in the source tree |
| 445 | String packageName = m_sourceClasses.getSelectedPackage(); | 433 | String packageName = this.sourceClasses.getSelectedPackage(); |
| 446 | 434 | ||
| 447 | setSourceType(m_sourceType); | 435 | setSourceType(this.sourceType); |
| 448 | 436 | ||
| 449 | m_sourceClasses.expandPackage(packageName); | 437 | this.sourceClasses.expandPackage(packageName); |
| 450 | } | 438 | } |
| 451 | 439 | ||
| 452 | private void save() { | 440 | private void save() { |
| 453 | if (m_saveListener != null) { | 441 | if (this.saveListener != null) { |
| 454 | m_saveListener.save(m_classMatches); | 442 | this.saveListener.save(this.classMatches); |
| 455 | } | 443 | } |
| 456 | } | 444 | } |
| 457 | 445 | ||
| @@ -460,18 +448,13 @@ public class ClassMatchingGui { | |||
| 460 | System.out.println("Automatching..."); | 448 | System.out.println("Automatching..."); |
| 461 | 449 | ||
| 462 | // compute a new matching | 450 | // compute a new matching |
| 463 | ClassMatching matching = MappingsConverter.computeMatching( | 451 | ClassMatching matching = MappingsConverter.computeMatching(this.sourceDeobfuscator.getJar(), this.sourceDeobfuscator.getJarIndex(), |
| 464 | m_sourceDeobfuscator.getJar(), m_sourceDeobfuscator.getJarIndex(), | 452 | this.destDeobfuscator.getJar(), this.destDeobfuscator.getJarIndex(), this.classMatches.getUniqueMatches()); |
| 465 | m_destDeobfuscator.getJar(), m_destDeobfuscator.getJarIndex(), | ||
| 466 | m_classMatches.getUniqueMatches() | ||
| 467 | ); | ||
| 468 | ClassMatches newMatches = new ClassMatches(matching.matches()); | 453 | ClassMatches newMatches = new ClassMatches(matching.matches()); |
| 469 | System.out.println(String.format("Automatch found %d new matches", | 454 | System.out.println(String.format("Automatch found %d new matches", newMatches.getUniqueMatches().size() - this.classMatches.getUniqueMatches().size())); |
| 470 | newMatches.getUniqueMatches().size() - m_classMatches.getUniqueMatches().size() | ||
| 471 | )); | ||
| 472 | 455 | ||
| 473 | // update the current matches | 456 | // update the current matches |
| 474 | m_classMatches = newMatches; | 457 | this.classMatches = newMatches; |
| 475 | save(); | 458 | save(); |
| 476 | updateMatches(); | 459 | updateMatches(); |
| 477 | } | 460 | } |
| @@ -484,17 +467,17 @@ public class ClassMatchingGui { | |||
| 484 | 467 | ||
| 485 | // make sure we have a source class | 468 | // make sure we have a source class |
| 486 | if (sourceClass == null) { | 469 | if (sourceClass == null) { |
| 487 | sourceClass = m_sourceClasses.getSelectedClass(); | 470 | sourceClass = this.sourceClasses.getSelectedClass(); |
| 488 | if (sourceClass != null) { | 471 | if (sourceClass != null) { |
| 489 | sourceClass = m_sourceClasses.getNextClass(sourceClass); | 472 | sourceClass = this.sourceClasses.getNextClass(sourceClass); |
| 490 | } else { | 473 | } else { |
| 491 | sourceClass = m_sourceClasses.getFirstClass(); | 474 | sourceClass = this.sourceClasses.getFirstClass(); |
| 492 | } | 475 | } |
| 493 | } | 476 | } |
| 494 | 477 | ||
| 495 | // set the source class | 478 | // set the source class |
| 496 | setSourceClass(sourceClass, this::pickBestDestClass); | 479 | setSourceClass(sourceClass, this::pickBestDestClass); |
| 497 | m_sourceClasses.setSelectionClass(sourceClass); | 480 | this.sourceClasses.setSelectionClass(sourceClass); |
| 498 | } | 481 | } |
| 499 | 482 | ||
| 500 | private void pickBestDestClass() { | 483 | private void pickBestDestClass() { |
| @@ -502,8 +485,8 @@ public class ClassMatchingGui { | |||
| 502 | // then, pick the best dest class | 485 | // then, pick the best dest class |
| 503 | ClassEntry firstClass = null; | 486 | ClassEntry firstClass = null; |
| 504 | ScoredClassEntry bestDestClass = null; | 487 | ScoredClassEntry bestDestClass = null; |
| 505 | for (ClassSelectorPackageNode packageNode : m_destClasses.packageNodes()) { | 488 | for (ClassSelectorPackageNode packageNode : this.destClasses.packageNodes()) { |
| 506 | for (ClassSelectorClassNode classNode : m_destClasses.classNodes(packageNode)) { | 489 | for (ClassSelectorClassNode classNode : this.destClasses.classNodes(packageNode)) { |
| 507 | if (firstClass == null) { | 490 | if (firstClass == null) { |
| 508 | firstClass = classNode.getClassEntry(); | 491 | firstClass = classNode.getClassEntry(); |
| 509 | } | 492 | } |
| @@ -525,14 +508,14 @@ public class ClassMatchingGui { | |||
| 525 | } | 508 | } |
| 526 | 509 | ||
| 527 | setDestClass(destClass); | 510 | setDestClass(destClass); |
| 528 | m_destClasses.setSelectionClass(destClass); | 511 | this.destClasses.setSelectionClass(destClass); |
| 529 | } | 512 | } |
| 530 | 513 | ||
| 531 | private void toggleTop10Matches() { | 514 | private void toggleTop10Matches() { |
| 532 | if (m_sourceClass != null) { | 515 | if (this.sourceClass != null) { |
| 533 | m_destClasses.clearSelection(); | 516 | this.destClasses.clearSelection(); |
| 534 | m_destClasses.setClasses(deobfuscateClasses(getLikelyMatches(m_sourceClass), m_destDeobfuscator)); | 517 | this.destClasses.setClasses(deobfuscateClasses(getLikelyMatches(this.sourceClass), this.destDeobfuscator)); |
| 535 | m_destClasses.expandAll(); | 518 | this.destClasses.expandAll(); |
| 536 | } | 519 | } |
| 537 | } | 520 | } |
| 538 | } | 521 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/ClassSelector.java b/src/main/java/cuchaz/enigma/gui/ClassSelector.java index 0c93c43..f6abd51 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassSelector.java +++ b/src/main/java/cuchaz/enigma/gui/ClassSelector.java | |||
| @@ -58,11 +58,11 @@ public class ClassSelector extends JTree { | |||
| 58 | }; | 58 | }; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | private ClassSelectionListener m_listener; | 61 | private ClassSelectionListener listener; |
| 62 | private Comparator<ClassEntry> m_comparator; | 62 | private Comparator<ClassEntry> comparator; |
| 63 | 63 | ||
| 64 | public ClassSelector(Comparator<ClassEntry> comparator) { | 64 | public ClassSelector(Comparator<ClassEntry> comparator) { |
| 65 | m_comparator = comparator; | 65 | this.comparator = comparator; |
| 66 | 66 | ||
| 67 | // configure the tree control | 67 | // configure the tree control |
| 68 | setRootVisible(false); | 68 | setRootVisible(false); |
| @@ -73,23 +73,23 @@ public class ClassSelector extends JTree { | |||
| 73 | addMouseListener(new MouseAdapter() { | 73 | addMouseListener(new MouseAdapter() { |
| 74 | @Override | 74 | @Override |
| 75 | public void mouseClicked(MouseEvent event) { | 75 | public void mouseClicked(MouseEvent event) { |
| 76 | if (m_listener != null && event.getClickCount() == 2) { | 76 | if (listener != null && event.getClickCount() == 2) { |
| 77 | // get the selected node | 77 | // get the selected node |
| 78 | TreePath path = getSelectionPath(); | 78 | TreePath path = getSelectionPath(); |
| 79 | if (path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode) { | 79 | if (path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode) { |
| 80 | ClassSelectorClassNode node = (ClassSelectorClassNode) path.getLastPathComponent(); | 80 | ClassSelectorClassNode node = (ClassSelectorClassNode) path.getLastPathComponent(); |
| 81 | m_listener.onSelectClass(node.getClassEntry()); | 81 | listener.onSelectClass(node.getClassEntry()); |
| 82 | } | 82 | } |
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | }); | 85 | }); |
| 86 | 86 | ||
| 87 | // init defaults | 87 | // init defaults |
| 88 | m_listener = null; | 88 | this.listener = null; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | public void setListener(ClassSelectionListener val) { | 91 | public void setListener(ClassSelectionListener val) { |
| 92 | m_listener = val; | 92 | this.listener = val; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | public void setClasses(Collection<ClassEntry> classEntries) { | 95 | public void setClasses(Collection<ClassEntry> classEntries) { |
| @@ -144,7 +144,7 @@ public class ClassSelector extends JTree { | |||
| 144 | for (String packageName : packagedClassEntries.keySet()) { | 144 | for (String packageName : packagedClassEntries.keySet()) { |
| 145 | // sort the class entries | 145 | // sort the class entries |
| 146 | List<ClassEntry> classEntriesInPackage = Lists.newArrayList(packagedClassEntries.get(packageName)); | 146 | List<ClassEntry> classEntriesInPackage = Lists.newArrayList(packagedClassEntries.get(packageName)); |
| 147 | Collections.sort(classEntriesInPackage, m_comparator); | 147 | Collections.sort(classEntriesInPackage, this.comparator); |
| 148 | 148 | ||
| 149 | // create the nodes in order | 149 | // create the nodes in order |
| 150 | for (ClassEntry classEntry : classEntriesInPackage) { | 150 | for (ClassEntry classEntry : classEntriesInPackage) { |
diff --git a/src/main/java/cuchaz/enigma/gui/ClassSelectorClassNode.java b/src/main/java/cuchaz/enigma/gui/ClassSelectorClassNode.java index 6da9782..e73340a 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassSelectorClassNode.java +++ b/src/main/java/cuchaz/enigma/gui/ClassSelectorClassNode.java | |||
| @@ -18,33 +18,30 @@ 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 classEntry; |
| 22 | 22 | ||
| 23 | public ClassSelectorClassNode(ClassEntry classEntry) { | 23 | public ClassSelectorClassNode(ClassEntry classEntry) { |
| 24 | m_classEntry = classEntry; | 24 | this.classEntry = classEntry; |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | public ClassEntry getClassEntry() { | 27 | public ClassEntry getClassEntry() { |
| 28 | return m_classEntry; | 28 | return this.classEntry; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | @Override | 31 | @Override |
| 32 | public String toString() { | 32 | public String toString() { |
| 33 | if (m_classEntry instanceof ScoredClassEntry) { | 33 | if (this.classEntry instanceof ScoredClassEntry) { |
| 34 | return String.format("%d%% %s", (int) ((ScoredClassEntry) m_classEntry).getScore(), m_classEntry.getSimpleName()); | 34 | return String.format("%d%% %s", (int) ((ScoredClassEntry) this.classEntry).getScore(), this.classEntry.getSimpleName()); |
| 35 | } | 35 | } |
| 36 | return m_classEntry.getSimpleName(); | 36 | return this.classEntry.getSimpleName(); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | @Override | 39 | @Override |
| 40 | public boolean equals(Object other) { | 40 | public boolean equals(Object other) { |
| 41 | if (other instanceof ClassSelectorClassNode) { | 41 | return other instanceof ClassSelectorClassNode && equals((ClassSelectorClassNode) other); |
| 42 | return equals((ClassSelectorClassNode) other); | ||
| 43 | } | ||
| 44 | return false; | ||
| 45 | } | 42 | } |
| 46 | 43 | ||
| 47 | public boolean equals(ClassSelectorClassNode other) { | 44 | public boolean equals(ClassSelectorClassNode other) { |
| 48 | return m_classEntry.equals(other.m_classEntry); | 45 | return this.classEntry.equals(other.classEntry); |
| 49 | } | 46 | } |
| 50 | } | 47 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/ClassSelectorPackageNode.java b/src/main/java/cuchaz/enigma/gui/ClassSelectorPackageNode.java index 3622042..3b5ba8c 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassSelectorPackageNode.java +++ b/src/main/java/cuchaz/enigma/gui/ClassSelectorPackageNode.java | |||
| @@ -16,30 +16,27 @@ 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 packageName; |
| 20 | 20 | ||
| 21 | public ClassSelectorPackageNode(String packageName) { | 21 | public ClassSelectorPackageNode(String packageName) { |
| 22 | m_packageName = packageName; | 22 | this.packageName = packageName; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | public String getPackageName() { | 25 | public String getPackageName() { |
| 26 | return m_packageName; | 26 | return this.packageName; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | @Override | 29 | @Override |
| 30 | public String toString() { | 30 | public String toString() { |
| 31 | return m_packageName; | 31 | return this.packageName; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | @Override | 34 | @Override |
| 35 | public boolean equals(Object other) { | 35 | public boolean equals(Object other) { |
| 36 | if (other instanceof ClassSelectorPackageNode) { | 36 | return other instanceof ClassSelectorPackageNode && equals((ClassSelectorPackageNode) other); |
| 37 | return equals((ClassSelectorPackageNode) other); | ||
| 38 | } | ||
| 39 | return false; | ||
| 40 | } | 37 | } |
| 41 | 38 | ||
| 42 | public boolean equals(ClassSelectorPackageNode other) { | 39 | public boolean equals(ClassSelectorPackageNode other) { |
| 43 | return m_packageName.equals(other.m_packageName); | 40 | return this.packageName.equals(other.packageName); |
| 44 | } | 41 | } |
| 45 | } | 42 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/CodeReader.java b/src/main/java/cuchaz/enigma/gui/CodeReader.java index 93f9a75..a476fa5 100644 --- a/src/main/java/cuchaz/enigma/gui/CodeReader.java +++ b/src/main/java/cuchaz/enigma/gui/CodeReader.java | |||
| @@ -19,8 +19,6 @@ import java.awt.event.ActionListener; | |||
| 19 | import javax.swing.JEditorPane; | 19 | import javax.swing.JEditorPane; |
| 20 | import javax.swing.SwingUtilities; | 20 | import javax.swing.SwingUtilities; |
| 21 | import javax.swing.Timer; | 21 | import javax.swing.Timer; |
| 22 | import javax.swing.event.CaretEvent; | ||
| 23 | import javax.swing.event.CaretListener; | ||
| 24 | import javax.swing.text.BadLocationException; | 22 | import javax.swing.text.BadLocationException; |
| 25 | import javax.swing.text.Highlighter.HighlightPainter; | 23 | import javax.swing.text.Highlighter.HighlightPainter; |
| 26 | 24 | ||
| @@ -37,15 +35,15 @@ public class CodeReader extends JEditorPane { | |||
| 37 | 35 | ||
| 38 | private static final long serialVersionUID = 3673180950485748810L; | 36 | private static final long serialVersionUID = 3673180950485748810L; |
| 39 | 37 | ||
| 40 | private static final Object m_lock = new Object(); | 38 | private static final Object lock = new Object(); |
| 41 | 39 | ||
| 42 | public interface SelectionListener { | 40 | public interface SelectionListener { |
| 43 | void onSelect(EntryReference<Entry, Entry> reference); | 41 | void onSelect(EntryReference<Entry, Entry> reference); |
| 44 | } | 42 | } |
| 45 | 43 | ||
| 46 | private SelectionHighlightPainter m_selectionHighlightPainter; | 44 | private SelectionHighlightPainter selectionHighlightPainter; |
| 47 | private SourceIndex m_sourceIndex; | 45 | private SourceIndex sourceIndex; |
| 48 | private SelectionListener m_selectionListener; | 46 | private SelectionListener selectionListener; |
| 49 | 47 | ||
| 50 | public CodeReader() { | 48 | public CodeReader() { |
| 51 | 49 | ||
| @@ -57,42 +55,35 @@ public class CodeReader extends JEditorPane { | |||
| 57 | kit.toggleComponent(this, "de.sciss.syntaxpane.components.TokenMarker"); | 55 | kit.toggleComponent(this, "de.sciss.syntaxpane.components.TokenMarker"); |
| 58 | 56 | ||
| 59 | // hook events | 57 | // hook events |
| 60 | addCaretListener(new CaretListener() { | 58 | addCaretListener(event -> { |
| 61 | @Override | 59 | if (this.selectionListener != null && this.sourceIndex != null) { |
| 62 | public void caretUpdate(CaretEvent event) { | 60 | Token token = this.sourceIndex.getReferenceToken(event.getDot()); |
| 63 | if (m_selectionListener != null && m_sourceIndex != null) { | 61 | if (token != null) { |
| 64 | Token token = m_sourceIndex.getReferenceToken(event.getDot()); | 62 | this.selectionListener.onSelect(this.sourceIndex.getDeobfReference(token)); |
| 65 | if (token != null) { | 63 | } else { |
| 66 | m_selectionListener.onSelect(m_sourceIndex.getDeobfReference(token)); | 64 | this.selectionListener.onSelect(null); |
| 67 | } else { | ||
| 68 | m_selectionListener.onSelect(null); | ||
| 69 | } | ||
| 70 | } | 65 | } |
| 71 | } | 66 | } |
| 72 | }); | 67 | }); |
| 73 | 68 | ||
| 74 | m_selectionHighlightPainter = new SelectionHighlightPainter(); | 69 | this.selectionHighlightPainter = new SelectionHighlightPainter(); |
| 75 | m_sourceIndex = null; | 70 | this.sourceIndex = null; |
| 76 | m_selectionListener = null; | 71 | this.selectionListener = null; |
| 77 | } | 72 | } |
| 78 | 73 | ||
| 79 | public void setSelectionListener(SelectionListener val) { | 74 | public void setSelectionListener(SelectionListener val) { |
| 80 | m_selectionListener = val; | 75 | this.selectionListener = val; |
| 81 | } | 76 | } |
| 82 | 77 | ||
| 83 | public void setCode(String code) { | 78 | public void setCode(String code) { |
| 84 | // sadly, the java lexer is not thread safe, so we have to serialize all these calls | 79 | // sadly, the java lexer is not thread safe, so we have to serialize all these calls |
| 85 | synchronized (m_lock) { | 80 | synchronized (lock) { |
| 86 | setText(code); | 81 | setText(code); |
| 87 | } | 82 | } |
| 88 | } | 83 | } |
| 89 | 84 | ||
| 90 | public SourceIndex getSourceIndex() { | 85 | public SourceIndex getSourceIndex() { |
| 91 | return m_sourceIndex; | 86 | return this.sourceIndex; |
| 92 | } | ||
| 93 | |||
| 94 | public void decompileClass(ClassEntry classEntry, Deobfuscator deobfuscator) { | ||
| 95 | decompileClass(classEntry, deobfuscator, null); | ||
| 96 | } | 87 | } |
| 97 | 88 | ||
| 98 | public void decompileClass(ClassEntry classEntry, Deobfuscator deobfuscator, Runnable callback) { | 89 | public void decompileClass(ClassEntry classEntry, Deobfuscator deobfuscator, Runnable callback) { |
| @@ -117,7 +108,7 @@ public class CodeReader extends JEditorPane { | |||
| 117 | CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getOutermostClassName()); | 108 | CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getOutermostClassName()); |
| 118 | String source = deobfuscator.getSource(sourceTree); | 109 | String source = deobfuscator.getSource(sourceTree); |
| 119 | setCode(source); | 110 | setCode(source); |
| 120 | m_sourceIndex = deobfuscator.getSourceIndex(sourceTree, source, ignoreBadTokens); | 111 | sourceIndex = deobfuscator.getSourceIndex(sourceTree, source, ignoreBadTokens); |
| 121 | 112 | ||
| 122 | if (callback != null) { | 113 | if (callback != null) { |
| 123 | callback.run(); | 114 | callback.run(); |
| @@ -129,13 +120,13 @@ public class CodeReader extends JEditorPane { | |||
| 129 | public void navigateToClassDeclaration(ClassEntry classEntry) { | 120 | public void navigateToClassDeclaration(ClassEntry classEntry) { |
| 130 | 121 | ||
| 131 | // navigate to the class declaration | 122 | // navigate to the class declaration |
| 132 | Token token = m_sourceIndex.getDeclarationToken(classEntry); | 123 | Token token = this.sourceIndex.getDeclarationToken(classEntry); |
| 133 | if (token == null) { | 124 | if (token == null) { |
| 134 | // couldn't find the class declaration token, might be an anonymous class | 125 | // couldn't find the class declaration token, might be an anonymous class |
| 135 | // look for any declaration in that class instead | 126 | // look for any declaration in that class instead |
| 136 | for (Entry entry : m_sourceIndex.declarations()) { | 127 | for (Entry entry : this.sourceIndex.declarations()) { |
| 137 | if (entry.getClassEntry().equals(classEntry)) { | 128 | if (entry.getClassEntry().equals(classEntry)) { |
| 138 | token = m_sourceIndex.getDeclarationToken(entry); | 129 | token = this.sourceIndex.getDeclarationToken(entry); |
| 139 | break; | 130 | break; |
| 140 | } | 131 | } |
| 141 | } | 132 | } |
| @@ -150,7 +141,7 @@ public class CodeReader extends JEditorPane { | |||
| 150 | } | 141 | } |
| 151 | 142 | ||
| 152 | public void navigateToToken(final Token token) { | 143 | public void navigateToToken(final Token token) { |
| 153 | navigateToToken(this, token, m_selectionHighlightPainter); | 144 | navigateToToken(this, token, this.selectionHighlightPainter); |
| 154 | } | 145 | } |
| 155 | 146 | ||
| 156 | // HACKHACK: someday we can update the main GUI to use this code reader | 147 | // HACKHACK: someday we can update the main GUI to use this code reader |
| @@ -166,12 +157,7 @@ public class CodeReader extends JEditorPane { | |||
| 166 | Rectangle end = editor.modelToView(token.end); | 157 | Rectangle end = editor.modelToView(token.end); |
| 167 | final Rectangle show = start.union(end); | 158 | final Rectangle show = start.union(end); |
| 168 | show.grow(start.width * 10, start.height * 6); | 159 | show.grow(start.width * 10, start.height * 6); |
| 169 | SwingUtilities.invokeLater(new Runnable() { | 160 | SwingUtilities.invokeLater(() -> editor.scrollRectToVisible(show)); |
| 170 | @Override | ||
| 171 | public void run() { | ||
| 172 | editor.scrollRectToVisible(show); | ||
| 173 | } | ||
| 174 | }); | ||
| 175 | } catch (BadLocationException ex) { | 161 | } catch (BadLocationException ex) { |
| 176 | throw new Error(ex); | 162 | throw new Error(ex); |
| 177 | } | 163 | } |
| @@ -202,12 +188,6 @@ public class CodeReader extends JEditorPane { | |||
| 202 | timer.start(); | 188 | timer.start(); |
| 203 | } | 189 | } |
| 204 | 190 | ||
| 205 | public void setHighlightedTokens(Iterable<Token> tokens, HighlightPainter painter) { | ||
| 206 | for (Token token : tokens) { | ||
| 207 | setHighlightedToken(token, painter); | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | public void setHighlightedToken(Token token, HighlightPainter painter) { | 191 | public void setHighlightedToken(Token token, HighlightPainter painter) { |
| 212 | try { | 192 | try { |
| 213 | getHighlighter().addHighlight(token.start, token.end, painter); | 193 | getHighlighter().addHighlight(token.start, token.end, painter); |
diff --git a/src/main/java/cuchaz/enigma/gui/CrashDialog.java b/src/main/java/cuchaz/enigma/gui/CrashDialog.java index c0c0869..3806f54 100644 --- a/src/main/java/cuchaz/enigma/gui/CrashDialog.java +++ b/src/main/java/cuchaz/enigma/gui/CrashDialog.java | |||
| @@ -13,8 +13,6 @@ package cuchaz.enigma.gui; | |||
| 13 | import java.awt.BorderLayout; | 13 | import java.awt.BorderLayout; |
| 14 | import java.awt.Container; | 14 | import java.awt.Container; |
| 15 | import java.awt.FlowLayout; | 15 | import java.awt.FlowLayout; |
| 16 | import java.awt.event.ActionEvent; | ||
| 17 | import java.awt.event.ActionListener; | ||
| 18 | import java.io.PrintWriter; | 16 | import java.io.PrintWriter; |
| 19 | import java.io.StringWriter; | 17 | import java.io.StringWriter; |
| 20 | 18 | ||
| @@ -31,11 +29,11 @@ public class CrashDialog { | |||
| 31 | 29 | ||
| 32 | private CrashDialog(JFrame parent) { | 30 | private CrashDialog(JFrame parent) { |
| 33 | // init frame | 31 | // init frame |
| 34 | m_frame = new JFrame(Constants.Name + " - Crash Report"); | 32 | m_frame = new JFrame(Constants.NAME + " - Crash Report"); |
| 35 | final Container pane = m_frame.getContentPane(); | 33 | final Container pane = m_frame.getContentPane(); |
| 36 | pane.setLayout(new BorderLayout()); | 34 | pane.setLayout(new BorderLayout()); |
| 37 | 35 | ||
| 38 | JLabel label = new JLabel(Constants.Name + " has crashed! =("); | 36 | JLabel label = new JLabel(Constants.NAME + " has crashed! =("); |
| 39 | label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); | 37 | label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
| 40 | pane.add(label, BorderLayout.NORTH); | 38 | pane.add(label, BorderLayout.NORTH); |
| 41 | 39 | ||
| @@ -51,21 +49,15 @@ public class CrashDialog { | |||
| 51 | buttonsPanel.setLayout(buttonsLayout); | 49 | buttonsPanel.setLayout(buttonsLayout); |
| 52 | buttonsPanel.add(GuiTricks.unboldLabel(new JLabel("If you choose exit, you will lose any unsaved work."))); | 50 | buttonsPanel.add(GuiTricks.unboldLabel(new JLabel("If you choose exit, you will lose any unsaved work."))); |
| 53 | JButton ignoreButton = new JButton("Ignore"); | 51 | JButton ignoreButton = new JButton("Ignore"); |
| 54 | ignoreButton.addActionListener(new ActionListener() { | 52 | ignoreButton.addActionListener(event -> { |
| 55 | @Override | 53 | // close (hide) the dialog |
| 56 | public void actionPerformed(ActionEvent event) { | 54 | m_frame.setVisible(false); |
| 57 | // close (hide) the dialog | ||
| 58 | m_frame.setVisible(false); | ||
| 59 | } | ||
| 60 | }); | 55 | }); |
| 61 | buttonsPanel.add(ignoreButton); | 56 | buttonsPanel.add(ignoreButton); |
| 62 | JButton exitButton = new JButton("Exit"); | 57 | JButton exitButton = new JButton("Exit"); |
| 63 | exitButton.addActionListener(new ActionListener() { | 58 | exitButton.addActionListener(event -> { |
| 64 | @Override | 59 | // exit enigma |
| 65 | public void actionPerformed(ActionEvent event) { | 60 | System.exit(1); |
| 66 | // exit enigma | ||
| 67 | System.exit(1); | ||
| 68 | } | ||
| 69 | }); | 61 | }); |
| 70 | buttonsPanel.add(exitButton); | 62 | buttonsPanel.add(exitButton); |
| 71 | pane.add(buttonsPanel, BorderLayout.SOUTH); | 63 | pane.add(buttonsPanel, BorderLayout.SOUTH); |
diff --git a/src/main/java/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java index d92bb0d..d5ad0c8 100644 --- a/src/main/java/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java | |||
| @@ -15,7 +15,6 @@ import java.awt.Color; | |||
| 15 | public class DeobfuscatedHighlightPainter extends BoxHighlightPainter { | 15 | public class DeobfuscatedHighlightPainter extends BoxHighlightPainter { |
| 16 | 16 | ||
| 17 | public DeobfuscatedHighlightPainter() { | 17 | public DeobfuscatedHighlightPainter() { |
| 18 | // green ish | ||
| 19 | super(new Color(220, 255, 220), new Color(80, 160, 80)); | 18 | super(new Color(220, 255, 220), new Color(80, 160, 80)); |
| 20 | } | 19 | } |
| 21 | } | 20 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index eb26ddd..fee9c9f 100644 --- a/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -16,7 +16,6 @@ import java.awt.*; | |||
| 16 | import java.awt.event.*; | 16 | import java.awt.event.*; |
| 17 | import java.io.File; | 17 | import java.io.File; |
| 18 | import java.io.IOException; | 18 | import java.io.IOException; |
| 19 | import java.lang.Thread.UncaughtExceptionHandler; | ||
| 20 | import java.util.Collection; | 19 | import java.util.Collection; |
| 21 | import java.util.Collections; | 20 | import java.util.Collections; |
| 22 | import java.util.List; | 21 | import java.util.List; |
| @@ -24,8 +23,6 @@ import java.util.Vector; | |||
| 24 | import java.util.jar.JarFile; | 23 | import java.util.jar.JarFile; |
| 25 | 24 | ||
| 26 | import javax.swing.*; | 25 | import javax.swing.*; |
| 27 | import javax.swing.event.CaretEvent; | ||
| 28 | import javax.swing.event.CaretListener; | ||
| 29 | import javax.swing.text.BadLocationException; | 26 | import javax.swing.text.BadLocationException; |
| 30 | import javax.swing.text.Highlighter; | 27 | import javax.swing.text.Highlighter; |
| 31 | import javax.swing.tree.DefaultTreeModel; | 28 | import javax.swing.tree.DefaultTreeModel; |
| @@ -35,7 +32,6 @@ import javax.swing.tree.TreePath; | |||
| 35 | import cuchaz.enigma.Constants; | 32 | import cuchaz.enigma.Constants; |
| 36 | import cuchaz.enigma.ExceptionIgnorer; | 33 | import cuchaz.enigma.ExceptionIgnorer; |
| 37 | import cuchaz.enigma.analysis.*; | 34 | import cuchaz.enigma.analysis.*; |
| 38 | import cuchaz.enigma.gui.ClassSelector.ClassSelectionListener; | ||
| 39 | import cuchaz.enigma.mapping.*; | 35 | import cuchaz.enigma.mapping.*; |
| 40 | import de.sciss.syntaxpane.DefaultSyntaxKit; | 36 | import de.sciss.syntaxpane.DefaultSyntaxKit; |
| 41 | 37 | ||
| @@ -90,20 +86,17 @@ public class Gui { | |||
| 90 | public Gui() { | 86 | public Gui() { |
| 91 | 87 | ||
| 92 | // init frame | 88 | // init frame |
| 93 | m_frame = new JFrame(Constants.Name); | 89 | m_frame = new JFrame(Constants.NAME); |
| 94 | final Container pane = m_frame.getContentPane(); | 90 | final Container pane = m_frame.getContentPane(); |
| 95 | pane.setLayout(new BorderLayout()); | 91 | pane.setLayout(new BorderLayout()); |
| 96 | 92 | ||
| 97 | if (Boolean.parseBoolean(System.getProperty("enigma.catchExceptions", "true"))) { | 93 | if (Boolean.parseBoolean(System.getProperty("enigma.catchExceptions", "true"))) { |
| 98 | // install a global exception handler to the event thread | 94 | // install a global exception handler to the event thread |
| 99 | CrashDialog.init(m_frame); | 95 | CrashDialog.init(m_frame); |
| 100 | Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { | 96 | Thread.setDefaultUncaughtExceptionHandler((thread, t) -> { |
| 101 | @Override | 97 | t.printStackTrace(System.err); |
| 102 | public void uncaughtException(Thread thread, Throwable t) { | 98 | if (!ExceptionIgnorer.shouldIgnore(t)) { |
| 103 | t.printStackTrace(System.err); | 99 | CrashDialog.show(t); |
| 104 | if (!ExceptionIgnorer.shouldIgnore(t)) { | ||
| 105 | CrashDialog.show(t); | ||
| 106 | } | ||
| 107 | } | 100 | } |
| 108 | }); | 101 | }); |
| 109 | } | 102 | } |
| @@ -116,19 +109,14 @@ public class Gui { | |||
| 116 | m_mappingsFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); | 109 | m_mappingsFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
| 117 | m_mappingsFileChooser.setAcceptAllFileFilterUsed(false); | 110 | m_mappingsFileChooser.setAcceptAllFileFilterUsed(false); |
| 118 | 111 | ||
| 119 | m_oldMappingsFileChooser= new JFileChooser(); | 112 | m_oldMappingsFileChooser = new JFileChooser(); |
| 120 | m_exportSourceFileChooser = new JFileChooser(); | 113 | m_exportSourceFileChooser = new JFileChooser(); |
| 121 | m_exportSourceFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); | 114 | m_exportSourceFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
| 122 | m_exportJarFileChooser = new JFileChooser(); | 115 | m_exportJarFileChooser = new JFileChooser(); |
| 123 | 116 | ||
| 124 | // init obfuscated classes list | 117 | // init obfuscated classes list |
| 125 | m_obfClasses = new ClassSelector(ClassSelector.ObfuscatedClassEntryComparator); | 118 | m_obfClasses = new ClassSelector(ClassSelector.ObfuscatedClassEntryComparator); |
| 126 | m_obfClasses.setListener(new ClassSelectionListener() { | 119 | m_obfClasses.setListener(this::navigateTo); |
| 127 | @Override | ||
| 128 | public void onSelectClass(ClassEntry classEntry) { | ||
| 129 | navigateTo(classEntry); | ||
| 130 | } | ||
| 131 | }); | ||
| 132 | JScrollPane obfScroller = new JScrollPane(m_obfClasses); | 120 | JScrollPane obfScroller = new JScrollPane(m_obfClasses); |
| 133 | JPanel obfPanel = new JPanel(); | 121 | JPanel obfPanel = new JPanel(); |
| 134 | obfPanel.setLayout(new BorderLayout()); | 122 | obfPanel.setLayout(new BorderLayout()); |
| @@ -137,12 +125,7 @@ public class Gui { | |||
| 137 | 125 | ||
| 138 | // init deobfuscated classes list | 126 | // init deobfuscated classes list |
| 139 | m_deobfClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); | 127 | m_deobfClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); |
| 140 | m_deobfClasses.setListener(new ClassSelectionListener() { | 128 | m_deobfClasses.setListener(this::navigateTo); |
| 141 | @Override | ||
| 142 | public void onSelectClass(ClassEntry classEntry) { | ||
| 143 | navigateTo(classEntry); | ||
| 144 | } | ||
| 145 | }); | ||
| 146 | JScrollPane deobfScroller = new JScrollPane(m_deobfClasses); | 129 | JScrollPane deobfScroller = new JScrollPane(m_deobfClasses); |
| 147 | JPanel deobfPanel = new JPanel(); | 130 | JPanel deobfPanel = new JPanel(); |
| 148 | deobfPanel.setLayout(new BorderLayout()); | 131 | deobfPanel.setLayout(new BorderLayout()); |
| @@ -174,12 +157,7 @@ public class Gui { | |||
| 174 | m_editor.setCaret(new BrowserCaret()); | 157 | m_editor.setCaret(new BrowserCaret()); |
| 175 | JScrollPane sourceScroller = new JScrollPane(m_editor); | 158 | JScrollPane sourceScroller = new JScrollPane(m_editor); |
| 176 | m_editor.setContentType("text/java"); | 159 | m_editor.setContentType("text/java"); |
| 177 | m_editor.addCaretListener(new CaretListener() { | 160 | m_editor.addCaretListener(event -> onCaretMove(event.getDot())); |
| 178 | @Override | ||
| 179 | public void caretUpdate(CaretEvent event) { | ||
| 180 | onCaretMove(event.getDot()); | ||
| 181 | } | ||
| 182 | }); | ||
| 183 | m_editor.addKeyListener(new KeyAdapter() { | 161 | m_editor.addKeyListener(new KeyAdapter() { |
| 184 | @Override | 162 | @Override |
| 185 | public void keyPressed(KeyEvent event) { | 163 | public void keyPressed(KeyEvent event) { |
| @@ -224,12 +202,7 @@ public class Gui { | |||
| 224 | m_editor.setComponentPopupMenu(popupMenu); | 202 | m_editor.setComponentPopupMenu(popupMenu); |
| 225 | { | 203 | { |
| 226 | JMenuItem menu = new JMenuItem("Rename"); | 204 | JMenuItem menu = new JMenuItem("Rename"); |
| 227 | menu.addActionListener(new ActionListener() { | 205 | menu.addActionListener(event -> startRename()); |
| 228 | @Override | ||
| 229 | public void actionPerformed(ActionEvent event) { | ||
| 230 | startRename(); | ||
| 231 | } | ||
| 232 | }); | ||
| 233 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, 0)); | 206 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, 0)); |
| 234 | menu.setEnabled(false); | 207 | menu.setEnabled(false); |
| 235 | popupMenu.add(menu); | 208 | popupMenu.add(menu); |
| @@ -237,12 +210,7 @@ public class Gui { | |||
| 237 | } | 210 | } |
| 238 | { | 211 | { |
| 239 | JMenuItem menu = new JMenuItem("Show Inheritance"); | 212 | JMenuItem menu = new JMenuItem("Show Inheritance"); |
| 240 | menu.addActionListener(new ActionListener() { | 213 | menu.addActionListener(event -> showInheritance()); |
| 241 | @Override | ||
| 242 | public void actionPerformed(ActionEvent event) { | ||
| 243 | showInheritance(); | ||
| 244 | } | ||
| 245 | }); | ||
| 246 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, 0)); | 214 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, 0)); |
| 247 | menu.setEnabled(false); | 215 | menu.setEnabled(false); |
| 248 | popupMenu.add(menu); | 216 | popupMenu.add(menu); |
| @@ -250,12 +218,7 @@ public class Gui { | |||
| 250 | } | 218 | } |
| 251 | { | 219 | { |
| 252 | JMenuItem menu = new JMenuItem("Show Implementations"); | 220 | JMenuItem menu = new JMenuItem("Show Implementations"); |
| 253 | menu.addActionListener(new ActionListener() { | 221 | menu.addActionListener(event -> showImplementations()); |
| 254 | @Override | ||
| 255 | public void actionPerformed(ActionEvent event) { | ||
| 256 | showImplementations(); | ||
| 257 | } | ||
| 258 | }); | ||
| 259 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, 0)); | 222 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, 0)); |
| 260 | menu.setEnabled(false); | 223 | menu.setEnabled(false); |
| 261 | popupMenu.add(menu); | 224 | popupMenu.add(menu); |
| @@ -263,12 +226,7 @@ public class Gui { | |||
| 263 | } | 226 | } |
| 264 | { | 227 | { |
| 265 | JMenuItem menu = new JMenuItem("Show Calls"); | 228 | JMenuItem menu = new JMenuItem("Show Calls"); |
| 266 | menu.addActionListener(new ActionListener() { | 229 | menu.addActionListener(event -> showCalls()); |
| 267 | @Override | ||
| 268 | public void actionPerformed(ActionEvent event) { | ||
| 269 | showCalls(); | ||
| 270 | } | ||
| 271 | }); | ||
| 272 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 0)); | 230 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 0)); |
| 273 | menu.setEnabled(false); | 231 | menu.setEnabled(false); |
| 274 | popupMenu.add(menu); | 232 | popupMenu.add(menu); |
| @@ -276,12 +234,7 @@ public class Gui { | |||
| 276 | } | 234 | } |
| 277 | { | 235 | { |
| 278 | JMenuItem menu = new JMenuItem("Go to Declaration"); | 236 | JMenuItem menu = new JMenuItem("Go to Declaration"); |
| 279 | menu.addActionListener(new ActionListener() { | 237 | menu.addActionListener(event -> navigateTo(m_reference.entry)); |
| 280 | @Override | ||
| 281 | public void actionPerformed(ActionEvent event) { | ||
| 282 | navigateTo(m_reference.entry); | ||
| 283 | } | ||
| 284 | }); | ||
| 285 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 0)); | 238 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 0)); |
| 286 | menu.setEnabled(false); | 239 | menu.setEnabled(false); |
| 287 | popupMenu.add(menu); | 240 | popupMenu.add(menu); |
| @@ -289,12 +242,7 @@ public class Gui { | |||
| 289 | } | 242 | } |
| 290 | { | 243 | { |
| 291 | JMenuItem menu = new JMenuItem("Go to previous"); | 244 | JMenuItem menu = new JMenuItem("Go to previous"); |
| 292 | menu.addActionListener(new ActionListener() { | 245 | menu.addActionListener(event -> m_controller.openPreviousReference()); |
| 293 | @Override | ||
| 294 | public void actionPerformed(ActionEvent event) { | ||
| 295 | m_controller.openPreviousReference(); | ||
| 296 | } | ||
| 297 | }); | ||
| 298 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, 0)); | 246 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, 0)); |
| 299 | menu.setEnabled(false); | 247 | menu.setEnabled(false); |
| 300 | popupMenu.add(menu); | 248 | popupMenu.add(menu); |
| @@ -302,12 +250,7 @@ public class Gui { | |||
| 302 | } | 250 | } |
| 303 | { | 251 | { |
| 304 | JMenuItem menu = new JMenuItem("Mark as deobfuscated"); | 252 | JMenuItem menu = new JMenuItem("Mark as deobfuscated"); |
| 305 | menu.addActionListener(new ActionListener() { | 253 | menu.addActionListener(event -> toggleMapping()); |
| 306 | @Override | ||
| 307 | public void actionPerformed(ActionEvent event) { | ||
| 308 | toggleMapping(); | ||
| 309 | } | ||
| 310 | }); | ||
| 311 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, 0)); | 254 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, 0)); |
| 312 | menu.setEnabled(false); | 255 | menu.setEnabled(false); |
| 313 | popupMenu.add(menu); | 256 | popupMenu.add(menu); |
| @@ -398,7 +341,7 @@ public class Gui { | |||
| 398 | } | 341 | } |
| 399 | } | 342 | } |
| 400 | }); | 343 | }); |
| 401 | m_tokens = new JList<Token>(); | 344 | m_tokens = new JList<>(); |
| 402 | m_tokens.setCellRenderer(new TokenListCellRenderer(m_controller)); | 345 | m_tokens.setCellRenderer(new TokenListCellRenderer(m_controller)); |
| 403 | m_tokens.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | 346 | m_tokens.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
| 404 | m_tokens.setLayoutOrientation(JList.VERTICAL); | 347 | m_tokens.setLayoutOrientation(JList.VERTICAL); |
| @@ -450,51 +393,40 @@ public class Gui { | |||
| 450 | { | 393 | { |
| 451 | JMenuItem item = new JMenuItem("Open Jar..."); | 394 | JMenuItem item = new JMenuItem("Open Jar..."); |
| 452 | menu.add(item); | 395 | menu.add(item); |
| 453 | item.addActionListener(new ActionListener() { | 396 | item.addActionListener(event -> { |
| 454 | @Override | 397 | if (m_jarFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { |
| 455 | public void actionPerformed(ActionEvent event) { | 398 | // load the jar in a separate thread |
| 456 | if (m_jarFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { | 399 | new Thread() { |
| 457 | // load the jar in a separate thread | 400 | @Override |
| 458 | new Thread() { | 401 | public void run() { |
| 459 | @Override | 402 | try { |
| 460 | public void run() { | 403 | m_controller.openJar(new JarFile(m_jarFileChooser.getSelectedFile())); |
| 461 | try { | 404 | } catch (IOException ex) { |
| 462 | m_controller.openJar(new JarFile(m_jarFileChooser.getSelectedFile())); | 405 | throw new Error(ex); |
| 463 | } catch (IOException ex) { | ||
| 464 | throw new Error(ex); | ||
| 465 | } | ||
| 466 | } | 406 | } |
| 467 | }.start(); | 407 | } |
| 468 | } | 408 | }.start(); |
| 469 | } | 409 | } |
| 470 | }); | 410 | }); |
| 471 | } | 411 | } |
| 472 | { | 412 | { |
| 473 | JMenuItem item = new JMenuItem("Close Jar"); | 413 | JMenuItem item = new JMenuItem("Close Jar"); |
| 474 | menu.add(item); | 414 | menu.add(item); |
| 475 | item.addActionListener(new ActionListener() { | 415 | item.addActionListener(event -> m_controller.closeJar()); |
| 476 | @Override | ||
| 477 | public void actionPerformed(ActionEvent event) { | ||
| 478 | m_controller.closeJar(); | ||
| 479 | } | ||
| 480 | }); | ||
| 481 | m_closeJarMenu = item; | 416 | m_closeJarMenu = item; |
| 482 | } | 417 | } |
| 483 | menu.addSeparator(); | 418 | menu.addSeparator(); |
| 484 | { | 419 | { |
| 485 | JMenuItem item = new JMenuItem("Open Mappings..."); | 420 | JMenuItem item = new JMenuItem("Open Mappings..."); |
| 486 | menu.add(item); | 421 | menu.add(item); |
| 487 | item.addActionListener(new ActionListener() { | 422 | item.addActionListener(event -> { |
| 488 | @Override | 423 | if (m_mappingsFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { |
| 489 | public void actionPerformed(ActionEvent event) { | 424 | try { |
| 490 | if (m_mappingsFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { | 425 | m_controller.openMappings(m_mappingsFileChooser.getSelectedFile()); |
| 491 | try { | 426 | } catch (IOException ex) { |
| 492 | m_controller.openMappings(m_mappingsFileChooser.getSelectedFile()); | 427 | throw new Error(ex); |
| 493 | } catch (IOException ex) { | 428 | } catch (MappingParseException ex) { |
| 494 | throw new Error(ex); | 429 | JOptionPane.showMessageDialog(m_frame, ex.getMessage()); |
| 495 | } catch (MappingParseException ex) { | ||
| 496 | JOptionPane.showMessageDialog(m_frame, ex.getMessage()); | ||
| 497 | } | ||
| 498 | } | 430 | } |
| 499 | } | 431 | } |
| 500 | }); | 432 | }); |
| @@ -520,14 +452,11 @@ public class Gui { | |||
| 520 | { | 452 | { |
| 521 | JMenuItem item = new JMenuItem("Save Mappings"); | 453 | JMenuItem item = new JMenuItem("Save Mappings"); |
| 522 | menu.add(item); | 454 | menu.add(item); |
| 523 | item.addActionListener(new ActionListener() { | 455 | item.addActionListener(event -> { |
| 524 | @Override | 456 | try { |
| 525 | public void actionPerformed(ActionEvent event) { | 457 | m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); |
| 526 | try { | 458 | } catch (IOException ex) { |
| 527 | m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); | 459 | throw new Error(ex); |
| 528 | } catch (IOException ex) { | ||
| 529 | throw new Error(ex); | ||
| 530 | } | ||
| 531 | } | 460 | } |
| 532 | }); | 461 | }); |
| 533 | item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); | 462 | item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); |
| @@ -536,16 +465,13 @@ public class Gui { | |||
| 536 | { | 465 | { |
| 537 | JMenuItem item = new JMenuItem("Save Mappings As..."); | 466 | JMenuItem item = new JMenuItem("Save Mappings As..."); |
| 538 | menu.add(item); | 467 | menu.add(item); |
| 539 | item.addActionListener(new ActionListener() { | 468 | item.addActionListener(event -> { |
| 540 | @Override | 469 | if (m_mappingsFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { |
| 541 | public void actionPerformed(ActionEvent event) { | 470 | try { |
| 542 | if (m_mappingsFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { | 471 | m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); |
| 543 | try { | 472 | m_saveMappingsMenu.setEnabled(true); |
| 544 | m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); | 473 | } catch (IOException ex) { |
| 545 | m_saveMappingsMenu.setEnabled(true); | 474 | throw new Error(ex); |
| 546 | } catch (IOException ex) { | ||
| 547 | throw new Error(ex); | ||
| 548 | } | ||
| 549 | } | 475 | } |
| 550 | } | 476 | } |
| 551 | }); | 477 | }); |
| @@ -555,24 +481,16 @@ public class Gui { | |||
| 555 | { | 481 | { |
| 556 | JMenuItem item = new JMenuItem("Close Mappings"); | 482 | JMenuItem item = new JMenuItem("Close Mappings"); |
| 557 | menu.add(item); | 483 | menu.add(item); |
| 558 | item.addActionListener(new ActionListener() { | 484 | item.addActionListener(event -> m_controller.closeMappings()); |
| 559 | @Override | ||
| 560 | public void actionPerformed(ActionEvent event) { | ||
| 561 | m_controller.closeMappings(); | ||
| 562 | } | ||
| 563 | }); | ||
| 564 | m_closeMappingsMenu = item; | 485 | m_closeMappingsMenu = item; |
| 565 | } | 486 | } |
| 566 | menu.addSeparator(); | 487 | menu.addSeparator(); |
| 567 | { | 488 | { |
| 568 | JMenuItem item = new JMenuItem("Export Source..."); | 489 | JMenuItem item = new JMenuItem("Export Source..."); |
| 569 | menu.add(item); | 490 | menu.add(item); |
| 570 | item.addActionListener(new ActionListener() { | 491 | item.addActionListener(event -> { |
| 571 | @Override | 492 | if (m_exportSourceFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { |
| 572 | public void actionPerformed(ActionEvent event) { | 493 | m_controller.exportSource(m_exportSourceFileChooser.getSelectedFile()); |
| 573 | if (m_exportSourceFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { | ||
| 574 | m_controller.exportSource(m_exportSourceFileChooser.getSelectedFile()); | ||
| 575 | } | ||
| 576 | } | 494 | } |
| 577 | }); | 495 | }); |
| 578 | m_exportSourceMenu = item; | 496 | m_exportSourceMenu = item; |
| @@ -580,12 +498,9 @@ public class Gui { | |||
| 580 | { | 498 | { |
| 581 | JMenuItem item = new JMenuItem("Export Jar..."); | 499 | JMenuItem item = new JMenuItem("Export Jar..."); |
| 582 | menu.add(item); | 500 | menu.add(item); |
| 583 | item.addActionListener(new ActionListener() { | 501 | item.addActionListener(event -> { |
| 584 | @Override | 502 | if (m_exportJarFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { |
| 585 | public void actionPerformed(ActionEvent event) { | 503 | m_controller.exportJar(m_exportJarFileChooser.getSelectedFile()); |
| 586 | if (m_exportJarFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { | ||
| 587 | m_controller.exportJar(m_exportJarFileChooser.getSelectedFile()); | ||
| 588 | } | ||
| 589 | } | 504 | } |
| 590 | }); | 505 | }); |
| 591 | m_exportJarMenu = item; | 506 | m_exportJarMenu = item; |
| @@ -594,12 +509,7 @@ public class Gui { | |||
| 594 | { | 509 | { |
| 595 | JMenuItem item = new JMenuItem("Exit"); | 510 | JMenuItem item = new JMenuItem("Exit"); |
| 596 | menu.add(item); | 511 | menu.add(item); |
| 597 | item.addActionListener(new ActionListener() { | 512 | item.addActionListener(event -> close()); |
| 598 | @Override | ||
| 599 | public void actionPerformed(ActionEvent event) { | ||
| 600 | close(); | ||
| 601 | } | ||
| 602 | }); | ||
| 603 | } | 513 | } |
| 604 | } | 514 | } |
| 605 | { | 515 | { |
| @@ -608,12 +518,7 @@ public class Gui { | |||
| 608 | { | 518 | { |
| 609 | JMenuItem item = new JMenuItem("About"); | 519 | JMenuItem item = new JMenuItem("About"); |
| 610 | menu.add(item); | 520 | menu.add(item); |
| 611 | item.addActionListener(new ActionListener() { | 521 | item.addActionListener(event -> AboutDialog.show(m_frame)); |
| 612 | @Override | ||
| 613 | public void actionPerformed(ActionEvent event) { | ||
| 614 | AboutDialog.show(m_frame); | ||
| 615 | } | ||
| 616 | }); | ||
| 617 | } | 522 | } |
| 618 | } | 523 | } |
| 619 | 524 | ||
| @@ -654,7 +559,7 @@ public class Gui { | |||
| 654 | 559 | ||
| 655 | public void onFinishOpenJar(String jarName) { | 560 | public void onFinishOpenJar(String jarName) { |
| 656 | // update gui | 561 | // update gui |
| 657 | m_frame.setTitle(Constants.Name + " - " + jarName); | 562 | m_frame.setTitle(Constants.NAME + " - " + jarName); |
| 658 | m_classesPanel.removeAll(); | 563 | m_classesPanel.removeAll(); |
| 659 | m_classesPanel.add(m_splitClasses); | 564 | m_classesPanel.add(m_splitClasses); |
| 660 | setSource(null); | 565 | setSource(null); |
| @@ -674,7 +579,7 @@ public class Gui { | |||
| 674 | 579 | ||
| 675 | public void onCloseJar() { | 580 | public void onCloseJar() { |
| 676 | // update gui | 581 | // update gui |
| 677 | m_frame.setTitle(Constants.Name); | 582 | m_frame.setTitle(Constants.NAME); |
| 678 | setObfClasses(null); | 583 | setObfClasses(null); |
| 679 | setDeobfClasses(null); | 584 | setDeobfClasses(null); |
| 680 | setSource(null); | 585 | setSource(null); |
| @@ -720,14 +625,14 @@ public class Gui { | |||
| 720 | } | 625 | } |
| 721 | 626 | ||
| 722 | public void showTokens(Collection<Token> tokens) { | 627 | public void showTokens(Collection<Token> tokens) { |
| 723 | Vector<Token> sortedTokens = new Vector<Token>(tokens); | 628 | Vector<Token> sortedTokens = new Vector<>(tokens); |
| 724 | Collections.sort(sortedTokens); | 629 | Collections.sort(sortedTokens); |
| 725 | if (sortedTokens.size() > 1) { | 630 | if (sortedTokens.size() > 1) { |
| 726 | // sort the tokens and update the tokens panel | 631 | // sort the tokens and update the tokens panel |
| 727 | m_tokens.setListData(sortedTokens); | 632 | m_tokens.setListData(sortedTokens); |
| 728 | m_tokens.setSelectedIndex(0); | 633 | m_tokens.setSelectedIndex(0); |
| 729 | } else { | 634 | } else { |
| 730 | m_tokens.setListData(new Vector<Token>()); | 635 | m_tokens.setListData(new Vector<>()); |
| 731 | } | 636 | } |
| 732 | 637 | ||
| 733 | // show the first token | 638 | // show the first token |
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index a6a2ec5..868e0d4 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -24,162 +24,138 @@ import java.util.List; | |||
| 24 | import java.util.jar.JarFile; | 24 | import java.util.jar.JarFile; |
| 25 | 25 | ||
| 26 | import cuchaz.enigma.Deobfuscator; | 26 | import cuchaz.enigma.Deobfuscator; |
| 27 | import cuchaz.enigma.Deobfuscator.ProgressListener; | ||
| 28 | import cuchaz.enigma.analysis.*; | 27 | import cuchaz.enigma.analysis.*; |
| 29 | import cuchaz.enigma.gui.ProgressDialog.ProgressRunnable; | ||
| 30 | import cuchaz.enigma.mapping.*; | 28 | import cuchaz.enigma.mapping.*; |
| 31 | 29 | ||
| 32 | public class GuiController { | 30 | public class GuiController { |
| 33 | 31 | ||
| 34 | private Deobfuscator m_deobfuscator; | 32 | private Deobfuscator deobfuscator; |
| 35 | private Gui m_gui; | 33 | private Gui gui; |
| 36 | private SourceIndex m_index; | 34 | private SourceIndex index; |
| 37 | private ClassEntry m_currentObfClass; | 35 | private ClassEntry currentObfClass; |
| 38 | private boolean m_isDirty; | 36 | private boolean isDirty; |
| 39 | private Deque<EntryReference<Entry, Entry>> m_referenceStack; | 37 | private Deque<EntryReference<Entry, Entry>> referenceStack; |
| 40 | 38 | ||
| 41 | public GuiController(Gui gui) { | 39 | public GuiController(Gui gui) { |
| 42 | m_gui = gui; | 40 | this.gui = gui; |
| 43 | m_deobfuscator = null; | 41 | this.deobfuscator = null; |
| 44 | m_index = null; | 42 | this.index = null; |
| 45 | m_currentObfClass = null; | 43 | this.currentObfClass = null; |
| 46 | m_isDirty = false; | 44 | this.isDirty = false; |
| 47 | m_referenceStack = Queues.newArrayDeque(); | 45 | this.referenceStack = Queues.newArrayDeque(); |
| 48 | } | 46 | } |
| 49 | 47 | ||
| 50 | public boolean isDirty() { | 48 | public boolean isDirty() { |
| 51 | return m_isDirty; | 49 | return this.isDirty; |
| 52 | } | 50 | } |
| 53 | 51 | ||
| 54 | public void openJar(final JarFile jar) throws IOException { | 52 | public void openJar(final JarFile jar) throws IOException { |
| 55 | m_gui.onStartOpenJar(); | 53 | this.gui.onStartOpenJar(); |
| 56 | m_deobfuscator = new Deobfuscator(jar); | 54 | this.deobfuscator = new Deobfuscator(jar); |
| 57 | m_gui.onFinishOpenJar(m_deobfuscator.getJarName()); | 55 | this.gui.onFinishOpenJar(this.deobfuscator.getJarName()); |
| 58 | refreshClasses(); | 56 | refreshClasses(); |
| 59 | } | 57 | } |
| 60 | 58 | ||
| 61 | public void closeJar() { | 59 | public void closeJar() { |
| 62 | m_deobfuscator = null; | 60 | this.deobfuscator = null; |
| 63 | m_gui.onCloseJar(); | 61 | this.gui.onCloseJar(); |
| 64 | } | 62 | } |
| 65 | 63 | ||
| 66 | public void openOldMappings(File file) throws IOException, MappingParseException { | 64 | public void openOldMappings(File file) throws IOException, MappingParseException { |
| 67 | FileReader in = new FileReader(file); | 65 | FileReader in = new FileReader(file); |
| 68 | m_deobfuscator.setMappings(new MappingsReaderOld().read(in)); | 66 | this.deobfuscator.setMappings(new MappingsReaderOld().read(in)); |
| 69 | in.close(); | 67 | in.close(); |
| 70 | m_isDirty = false; | 68 | this.isDirty = false; |
| 71 | m_gui.setMappingsFile(file); | 69 | this.gui.setMappingsFile(file); |
| 72 | refreshClasses(); | 70 | refreshClasses(); |
| 73 | refreshCurrentClass(); | 71 | refreshCurrentClass(); |
| 74 | } | 72 | } |
| 75 | 73 | ||
| 76 | public void openMappings(File file) throws IOException, MappingParseException { | 74 | public void openMappings(File file) throws IOException, MappingParseException { |
| 77 | m_deobfuscator.setMappings(new MappingsReader().read(file)); | 75 | this.deobfuscator.setMappings(new MappingsReader().read(file)); |
| 78 | m_isDirty = false; | 76 | this.isDirty = false; |
| 79 | m_gui.setMappingsFile(file); | 77 | this.gui.setMappingsFile(file); |
| 80 | refreshClasses(); | 78 | refreshClasses(); |
| 81 | refreshCurrentClass(); | 79 | refreshCurrentClass(); |
| 82 | } | 80 | } |
| 83 | 81 | ||
| 84 | public void saveMappings(File file) throws IOException { | 82 | public void saveMappings(File file) throws IOException { |
| 85 | new MappingsWriter().write(file, m_deobfuscator.getMappings()); | 83 | new MappingsWriter().write(file, this.deobfuscator.getMappings()); |
| 86 | m_isDirty = false; | 84 | this.isDirty = false; |
| 87 | } | 85 | } |
| 88 | 86 | ||
| 89 | public void closeMappings() { | 87 | public void closeMappings() { |
| 90 | m_deobfuscator.setMappings(null); | 88 | this.deobfuscator.setMappings(null); |
| 91 | m_gui.setMappingsFile(null); | 89 | this.gui.setMappingsFile(null); |
| 92 | refreshClasses(); | 90 | refreshClasses(); |
| 93 | refreshCurrentClass(); | 91 | refreshCurrentClass(); |
| 94 | } | 92 | } |
| 95 | 93 | ||
| 96 | public void exportSource(final File dirOut) { | 94 | public void exportSource(final File dirOut) { |
| 97 | ProgressDialog.runInThread(m_gui.getFrame(), new ProgressRunnable() { | 95 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeSources(dirOut, progress)); |
| 98 | @Override | ||
| 99 | public void run(ProgressListener progress) throws Exception { | ||
| 100 | m_deobfuscator.writeSources(dirOut, progress); | ||
| 101 | } | ||
| 102 | }); | ||
| 103 | } | 96 | } |
| 104 | 97 | ||
| 105 | public void exportJar(final File fileOut) { | 98 | public void exportJar(final File fileOut) { |
| 106 | ProgressDialog.runInThread(m_gui.getFrame(), new ProgressRunnable() { | 99 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeJar(fileOut, progress)); |
| 107 | @Override | ||
| 108 | public void run(ProgressListener progress) { | ||
| 109 | m_deobfuscator.writeJar(fileOut, progress); | ||
| 110 | } | ||
| 111 | }); | ||
| 112 | } | 100 | } |
| 113 | 101 | ||
| 114 | public Token getToken(int pos) { | 102 | public Token getToken(int pos) { |
| 115 | if (m_index == null) { | 103 | if (this.index == null) { |
| 116 | return null; | 104 | return null; |
| 117 | } | 105 | } |
| 118 | return m_index.getReferenceToken(pos); | 106 | return this.index.getReferenceToken(pos); |
| 119 | } | 107 | } |
| 120 | 108 | ||
| 121 | public EntryReference<Entry, Entry> getDeobfReference(Token token) { | 109 | public EntryReference<Entry, Entry> getDeobfReference(Token token) { |
| 122 | if (m_index == null) { | 110 | if (this.index == null) { |
| 123 | return null; | 111 | return null; |
| 124 | } | 112 | } |
| 125 | return m_index.getDeobfReference(token); | 113 | return this.index.getDeobfReference(token); |
| 126 | } | 114 | } |
| 127 | 115 | ||
| 128 | public ReadableToken getReadableToken(Token token) { | 116 | public ReadableToken getReadableToken(Token token) { |
| 129 | if (m_index == null) { | 117 | if (this.index == null) { |
| 130 | return null; | 118 | return null; |
| 131 | } | 119 | } |
| 132 | return new ReadableToken( | 120 | return new ReadableToken( |
| 133 | m_index.getLineNumber(token.start), | 121 | this.index.getLineNumber(token.start), |
| 134 | m_index.getColumnNumber(token.start), | 122 | this.index.getColumnNumber(token.start), |
| 135 | m_index.getColumnNumber(token.end) | 123 | this.index.getColumnNumber(token.end) |
| 136 | ); | 124 | ); |
| 137 | } | 125 | } |
| 138 | 126 | ||
| 139 | public boolean entryHasDeobfuscatedName(Entry deobfEntry) { | 127 | public boolean entryHasDeobfuscatedName(Entry deobfEntry) { |
| 140 | return m_deobfuscator.hasDeobfuscatedName(m_deobfuscator.obfuscateEntry(deobfEntry)); | 128 | return this.deobfuscator.hasDeobfuscatedName(this.deobfuscator.obfuscateEntry(deobfEntry)); |
| 141 | } | 129 | } |
| 142 | 130 | ||
| 143 | public boolean entryIsInJar(Entry deobfEntry) { | 131 | public boolean entryIsInJar(Entry deobfEntry) { |
| 144 | return m_deobfuscator.isObfuscatedIdentifier(m_deobfuscator.obfuscateEntry(deobfEntry)); | 132 | return this.deobfuscator.isObfuscatedIdentifier(this.deobfuscator.obfuscateEntry(deobfEntry)); |
| 145 | } | 133 | } |
| 146 | 134 | ||
| 147 | public boolean referenceIsRenameable(EntryReference<Entry, Entry> deobfReference) { | 135 | public boolean referenceIsRenameable(EntryReference<Entry, Entry> deobfReference) { |
| 148 | return m_deobfuscator.isRenameable(m_deobfuscator.obfuscateReference(deobfReference)); | 136 | return this.deobfuscator.isRenameable(this.deobfuscator.obfuscateReference(deobfReference)); |
| 149 | } | 137 | } |
| 150 | 138 | ||
| 151 | public ClassInheritanceTreeNode getClassInheritance(ClassEntry deobfClassEntry) { | 139 | public ClassInheritanceTreeNode getClassInheritance(ClassEntry deobfClassEntry) { |
| 152 | ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry(deobfClassEntry); | 140 | ClassEntry obfClassEntry = this.deobfuscator.obfuscateEntry(deobfClassEntry); |
| 153 | ClassInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getClassInheritance( | 141 | ClassInheritanceTreeNode rootNode = this.deobfuscator.getJarIndex().getClassInheritance(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry); |
| 154 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), | ||
| 155 | obfClassEntry | ||
| 156 | ); | ||
| 157 | return ClassInheritanceTreeNode.findNode(rootNode, obfClassEntry); | 142 | return ClassInheritanceTreeNode.findNode(rootNode, obfClassEntry); |
| 158 | } | 143 | } |
| 159 | 144 | ||
| 160 | public ClassImplementationsTreeNode getClassImplementations(ClassEntry deobfClassEntry) { | 145 | public ClassImplementationsTreeNode getClassImplementations(ClassEntry deobfClassEntry) { |
| 161 | ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry(deobfClassEntry); | 146 | ClassEntry obfClassEntry = this.deobfuscator.obfuscateEntry(deobfClassEntry); |
| 162 | return m_deobfuscator.getJarIndex().getClassImplementations( | 147 | return this.deobfuscator.getJarIndex().getClassImplementations(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry); |
| 163 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), | ||
| 164 | obfClassEntry | ||
| 165 | ); | ||
| 166 | } | 148 | } |
| 167 | 149 | ||
| 168 | public MethodInheritanceTreeNode getMethodInheritance(MethodEntry deobfMethodEntry) { | 150 | public MethodInheritanceTreeNode getMethodInheritance(MethodEntry deobfMethodEntry) { |
| 169 | MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry(deobfMethodEntry); | 151 | MethodEntry obfMethodEntry = this.deobfuscator.obfuscateEntry(deobfMethodEntry); |
| 170 | MethodInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getMethodInheritance( | 152 | MethodInheritanceTreeNode rootNode = this.deobfuscator.getJarIndex().getMethodInheritance(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry); |
| 171 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), | ||
| 172 | obfMethodEntry | ||
| 173 | ); | ||
| 174 | return MethodInheritanceTreeNode.findNode(rootNode, obfMethodEntry); | 153 | return MethodInheritanceTreeNode.findNode(rootNode, obfMethodEntry); |
| 175 | } | 154 | } |
| 176 | 155 | ||
| 177 | public MethodImplementationsTreeNode getMethodImplementations(MethodEntry deobfMethodEntry) { | 156 | public MethodImplementationsTreeNode getMethodImplementations(MethodEntry deobfMethodEntry) { |
| 178 | MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry(deobfMethodEntry); | 157 | MethodEntry obfMethodEntry = this.deobfuscator.obfuscateEntry(deobfMethodEntry); |
| 179 | List<MethodImplementationsTreeNode> rootNodes = m_deobfuscator.getJarIndex().getMethodImplementations( | 158 | List<MethodImplementationsTreeNode> rootNodes = this.deobfuscator.getJarIndex().getMethodImplementations(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry); |
| 180 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), | ||
| 181 | obfMethodEntry | ||
| 182 | ); | ||
| 183 | if (rootNodes.isEmpty()) { | 159 | if (rootNodes.isEmpty()) { |
| 184 | return null; | 160 | return null; |
| 185 | } | 161 | } |
| @@ -190,45 +166,39 @@ public class GuiController { | |||
| 190 | } | 166 | } |
| 191 | 167 | ||
| 192 | public FieldReferenceTreeNode getFieldReferences(FieldEntry deobfFieldEntry) { | 168 | public FieldReferenceTreeNode getFieldReferences(FieldEntry deobfFieldEntry) { |
| 193 | FieldEntry obfFieldEntry = m_deobfuscator.obfuscateEntry(deobfFieldEntry); | 169 | FieldEntry obfFieldEntry = this.deobfuscator.obfuscateEntry(deobfFieldEntry); |
| 194 | FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode( | 170 | FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfFieldEntry); |
| 195 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), | 171 | rootNode.load(this.deobfuscator.getJarIndex(), true); |
| 196 | obfFieldEntry | ||
| 197 | ); | ||
| 198 | rootNode.load(m_deobfuscator.getJarIndex(), true); | ||
| 199 | return rootNode; | 172 | return rootNode; |
| 200 | } | 173 | } |
| 201 | 174 | ||
| 202 | public BehaviorReferenceTreeNode getMethodReferences(BehaviorEntry deobfBehaviorEntry) { | 175 | public BehaviorReferenceTreeNode getMethodReferences(BehaviorEntry deobfBehaviorEntry) { |
| 203 | BehaviorEntry obfBehaviorEntry = m_deobfuscator.obfuscateEntry(deobfBehaviorEntry); | 176 | BehaviorEntry obfBehaviorEntry = this.deobfuscator.obfuscateEntry(deobfBehaviorEntry); |
| 204 | BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode( | 177 | BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfBehaviorEntry); |
| 205 | m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), | 178 | rootNode.load(this.deobfuscator.getJarIndex(), true); |
| 206 | obfBehaviorEntry | ||
| 207 | ); | ||
| 208 | rootNode.load(m_deobfuscator.getJarIndex(), true); | ||
| 209 | return rootNode; | 179 | return rootNode; |
| 210 | } | 180 | } |
| 211 | 181 | ||
| 212 | public void rename(EntryReference<Entry, Entry> deobfReference, String newName) { | 182 | public void rename(EntryReference<Entry, Entry> deobfReference, String newName) { |
| 213 | EntryReference<Entry, Entry> obfReference = m_deobfuscator.obfuscateReference(deobfReference); | 183 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); |
| 214 | m_deobfuscator.rename(obfReference.getNameableEntry(), newName); | 184 | this.deobfuscator.rename(obfReference.getNameableEntry(), newName); |
| 215 | m_isDirty = true; | 185 | this.isDirty = true; |
| 216 | refreshClasses(); | 186 | refreshClasses(); |
| 217 | refreshCurrentClass(obfReference); | 187 | refreshCurrentClass(obfReference); |
| 218 | } | 188 | } |
| 219 | 189 | ||
| 220 | public void removeMapping(EntryReference<Entry, Entry> deobfReference) { | 190 | public void removeMapping(EntryReference<Entry, Entry> deobfReference) { |
| 221 | EntryReference<Entry, Entry> obfReference = m_deobfuscator.obfuscateReference(deobfReference); | 191 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); |
| 222 | m_deobfuscator.removeMapping(obfReference.getNameableEntry()); | 192 | this.deobfuscator.removeMapping(obfReference.getNameableEntry()); |
| 223 | m_isDirty = true; | 193 | this.isDirty = true; |
| 224 | refreshClasses(); | 194 | refreshClasses(); |
| 225 | refreshCurrentClass(obfReference); | 195 | refreshCurrentClass(obfReference); |
| 226 | } | 196 | } |
| 227 | 197 | ||
| 228 | public void markAsDeobfuscated(EntryReference<Entry, Entry> deobfReference) { | 198 | public void markAsDeobfuscated(EntryReference<Entry, Entry> deobfReference) { |
| 229 | EntryReference<Entry, Entry> obfReference = m_deobfuscator.obfuscateReference(deobfReference); | 199 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); |
| 230 | m_deobfuscator.markAsDeobfuscated(obfReference.getNameableEntry()); | 200 | this.deobfuscator.markAsDeobfuscated(obfReference.getNameableEntry()); |
| 231 | m_isDirty = true; | 201 | this.isDirty = true; |
| 232 | refreshClasses(); | 202 | refreshClasses(); |
| 233 | refreshCurrentClass(obfReference); | 203 | refreshCurrentClass(obfReference); |
| 234 | } | 204 | } |
| @@ -237,7 +207,7 @@ public class GuiController { | |||
| 237 | if (deobfEntry == null) { | 207 | if (deobfEntry == null) { |
| 238 | throw new IllegalArgumentException("Entry cannot be null!"); | 208 | throw new IllegalArgumentException("Entry cannot be null!"); |
| 239 | } | 209 | } |
| 240 | openReference(new EntryReference<Entry, Entry>(deobfEntry, deobfEntry.getName())); | 210 | openReference(new EntryReference<>(deobfEntry, deobfEntry.getName())); |
| 241 | } | 211 | } |
| 242 | 212 | ||
| 243 | public void openReference(EntryReference<Entry, Entry> deobfReference) { | 213 | public void openReference(EntryReference<Entry, Entry> deobfReference) { |
| @@ -246,51 +216,51 @@ public class GuiController { | |||
| 246 | } | 216 | } |
| 247 | 217 | ||
| 248 | // get the reference target class | 218 | // get the reference target class |
| 249 | EntryReference<Entry, Entry> obfReference = m_deobfuscator.obfuscateReference(deobfReference); | 219 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); |
| 250 | ClassEntry obfClassEntry = obfReference.getLocationClassEntry().getOutermostClassEntry(); | 220 | ClassEntry obfClassEntry = obfReference.getLocationClassEntry().getOutermostClassEntry(); |
| 251 | if (!m_deobfuscator.isObfuscatedIdentifier(obfClassEntry)) { | 221 | if (!this.deobfuscator.isObfuscatedIdentifier(obfClassEntry)) { |
| 252 | throw new IllegalArgumentException("Obfuscated class " + obfClassEntry + " was not found in the jar!"); | 222 | throw new IllegalArgumentException("Obfuscated class " + obfClassEntry + " was not found in the jar!"); |
| 253 | } | 223 | } |
| 254 | if (m_currentObfClass == null || !m_currentObfClass.equals(obfClassEntry)) { | 224 | if (this.currentObfClass == null || !this.currentObfClass.equals(obfClassEntry)) { |
| 255 | // deobfuscate the class, then navigate to the reference | 225 | // deobfuscate the class, then navigate to the reference |
| 256 | m_currentObfClass = obfClassEntry; | 226 | this.currentObfClass = obfClassEntry; |
| 257 | deobfuscate(m_currentObfClass, obfReference); | 227 | deobfuscate(this.currentObfClass, obfReference); |
| 258 | } else { | 228 | } else { |
| 259 | showReference(obfReference); | 229 | showReference(obfReference); |
| 260 | } | 230 | } |
| 261 | } | 231 | } |
| 262 | 232 | ||
| 263 | private void showReference(EntryReference<Entry, Entry> obfReference) { | 233 | private void showReference(EntryReference<Entry, Entry> obfReference) { |
| 264 | EntryReference<Entry, Entry> deobfReference = m_deobfuscator.deobfuscateReference(obfReference); | 234 | EntryReference<Entry, Entry> deobfReference = this.deobfuscator.deobfuscateReference(obfReference); |
| 265 | Collection<Token> tokens = m_index.getReferenceTokens(deobfReference); | 235 | Collection<Token> tokens = this.index.getReferenceTokens(deobfReference); |
| 266 | if (tokens.isEmpty()) { | 236 | if (tokens.isEmpty()) { |
| 267 | // DEBUG | 237 | // DEBUG |
| 268 | System.err.println(String.format("WARNING: no tokens found for %s in %s", deobfReference, m_currentObfClass)); | 238 | System.err.println(String.format("WARNING: no tokens found for %s in %s", deobfReference, this.currentObfClass)); |
| 269 | } else { | 239 | } else { |
| 270 | m_gui.showTokens(tokens); | 240 | this.gui.showTokens(tokens); |
| 271 | } | 241 | } |
| 272 | } | 242 | } |
| 273 | 243 | ||
| 274 | public void savePreviousReference(EntryReference<Entry, Entry> deobfReference) { | 244 | public void savePreviousReference(EntryReference<Entry, Entry> deobfReference) { |
| 275 | m_referenceStack.push(m_deobfuscator.obfuscateReference(deobfReference)); | 245 | this.referenceStack.push(this.deobfuscator.obfuscateReference(deobfReference)); |
| 276 | } | 246 | } |
| 277 | 247 | ||
| 278 | public void openPreviousReference() { | 248 | public void openPreviousReference() { |
| 279 | if (hasPreviousLocation()) { | 249 | if (hasPreviousLocation()) { |
| 280 | openReference(m_deobfuscator.deobfuscateReference(m_referenceStack.pop())); | 250 | openReference(this.deobfuscator.deobfuscateReference(this.referenceStack.pop())); |
| 281 | } | 251 | } |
| 282 | } | 252 | } |
| 283 | 253 | ||
| 284 | public boolean hasPreviousLocation() { | 254 | public boolean hasPreviousLocation() { |
| 285 | return !m_referenceStack.isEmpty(); | 255 | return !this.referenceStack.isEmpty(); |
| 286 | } | 256 | } |
| 287 | 257 | ||
| 288 | private void refreshClasses() { | 258 | private void refreshClasses() { |
| 289 | List<ClassEntry> obfClasses = Lists.newArrayList(); | 259 | List<ClassEntry> obfClasses = Lists.newArrayList(); |
| 290 | List<ClassEntry> deobfClasses = Lists.newArrayList(); | 260 | List<ClassEntry> deobfClasses = Lists.newArrayList(); |
| 291 | m_deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); | 261 | this.deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); |
| 292 | m_gui.setObfClasses(obfClasses); | 262 | this.gui.setObfClasses(obfClasses); |
| 293 | m_gui.setDeobfClasses(deobfClasses); | 263 | this.gui.setDeobfClasses(deobfClasses); |
| 294 | } | 264 | } |
| 295 | 265 | ||
| 296 | private void refreshCurrentClass() { | 266 | private void refreshCurrentClass() { |
| @@ -298,29 +268,29 @@ public class GuiController { | |||
| 298 | } | 268 | } |
| 299 | 269 | ||
| 300 | private void refreshCurrentClass(EntryReference<Entry, Entry> obfReference) { | 270 | private void refreshCurrentClass(EntryReference<Entry, Entry> obfReference) { |
| 301 | if (m_currentObfClass != null) { | 271 | if (this.currentObfClass != null) { |
| 302 | deobfuscate(m_currentObfClass, obfReference); | 272 | deobfuscate(this.currentObfClass, obfReference); |
| 303 | } | 273 | } |
| 304 | } | 274 | } |
| 305 | 275 | ||
| 306 | private void deobfuscate(final ClassEntry classEntry, final EntryReference<Entry, Entry> obfReference) { | 276 | private void deobfuscate(final ClassEntry classEntry, final EntryReference<Entry, Entry> obfReference) { |
| 307 | 277 | ||
| 308 | m_gui.setSource("(deobfuscating...)"); | 278 | this.gui.setSource("(deobfuscating...)"); |
| 309 | 279 | ||
| 310 | // run the deobfuscator in a separate thread so we don't block the GUI event queue | 280 | // run the deobfuscator in a separate thread so we don't block the GUI event queue |
| 311 | new Thread() { | 281 | new Thread() { |
| 312 | @Override | 282 | @Override |
| 313 | public void run() { | 283 | public void run() { |
| 314 | // decompile,deobfuscate the bytecode | 284 | // decompile,deobfuscate the bytecode |
| 315 | CompilationUnit sourceTree = m_deobfuscator.getSourceTree(classEntry.getClassName()); | 285 | CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getClassName()); |
| 316 | if (sourceTree == null) { | 286 | if (sourceTree == null) { |
| 317 | // decompilation of this class is not supported | 287 | // decompilation of this class is not supported |
| 318 | m_gui.setSource("Unable to find class: " + classEntry); | 288 | gui.setSource("Unable to find class: " + classEntry); |
| 319 | return; | 289 | return; |
| 320 | } | 290 | } |
| 321 | String source = m_deobfuscator.getSource(sourceTree); | 291 | String source = deobfuscator.getSource(sourceTree); |
| 322 | m_index = m_deobfuscator.getSourceIndex(sourceTree, source); | 292 | index = deobfuscator.getSourceIndex(sourceTree, source); |
| 323 | m_gui.setSource(m_index.getSource()); | 293 | gui.setSource(index.getSource()); |
| 324 | if (obfReference != null) { | 294 | if (obfReference != null) { |
| 325 | showReference(obfReference); | 295 | showReference(obfReference); |
| 326 | } | 296 | } |
| @@ -329,8 +299,8 @@ public class GuiController { | |||
| 329 | List<Token> obfuscatedTokens = Lists.newArrayList(); | 299 | List<Token> obfuscatedTokens = Lists.newArrayList(); |
| 330 | List<Token> deobfuscatedTokens = Lists.newArrayList(); | 300 | List<Token> deobfuscatedTokens = Lists.newArrayList(); |
| 331 | List<Token> otherTokens = Lists.newArrayList(); | 301 | List<Token> otherTokens = Lists.newArrayList(); |
| 332 | for (Token token : m_index.referenceTokens()) { | 302 | for (Token token : index.referenceTokens()) { |
| 333 | EntryReference<Entry, Entry> reference = m_index.getDeobfReference(token); | 303 | EntryReference<Entry, Entry> reference = index.getDeobfReference(token); |
| 334 | if (referenceIsRenameable(reference)) { | 304 | if (referenceIsRenameable(reference)) { |
| 335 | if (entryHasDeobfuscatedName(reference.getNameableEntry())) { | 305 | if (entryHasDeobfuscatedName(reference.getNameableEntry())) { |
| 336 | deobfuscatedTokens.add(token); | 306 | deobfuscatedTokens.add(token); |
| @@ -341,7 +311,7 @@ public class GuiController { | |||
| 341 | otherTokens.add(token); | 311 | otherTokens.add(token); |
| 342 | } | 312 | } |
| 343 | } | 313 | } |
| 344 | m_gui.setHighlightedTokens(obfuscatedTokens, deobfuscatedTokens, otherTokens); | 314 | gui.setHighlightedTokens(obfuscatedTokens, deobfuscatedTokens, otherTokens); |
| 345 | } | 315 | } |
| 346 | }.start(); | 316 | }.start(); |
| 347 | } | 317 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/GuiTricks.java b/src/main/java/cuchaz/enigma/gui/GuiTricks.java index da2ec74..ffacfec 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiTricks.java +++ b/src/main/java/cuchaz/enigma/gui/GuiTricks.java | |||
| @@ -40,17 +40,13 @@ public class GuiTricks { | |||
| 40 | public static void deactivateButton(JButton button) { | 40 | public static void deactivateButton(JButton button) { |
| 41 | button.setEnabled(false); | 41 | button.setEnabled(false); |
| 42 | button.setText(""); | 42 | button.setText(""); |
| 43 | for (ActionListener listener : Arrays.asList(button.getActionListeners())) { | 43 | Arrays.asList(button.getActionListeners()).forEach(button::removeActionListener); |
| 44 | button.removeActionListener(listener); | ||
| 45 | } | ||
| 46 | } | 44 | } |
| 47 | 45 | ||
| 48 | public static void activateButton(JButton button, String text, ActionListener newListener) { | 46 | public static void activateButton(JButton button, String text, ActionListener newListener) { |
| 49 | button.setText(text); | 47 | button.setText(text); |
| 50 | button.setEnabled(true); | 48 | button.setEnabled(true); |
| 51 | for (ActionListener listener : Arrays.asList(button.getActionListeners())) { | 49 | Arrays.asList(button.getActionListeners()).forEach(button::removeActionListener); |
| 52 | button.removeActionListener(listener); | ||
| 53 | } | ||
| 54 | button.addActionListener(newListener); | 50 | button.addActionListener(newListener); |
| 55 | } | 51 | } |
| 56 | } | 52 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java b/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java index 4b79b77..f083e50 100644 --- a/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java +++ b/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java | |||
| @@ -17,7 +17,6 @@ import java.awt.BorderLayout; | |||
| 17 | import java.awt.Container; | 17 | import java.awt.Container; |
| 18 | import java.awt.Dimension; | 18 | import java.awt.Dimension; |
| 19 | import java.awt.FlowLayout; | 19 | import java.awt.FlowLayout; |
| 20 | import java.awt.event.ActionEvent; | ||
| 21 | import java.awt.event.ActionListener; | 20 | import java.awt.event.ActionListener; |
| 22 | import java.awt.event.KeyAdapter; | 21 | import java.awt.event.KeyAdapter; |
| 23 | import java.awt.event.KeyEvent; | 22 | import java.awt.event.KeyEvent; |
| @@ -30,12 +29,10 @@ import javax.swing.text.Highlighter.HighlightPainter; | |||
| 30 | 29 | ||
| 31 | import cuchaz.enigma.Constants; | 30 | import cuchaz.enigma.Constants; |
| 32 | import cuchaz.enigma.Deobfuscator; | 31 | import cuchaz.enigma.Deobfuscator; |
| 33 | import cuchaz.enigma.analysis.EntryReference; | ||
| 34 | import cuchaz.enigma.analysis.SourceIndex; | 32 | import cuchaz.enigma.analysis.SourceIndex; |
| 35 | import cuchaz.enigma.analysis.Token; | 33 | import cuchaz.enigma.analysis.Token; |
| 36 | import cuchaz.enigma.convert.ClassMatches; | 34 | import cuchaz.enigma.convert.ClassMatches; |
| 37 | import cuchaz.enigma.convert.MemberMatches; | 35 | import cuchaz.enigma.convert.MemberMatches; |
| 38 | import cuchaz.enigma.gui.ClassSelector.ClassSelectionListener; | ||
| 39 | import cuchaz.enigma.mapping.ClassEntry; | 36 | import cuchaz.enigma.mapping.ClassEntry; |
| 40 | import cuchaz.enigma.mapping.Entry; | 37 | import cuchaz.enigma.mapping.Entry; |
| 41 | import de.sciss.syntaxpane.DefaultSyntaxKit; | 38 | import de.sciss.syntaxpane.DefaultSyntaxKit; |
| @@ -108,7 +105,7 @@ public class MemberMatchingGui<T extends Entry> { | |||
| 108 | m_destDeobfuscator = destDeobfuscator; | 105 | m_destDeobfuscator = destDeobfuscator; |
| 109 | 106 | ||
| 110 | // init frame | 107 | // init frame |
| 111 | m_frame = new JFrame(Constants.Name + " - Member Matcher"); | 108 | m_frame = new JFrame(Constants.NAME + " - Member Matcher"); |
| 112 | final Container pane = m_frame.getContentPane(); | 109 | final Container pane = m_frame.getContentPane(); |
| 113 | pane.setLayout(new BorderLayout()); | 110 | pane.setLayout(new BorderLayout()); |
| 114 | 111 | ||
| @@ -123,12 +120,7 @@ public class MemberMatchingGui<T extends Entry> { | |||
| 123 | JPanel sourceTypePanel = new JPanel(); | 120 | JPanel sourceTypePanel = new JPanel(); |
| 124 | classesPanel.add(sourceTypePanel); | 121 | classesPanel.add(sourceTypePanel); |
| 125 | sourceTypePanel.setLayout(new BoxLayout(sourceTypePanel, BoxLayout.PAGE_AXIS)); | 122 | sourceTypePanel.setLayout(new BoxLayout(sourceTypePanel, BoxLayout.PAGE_AXIS)); |
| 126 | ActionListener sourceTypeListener = new ActionListener() { | 123 | ActionListener sourceTypeListener = event -> setSourceType(SourceType.valueOf(event.getActionCommand())); |
| 127 | @Override | ||
| 128 | public void actionPerformed(ActionEvent event) { | ||
| 129 | setSourceType(SourceType.valueOf(event.getActionCommand())); | ||
| 130 | } | ||
| 131 | }; | ||
| 132 | ButtonGroup sourceTypeButtons = new ButtonGroup(); | 124 | ButtonGroup sourceTypeButtons = new ButtonGroup(); |
| 133 | m_sourceTypeButtons = Maps.newHashMap(); | 125 | m_sourceTypeButtons = Maps.newHashMap(); |
| 134 | for (SourceType sourceType : SourceType.values()) { | 126 | for (SourceType sourceType : SourceType.values()) { |
| @@ -138,37 +130,26 @@ public class MemberMatchingGui<T extends Entry> { | |||
| 138 | } | 130 | } |
| 139 | 131 | ||
| 140 | m_sourceClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); | 132 | m_sourceClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); |
| 141 | m_sourceClasses.setListener(new ClassSelectionListener() { | 133 | m_sourceClasses.setListener(this::setSourceClass); |
| 142 | @Override | ||
| 143 | public void onSelectClass(ClassEntry classEntry) { | ||
| 144 | setSourceClass(classEntry); | ||
| 145 | } | ||
| 146 | }); | ||
| 147 | JScrollPane sourceScroller = new JScrollPane(m_sourceClasses); | 134 | JScrollPane sourceScroller = new JScrollPane(m_sourceClasses); |
| 148 | classesPanel.add(sourceScroller); | 135 | classesPanel.add(sourceScroller); |
| 149 | 136 | ||
| 150 | // init readers | 137 | // init readers |
| 151 | DefaultSyntaxKit.initKit(); | 138 | DefaultSyntaxKit.initKit(); |
| 152 | m_sourceReader = new CodeReader(); | 139 | m_sourceReader = new CodeReader(); |
| 153 | m_sourceReader.setSelectionListener(new CodeReader.SelectionListener() { | 140 | m_sourceReader.setSelectionListener(reference -> { |
| 154 | @Override | 141 | if (reference != null) { |
| 155 | public void onSelect(EntryReference<Entry, Entry> reference) { | 142 | onSelectSource(reference.entry); |
| 156 | if (reference != null) { | 143 | } else { |
| 157 | onSelectSource(reference.entry); | 144 | onSelectSource(null); |
| 158 | } else { | ||
| 159 | onSelectSource(null); | ||
| 160 | } | ||
| 161 | } | 145 | } |
| 162 | }); | 146 | }); |
| 163 | m_destReader = new CodeReader(); | 147 | m_destReader = new CodeReader(); |
| 164 | m_destReader.setSelectionListener(new CodeReader.SelectionListener() { | 148 | m_destReader.setSelectionListener(reference -> { |
| 165 | @Override | 149 | if (reference != null) { |
| 166 | public void onSelect(EntryReference<Entry, Entry> reference) { | 150 | onSelectDest(reference.entry); |
| 167 | if (reference != null) { | 151 | } else { |
| 168 | onSelectDest(reference.entry); | 152 | onSelectDest(null); |
| 169 | } else { | ||
| 170 | onSelectDest(null); | ||
| 171 | } | ||
| 172 | } | 153 | } |
| 173 | }); | 154 | }); |
| 174 | 155 | ||
| @@ -267,18 +248,8 @@ public class MemberMatchingGui<T extends Entry> { | |||
| 267 | throw new Error("No matching dest class for source class: " + m_obfSourceClass); | 248 | throw new Error("No matching dest class for source class: " + m_obfSourceClass); |
| 268 | } | 249 | } |
| 269 | 250 | ||
| 270 | m_sourceReader.decompileClass(m_obfSourceClass, m_sourceDeobfuscator, false, new Runnable() { | 251 | m_sourceReader.decompileClass(m_obfSourceClass, m_sourceDeobfuscator, false, this::updateSourceHighlights); |
| 271 | @Override | 252 | m_destReader.decompileClass(m_obfDestClass, m_destDeobfuscator, false, this::updateDestHighlights); |
| 272 | public void run() { | ||
| 273 | updateSourceHighlights(); | ||
| 274 | } | ||
| 275 | }); | ||
| 276 | m_destReader.decompileClass(m_obfDestClass, m_destDeobfuscator, false, new Runnable() { | ||
| 277 | @Override | ||
| 278 | public void run() { | ||
| 279 | updateDestHighlights(); | ||
| 280 | } | ||
| 281 | }); | ||
| 282 | } | 253 | } |
| 283 | 254 | ||
| 284 | protected void updateSourceHighlights() { | 255 | protected void updateSourceHighlights() { |
| @@ -382,21 +353,19 @@ public class MemberMatchingGui<T extends Entry> { | |||
| 382 | } | 353 | } |
| 383 | 354 | ||
| 384 | private void setSource(T obfEntry) { | 355 | private void setSource(T obfEntry) { |
| 356 | m_obfSourceEntry = obfEntry; | ||
| 385 | if (obfEntry == null) { | 357 | if (obfEntry == null) { |
| 386 | m_obfSourceEntry = obfEntry; | ||
| 387 | m_sourceLabel.setText(""); | 358 | m_sourceLabel.setText(""); |
| 388 | } else { | 359 | } else { |
| 389 | m_obfSourceEntry = obfEntry; | ||
| 390 | m_sourceLabel.setText(getEntryLabel(obfEntry, m_sourceDeobfuscator)); | 360 | m_sourceLabel.setText(getEntryLabel(obfEntry, m_sourceDeobfuscator)); |
| 391 | } | 361 | } |
| 392 | } | 362 | } |
| 393 | 363 | ||
| 394 | private void setDest(T obfEntry) { | 364 | private void setDest(T obfEntry) { |
| 365 | m_obfDestEntry = obfEntry; | ||
| 395 | if (obfEntry == null) { | 366 | if (obfEntry == null) { |
| 396 | m_obfDestEntry = obfEntry; | ||
| 397 | m_destLabel.setText(""); | 367 | m_destLabel.setText(""); |
| 398 | } else { | 368 | } else { |
| 399 | m_obfDestEntry = obfEntry; | ||
| 400 | m_destLabel.setText(getEntryLabel(obfEntry, m_destDeobfuscator)); | 369 | m_destLabel.setText(getEntryLabel(obfEntry, m_destDeobfuscator)); |
| 401 | } | 370 | } |
| 402 | } | 371 | } |
| @@ -414,27 +383,12 @@ public class MemberMatchingGui<T extends Entry> { | |||
| 414 | 383 | ||
| 415 | if (m_obfSourceEntry != null && m_obfDestEntry != null) { | 384 | if (m_obfSourceEntry != null && m_obfDestEntry != null) { |
| 416 | if (m_memberMatches.isMatched(m_obfSourceEntry, m_obfDestEntry)) { | 385 | if (m_memberMatches.isMatched(m_obfSourceEntry, m_obfDestEntry)) { |
| 417 | GuiTricks.activateButton(m_matchButton, "Unmatch", new ActionListener() { | 386 | GuiTricks.activateButton(m_matchButton, "Unmatch", event -> unmatch()); |
| 418 | @Override | ||
| 419 | public void actionPerformed(ActionEvent event) { | ||
| 420 | unmatch(); | ||
| 421 | } | ||
| 422 | }); | ||
| 423 | } else if (!m_memberMatches.isMatchedSourceEntry(m_obfSourceEntry) && !m_memberMatches.isMatchedDestEntry(m_obfDestEntry)) { | 387 | } else if (!m_memberMatches.isMatchedSourceEntry(m_obfSourceEntry) && !m_memberMatches.isMatchedDestEntry(m_obfDestEntry)) { |
| 424 | GuiTricks.activateButton(m_matchButton, "Match", new ActionListener() { | 388 | GuiTricks.activateButton(m_matchButton, "Match", event -> match()); |
| 425 | @Override | ||
| 426 | public void actionPerformed(ActionEvent event) { | ||
| 427 | match(); | ||
| 428 | } | ||
| 429 | }); | ||
| 430 | } | 389 | } |
| 431 | } else if (m_obfSourceEntry != null) { | 390 | } else if (m_obfSourceEntry != null) { |
| 432 | GuiTricks.activateButton(m_unmatchableButton, "Set Unmatchable", new ActionListener() { | 391 | GuiTricks.activateButton(m_unmatchableButton, "Set Unmatchable", event -> unmatchable()); |
| 433 | @Override | ||
| 434 | public void actionPerformed(ActionEvent event) { | ||
| 435 | unmatchable(); | ||
| 436 | } | ||
| 437 | }); | ||
| 438 | } | 392 | } |
| 439 | } | 393 | } |
| 440 | 394 | ||
diff --git a/src/main/java/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java index caaf99c..5afc767 100644 --- a/src/main/java/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java | |||
| @@ -15,7 +15,6 @@ import java.awt.Color; | |||
| 15 | public class ObfuscatedHighlightPainter extends BoxHighlightPainter { | 15 | public class ObfuscatedHighlightPainter extends BoxHighlightPainter { |
| 16 | 16 | ||
| 17 | public ObfuscatedHighlightPainter() { | 17 | public ObfuscatedHighlightPainter() { |
| 18 | // red ish | ||
| 19 | super(new Color(255, 220, 220), new Color(160, 80, 80)); | 18 | super(new Color(255, 220, 220), new Color(160, 80, 80)); |
| 20 | } | 19 | } |
| 21 | } | 20 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/OtherHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/OtherHighlightPainter.java index d2a2f02..256f69e 100644 --- a/src/main/java/cuchaz/enigma/gui/OtherHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/OtherHighlightPainter.java | |||
| @@ -15,7 +15,6 @@ import java.awt.Color; | |||
| 15 | public class OtherHighlightPainter extends BoxHighlightPainter { | 15 | public class OtherHighlightPainter extends BoxHighlightPainter { |
| 16 | 16 | ||
| 17 | public OtherHighlightPainter() { | 17 | public OtherHighlightPainter() { |
| 18 | // grey | ||
| 19 | super(null, new Color(180, 180, 180)); | 18 | super(null, new Color(180, 180, 180)); |
| 20 | } | 19 | } |
| 21 | } | 20 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/ProgressDialog.java b/src/main/java/cuchaz/enigma/gui/ProgressDialog.java index 087d843..70bca15 100644 --- a/src/main/java/cuchaz/enigma/gui/ProgressDialog.java +++ b/src/main/java/cuchaz/enigma/gui/ProgressDialog.java | |||
| @@ -22,63 +22,63 @@ import cuchaz.enigma.Deobfuscator.ProgressListener; | |||
| 22 | 22 | ||
| 23 | public class ProgressDialog implements ProgressListener, AutoCloseable { | 23 | public class ProgressDialog implements ProgressListener, AutoCloseable { |
| 24 | 24 | ||
| 25 | private JFrame m_frame; | 25 | private JFrame frame; |
| 26 | private JLabel m_title; | 26 | private JLabel labelTitle; |
| 27 | private JLabel m_text; | 27 | private JLabel labelText; |
| 28 | private JProgressBar m_progress; | 28 | private JProgressBar progress; |
| 29 | 29 | ||
| 30 | public ProgressDialog(JFrame parent) { | 30 | public ProgressDialog(JFrame parent) { |
| 31 | 31 | ||
| 32 | // init frame | 32 | // init frame |
| 33 | m_frame = new JFrame(Constants.Name + " - Operation in progress"); | 33 | this.frame = new JFrame(Constants.NAME + " - Operation in progress"); |
| 34 | final Container pane = m_frame.getContentPane(); | 34 | final Container pane = this.frame.getContentPane(); |
| 35 | FlowLayout layout = new FlowLayout(); | 35 | FlowLayout layout = new FlowLayout(); |
| 36 | layout.setAlignment(FlowLayout.LEFT); | 36 | layout.setAlignment(FlowLayout.LEFT); |
| 37 | pane.setLayout(layout); | 37 | pane.setLayout(layout); |
| 38 | 38 | ||
| 39 | m_title = new JLabel(); | 39 | this.labelTitle = new JLabel(); |
| 40 | pane.add(m_title); | 40 | pane.add(this.labelTitle); |
| 41 | 41 | ||
| 42 | // set up the progress bar | 42 | // set up the progress bar |
| 43 | JPanel panel = new JPanel(); | 43 | JPanel panel = new JPanel(); |
| 44 | pane.add(panel); | 44 | pane.add(panel); |
| 45 | panel.setLayout(new BorderLayout()); | 45 | panel.setLayout(new BorderLayout()); |
| 46 | m_text = GuiTricks.unboldLabel(new JLabel()); | 46 | this.labelText = GuiTricks.unboldLabel(new JLabel()); |
| 47 | m_progress = new JProgressBar(); | 47 | this.progress = new JProgressBar(); |
| 48 | m_text.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); | 48 | this.labelText.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); |
| 49 | panel.add(m_text, BorderLayout.NORTH); | 49 | panel.add(this.labelText, BorderLayout.NORTH); |
| 50 | panel.add(m_progress, BorderLayout.CENTER); | 50 | panel.add(this.progress, BorderLayout.CENTER); |
| 51 | panel.setPreferredSize(new Dimension(360, 50)); | 51 | panel.setPreferredSize(new Dimension(360, 50)); |
| 52 | 52 | ||
| 53 | // show the frame | 53 | // show the frame |
| 54 | pane.doLayout(); | 54 | pane.doLayout(); |
| 55 | m_frame.setSize(400, 120); | 55 | this.frame.setSize(400, 120); |
| 56 | m_frame.setResizable(false); | 56 | this.frame.setResizable(false); |
| 57 | m_frame.setLocationRelativeTo(parent); | 57 | this.frame.setLocationRelativeTo(parent); |
| 58 | m_frame.setVisible(true); | 58 | this.frame.setVisible(true); |
| 59 | m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); | 59 | this.frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | public void close() { | 62 | public void close() { |
| 63 | m_frame.dispose(); | 63 | this.frame.dispose(); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | @Override | 66 | @Override |
| 67 | public void init(int totalWork, String title) { | 67 | public void init(int totalWork, String title) { |
| 68 | m_title.setText(title); | 68 | this.labelTitle.setText(title); |
| 69 | m_progress.setMinimum(0); | 69 | this.progress.setMinimum(0); |
| 70 | m_progress.setMaximum(totalWork); | 70 | this.progress.setMaximum(totalWork); |
| 71 | m_progress.setValue(0); | 71 | this.progress.setValue(0); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | @Override | 74 | @Override |
| 75 | public void onProgress(int numDone, String message) { | 75 | public void onProgress(int numDone, String message) { |
| 76 | m_text.setText(message); | 76 | this.labelText.setText(message); |
| 77 | m_progress.setValue(numDone); | 77 | this.progress.setValue(numDone); |
| 78 | 78 | ||
| 79 | // update the frame | 79 | // update the frame |
| 80 | m_frame.validate(); | 80 | this.frame.validate(); |
| 81 | m_frame.repaint(); | 81 | this.frame.repaint(); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | public interface ProgressRunnable { | 84 | public interface ProgressRunnable { |
diff --git a/src/main/java/cuchaz/enigma/gui/RenameListener.java b/src/main/java/cuchaz/enigma/gui/RenameListener.java deleted file mode 100644 index f0f9dcc..0000000 --- a/src/main/java/cuchaz/enigma/gui/RenameListener.java +++ /dev/null | |||
| @@ -1,17 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.gui; | ||
| 12 | |||
| 13 | import cuchaz.enigma.mapping.Entry; | ||
| 14 | |||
| 15 | public interface RenameListener { | ||
| 16 | void rename(Entry obfEntry, String newName); | ||
| 17 | } | ||
diff --git a/src/main/java/cuchaz/enigma/gui/ScoredClassEntry.java b/src/main/java/cuchaz/enigma/gui/ScoredClassEntry.java index d1e2de0..359ec7a 100644 --- a/src/main/java/cuchaz/enigma/gui/ScoredClassEntry.java +++ b/src/main/java/cuchaz/enigma/gui/ScoredClassEntry.java | |||
| @@ -12,19 +12,18 @@ package cuchaz.enigma.gui; | |||
| 12 | 12 | ||
| 13 | import cuchaz.enigma.mapping.ClassEntry; | 13 | import cuchaz.enigma.mapping.ClassEntry; |
| 14 | 14 | ||
| 15 | |||
| 16 | public class ScoredClassEntry extends ClassEntry { | 15 | public class ScoredClassEntry extends ClassEntry { |
| 17 | 16 | ||
| 18 | private static final long serialVersionUID = -8798725308554217105L; | 17 | private static final long serialVersionUID = -8798725308554217105L; |
| 19 | 18 | ||
| 20 | private float m_score; | 19 | private float score; |
| 21 | 20 | ||
| 22 | public ScoredClassEntry(ClassEntry other, float score) { | 21 | public ScoredClassEntry(ClassEntry other, float score) { |
| 23 | super(other); | 22 | super(other); |
| 24 | m_score = score; | 23 | this.score = score; |
| 25 | } | 24 | } |
| 26 | 25 | ||
| 27 | public float getScore() { | 26 | public float getScore() { |
| 28 | return m_score; | 27 | return this.score; |
| 29 | } | 28 | } |
| 30 | } | 29 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/TokenListCellRenderer.java b/src/main/java/cuchaz/enigma/gui/TokenListCellRenderer.java index efc8df8..518055f 100644 --- a/src/main/java/cuchaz/enigma/gui/TokenListCellRenderer.java +++ b/src/main/java/cuchaz/enigma/gui/TokenListCellRenderer.java | |||
| @@ -21,18 +21,18 @@ 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 controller; |
| 25 | private DefaultListCellRenderer m_defaultRenderer; | 25 | private DefaultListCellRenderer defaultRenderer; |
| 26 | 26 | ||
| 27 | public TokenListCellRenderer(GuiController controller) { | 27 | public TokenListCellRenderer(GuiController controller) { |
| 28 | m_controller = controller; | 28 | this.controller = controller; |
| 29 | m_defaultRenderer = new DefaultListCellRenderer(); | 29 | this.defaultRenderer = new DefaultListCellRenderer(); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | @Override | 32 | @Override |
| 33 | 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) { |
| 34 | JLabel label = (JLabel) m_defaultRenderer.getListCellRendererComponent(list, token, index, isSelected, hasFocus); | 34 | JLabel label = (JLabel) this.defaultRenderer.getListCellRendererComponent(list, token, index, isSelected, hasFocus); |
| 35 | label.setText(m_controller.getReadableToken(token).toString()); | 35 | label.setText(this.controller.getReadableToken(token).toString()); |
| 36 | return label; | 36 | return label; |
| 37 | } | 37 | } |
| 38 | } | 38 | } |