Skip to content

Commit

Permalink
add inactive states for inheritance tree dockers
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Apr 4, 2024
1 parent e46230c commit efa04ca
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,44 @@
import org.quiltmc.enigma.gui.util.GuiUtil;
import org.quiltmc.enigma.gui.util.SingleTreeSelectionModel;
import org.quiltmc.enigma.api.translation.representation.entry.Entry;
import org.quiltmc.enigma.util.I18n;

import javax.annotation.Nullable;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.awt.BorderLayout;
import java.awt.event.MouseEvent;

public abstract class AbstractInheritanceTreeDocker extends Docker {
private final JTree tree = new JTree();
private final JLabel inactiveLabel = new JLabel();
private final JLabel notFoundLabel = new JLabel();
private final JPanel textPanel;
private final String inactiveTextKey;
private final String notFoundKey;

protected AbstractInheritanceTreeDocker(Gui gui, TreeCellRenderer cellRenderer) {
protected AbstractInheritanceTreeDocker(Gui gui, TreeCellRenderer cellRenderer, String inactiveTextKey, String notFoundKey) {
super(gui);

this.textPanel = new JPanel(new BorderLayout());
this.inactiveTextKey = inactiveTextKey;
this.notFoundKey = notFoundKey;
this.retranslateUi();
this.textPanel.add(this.inactiveLabel, BorderLayout.NORTH);
this.add(this.textPanel);

this.tree.setModel(null);
this.tree.setCellRenderer(cellRenderer);
this.tree.setSelectionModel(new SingleTreeSelectionModel());
this.tree.setShowsRootHandles(true);
this.tree.addMouseListener(GuiUtil.onMouseClick(this::onClick));

this.add(new JScrollPane(this.tree));
}

private void onClick(MouseEvent event) {
Expand All @@ -49,6 +63,17 @@ private void onClick(MouseEvent event) {
}
}

private void setupTree(@Nullable TreeModel model) {
this.tree.setModel(model);
if (model != null) {
this.remove(this.textPanel);
this.add(this.tree);
} else {
this.textPanel.remove(this.inactiveLabel);
this.textPanel.add(this.notFoundLabel, BorderLayout.NORTH);
}
}

public void display(Entry<?> entry) {
this.tree.setModel(null);

Expand All @@ -57,9 +82,11 @@ public void display(Entry<?> entry) {
if (node != null) {
// show the tree at the root
TreePath path = GuiUtil.getPathToRoot(node);
this.tree.setModel(new DefaultTreeModel((TreeNode) path.getPathComponent(0)));
this.setupTree(new DefaultTreeModel((TreeNode) path.getPathComponent(0)));
this.tree.expandPath(path);
this.tree.setSelectionRow(this.tree.getRowForPath(path));
} else {
setupTree(null);
}

this.setVisible(true);
Expand All @@ -72,4 +99,10 @@ public void display(Entry<?> entry) {
public Location getPreferredButtonLocation() {
return new Location(Side.RIGHT, VerticalLocation.TOP);
}

@Override
public void retranslateUi() {
this.inactiveLabel.setText(I18n.translate(this.inactiveTextKey));
this.notFoundLabel.setText(I18n.translate(this.notFoundKey));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class ImplementationsTreeDocker extends AbstractInheritanceTreeDocker {
public ImplementationsTreeDocker(Gui gui) {
super(gui, new ImplementationsTreeCellRenderer(gui));
super(gui, new ImplementationsTreeCellRenderer(gui), "docker.implementations.inactive", "docker.implementations.not_found");
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class InheritanceTreeDocker extends AbstractInheritanceTreeDocker {
public InheritanceTreeDocker(Gui gui) {
super(gui, new InheritanceTreeCellRenderer(gui));
super(gui, new InheritanceTreeCellRenderer(gui), "docker.inheritance.inactive", "docker.inheritance.not_found");
}

@Nullable
Expand Down
4 changes: 4 additions & 0 deletions enigma/src/main/resources/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,11 @@
"docker.calls.title": "Calls",
"docker.structure.title": "Structure",
"docker.inheritance.title": "Inheritance",
"docker.inheritance.inactive": "No entry selected!",
"docker.inheritance.not_found": "No inheritors found!",
"docker.implementations.title": "Implementations",
"docker.implementations.inactive": "No entry selected!",
"docker.implementations.not_found": "No implementations found!",
"docker.all_classes.title": "Classes",
"docker.obfuscated_classes.title": "Obfuscated Classes",
"docker.deobfuscated_classes.title": "Deobfuscated Classes",
Expand Down

0 comments on commit efa04ca

Please sign in to comment.