Skip to content

Commit

Permalink
Fix for issue Konloch#499.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bl3nd committed Jul 4, 2024
1 parent cdb6573 commit d441bb9
Showing 1 changed file with 70 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Point;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JSplitPane;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
import javax.swing.*;
import javax.swing.text.BadLocationException;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
Expand Down Expand Up @@ -60,25 +52,17 @@ public class ClassViewer extends ResourceViewer
public BytecodeViewPanel bytecodeViewPanel1 = new BytecodeViewPanel(0, this);
public BytecodeViewPanel bytecodeViewPanel2 = new BytecodeViewPanel(1, this);
public BytecodeViewPanel bytecodeViewPanel3 = new BytecodeViewPanel(2, this);

public List<MethodParser> methods = Arrays.asList(new MethodParser(), new MethodParser(), new MethodParser());

public ClassViewer(final ResourceContainer container, final String name)
{
super(new Resource(name, container.getWorkingName(name), container));

this.setName(name);
this.setLayout(new BorderLayout());
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() {
@Override
public void componentResized(ComponentEvent e) {
resetDivider();
}
});

this.sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
}

@Override
Expand All @@ -92,7 +76,7 @@ public void refresh(final JButton button)
bytecodeViewPanel3.createPane(this);

byte[] classBytes = getResourceBytes();

//TODO remove this once all of the importers have been properly updated to use a FileContainerImporter
if(classBytes == null || classBytes.length == 0 || Configuration.forceResourceUpdateFromClassNode)
{
Expand All @@ -103,18 +87,18 @@ public void refresh(final JButton button)
System.err.println("WARNING: Class Resource imported using the old importer!");
System.err.println("TODO: Update it to use the FileContainerImporter");
}

classBytes = ASMUtil.nodeToBytes(resource.getResourceClassNode());
}

bytecodeViewPanel1.updatePane(this, classBytes, button, isPanel1Editable());
bytecodeViewPanel2.updatePane(this, classBytes, button, isPanel2Editable());
bytecodeViewPanel3.updatePane(this, classBytes, button, isPanel3Editable());

Thread dumpBuild = new Thread(() ->
{
BytecodeViewer.updateBusyStatus(true);

while (Configuration.currentlyDumping)
{
//wait until it's not dumping
Expand All @@ -140,20 +124,20 @@ public void refresh(final JButton button)
{
if (Configuration.warnForEditing)
return;

Configuration.warnForEditing = true;
if (!BytecodeViewer.viewer.autoCompileOnRefresh.isSelected()
&& !BytecodeViewer.viewer.compileOnSave.isSelected())
{
BytecodeViewer.showMessage("Make sure to compile (File>Compile or Ctrl + T) whenever you want to "
+ "test or export your changes.\nYou can set compile automatically on refresh or on save "
+ "in the settings menu.");

SettingsSerializer.saveSettingsAsync();
}
}
}

public void setPanes() {
bytecodeViewPanel1.decompiler = BytecodeViewer.viewer.viewPane1.getSelectedDecompiler();
bytecodeViewPanel2.decompiler = BytecodeViewer.viewer.viewPane2.getSelectedDecompiler();
Expand Down Expand Up @@ -218,7 +202,7 @@ public static int getMaxViewLine(RSyntaxTextArea area)
int lineHeight = area.getLineHeight();
return y >= lineHeight ? y / lineHeight : 0;
}

return 0;
}

Expand All @@ -232,7 +216,7 @@ public static int getViewLine(RSyntaxTextArea area)
int lineHeight = area.getLineHeight();
return point.y >= lineHeight ? point.y / lineHeight : 0;
}

return 0;
}

Expand All @@ -254,41 +238,66 @@ public static void setCaretLine(RSyntaxTextArea area, int line)
area.setCaretPosition(area.getLineStartOffset(line));
} catch (BadLocationException ignored) { }
}



