diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/AbstractInheritanceTreeDocker.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/AbstractInheritanceTreeDocker.java index fe25aeb05..9acf17d29 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/AbstractInheritanceTreeDocker.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/AbstractInheritanceTreeDocker.java @@ -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) { @@ -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); @@ -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); @@ -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)); + } } diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/ImplementationsTreeDocker.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/ImplementationsTreeDocker.java index 8bf56101e..2e998b74c 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/ImplementationsTreeDocker.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/ImplementationsTreeDocker.java @@ -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 diff --git a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/InheritanceTreeDocker.java b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/InheritanceTreeDocker.java index 72148ae14..cb839ec6d 100644 --- a/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/InheritanceTreeDocker.java +++ b/enigma-swing/src/main/java/org/quiltmc/enigma/gui/docker/InheritanceTreeDocker.java @@ -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 diff --git a/enigma/src/main/resources/lang/en_us.json b/enigma/src/main/resources/lang/en_us.json index 373690d8d..005ca5175 100644 --- a/enigma/src/main/resources/lang/en_us.json +++ b/enigma/src/main/resources/lang/en_us.json @@ -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",