From 1ec1ece9efbcc668b9c79de58d79b3176da1b7ca Mon Sep 17 00:00:00 2001 From: YanisBft Date: Tue, 15 Jun 2021 23:30:03 +0200 Subject: 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--- .../src/main/java/cuchaz/enigma/gui/Gui.java | 2 +- .../main/java/cuchaz/enigma/gui/GuiController.java | 4 +- .../cuchaz/enigma/gui/panels/StructurePanel.java | 63 +++++++++++++++++----- .../renderer/StructureOptionListCellRenderer.java | 21 ++++++++ 4 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/StructureOptionListCellRenderer.java (limited to 'enigma-swing') 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 { this.structurePanel.getSortingPanel().setVisible(true); // get the class structure - StructureTreeNode node = this.controller.getClassStructure(classEntry, this.structurePanel.shouldHideDeobfuscated()); + StructureTreeNode node = this.controller.getClassStructure(classEntry, this.structurePanel.getOptions()); // show the tree at the root 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 { chp.invalidateMapped(); } - public StructureTreeNode getClassStructure(ClassEntry entry, boolean hideDeobfuscated) { + public StructureTreeNode getClassStructure(ClassEntry entry, StructureTreeOptions options) { StructureTreeNode rootNode = new StructureTreeNode(this.project, entry, entry); - rootNode.load(this.project, hideDeobfuscated); + rootNode.load(this.project, options); return rootNode; } 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 @@ package cuchaz.enigma.gui.panels; +import cuchaz.enigma.analysis.StructureTreeOptions; import cuchaz.enigma.analysis.StructureTreeNode; import cuchaz.enigma.gui.Gui; +import cuchaz.enigma.gui.renderer.StructureOptionListCellRenderer; +import cuchaz.enigma.gui.util.GridBagConstraintsBuilder; import cuchaz.enigma.gui.util.GuiUtil; import cuchaz.enigma.gui.util.SingleTreeSelectionModel; import cuchaz.enigma.translation.representation.entry.ClassEntry; @@ -18,17 +21,41 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class StructurePanel extends JPanel { - private JPanel sortingPanel; - private JCheckBox hideDeobfuscated; + private final JPanel optionsPanel; - private JTree structureTree; + private final JLabel obfuscationVisibilityLabel = new JLabel(); + private final JLabel documentationVisibilityLabel = new JLabel(); + private final JLabel sortingOrderLabel = new JLabel(); + + private final JComboBox obfuscationVisibility; + private final JComboBox documentationVisibility; + private final JComboBox sortingOrder; + + private final JTree structureTree; public StructurePanel(Gui gui) { - this.sortingPanel = new JPanel(); - this.hideDeobfuscated = new JCheckBox(I18n.translate("info_panel.tree.structure.hide_deobfuscated")); - this.hideDeobfuscated.addActionListener(event -> gui.showStructure(gui.getActiveEditor())); - this.sortingPanel.add(this.hideDeobfuscated); - this.sortingPanel.setVisible(false); + this.optionsPanel = new JPanel(new GridBagLayout()); + this.optionsPanel.setVisible(false); + + GridBagConstraintsBuilder cb = GridBagConstraintsBuilder.create().insets(5).fill(GridBagConstraints.HORIZONTAL); + + this.optionsPanel.add(this.obfuscationVisibilityLabel, cb.pos(0, 0).build()); + this.obfuscationVisibility = new JComboBox<>(StructureTreeOptions.ObfuscationVisibility.values()); + this.obfuscationVisibility.setRenderer(new StructureOptionListCellRenderer()); + this.obfuscationVisibility.addActionListener(event -> gui.showStructure(gui.getActiveEditor())); + this.optionsPanel.add(this.obfuscationVisibility, cb.pos(1, 0).build()); + + this.optionsPanel.add(this.documentationVisibilityLabel, cb.pos(0, 1).build()); + this.documentationVisibility = new JComboBox<>(StructureTreeOptions.DocumentationVisibility.values()); + this.documentationVisibility.setRenderer(new StructureOptionListCellRenderer()); + this.documentationVisibility.addActionListener(event -> gui.showStructure(gui.getActiveEditor())); + this.optionsPanel.add(this.documentationVisibility, cb.pos(1, 1).build()); + + this.optionsPanel.add(this.sortingOrderLabel, cb.pos(0, 2).build()); + this.sortingOrder = new JComboBox<>(StructureTreeOptions.SortingOrder.values()); + this.sortingOrder.setRenderer(new StructureOptionListCellRenderer()); + this.sortingOrder.addActionListener(event -> gui.showStructure(gui.getActiveEditor())); + this.optionsPanel.add(this.sortingOrder, cb.pos(1, 2).build()); this.structureTree = new JTree(); this.structureTree.setModel(null); @@ -53,20 +80,26 @@ public class StructurePanel extends JPanel { } }); + this.retranslateUi(); + this.setLayout(new BorderLayout()); - this.add(this.sortingPanel, BorderLayout.NORTH); + this.add(this.optionsPanel, BorderLayout.NORTH); this.add(new JScrollPane(this.structureTree)); } public JPanel getSortingPanel() { - return this.sortingPanel; + return this.optionsPanel; } /** - * Returns whether the "Hide Deobfuscated" option of this structure panel is selected. + * Creates and returns the options of this structure panel. */ - public boolean shouldHideDeobfuscated() { - return this.hideDeobfuscated.isSelected(); + public StructureTreeOptions getOptions() { + return new StructureTreeOptions( + (StructureTreeOptions.ObfuscationVisibility) this.obfuscationVisibility.getSelectedItem(), + (StructureTreeOptions.DocumentationVisibility) this.documentationVisibility.getSelectedItem(), + (StructureTreeOptions.SortingOrder) this.sortingOrder.getSelectedItem() + ); } public JTree getStructureTree() { @@ -74,7 +107,9 @@ public class StructurePanel extends JPanel { } public void retranslateUi() { - this.hideDeobfuscated.setText(I18n.translate("info_panel.tree.structure.hide_deobfuscated")); + this.obfuscationVisibilityLabel.setText(I18n.translate("structure.options.obfuscation")); + this.documentationVisibilityLabel.setText(I18n.translate("structure.options.documentation")); + this.sortingOrderLabel.setText(I18n.translate("structure.options.sorting")); } 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 @@ +package cuchaz.enigma.gui.renderer; + +import cuchaz.enigma.analysis.StructureTreeOptions; +import cuchaz.enigma.utils.I18n; + +import javax.swing.*; +import java.awt.*; + +public class StructureOptionListCellRenderer extends DefaultListCellRenderer { + + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + + if (value instanceof StructureTreeOptions.Option option) { + this.setText(I18n.translate(option.getTranslationKey())); + } + + return c; + } +} -- cgit v1.2.3