public void resetDivider()
{
/*
This may be a bit overkill on how we handle setting/changing selected panels, but we now handle if only one panel is
selected, to not show any split panes but just the panel text.
*/

SwingUtilities.invokeLater(() ->
{
sp.setResizeWeight(0.5);

if (bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel1.decompiler != Decompiler.NONE) {
setDividerLocation(sp, 0.5);
} else if (bytecodeViewPanel1.decompiler != Decompiler.NONE) {
setDividerLocation(sp, 1);
} else if (bytecodeViewPanel2.decompiler != Decompiler.NONE) {
sp.setResizeWeight(1);
setDividerLocation(sp, 0);
} else {
setDividerLocation(sp, 0);
// This clears any component so we can "repaint" our components based on the users selections
for (Component c : this.getComponents()) {
if (c instanceof BytecodeViewPanel || c instanceof JSplitPane) {
this.remove(c);
}
}

if (bytecodeViewPanel3.decompiler != Decompiler.NONE) {
sp2.setResizeWeight(0.7);
setDividerLocation(sp2, 0.7);
if ((bytecodeViewPanel2.decompiler == Decompiler.NONE && bytecodeViewPanel1.decompiler != Decompiler.NONE)
|| (bytecodeViewPanel1.decompiler == Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE)) {
setDividerLocation(sp2, 0.5);
} else if (bytecodeViewPanel1.decompiler == Decompiler.NONE) {
setDividerLocation(sp2, 0);
}
} else {
sp.setResizeWeight(1);
sp2.setResizeWeight(0);
setDividerLocation(sp2, 1);

this.sp.setResizeWeight(0.5);
setDividerLocation(sp, 0.5);

/* If panel 1 and panel 2 are ticked but not panel 3 */
if (bytecodeViewPanel1.decompiler != Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel3.decompiler == Decompiler.NONE) {
this.sp.setLeftComponent(bytecodeViewPanel1);
this.sp.setRightComponent(bytecodeViewPanel2);
this.add(sp, BorderLayout.CENTER);
} /* If panel 1 and panel 3 are ticked but not panel 2 */
else if (bytecodeViewPanel1.decompiler != Decompiler.NONE && bytecodeViewPanel2.decompiler == Decompiler.NONE && bytecodeViewPanel3.decompiler != Decompiler.NONE) {
this.sp.setLeftComponent(bytecodeViewPanel1);
this.sp.setRightComponent(bytecodeViewPanel3);
this.add(sp, BorderLayout.CENTER);
} /* If panel 2 and panel 3 are ticked but not panel 1 */
else if (bytecodeViewPanel1.decompiler == Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel3.decompiler != Decompiler.NONE) {
this.sp.setLeftComponent(bytecodeViewPanel2);
this.sp.setRightComponent(bytecodeViewPanel3);
this.add(sp, BorderLayout.CENTER);
}

// If all panels are selected, create the second split pane
if (bytecodeViewPanel1.decompiler != Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel3.decompiler != Decompiler.NONE) {
this.sp.setLeftComponent(bytecodeViewPanel1);
this.sp.setRightComponent(bytecodeViewPanel2);
this.sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp, bytecodeViewPanel3);
this.sp2.setResizeWeight(0.7);
this.add(sp2);
}

/* If view panel 1 is only ticked... */
if (bytecodeViewPanel1.decompiler != Decompiler.NONE && bytecodeViewPanel2.decompiler == Decompiler.NONE && bytecodeViewPanel3.decompiler == Decompiler.NONE) {
this.add(bytecodeViewPanel1, BorderLayout.CENTER);
} /* If view panel 2 is only ticked... */
else if (bytecodeViewPanel1.decompiler == Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel3.decompiler == Decompiler.NONE) {
this.add(bytecodeViewPanel2, BorderLayout.CENTER);
} /* If view panel 3 is only ticked... */
else if (bytecodeViewPanel1.decompiler == Decompiler.NONE && bytecodeViewPanel2.decompiler == Decompiler.NONE && bytecodeViewPanel3.decompiler != Decompiler.NONE){
this.add(bytecodeViewPanel3, BorderLayout.CENTER);
}
});
}

/**
* Whoever wrote this function, THANK YOU!
*/
Expand Down Expand Up @@ -321,6 +330,6 @@ public void hierarchyChanged(HierarchyEvent e) {
}
return splitter;
}

private static final long serialVersionUID = -8650495368920680024L;
}

0 comments on commit d441bb9

Please sign in to comment.