Better resource importing

This commit is contained in:
Konloch 2021-06-26 05:33:42 -07:00
parent e25d6179f3
commit c90b1d45a6
4 changed files with 26 additions and 38 deletions

View file

@ -156,45 +156,30 @@ public class WorkPaneMainComponent extends VisibleComponent
}
//load class resources
public void addClassResource(final FileContainer container, String name, final ClassNode cn)
public void addClassResource(final FileContainer container, final String name, final ClassNode cn)
{
String workingName = container.name + ">" + name;
final String workingName = container.name + ">" + name;
if (!workingOn.containsKey(workingName))
{
final ClassViewer resourceView = new ClassViewer(container, name, cn, workingName);
tabs.add(resourceView);
final int tabIndex = tabs.indexOfComponent(resourceView);
workingOn.put(workingName, tabIndex);
TabbedPane tabbedPane = new TabbedPane(tabIndex, workingName, container.name, name, tabs, resourceView);
resourceView.tabbedPane = tabbedPane;
tabs.setTabComponentAt(tabIndex, tabbedPane);
tabs.setSelectedIndex(tabIndex);
resourceView.refreshTitle();
}
else
{
tabs.setSelectedIndex(workingOn.get(workingName));
}
addResource(container, name, new ClassViewer(container, name, cn, workingName));
}
//Load file resources
public void addFileResource(final FileContainer container, String name, byte[] contents)
public void addFileResource(final FileContainer container, final String name, byte[] contents)
{
if (contents == null) //a directory
return;
final String workingName = container.name + ">" + name;
/*if (Configuration.simplifiedTabNames)
name = MiscUtils.getChildFromPath(name);
if (Configuration.displayParentInTab)
name = container.name + ">" + name;*/
addResource(container, name, new FileViewer(container, name, contents, workingName));
}
private void addResource(final FileContainer container, final String name, final ResourceViewer resourceView)
{
final String workingName = container.name + ">" + name;
if (!workingOn.containsKey(workingName))
{
final FileViewer resourceView = new FileViewer(container, name, contents, workingName);
tabs.add(resourceView);
final int tabIndex = tabs.indexOfComponent(resourceView);
workingOn.put(workingName, tabIndex);
@ -207,8 +192,11 @@ public class WorkPaneMainComponent extends VisibleComponent
}
else
{
try {
tabs.setSelectedIndex(workingOn.get(workingName));
// TODO: need to look into if this exception is actually needed
// removing it for now, but keeping it incase this causes issues
try {
} catch (Exception e) {
//workingOn.remove(workingName);
e.printStackTrace();

View file

@ -61,7 +61,6 @@ public class ClassViewer extends ResourceViewer
{
public JSplitPane sp;
public JSplitPane sp2;
public TabbedPane tabbedPane;
public ResourceViewPanel resourceViewPanel1 = new ResourceViewPanel(0);
public ResourceViewPanel resourceViewPanel2 = new ResourceViewPanel(1);
public ResourceViewPanel resourceViewPanel3 = new ResourceViewPanel(2);

View file

@ -58,7 +58,6 @@ public class FileViewer extends ResourceViewer
Configuration.rstaTheme.apply(new SearchableRSyntaxTextArea());
public final JPanel mainPanel = new JPanel(new BorderLayout());
public TabbedPane tabbedPane;
public BufferedImage image;
public boolean canRefresh;

View file

@ -3,6 +3,7 @@ package the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer;
import javax.swing.JPanel;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.TabbedPane;
import the.bytecode.club.bytecodeviewer.util.FileContainer;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
@ -35,6 +36,7 @@ public abstract class ResourceViewer extends JPanel
public ClassNode cn;
public String name;
public FileContainer container;
public TabbedPane tabbedPane;
public abstract void refreshTitle();