summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui/Gui.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/Gui.java')
-rw-r--r--src/main/java/cuchaz/enigma/gui/Gui.java102
1 files changed, 49 insertions, 53 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java
index d119735..a6e20a2 100644
--- a/src/main/java/cuchaz/enigma/gui/Gui.java
+++ b/src/main/java/cuchaz/enigma/gui/Gui.java
@@ -24,7 +24,7 @@ import cuchaz.enigma.gui.filechooser.FileChooserAny;
24import cuchaz.enigma.gui.filechooser.FileChooserFolder; 24import cuchaz.enigma.gui.filechooser.FileChooserFolder;
25import cuchaz.enigma.gui.highlight.BoxHighlightPainter; 25import cuchaz.enigma.gui.highlight.BoxHighlightPainter;
26import cuchaz.enigma.gui.highlight.SelectionHighlightPainter; 26import cuchaz.enigma.gui.highlight.SelectionHighlightPainter;
27import cuchaz.enigma.gui.node.ClassSelectorPackageNode; 27import cuchaz.enigma.gui.highlight.TokenHighlightType;
28import cuchaz.enigma.gui.panels.PanelDeobf; 28import cuchaz.enigma.gui.panels.PanelDeobf;
29import cuchaz.enigma.gui.panels.PanelEditor; 29import cuchaz.enigma.gui.panels.PanelEditor;
30import cuchaz.enigma.gui.panels.PanelIdentifier; 30import cuchaz.enigma.gui.panels.PanelIdentifier;
@@ -44,10 +44,9 @@ import javax.swing.tree.TreeNode;
44import javax.swing.tree.TreePath; 44import javax.swing.tree.TreePath;
45import java.awt.*; 45import java.awt.*;
46import java.awt.event.*; 46import java.awt.event.*;
47import java.io.IOException;
48import java.nio.file.Path; 47import java.nio.file.Path;
49import java.util.*;
50import java.util.List; 48import java.util.List;
49import java.util.*;
51import java.util.function.Function; 50import java.util.function.Function;
52 51
53public class Gui { 52public class Gui {
@@ -71,7 +70,7 @@ public class Gui {
71 private JPanel classesPanel; 70 private JPanel classesPanel;
72 private JSplitPane splitClasses; 71 private JSplitPane splitClasses;
73 private PanelIdentifier infoPanel; 72 private PanelIdentifier infoPanel;
74 public Map<String, BoxHighlightPainter> boxHighlightPainters; 73 public Map<TokenHighlightType, BoxHighlightPainter> boxHighlightPainters;
75 private SelectionHighlightPainter selectionHighlightPainter; 74 private SelectionHighlightPainter selectionHighlightPainter;
76 private JTree inheritanceTree; 75 private JTree inheritanceTree;
77 private JTree implementationsTree; 76 private JTree implementationsTree;
@@ -320,7 +319,7 @@ public class Gui {
320 this.frame.setTitle(Constants.NAME + " - " + jarName); 319 this.frame.setTitle(Constants.NAME + " - " + jarName);
321 this.classesPanel.removeAll(); 320 this.classesPanel.removeAll();
322 this.classesPanel.add(splitClasses); 321 this.classesPanel.add(splitClasses);
323 setSource(null); 322 setEditorText(null);
324 323
325 // update menu 324 // update menu
326 this.menuBar.closeJarMenu.setEnabled(true); 325 this.menuBar.closeJarMenu.setEnabled(true);
@@ -342,7 +341,7 @@ public class Gui {
342 this.frame.setTitle(Constants.NAME); 341 this.frame.setTitle(Constants.NAME);
343 setObfClasses(null); 342 setObfClasses(null);
344 setDeobfClasses(null); 343 setDeobfClasses(null);
345 setSource(null); 344 setEditorText(null);
346 this.classesPanel.removeAll(); 345 this.classesPanel.removeAll();
347 346
348 // update menu 347 // update menu
@@ -373,11 +372,16 @@ public class Gui {
373 this.menuBar.saveMappingsMenu.setEnabled(path != null); 372 this.menuBar.saveMappingsMenu.setEnabled(path != null);
374 } 373 }
375 374
376 public void setSource(String source) { 375 public void setEditorText(String source) {
377 this.editor.getHighlighter().removeAllHighlights(); 376 this.editor.getHighlighter().removeAllHighlights();
378 this.editor.setText(source); 377 this.editor.setText(source);
379 } 378 }
380 379
380 public void setSource(DecompiledClassSource source) {
381 editor.setText(source.toString());
382 setHighlightedTokens(source.getHighlightedTokens());
383 }
384
381 public void showToken(final Token token) { 385 public void showToken(final Token token) {
382 if (token == null) { 386 if (token == null) {
383 throw new IllegalArgumentException("Token cannot be null!"); 387 throw new IllegalArgumentException("Token cannot be null!");
@@ -401,15 +405,15 @@ public class Gui {
401 showToken(sortedTokens.get(0)); 405 showToken(sortedTokens.get(0));
402 } 406 }
403 407
404 public void setHighlightedTokens(Map<String, Iterable<Token>> tokens) { 408 public void setHighlightedTokens(Map<TokenHighlightType, Collection<Token>> tokens) {
405 // remove any old highlighters 409 // remove any old highlighters
406 this.editor.getHighlighter().removeAllHighlights(); 410 this.editor.getHighlighter().removeAllHighlights();
407 411
408 if (boxHighlightPainters != null) { 412 if (boxHighlightPainters != null) {
409 for (String s : tokens.keySet()) { 413 for (TokenHighlightType type : tokens.keySet()) {
410 BoxHighlightPainter painter = boxHighlightPainters.get(s); 414 BoxHighlightPainter painter = boxHighlightPainters.get(type);
411 if (painter != null) { 415 if (painter != null) {
412 setHighlightedTokens(tokens.get(s), painter); 416 setHighlightedTokens(tokens.get(type), painter);
413 } 417 }
414 } 418 }
415 } 419 }
@@ -435,17 +439,19 @@ public class Gui {
435 439
436 this.reference = reference; 440 this.reference = reference;
437 441
442 EntryReference<Entry<?>, Entry<?>> translatedReference = controller.getDeobfuscator().deobfuscate(reference);
443
438 infoPanel.removeAll(); 444 infoPanel.removeAll();
439 if (reference.entry instanceof ClassEntry) { 445 if (translatedReference.entry instanceof ClassEntry) {
440 showClassEntry((ClassEntry) this.reference.entry); 446 showClassEntry((ClassEntry) translatedReference.entry);
441 } else if (this.reference.entry instanceof FieldEntry) { 447 } else if (translatedReference.entry instanceof FieldEntry) {
442 showFieldEntry((FieldEntry) this.reference.entry); 448 showFieldEntry((FieldEntry) translatedReference.entry);
443 } else if (this.reference.entry instanceof MethodEntry) { 449 } else if (translatedReference.entry instanceof MethodEntry) {
444 showMethodEntry((MethodEntry) this.reference.entry); 450 showMethodEntry((MethodEntry) translatedReference.entry);
445 } else if (this.reference.entry instanceof LocalVariableEntry) { 451 } else if (translatedReference.entry instanceof LocalVariableEntry) {
446 showLocalVariableEntry((LocalVariableEntry) this.reference.entry); 452 showLocalVariableEntry((LocalVariableEntry) translatedReference.entry);
447 } else { 453 } else {
448 throw new Error("Unknown entry desc: " + this.reference.entry.getClass().getName()); 454 throw new Error("Unknown entry desc: " + translatedReference.entry.getClass().getName());
449 } 455 }
450 456
451 redraw(); 457 redraw();
@@ -519,7 +525,7 @@ public class Gui {
519 Token token = this.controller.getToken(pos); 525 Token token = this.controller.getToken(pos);
520 boolean isToken = token != null; 526 boolean isToken = token != null;
521 527
522 reference = this.controller.getDeobfReference(token); 528 reference = this.controller.getReference(token);
523 529
524 Entry<?> referenceEntry = reference != null ? reference.entry : null; 530 Entry<?> referenceEntry = reference != null ? reference.entry : null;
525 boolean isClassEntry = isToken && referenceEntry instanceof ClassEntry; 531 boolean isClassEntry = isToken && referenceEntry instanceof ClassEntry;
@@ -527,7 +533,7 @@ public class Gui {
527 boolean isMethodEntry = isToken && referenceEntry instanceof MethodEntry && !((MethodEntry) referenceEntry).isConstructor(); 533 boolean isMethodEntry = isToken && referenceEntry instanceof MethodEntry && !((MethodEntry) referenceEntry).isConstructor();
528 boolean isConstructorEntry = isToken && referenceEntry instanceof MethodEntry && ((MethodEntry) referenceEntry).isConstructor(); 534 boolean isConstructorEntry = isToken && referenceEntry instanceof MethodEntry && ((MethodEntry) referenceEntry).isConstructor();
529 boolean isInJar = isToken && this.controller.entryIsInJar(referenceEntry); 535 boolean isInJar = isToken && this.controller.entryIsInJar(referenceEntry);
530 boolean isRenameable = isToken && this.controller.referenceIsRenameable(reference); 536 boolean isRenameable = isToken && this.controller.getDeobfuscator().isRenamable(reference);
531 537
532 if (isToken) { 538 if (isToken) {
533 showReference(reference); 539 showReference(reference);
@@ -544,7 +550,7 @@ public class Gui {
544 this.popupMenu.openPreviousMenu.setEnabled(this.controller.hasPreviousLocation()); 550 this.popupMenu.openPreviousMenu.setEnabled(this.controller.hasPreviousLocation());
545 this.popupMenu.toggleMappingMenu.setEnabled(isRenameable); 551 this.popupMenu.toggleMappingMenu.setEnabled(isRenameable);
546 552
547 if (isToken && this.controller.entryHasDeobfuscatedName(referenceEntry)) { 553 if (isToken && this.controller.getDeobfuscator().isRemapped(referenceEntry)) {
548 this.popupMenu.toggleMappingMenu.setText("Reset to obfuscated"); 554 this.popupMenu.toggleMappingMenu.setText("Reset to obfuscated");
549 } else { 555 } else {
550 this.popupMenu.toggleMappingMenu.setText("Mark as deobfuscated"); 556 this.popupMenu.toggleMappingMenu.setText("Mark as deobfuscated");
@@ -576,7 +582,10 @@ public class Gui {
576 582
577 // init the text box 583 // init the text box
578 final JTextField text = new JTextField(); 584 final JTextField text = new JTextField();
579 text.setText(reference.getNameableName()); 585
586 EntryReference<Entry<?>, Entry<?>> translatedReference = controller.getDeobfuscator().deobfuscate(reference);
587 text.setText(translatedReference.getNameableName());
588
580 text.setPreferredSize(new Dimension(360, text.getPreferredSize().height)); 589 text.setPreferredSize(new Dimension(360, text.getPreferredSize().height));
581 text.addKeyListener(new KeyAdapter() { 590 text.addKeyListener(new KeyAdapter() {
582 @Override 591 @Override
@@ -603,7 +612,7 @@ public class Gui {
603 612
604 int offset = text.getText().lastIndexOf('/') + 1; 613 int offset = text.getText().lastIndexOf('/') + 1;
605 // If it's a class and isn't in the default package, assume that it's deobfuscated. 614 // If it's a class and isn't in the default package, assume that it's deobfuscated.
606 if (reference.getNameableEntry() instanceof ClassEntry && text.getText().contains("/") && offset != 0) 615 if (translatedReference.getNameableEntry() instanceof ClassEntry && text.getText().contains("/") && offset != 0)
607 text.select(offset, text.getText().length()); 616 text.select(offset, text.getText().length());
608 else 617 else
609 text.selectAll(); 618 text.selectAll();
@@ -719,7 +728,7 @@ public class Gui {
719 } 728 }
720 729
721 public void toggleMapping() { 730 public void toggleMapping() {
722 if (this.controller.entryHasDeobfuscatedName(reference.entry)) { 731 if (this.controller.getDeobfuscator().isRemapped(reference.entry)) {
723 this.controller.removeMapping(reference); 732 this.controller.removeMapping(reference);
724 } else { 733 } else {
725 this.controller.markAsDeobfuscated(reference); 734 this.controller.markAsDeobfuscated(reference);
@@ -743,7 +752,7 @@ public class Gui {
743 callback.apply(response); 752 callback.apply(response);
744 } 753 }
745 754
746 public void saveMapping() throws IOException { 755 public void saveMapping() {
747 if (this.enigmaMappingsFileChooser.getSelectedFile() != null || this.enigmaMappingsFileChooser.showSaveDialog(this.frame) == JFileChooser.APPROVE_OPTION) 756 if (this.enigmaMappingsFileChooser.getSelectedFile() != null || this.enigmaMappingsFileChooser.showSaveDialog(this.frame) == JFileChooser.APPROVE_OPTION)
748 this.controller.saveMappings(this.enigmaMappingsFileChooser.getSelectedFile().toPath()); 757 this.controller.saveMappings(this.enigmaMappingsFileChooser.getSelectedFile().toPath());
749 } 758 }
@@ -757,13 +766,8 @@ public class Gui {
757 // ask to save before closing 766 // ask to save before closing
758 showDiscardDiag((response) -> { 767 showDiscardDiag((response) -> {
759 if (response == JOptionPane.YES_OPTION) { 768 if (response == JOptionPane.YES_OPTION) {
760 try { 769 this.saveMapping();
761 this.saveMapping(); 770 this.frame.dispose();
762 this.frame.dispose();
763
764 } catch (IOException ex) {
765 throw new Error(ex);
766 }
767 } else if (response == JOptionPane.NO_OPTION) 771 } else if (response == JOptionPane.NO_OPTION)
768 this.frame.dispose(); 772 this.frame.dispose();
769 773
@@ -796,47 +800,39 @@ public class Gui {
796 this.controller.rename(new EntryReference<>((ClassEntry) prevData, ((ClassEntry) prevData).getFullName()), ((ClassEntry) data).getFullName(), false); 800 this.controller.rename(new EntryReference<>((ClassEntry) prevData, ((ClassEntry) prevData).getFullName()), ((ClassEntry) data).getFullName(), false);
797 } 801 }
798 802
799 public void moveClassTree(EntryReference<Entry<?>, Entry<?>> deobfReference, String newName) { 803 public void moveClassTree(EntryReference<Entry<?>, Entry<?>> obfReference, String newName) {
800 String oldEntry = deobfReference.entry.getContainingClass().getPackageName(); 804 String oldEntry = obfReference.entry.getContainingClass().getPackageName();
801 String newEntry = new ClassEntry(newName).getPackageName(); 805 String newEntry = new ClassEntry(newName).getPackageName();
802 moveClassTree(deobfReference, newName, oldEntry == null, 806 moveClassTree(obfReference, oldEntry == null, newEntry == null);
803 newEntry == null);
804 } 807 }
805 808
806 // TODO: getExpansionState will *not* actually update itself based on name changes! 809 // TODO: getExpansionState will *not* actually update itself based on name changes!
807 public void moveClassTree(EntryReference<Entry<?>, Entry<?>> deobfReference, String newName, boolean isOldOb, boolean isNewOb) { 810 public void moveClassTree(EntryReference<Entry<?>, Entry<?>> obfReference, boolean isOldOb, boolean isNewOb) {
808 ClassEntry oldEntry = deobfReference.entry.getContainingClass(); 811 ClassEntry classEntry = obfReference.entry.getContainingClass();
809 ClassEntry newEntry = new ClassEntry(newName);
810 812
811 // Ob -> deob 813 // Ob -> deob
812 List<ClassSelector.StateEntry> stateDeobf = this.deobfPanel.deobfClasses.getExpansionState(this.deobfPanel.deobfClasses); 814 List<ClassSelector.StateEntry> stateDeobf = this.deobfPanel.deobfClasses.getExpansionState(this.deobfPanel.deobfClasses);
813 List<ClassSelector.StateEntry> stateObf = this.obfPanel.obfClasses.getExpansionState(this.obfPanel.obfClasses); 815 List<ClassSelector.StateEntry> stateObf = this.obfPanel.obfClasses.getExpansionState(this.obfPanel.obfClasses);
814 816
815 if (isOldOb && !isNewOb) { 817 if (isOldOb && !isNewOb) {
816 this.deobfPanel.deobfClasses.moveClassTree(oldEntry, newEntry, obfPanel.obfClasses); 818 this.deobfPanel.deobfClasses.moveClassIn(classEntry);
817 ClassSelectorPackageNode packageNode = this.obfPanel.obfClasses.getPackageNode(oldEntry); 819 this.obfPanel.obfClasses.moveClassOut(classEntry);
818 this.obfPanel.obfClasses.removeNode(packageNode, oldEntry);
819 this.obfPanel.obfClasses.removeNodeIfEmpty(packageNode);
820 this.deobfPanel.deobfClasses.reload(); 820 this.deobfPanel.deobfClasses.reload();
821 this.obfPanel.obfClasses.reload(); 821 this.obfPanel.obfClasses.reload();
822 } 822 }
823 // Deob -> ob 823 // Deob -> ob
824 else if (isNewOb && !isOldOb) { 824 else if (isNewOb && !isOldOb) {
825 this.obfPanel.obfClasses.moveClassTree(oldEntry, newEntry, deobfPanel.deobfClasses); 825 this.obfPanel.obfClasses.moveClassIn(classEntry);
826 ClassSelectorPackageNode packageNode = this.deobfPanel.deobfClasses.getPackageNode(oldEntry); 826 this.deobfPanel.deobfClasses.moveClassOut(classEntry);
827 this.deobfPanel.deobfClasses.removeNode(packageNode, oldEntry);
828 this.deobfPanel.deobfClasses.removeNodeIfEmpty(packageNode);
829 this.deobfPanel.deobfClasses.reload(); 827 this.deobfPanel.deobfClasses.reload();
830 this.obfPanel.obfClasses.reload(); 828 this.obfPanel.obfClasses.reload();
831 } 829 }
832 // Local move 830 // Local move
833 else if (isOldOb) { 831 else if (isOldOb) {
834 this.obfPanel.obfClasses.moveClassTree(oldEntry, newEntry, null); 832 this.obfPanel.obfClasses.moveClassIn(classEntry);
835 this.obfPanel.obfClasses.removeNodeIfEmpty(this.obfPanel.obfClasses.getPackageNode(oldEntry));
836 this.obfPanel.obfClasses.reload(); 833 this.obfPanel.obfClasses.reload();
837 } else { 834 } else {
838 this.deobfPanel.deobfClasses.moveClassTree(oldEntry, newEntry, null); 835 this.deobfPanel.deobfClasses.moveClassIn(classEntry);
839 this.deobfPanel.deobfClasses.removeNodeIfEmpty(this.deobfPanel.deobfClasses.getPackageNode(oldEntry));
840 this.deobfPanel.deobfClasses.reload(); 836 this.deobfPanel.deobfClasses.reload();
841 } 837 }
842 838