diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 473c42af..28c64097 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -12,7 +12,6 @@ import org.apache.commons.io.FileUtils; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bootloader.Boot; import the.bytecode.club.bytecodeviewer.api.ClassNodeLoader; -import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.gui.components.*; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.TabbedPane; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer; @@ -276,14 +275,40 @@ public class BytecodeViewer return Configuration.java; } + + /** + * Returns true if there is currently a tab open with a resource inside of it + */ + public static boolean hasActiveResource() + { + return getActiveResource() != null; + } + + /** + * Returns true if there is currently a tab open with a resource inside of it + */ + public static boolean isActiveResourceClass() + { + ResourceViewer resource = getActiveResource(); + return resource instanceof ClassViewer; + } + + /** + * Returns the currently opened & viewed resource + */ + public static ResourceViewer getActiveResource() + { + return BytecodeViewer.viewer.workPane.getActiveResource(); + } /** * Returns the currently opened ClassNode * * @return the currently opened ClassNode */ - public static ClassNode getCurrentlyOpenedClassNode() { - return viewer.workPane.getCurrentViewer().cn; + public static ClassNode getCurrentlyOpenedClassNode() + { + return getActiveResource().cn; } /** diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java index 7faa3263..088dc3b4 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java @@ -96,8 +96,9 @@ public class GlobalHotKeys else if ((e.getKeyCode() == KeyEvent.VK_W) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { Configuration.lastHotKeyExecuted = System.currentTimeMillis(); - if (BytecodeViewer.viewer.workPane.getCurrentViewer() != null) - BytecodeViewer.viewer.workPane.tabs.remove(BytecodeViewer.viewer.workPane.getCurrentViewer()); + + if (BytecodeViewer.hasActiveResource()) + BytecodeViewer.viewer.workPane.tabs.remove(BytecodeViewer.viewer.workPane.getActiveResource()); } } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchBoxPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchBoxPane.java index 3e55952e..9d642ec3 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchBoxPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourcesearch/SearchBoxPane.java @@ -16,8 +16,6 @@ import javax.swing.tree.DefaultMutableTreeNode; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI; -import the.bytecode.club.bytecodeviewer.gui.resourceviewer.WorkPaneMainComponent; import the.bytecode.club.bytecodeviewer.gui.components.VisibleComponent; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer; import the.bytecode.club.bytecodeviewer.searching.BackgroundSearchThread; @@ -179,11 +177,10 @@ public class SearchBoxPane extends VisibleComponent } else if (radius == SearchRadius.Current_Class) { - final ResourceViewer cv = Objects.requireNonNull(MainViewerGUI.getComponent(WorkPaneMainComponent.class)).getCurrentViewer(); + final ResourceViewer cv = BytecodeViewer.getActiveResource(); + if (cv != null) - { searchType.details.search(cv.container, cv.cn, srn, exact.isSelected()); - } } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneMainComponent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneMainComponent.java index d8ea4ddb..71fd49bb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneMainComponent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneMainComponent.java @@ -211,7 +211,7 @@ public class WorkPaneMainComponent extends VisibleComponent } } - public ResourceViewer getCurrentViewer() { + public ResourceViewer getActiveResource() { return (ResourceViewer) tabs.getSelectedComponent(); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java index d00a5a01..65c7a465 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/CodeSequenceDiagram.java @@ -15,7 +15,6 @@ import org.objectweb.asm.tree.MethodNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Resources; import the.bytecode.club.bytecodeviewer.api.Plugin; -import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer; import the.bytecode.club.bytecodeviewer.plugin.PluginManager; /*************************************************************************** @@ -58,19 +57,13 @@ public class CodeSequenceDiagram extends Plugin if (BytecodeViewer.promptIfNoLoadedClasses()) return; - if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer)) + if (!BytecodeViewer.isActiveResourceClass()) { BytecodeViewer.showMessage("First open a class file."); return; } - ClassNode c = BytecodeViewer.viewer.workPane.getCurrentViewer().cn; - if (c == null) - { - BytecodeViewer.showMessage("Current viewer ClassNode is null inside of CodeSequenceDiagram. Please report to @Konloch"); - return; - } - + ClassNode c = BytecodeViewer.getCurrentlyOpenedClassNode(); JFrame frame = new JFrame("Code Sequence Diagram - " + c.name); frame.setIconImages(Resources.iconList); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java index 7a352dda..5c2724c2 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java @@ -5,10 +5,8 @@ import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.Configuration; -import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; -import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer; import the.bytecode.club.bytecodeviewer.util.DialogueUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.MiscUtils; @@ -182,7 +180,7 @@ public class ResourceDecompiling if (BytecodeViewer.promptIfNoLoadedClasses()) return; - if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null || !(BytecodeViewer.viewer.workPane.getCurrentViewer() instanceof ClassViewer)) + if (!BytecodeViewer.isActiveResourceClass()) { BytecodeViewer.showMessage("First open a class file."); return; @@ -193,7 +191,7 @@ public class ResourceDecompiling if (BytecodeViewer.autoCompileSuccessful()) return; - final String s = BytecodeViewer.viewer.workPane.getCurrentViewer().cn.name; + final String s = BytecodeViewer.getCurrentlyOpenedClassNode().name; if (s == null) return; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/RefreshWorkPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/RefreshWorkPane.java index 68b19a1e..ecd29775 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/RefreshWorkPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/RefreshWorkPane.java @@ -14,8 +14,9 @@ public class RefreshWorkPane implements ActionListener @Override public void actionPerformed(ActionEvent e) { - if (BytecodeViewer.viewer.refreshOnChange.isSelected()) { - if (BytecodeViewer.viewer.workPane.getCurrentViewer() == null) + if (BytecodeViewer.viewer.refreshOnChange.isSelected()) + { + if (!BytecodeViewer.hasActiveResource()) return; BytecodeViewer.viewer.workPane.refreshClass.doClick();