diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui')
6 files changed, 179 insertions, 4 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index 3ab1cee..1ea3e44 100644 --- a/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma.gui; | 12 | package cuchaz.enigma.gui; |
| 13 | 13 | ||
| 14 | import com.google.common.base.Strings; | ||
| 14 | import com.google.common.collect.Lists; | 15 | import com.google.common.collect.Lists; |
| 15 | import cuchaz.enigma.Constants; | 16 | import cuchaz.enigma.Constants; |
| 16 | import cuchaz.enigma.EnigmaProfile; | 17 | import cuchaz.enigma.EnigmaProfile; |
| @@ -19,6 +20,7 @@ import cuchaz.enigma.analysis.*; | |||
| 19 | import cuchaz.enigma.config.Config; | 20 | import cuchaz.enigma.config.Config; |
| 20 | import cuchaz.enigma.config.Themes; | 21 | import cuchaz.enigma.config.Themes; |
| 21 | import cuchaz.enigma.gui.dialog.CrashDialog; | 22 | import cuchaz.enigma.gui.dialog.CrashDialog; |
| 23 | import cuchaz.enigma.gui.dialog.JavadocDialog; | ||
| 22 | import cuchaz.enigma.gui.elements.MenuBar; | 24 | import cuchaz.enigma.gui.elements.MenuBar; |
| 23 | import cuchaz.enigma.gui.elements.PopupMenuBar; | 25 | import cuchaz.enigma.gui.elements.PopupMenuBar; |
| 24 | import cuchaz.enigma.gui.filechooser.FileChooserAny; | 26 | import cuchaz.enigma.gui.filechooser.FileChooserAny; |
| @@ -82,6 +84,7 @@ public class Gui { | |||
| 82 | private JTabbedPane tabs; | 84 | private JTabbedPane tabs; |
| 83 | 85 | ||
| 84 | public JTextField renameTextField; | 86 | public JTextField renameTextField; |
| 87 | public JTextArea javadocTextArea; | ||
| 85 | 88 | ||
| 86 | public void setEditorTheme(Config.LookAndFeel feel) { | 89 | public void setEditorTheme(Config.LookAndFeel feel) { |
| 87 | if (editor != null && (editorFeel == null || editorFeel != feel)) { | 90 | if (editor != null && (editorFeel == null || editorFeel != feel)) { |
| @@ -559,6 +562,7 @@ public class Gui { | |||
| 559 | } | 562 | } |
| 560 | 563 | ||
| 561 | this.popupMenu.renameMenu.setEnabled(isRenamable); | 564 | this.popupMenu.renameMenu.setEnabled(isRenamable); |
| 565 | this.popupMenu.editJavadocMenu.setEnabled(isRenamable); | ||
| 562 | this.popupMenu.showInheritanceMenu.setEnabled(isClassEntry || isMethodEntry || isConstructorEntry); | 566 | this.popupMenu.showInheritanceMenu.setEnabled(isClassEntry || isMethodEntry || isConstructorEntry); |
| 563 | this.popupMenu.showImplementationsMenu.setEnabled(isClassEntry || isMethodEntry); | 567 | this.popupMenu.showImplementationsMenu.setEnabled(isClassEntry || isMethodEntry); |
| 564 | this.popupMenu.showCallsMenu.setEnabled(isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry); | 568 | this.popupMenu.showCallsMenu.setEnabled(isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry); |
| @@ -575,6 +579,47 @@ public class Gui { | |||
| 575 | } | 579 | } |
| 576 | } | 580 | } |
| 577 | 581 | ||
| 582 | public void startDocChange() { | ||
| 583 | |||
| 584 | // init the text box | ||
| 585 | javadocTextArea = new JTextArea(10, 40); | ||
| 586 | |||
| 587 | EntryReference<Entry<?>, Entry<?>> translatedReference = controller.project.getMapper().deobfuscate(cursorReference); | ||
| 588 | javadocTextArea.setText(Strings.nullToEmpty(translatedReference.entry.getJavadocs())); | ||
| 589 | |||
| 590 | JavadocDialog.init(frame, javadocTextArea, this::finishDocChange); | ||
| 591 | javadocTextArea.grabFocus(); | ||
| 592 | |||
| 593 | redraw(); | ||
| 594 | } | ||
| 595 | |||
| 596 | private void finishDocChange(JFrame ui, boolean saveName) { | ||
| 597 | String newName = javadocTextArea.getText(); | ||
| 598 | if (saveName) { | ||
| 599 | try { | ||
| 600 | this.controller.changeDocs(cursorReference, newName); | ||
| 601 | } catch (IllegalNameException ex) { | ||
| 602 | javadocTextArea.setBorder(BorderFactory.createLineBorder(Color.red, 1)); | ||
| 603 | javadocTextArea.setToolTipText(ex.getReason()); | ||
| 604 | Utils.showToolTipNow(javadocTextArea); | ||
| 605 | return; | ||
| 606 | } | ||
| 607 | |||
| 608 | ui.setVisible(false); | ||
| 609 | showCursorReference(cursorReference); | ||
| 610 | return; | ||
| 611 | } | ||
| 612 | |||
| 613 | // abort the jd change | ||
| 614 | javadocTextArea = null; | ||
| 615 | ui.setVisible(false); | ||
| 616 | showCursorReference(cursorReference); | ||
| 617 | |||
| 618 | this.editor.grabFocus(); | ||
| 619 | |||
| 620 | redraw(); | ||
| 621 | } | ||
| 622 | |||
| 578 | public void startRename() { | 623 | public void startRename() { |
| 579 | 624 | ||
| 580 | // init the text box | 625 | // init the text box |
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index 69f12e2..0b2fe27 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -368,20 +368,29 @@ public class GuiController { | |||
| 368 | } | 368 | } |
| 369 | 369 | ||
| 370 | private void refreshCurrentClass(EntryReference<Entry<?>, Entry<?>> reference) { | 370 | private void refreshCurrentClass(EntryReference<Entry<?>, Entry<?>> reference) { |
| 371 | refreshCurrentClass(reference, false); | ||
| 372 | } | ||
| 373 | |||
| 374 | private void refreshCurrentClass(EntryReference<Entry<?>, Entry<?>> reference, boolean forceDecomp) { | ||
| 371 | if (currentSource != null) { | 375 | if (currentSource != null) { |
| 372 | loadClass(currentSource.getEntry(), () -> { | 376 | loadClass(currentSource.getEntry(), () -> { |
| 373 | if (reference != null) { | 377 | if (reference != null) { |
| 374 | showReference(reference); | 378 | showReference(reference); |
| 375 | } | 379 | } |
| 376 | }); | 380 | }, forceDecomp); |
| 377 | } | 381 | } |
| 378 | } | 382 | } |
| 379 | 383 | ||
| 380 | private void loadClass(ClassEntry classEntry, Runnable callback) { | 384 | private void loadClass(ClassEntry classEntry, Runnable callback) { |
| 385 | loadClass(classEntry, callback, false); | ||
| 386 | } | ||
| 387 | |||
| 388 | private void loadClass(ClassEntry classEntry, Runnable callback, boolean forceDecomp) { | ||
| 381 | ClassEntry targetClass = classEntry.getOutermostClass(); | 389 | ClassEntry targetClass = classEntry.getOutermostClass(); |
| 382 | 390 | ||
| 383 | boolean requiresDecompile = currentSource == null || !currentSource.getEntry().equals(targetClass); | 391 | boolean requiresDecompile = forceDecomp || currentSource == null || !currentSource.getEntry().equals(targetClass); |
| 384 | if (requiresDecompile) { | 392 | if (requiresDecompile) { |
| 393 | currentSource = null; // Or the GUI may try to find a nonexistent token | ||
| 385 | gui.setEditorText("(decompiling...)"); | 394 | gui.setEditorText("(decompiling...)"); |
| 386 | } | 395 | } |
| 387 | 396 | ||
| @@ -402,7 +411,7 @@ public class GuiController { | |||
| 402 | 411 | ||
| 403 | private DecompiledClassSource decompileSource(ClassEntry targetClass) { | 412 | private DecompiledClassSource decompileSource(ClassEntry targetClass) { |
| 404 | try { | 413 | try { |
| 405 | CompilationUnit sourceTree = sourceProvider.getSources(targetClass.getFullName()); | 414 | CompilationUnit sourceTree = (CompilationUnit) sourceProvider.getSources(targetClass.getFullName()).clone(); |
| 406 | if (sourceTree == null) { | 415 | if (sourceTree == null) { |
| 407 | gui.setEditorText("Unable to find class: " + targetClass); | 416 | gui.setEditorText("Unable to find class: " + targetClass); |
| 408 | return DecompiledClassSource.text(targetClass, "Unable to find class"); | 417 | return DecompiledClassSource.text(targetClass, "Unable to find class"); |
| @@ -410,6 +419,7 @@ public class GuiController { | |||
| 410 | 419 | ||
| 411 | DropImportAstTransform.INSTANCE.run(sourceTree); | 420 | DropImportAstTransform.INSTANCE.run(sourceTree); |
| 412 | DropVarModifiersAstTransform.INSTANCE.run(sourceTree); | 421 | DropVarModifiersAstTransform.INSTANCE.run(sourceTree); |
| 422 | new AddJavadocsAstTransform(project.getMapper()).run(sourceTree); | ||
| 413 | 423 | ||
| 414 | String sourceString = sourceProvider.writeSourceToString(sourceTree); | 424 | String sourceString = sourceProvider.writeSourceToString(sourceTree); |
| 415 | 425 | ||
| @@ -521,6 +531,25 @@ public class GuiController { | |||
| 521 | refreshCurrentClass(reference); | 531 | refreshCurrentClass(reference); |
| 522 | } | 532 | } |
| 523 | 533 | ||
| 534 | public void changeDocs(EntryReference<Entry<?>, Entry<?>> reference, String updatedDocs) { | ||
| 535 | changeDoc(reference.getNameableEntry(), updatedDocs); | ||
| 536 | |||
| 537 | refreshCurrentClass(reference, true); | ||
| 538 | } | ||
| 539 | |||
| 540 | public void changeDoc(Entry<?> obfEntry, String newDoc) { | ||
| 541 | EntryRemapper mapper = project.getMapper(); | ||
| 542 | if (mapper.getDeobfMapping(obfEntry) == null) { | ||
| 543 | markAsDeobfuscated(obfEntry,false); // NPE | ||
| 544 | } | ||
| 545 | mapper.mapFromObf(obfEntry, mapper.getDeobfMapping(obfEntry).withDocs(newDoc), false); | ||
| 546 | } | ||
| 547 | |||
| 548 | public void markAsDeobfuscated(Entry<?> obfEntry, boolean renaming) { | ||
| 549 | EntryRemapper mapper = project.getMapper(); | ||
| 550 | mapper.mapFromObf(obfEntry, new EntryMapping(mapper.deobfuscate(obfEntry).getName()), renaming); | ||
| 551 | } | ||
| 552 | |||
| 524 | public void markAsDeobfuscated(EntryReference<Entry<?>, Entry<?>> reference) { | 553 | public void markAsDeobfuscated(EntryReference<Entry<?>, Entry<?>> reference) { |
| 525 | EntryRemapper mapper = project.getMapper(); | 554 | EntryRemapper mapper = project.getMapper(); |
| 526 | Entry<?> entry = reference.getNameableEntry(); | 555 | Entry<?> entry = reference.getNameableEntry(); |
diff --git a/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java b/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java new file mode 100644 index 0000000..84e4d8f --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/dialog/JavadocDialog.java | |||
| @@ -0,0 +1,88 @@ | |||
| 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 | |||
| 12 | package cuchaz.enigma.gui.dialog; | ||
| 13 | |||
| 14 | import cuchaz.enigma.utils.Utils; | ||
| 15 | |||
| 16 | import javax.swing.*; | ||
| 17 | import java.awt.*; | ||
| 18 | import java.awt.event.KeyAdapter; | ||
| 19 | import java.awt.event.KeyEvent; | ||
| 20 | |||
| 21 | public class JavadocDialog { | ||
| 22 | |||
| 23 | private static JavadocDialog instance = null; | ||
| 24 | |||
| 25 | private JFrame frame; | ||
| 26 | |||
| 27 | private JavadocDialog(JFrame parent, JTextArea text, Callback callback) { | ||
| 28 | // init frame | ||
| 29 | frame = new JFrame("Edit Javadocs"); | ||
| 30 | final Container pane = frame.getContentPane(); | ||
| 31 | pane.setLayout(new BorderLayout()); | ||
| 32 | |||
| 33 | // editor panel | ||
| 34 | text.setTabSize(2); | ||
| 35 | pane.add(new JScrollPane(text), BorderLayout.CENTER); | ||
| 36 | text.addKeyListener(new KeyAdapter() { | ||
| 37 | @Override | ||
| 38 | public void keyPressed(KeyEvent event) { | ||
| 39 | switch (event.getKeyCode()) { | ||
| 40 | case KeyEvent.VK_ENTER: | ||
| 41 | if (event.isControlDown()) | ||
| 42 | callback.closeUi(frame, true); | ||
| 43 | break; | ||
| 44 | case KeyEvent.VK_ESCAPE: | ||
| 45 | callback.closeUi(frame, false); | ||
| 46 | break; | ||
| 47 | default: | ||
| 48 | break; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | }); | ||
| 52 | |||
| 53 | // buttons panel | ||
| 54 | JPanel buttonsPanel = new JPanel(); | ||
| 55 | FlowLayout buttonsLayout = new FlowLayout(); | ||
| 56 | buttonsLayout.setAlignment(FlowLayout.RIGHT); | ||
| 57 | buttonsPanel.setLayout(buttonsLayout); | ||
| 58 | buttonsPanel.add(Utils.unboldLabel(new JLabel("Edit javadocs here."))); | ||
| 59 | JButton cancelButton = new JButton("Cancel"); | ||
| 60 | cancelButton.addActionListener(event -> { | ||
| 61 | // close (hide) the dialog | ||
| 62 | callback.closeUi(frame, false); | ||
| 63 | }); | ||
| 64 | buttonsPanel.add(cancelButton); | ||
| 65 | JButton saveButton = new JButton("Save"); | ||
| 66 | saveButton.addActionListener(event -> { | ||
| 67 | // exit enigma | ||
| 68 | callback.closeUi(frame, true); | ||
| 69 | }); | ||
| 70 | buttonsPanel.add(saveButton); | ||
| 71 | pane.add(buttonsPanel, BorderLayout.SOUTH); | ||
| 72 | |||
| 73 | // show the frame | ||
| 74 | frame.setSize(600, 400); | ||
| 75 | frame.setLocationRelativeTo(parent); | ||
| 76 | frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); | ||
| 77 | } | ||
| 78 | |||
| 79 | public static void init(JFrame parent, JTextArea area, Callback callback) { | ||
| 80 | instance = new JavadocDialog(parent, area, callback); | ||
| 81 | instance.frame.doLayout(); | ||
| 82 | instance.frame.setVisible(true); | ||
| 83 | } | ||
| 84 | |||
| 85 | public interface Callback { | ||
| 86 | void closeUi(JFrame frame, boolean save); | ||
| 87 | } | ||
| 88 | } | ||
diff --git a/src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java index fbf39ac..b9d459f 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/PopupMenuBar.java | |||
| @@ -9,6 +9,7 @@ import java.awt.event.KeyEvent; | |||
| 9 | public class PopupMenuBar extends JPopupMenu { | 9 | public class PopupMenuBar extends JPopupMenu { |
| 10 | 10 | ||
| 11 | public final JMenuItem renameMenu; | 11 | public final JMenuItem renameMenu; |
| 12 | public final JMenuItem editJavadocMenu; | ||
| 12 | public final JMenuItem showInheritanceMenu; | 13 | public final JMenuItem showInheritanceMenu; |
| 13 | public final JMenuItem showImplementationsMenu; | 14 | public final JMenuItem showImplementationsMenu; |
| 14 | public final JMenuItem showCallsMenu; | 15 | public final JMenuItem showCallsMenu; |
| @@ -28,6 +29,14 @@ public class PopupMenuBar extends JPopupMenu { | |||
| 28 | this.renameMenu = menu; | 29 | this.renameMenu = menu; |
| 29 | } | 30 | } |
| 30 | { | 31 | { |
| 32 | JMenuItem menu = new JMenuItem("Edit Javadoc"); | ||
| 33 | menu.addActionListener(event -> gui.startDocChange()); | ||
| 34 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, 0)); | ||
| 35 | menu.setEnabled(false); | ||
| 36 | this.add(menu); | ||
| 37 | this.editJavadocMenu = menu; | ||
| 38 | } | ||
| 39 | { | ||
| 31 | JMenuItem menu = new JMenuItem("Show Inheritance"); | 40 | JMenuItem menu = new JMenuItem("Show Inheritance"); |
| 32 | menu.addActionListener(event -> gui.showInheritance()); | 41 | menu.addActionListener(event -> gui.showInheritance()); |
| 33 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, 0)); | 42 | menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, 0)); |
diff --git a/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java b/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java index 9e29699..71ee34c 100644 --- a/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java +++ b/src/main/java/cuchaz/enigma/gui/panels/PanelEditor.java | |||
| @@ -87,6 +87,10 @@ public class PanelEditor extends JEditorPane { | |||
| 87 | gui.popupMenu.renameMenu.doClick(); | 87 | gui.popupMenu.renameMenu.doClick(); |
| 88 | break; | 88 | break; |
| 89 | 89 | ||
| 90 | case KeyEvent.VK_D: | ||
| 91 | gui.popupMenu.editJavadocMenu.doClick(); | ||
| 92 | break; | ||
| 93 | |||
| 90 | case KeyEvent.VK_F5: | 94 | case KeyEvent.VK_F5: |
| 91 | gui.getController().refreshCurrentClass(); | 95 | gui.getController().refreshCurrentClass(); |
| 92 | break; | 96 | break; |
diff --git a/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java b/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java index 88ed96f..a6e465d 100644 --- a/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java +++ b/src/main/java/cuchaz/enigma/gui/stats/StatsGenerator.java | |||
| @@ -67,7 +67,7 @@ public class StatsGenerator { | |||
| 67 | if (includedMembers.contains(StatsMember.PARAMETERS)) { | 67 | if (includedMembers.contains(StatsMember.PARAMETERS)) { |
| 68 | int index = ((MethodDefEntry) method).getAccess().isStatic() ? 0 : 1; | 68 | int index = ((MethodDefEntry) method).getAccess().isStatic() ? 0 : 1; |
| 69 | for (TypeDescriptor argument : method.getDesc().getArgumentDescs()) { | 69 | for (TypeDescriptor argument : method.getDesc().getArgumentDescs()) { |
| 70 | update(counts, new LocalVariableEntry(method, index, "", true)); | 70 | update(counts, new LocalVariableEntry(method, index, "", true,null)); |
| 71 | index += argument.getSize(); | 71 | index += argument.getSize(); |
| 72 | } | 72 | } |
| 73 | } | 73 | } |