diff options
| author | 2021-06-15 23:30:03 +0200 | |
|---|---|---|
| committer | 2021-06-15 22:30:03 +0100 | |
| commit | 1ec1ece9efbcc668b9c79de58d79b3176da1b7ca (patch) | |
| tree | 5d34cf25763bde51b40461d5822ff99f33a2867b /enigma-swing | |
| parent | Fix some exceptions getting silently discarded (e.g. see #398) (diff) | |
| download | enigma-1ec1ece9efbcc668b9c79de58d79b3176da1b7ca.tar.gz enigma-1ec1ece9efbcc668b9c79de58d79b3176da1b7ca.tar.xz enigma-1ec1ece9efbcc668b9c79de58d79b3176da1b7ca.zip | |
Structure panel options (#400)
* Structure panel options
* changes
* always show inner classes in the tree
* workaround for toString() and similar
* show constructor methods depending on the class obfuscation
* use ListCellRenderer instead of toString
* list cell renderer
Diffstat (limited to 'enigma-swing')
4 files changed, 73 insertions, 17 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java index 8d4fb5be..60c535f5 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -622,7 +622,7 @@ public class Gui implements LanguageChangeListener { | |||
| 622 | this.structurePanel.getSortingPanel().setVisible(true); | 622 | this.structurePanel.getSortingPanel().setVisible(true); |
| 623 | 623 | ||
| 624 | // get the class structure | 624 | // get the class structure |
| 625 | StructureTreeNode node = this.controller.getClassStructure(classEntry, this.structurePanel.shouldHideDeobfuscated()); | 625 | StructureTreeNode node = this.controller.getClassStructure(classEntry, this.structurePanel.getOptions()); |
| 626 | 626 | ||
| 627 | // show the tree at the root | 627 | // show the tree at the root |
| 628 | TreePath path = getPathToRoot(node); | 628 | TreePath path = getPathToRoot(node); |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java index aeee242f..e6f7b832 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -396,9 +396,9 @@ public class GuiController implements ClientPacketHandler { | |||
| 396 | chp.invalidateMapped(); | 396 | chp.invalidateMapped(); |
| 397 | } | 397 | } |
| 398 | 398 | ||
| 399 | public StructureTreeNode getClassStructure(ClassEntry entry, boolean hideDeobfuscated) { | 399 | public StructureTreeNode getClassStructure(ClassEntry entry, StructureTreeOptions options) { |
| 400 | StructureTreeNode rootNode = new StructureTreeNode(this.project, entry, entry); | 400 | StructureTreeNode rootNode = new StructureTreeNode(this.project, entry, entry); |
| 401 | rootNode.load(this.project, hideDeobfuscated); | 401 | rootNode.load(this.project, options); |
| 402 | return rootNode; | 402 | return rootNode; |
| 403 | } | 403 | } |
| 404 | 404 | ||
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java index d6f7e5a7..1bff9a98 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java | |||
| @@ -1,7 +1,10 @@ | |||
| 1 | package cuchaz.enigma.gui.panels; | 1 | package cuchaz.enigma.gui.panels; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.analysis.StructureTreeOptions; | ||
| 3 | import cuchaz.enigma.analysis.StructureTreeNode; | 4 | import cuchaz.enigma.analysis.StructureTreeNode; |
| 4 | import cuchaz.enigma.gui.Gui; | 5 | import cuchaz.enigma.gui.Gui; |
| 6 | import cuchaz.enigma.gui.renderer.StructureOptionListCellRenderer; | ||
| 7 | import cuchaz.enigma.gui.util.GridBagConstraintsBuilder; | ||
| 5 | import cuchaz.enigma.gui.util.GuiUtil; | 8 | import cuchaz.enigma.gui.util.GuiUtil; |
| 6 | import cuchaz.enigma.gui.util.SingleTreeSelectionModel; | 9 | import cuchaz.enigma.gui.util.SingleTreeSelectionModel; |
| 7 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 10 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| @@ -18,17 +21,41 @@ import java.awt.event.MouseAdapter; | |||
| 18 | import java.awt.event.MouseEvent; | 21 | import java.awt.event.MouseEvent; |
| 19 | 22 | ||
| 20 | public class StructurePanel extends JPanel { | 23 | public class StructurePanel extends JPanel { |
| 21 | private JPanel sortingPanel; | 24 | private final JPanel optionsPanel; |
| 22 | private JCheckBox hideDeobfuscated; | ||
| 23 | 25 | ||
| 24 | private JTree structureTree; | 26 | private final JLabel obfuscationVisibilityLabel = new JLabel(); |
| 27 | private final JLabel documentationVisibilityLabel = new JLabel(); | ||
| 28 | private final JLabel sortingOrderLabel = new JLabel(); | ||
| 29 | |||
| 30 | private final JComboBox<StructureTreeOptions.ObfuscationVisibility> obfuscationVisibility; | ||
| 31 | private final JComboBox<StructureTreeOptions.DocumentationVisibility> documentationVisibility; | ||
| 32 | private final JComboBox<StructureTreeOptions.SortingOrder> sortingOrder; | ||
| 33 | |||
| 34 | private final JTree structureTree; | ||
| 25 | 35 | ||
| 26 | public StructurePanel(Gui gui) { | 36 | public StructurePanel(Gui gui) { |
| 27 | this.sortingPanel = new JPanel(); | 37 | this.optionsPanel = new JPanel(new GridBagLayout()); |
| 28 | this.hideDeobfuscated = new JCheckBox(I18n.translate("info_panel.tree.structure.hide_deobfuscated")); | 38 | this.optionsPanel.setVisible(false); |
| 29 | this.hideDeobfuscated.addActionListener(event -> gui.showStructure(gui.getActiveEditor())); | 39 | |
| 30 | this.sortingPanel.add(this.hideDeobfuscated); | 40 | GridBagConstraintsBuilder cb = GridBagConstraintsBuilder.create().insets(5).fill(GridBagConstraints.HORIZONTAL); |
| 31 | this.sortingPanel.setVisible(false); | 41 | |
| 42 | this.optionsPanel.add(this.obfuscationVisibilityLabel, cb.pos(0, 0).build()); | ||
| 43 | this.obfuscationVisibility = new JComboBox<>(StructureTreeOptions.ObfuscationVisibility.values()); | ||
| 44 | this.obfuscationVisibility.setRenderer(new StructureOptionListCellRenderer()); | ||
| 45 | this.obfuscationVisibility.addActionListener(event -> gui.showStructure(gui.getActiveEditor())); | ||
| 46 | this.optionsPanel.add(this.obfuscationVisibility, cb.pos(1, 0).build()); | ||
| 47 | |||
| 48 | this.optionsPanel.add(this.documentationVisibilityLabel, cb.pos(0, 1).build()); | ||
| 49 | this.documentationVisibility = new JComboBox<>(StructureTreeOptions.DocumentationVisibility.values()); | ||
| 50 | this.documentationVisibility.setRenderer(new StructureOptionListCellRenderer()); | ||
| 51 | this.documentationVisibility.addActionListener(event -> gui.showStructure(gui.getActiveEditor())); | ||
| 52 | this.optionsPanel.add(this.documentationVisibility, cb.pos(1, 1).build()); | ||
| 53 | |||
| 54 | this.optionsPanel.add(this.sortingOrderLabel, cb.pos(0, 2).build()); | ||
| 55 | this.sortingOrder = new JComboBox<>(StructureTreeOptions.SortingOrder.values()); | ||
| 56 | this.sortingOrder.setRenderer(new StructureOptionListCellRenderer()); | ||
| 57 | this.sortingOrder.addActionListener(event -> gui.showStructure(gui.getActiveEditor())); | ||
| 58 | this.optionsPanel.add(this.sortingOrder, cb.pos(1, 2).build()); | ||
| 32 | 59 | ||
| 33 | this.structureTree = new JTree(); | 60 | this.structureTree = new JTree(); |
| 34 | this.structureTree.setModel(null); | 61 | this.structureTree.setModel(null); |
| @@ -53,20 +80,26 @@ public class StructurePanel extends JPanel { | |||
| 53 | } | 80 | } |
| 54 | }); | 81 | }); |
| 55 | 82 | ||
| 83 | this.retranslateUi(); | ||
| 84 | |||
| 56 | this.setLayout(new BorderLayout()); | 85 | this.setLayout(new BorderLayout()); |
| 57 | this.add(this.sortingPanel, BorderLayout.NORTH); | 86 | this.add(this.optionsPanel, BorderLayout.NORTH); |
| 58 | this.add(new JScrollPane(this.structureTree)); | 87 | this.add(new JScrollPane(this.structureTree)); |
| 59 | } | 88 | } |
| 60 | 89 | ||
| 61 | public JPanel getSortingPanel() { | 90 | public JPanel getSortingPanel() { |
| 62 | return this.sortingPanel; | 91 | return this.optionsPanel; |
| 63 | } | 92 | } |
| 64 | 93 | ||
| 65 | /** | 94 | /** |
| 66 | * Returns whether the "Hide Deobfuscated" option of this structure panel is selected. | 95 | * Creates and returns the options of this structure panel. |
| 67 | */ | 96 | */ |
| 68 | public boolean shouldHideDeobfuscated() { | 97 | public StructureTreeOptions getOptions() { |
| 69 | return this.hideDeobfuscated.isSelected(); | 98 | return new StructureTreeOptions( |
| 99 | (StructureTreeOptions.ObfuscationVisibility) this.obfuscationVisibility.getSelectedItem(), | ||
| 100 | (StructureTreeOptions.DocumentationVisibility) this.documentationVisibility.getSelectedItem(), | ||
| 101 | (StructureTreeOptions.SortingOrder) this.sortingOrder.getSelectedItem() | ||
| 102 | ); | ||
| 70 | } | 103 | } |
| 71 | 104 | ||
| 72 | public JTree getStructureTree() { | 105 | public JTree getStructureTree() { |
| @@ -74,7 +107,9 @@ public class StructurePanel extends JPanel { | |||
| 74 | } | 107 | } |
| 75 | 108 | ||
| 76 | public void retranslateUi() { | 109 | public void retranslateUi() { |
| 77 | this.hideDeobfuscated.setText(I18n.translate("info_panel.tree.structure.hide_deobfuscated")); | 110 | this.obfuscationVisibilityLabel.setText(I18n.translate("structure.options.obfuscation")); |
| 111 | this.documentationVisibilityLabel.setText(I18n.translate("structure.options.documentation")); | ||
| 112 | this.sortingOrderLabel.setText(I18n.translate("structure.options.sorting")); | ||
| 78 | } | 113 | } |
| 79 | 114 | ||
| 80 | class StructureTreeCellRenderer extends DefaultTreeCellRenderer { | 115 | class StructureTreeCellRenderer extends DefaultTreeCellRenderer { |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/StructureOptionListCellRenderer.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/StructureOptionListCellRenderer.java new file mode 100644 index 00000000..f9a1cae6 --- /dev/null +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/StructureOptionListCellRenderer.java | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | package cuchaz.enigma.gui.renderer; | ||
| 2 | |||
| 3 | import cuchaz.enigma.analysis.StructureTreeOptions; | ||
| 4 | import cuchaz.enigma.utils.I18n; | ||
| 5 | |||
| 6 | import javax.swing.*; | ||
| 7 | import java.awt.*; | ||
| 8 | |||
| 9 | public class StructureOptionListCellRenderer extends DefaultListCellRenderer { | ||
| 10 | |||
| 11 | @Override | ||
| 12 | public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { | ||
| 13 | Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); | ||
| 14 | |||
| 15 | if (value instanceof StructureTreeOptions.Option option) { | ||
| 16 | this.setText(I18n.translate(option.getTranslationKey())); | ||
| 17 | } | ||
| 18 | |||
| 19 | return c; | ||
| 20 | } | ||
| 21 | } | ||