From 469681805654e5dc9c8d7eaeaa6474c230c6fe6e Mon Sep 17 00:00:00 2001 From: Konloch Date: Thu, 15 Jul 2021 20:50:05 -0700 Subject: [PATCH] Workspace Refactoring --- .../club/bytecodeviewer/BytecodeViewer.java | 5 ++- .../bytecodeviewer/gui/MainViewerGUI.java | 5 +-- .../components/DecompilerViewComponent.java | 4 +- .../gui/resourceviewer/BytecodeViewPanel.java | 9 ++--- ...kPaneMainComponent.java => Workspace.java} | 40 +++++++++++++------ ...PaneRefresh.java => WorkspaceRefresh.java} | 4 +- .../WorkspaceRefreshEvent.java} | 5 ++- .../resourceviewer/viewer/ClassViewer.java | 4 +- .../gui/util/BytecodeViewPanelUpdater.java | 10 ++--- 9 files changed, 50 insertions(+), 36 deletions(-) rename src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/{WorkPaneMainComponent.java => Workspace.java} (90%) rename src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/{WorkPaneRefresh.java => WorkspaceRefresh.java} (91%) rename src/main/java/the/bytecode/club/bytecodeviewer/{util/RefreshWorkPane.java => gui/resourceviewer/WorkspaceRefreshEvent.java} (93%) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 7626e84f..b82c5fe3 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -201,13 +201,14 @@ public class BytecodeViewer bootCheck.start(); Boot.boot(args, CLI != CommandLineInput.GUI); } - + + //CLI arguments say spawn the GUI if (CLI == CommandLineInput.GUI) { BytecodeViewer.boot(false); Configuration.bootState = Configuration.BootState.GUI_SHOWING; } - else + else //CLI arguments say keep it CLI { BytecodeViewer.boot(true); CommandLineInput.executeCommandLine(args); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index 9c15a6ae..bbdb5485 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Map; import javax.swing.*; -import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.*; import the.bytecode.club.bytecodeviewer.gui.components.*; import the.bytecode.club.bytecodeviewer.gui.plugins.MaliciousCodeScannerOptions; @@ -16,7 +15,7 @@ import the.bytecode.club.bytecodeviewer.gui.plugins.ReplaceStringsOptions; import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListPane; import the.bytecode.club.bytecodeviewer.gui.resourcesearch.SearchBoxPane; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.DecompilerSelectionPane; -import the.bytecode.club.bytecodeviewer.gui.resourceviewer.WorkPaneMainComponent; +import the.bytecode.club.bytecodeviewer.gui.resourceviewer.Workspace; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer; import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme; @@ -72,7 +71,7 @@ public class MainViewerGUI extends JFrame //main UI components private static final ArrayList uiComponents = new ArrayList<>(); - public final WorkPaneMainComponent workPane = new WorkPaneMainComponent(); + public final Workspace workPane = new Workspace(); public final ResourceListPane resourcePane = new ResourceListPane(); public final SearchBoxPane searchBoxPane = new SearchBoxPane(); public JSplitPane splitPane1; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java index 9d7951eb..e093d358 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/DecompilerViewComponent.java @@ -4,7 +4,7 @@ import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.translation.Translation; import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJCheckBoxMenuItem; import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJRadioButtonMenuItem; -import the.bytecode.club.bytecodeviewer.util.RefreshWorkPane; +import the.bytecode.club.bytecodeviewer.gui.resourceviewer.WorkspaceRefreshEvent; import javax.swing.*; @@ -68,7 +68,7 @@ public class DecompilerViewComponent menu.add(editable); } - java.addActionListener(new RefreshWorkPane()); + java.addActionListener(new WorkspaceRefreshEvent()); } public void addToGroup(ButtonGroup group) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/BytecodeViewPanel.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/BytecodeViewPanel.java index 1f7a58a9..187fd1f6 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/BytecodeViewPanel.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/BytecodeViewPanel.java @@ -39,10 +39,8 @@ import static the.bytecode.club.bytecodeviewer.Constants.nl; * @author Konloch * @since 6/24/2021 */ -public class BytecodeViewPanel +public class BytecodeViewPanel extends JPanel { - public final JPanel panel = new JPanel(new BorderLayout()); - public final int panelIndex; public final ClassViewer viewer; public SearchableRSyntaxTextArea textArea; @@ -52,17 +50,18 @@ public class BytecodeViewPanel public BytecodeViewPanel(int panelIndex, ClassViewer viewer) { + super(new BorderLayout()); this.panelIndex = panelIndex; this.viewer = viewer; } public void createPane(ClassViewer viewer) { - panel.removeAll(); + removeAll(); textArea = null; if(viewer.resource == null || viewer.resource.getResourceClassNode() == null) - panel.add(new JLabel("ERROR: Resource Viewer Corrupt ClassNode")); + add(new JLabel("ERROR: Resource Viewer Corrupt ClassNode")); } public void updatePane(ClassViewer cv, byte[] b, JButton button, boolean isPanelEditable) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneMainComponent.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java similarity index 90% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneMainComponent.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java index 2d633002..51a9de36 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneMainComponent.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java @@ -12,7 +12,7 @@ import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JTabbedPane; -import org.objectweb.asm.tree.ClassNode; + import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.FileViewer; @@ -49,14 +49,15 @@ import static the.bytecode.club.bytecodeviewer.Constants.BLOCK_TAB_MENU; * @author WaterWolf * @since 09/26/2011 */ -public class WorkPaneMainComponent extends TranslatedVisibleComponent + +public class Workspace extends TranslatedVisibleComponent { public final JTabbedPane tabs; public final JPanel buttonPanel; public final JButton refreshClass; public final HashSet openedTabs = new HashSet<>(); - public WorkPaneMainComponent() + public Workspace() { super("Workspace", Translation.WORK_SPACE); @@ -145,7 +146,7 @@ public class WorkPaneMainComponent extends TranslatedVisibleComponent refreshClass.addActionListener((event)-> { refreshClass.setEnabled(false); - Thread t = new Thread(() -> new WorkPaneRefresh(event).run(), "Refresh"); + Thread t = new Thread(() -> new WorkspaceRefresh(event).run(), "Refresh"); t.start(); }); @@ -179,28 +180,41 @@ public class WorkPaneMainComponent extends TranslatedVisibleComponent //create a new tab if the resource isn't opened currently if (!openedTabs.contains(workingName)) { + //start processing the resource to be viewed if(resourceView instanceof ClassViewer) - { - ((ClassViewer)resourceView).refresh(null); - } - - resourceView.resource.workingName = workingName; + resourceView.refresh(null); + //add the resource view to the tabs tabs.add(resourceView); + + //get the resource view index final int tabIndex = tabs.indexOfComponent(resourceView); - openedTabs.add(workingName); - + + //create a new tabbed pane TabbedPane tabbedPane = new TabbedPane(tabIndex, workingName, container.name, name, tabs, resourceView); resourceView.tabbedPane = tabbedPane; + resourceView.resource.workingName = workingName; + + //set the tabs index tabs.setTabComponentAt(tabIndex, tabbedPane); + + //open the tab that was just added tabs.setSelectedIndex(tabIndex); + + //set resource as opened in a tab + openedTabs.add(workingName); + + //refresh the tab title resourceView.refreshTitle(); } - //if the resource is already opened select this tab as the active one - else + else //if the resource is already opened select this tab as the active one { + //TODO openedTabs could be changed to a HashMap for faster lookups + + //search through each tab for(int i = 0; i < tabs.getTabCount(); i++) { + //find the matching resource and open it ResourceViewer tab = ((TabbedPane)tabs.getTabComponentAt(i)).resource; if(tab.resource.workingName.equals(workingName)) { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneRefresh.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkspaceRefresh.java similarity index 91% rename from src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneRefresh.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkspaceRefresh.java index 7824789d..87c8b533 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkPaneRefresh.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkspaceRefresh.java @@ -13,11 +13,11 @@ import java.awt.event.ActionEvent; * @author Konloch * @since 6/24/2021 */ -public class WorkPaneRefresh implements Runnable +public class WorkspaceRefresh implements Runnable { private final ActionEvent event; - public WorkPaneRefresh(ActionEvent event) { + public WorkspaceRefresh(ActionEvent event) { this.event = event; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/RefreshWorkPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkspaceRefreshEvent.java similarity index 93% rename from src/main/java/the/bytecode/club/bytecodeviewer/util/RefreshWorkPane.java rename to src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkspaceRefreshEvent.java index 3d824911..837752e8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/RefreshWorkPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/WorkspaceRefreshEvent.java @@ -1,4 +1,4 @@ -package the.bytecode.club.bytecodeviewer.util; +package the.bytecode.club.bytecodeviewer.gui.resourceviewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer; @@ -27,7 +27,8 @@ import java.awt.event.ActionListener; * @author Konloch * @since 6/21/2021 */ -public class RefreshWorkPane implements ActionListener + +public class WorkspaceRefreshEvent implements ActionListener { @Override public void actionPerformed(ActionEvent e) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java index 33ff224e..c94e44b4 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java @@ -72,8 +72,8 @@ public class ClassViewer extends ResourceViewer this.setName(name); this.setLayout(new BorderLayout()); - this.sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, bytecodeViewPanel1.panel, bytecodeViewPanel2.panel); - this.sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp, bytecodeViewPanel3.panel); + this.sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, bytecodeViewPanel1, bytecodeViewPanel2); + this.sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp, bytecodeViewPanel3); this.add(sp2, BorderLayout.CENTER); this.addComponentListener(new ComponentAdapter() { diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java index df78fa2b..b589f477 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java @@ -98,7 +98,7 @@ public class BytecodeViewPanelUpdater implements Runnable final JHexEditor hex = new JHexEditor(cw.toByteArray()); hex.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue())); - bytecodeViewPanel.panel.add(hex); + bytecodeViewPanel.add(hex); }); } else @@ -221,7 +221,7 @@ public class BytecodeViewPanelUpdater implements Runnable } if (BytecodeViewer.viewer.synchronizedViewing.isSelected()) { int panes = 2; - if (viewer.bytecodeViewPanel3.panel != null) + if (viewer.bytecodeViewPanel3 != null) panes = 3; for (int i = 0; i < panes; i++) { @@ -239,7 +239,7 @@ public class BytecodeViewPanelUpdater implements Runnable @Override public void stateChanged(ChangeEvent e) { int panes = 2; - if (viewer.bytecodeViewPanel3.panel != null) + if (viewer.bytecodeViewPanel3 != null) panes = 3; if (BytecodeViewer.viewer.synchronizedViewing.isSelected()) { @@ -381,8 +381,8 @@ public class BytecodeViewPanelUpdater implements Runnable updateUpdaterTextArea = new SearchableRSyntaxTextArea(); Configuration.rstaTheme.apply(updateUpdaterTextArea); - bytecodeViewPanel.panel.add(updateUpdaterTextArea.getScrollPane()); - bytecodeViewPanel.panel.add(updateUpdaterTextArea.getTitleHeader(), BorderLayout.NORTH); + bytecodeViewPanel.add(updateUpdaterTextArea.getScrollPane()); + bytecodeViewPanel.add(updateUpdaterTextArea.getTitleHeader(), BorderLayout.NORTH); bytecodeViewPanel.textArea = updateUpdaterTextArea; bytecodeViewPanel.textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);