Workspace Refactoring
This commit is contained in:
parent
45c9cd5d1a
commit
4696818056
9 changed files with 50 additions and 36 deletions
|
@ -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);
|
||||
|
|
|
@ -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<VisibleComponent> 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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<String> 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<String, Integer> 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))
|
||||
{
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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)
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue