Skip to content

Commit d441bb9

Browse files
committed
Fix for issue #499.
1 parent cdb6573 commit d441bb9

File tree

1 file changed

+70
-61
lines changed
  • src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer

1 file changed

+70
-61
lines changed

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/ClassViewer.java

Lines changed: 70 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
package the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer;
22

3-
import java.awt.BorderLayout;
4-
import java.awt.Container;
5-
import java.awt.Point;
6-
import java.awt.event.ComponentAdapter;
7-
import java.awt.event.ComponentEvent;
8-
import java.awt.event.HierarchyEvent;
9-
import java.awt.event.HierarchyListener;
3+
import java.awt.*;
4+
import java.awt.event.*;
105
import java.util.Arrays;
116
import java.util.List;
12-
import javax.swing.JButton;
13-
import javax.swing.JSplitPane;
14-
import javax.swing.JViewport;
15-
import javax.swing.SwingUtilities;
7+
import javax.swing.*;
168
import javax.swing.text.BadLocationException;
179
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
1810
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
@@ -60,25 +52,17 @@ public class ClassViewer extends ResourceViewer
6052
public BytecodeViewPanel bytecodeViewPanel1 = new BytecodeViewPanel(0, this);
6153
public BytecodeViewPanel bytecodeViewPanel2 = new BytecodeViewPanel(1, this);
6254
public BytecodeViewPanel bytecodeViewPanel3 = new BytecodeViewPanel(2, this);
63-
55+
6456
public List<MethodParser> methods = Arrays.asList(new MethodParser(), new MethodParser(), new MethodParser());
65-
57+
6658
public ClassViewer(final ResourceContainer container, final String name)
6759
{
6860
super(new Resource(name, container.getWorkingName(name), container));
69-
61+
7062
this.setName(name);
7163
this.setLayout(new BorderLayout());
72-
this.sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, bytecodeViewPanel1, bytecodeViewPanel2);
73-
this.sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp, bytecodeViewPanel3);
74-
this.add(sp2, BorderLayout.CENTER);
75-
76-
this.addComponentListener(new ComponentAdapter() {
77-
@Override
78-
public void componentResized(ComponentEvent e) {
79-
resetDivider();
80-
}
81-
});
64+
65+
this.sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
8266
}
8367

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

9478
byte[] classBytes = getResourceBytes();
95-
79+
9680
//TODO remove this once all of the importers have been properly updated to use a FileContainerImporter
9781
if(classBytes == null || classBytes.length == 0 || Configuration.forceResourceUpdateFromClassNode)
9882
{
@@ -103,18 +87,18 @@ public void refresh(final JButton button)
10387
System.err.println("WARNING: Class Resource imported using the old importer!");
10488
System.err.println("TODO: Update it to use the FileContainerImporter");
10589
}
106-
90+
10791
classBytes = ASMUtil.nodeToBytes(resource.getResourceClassNode());
10892
}
109-
93+
11094
bytecodeViewPanel1.updatePane(this, classBytes, button, isPanel1Editable());
11195
bytecodeViewPanel2.updatePane(this, classBytes, button, isPanel2Editable());
11296
bytecodeViewPanel3.updatePane(this, classBytes, button, isPanel3Editable());
11397

11498
Thread dumpBuild = new Thread(() ->
11599
{
116100
BytecodeViewer.updateBusyStatus(true);
117-
101+
118102
while (Configuration.currentlyDumping)
119103
{
120104
//wait until it's not dumping
@@ -140,20 +124,20 @@ public void refresh(final JButton button)
140124
{
141125
if (Configuration.warnForEditing)
142126
return;
143-
127+
144128
Configuration.warnForEditing = true;
145129
if (!BytecodeViewer.viewer.autoCompileOnRefresh.isSelected()
146130
&& !BytecodeViewer.viewer.compileOnSave.isSelected())
147131
{
148132
BytecodeViewer.showMessage("Make sure to compile (File>Compile or Ctrl + T) whenever you want to "
149133
+ "test or export your changes.\nYou can set compile automatically on refresh or on save "
150134
+ "in the settings menu.");
151-
135+
152136
SettingsSerializer.saveSettingsAsync();
153137
}
154138
}
155139
}
156-
140+
157141
public void setPanes() {
158142
bytecodeViewPanel1.decompiler = BytecodeViewer.viewer.viewPane1.getSelectedDecompiler();
159143
bytecodeViewPanel2.decompiler = BytecodeViewer.viewer.viewPane2.getSelectedDecompiler();
@@ -218,7 +202,7 @@ public static int getMaxViewLine(RSyntaxTextArea area)
218202
int lineHeight = area.getLineHeight();
219203
return y >= lineHeight ? y / lineHeight : 0;
220204
}
221-
205+
222206
return 0;
223207
}
224208

@@ -232,7 +216,7 @@ public static int getViewLine(RSyntaxTextArea area)
232216
int lineHeight = area.getLineHeight();
233217
return point.y >= lineHeight ? point.y / lineHeight : 0;
234218
}
235-
219+
236220
return 0;
237221
}
238222

@@ -254,41 +238,66 @@ public static void setCaretLine(RSyntaxTextArea area, int line)
254238
area.setCaretPosition(area.getLineStartOffset(line));
255239
} catch (BadLocationException ignored) { }
256240
}
257-
241+
242+
258243
public void resetDivider()
259244
{
245+
/*
246+
This may be a bit overkill on how we handle setting/changing selected panels, but we now handle if only one panel is
247+
selected, to not show any split panes but just the panel text.
248+
*/
249+
260250
SwingUtilities.invokeLater(() ->
261251
{
262-
sp.setResizeWeight(0.5);
263-
264-
if (bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel1.decompiler != Decompiler.NONE) {
265-
setDividerLocation(sp, 0.5);
266-
} else if (bytecodeViewPanel1.decompiler != Decompiler.NONE) {
267-
setDividerLocation(sp, 1);
268-
} else if (bytecodeViewPanel2.decompiler != Decompiler.NONE) {
269-
sp.setResizeWeight(1);
270-
setDividerLocation(sp, 0);
271-
} else {
272-
setDividerLocation(sp, 0);
252+
// This clears any component so we can "repaint" our components based on the users selections
253+
for (Component c : this.getComponents()) {
254+
if (c instanceof BytecodeViewPanel || c instanceof JSplitPane) {
255+
this.remove(c);
256+
}
273257
}
274-
275-
if (bytecodeViewPanel3.decompiler != Decompiler.NONE) {
276-
sp2.setResizeWeight(0.7);
277-
setDividerLocation(sp2, 0.7);
278-
if ((bytecodeViewPanel2.decompiler == Decompiler.NONE && bytecodeViewPanel1.decompiler != Decompiler.NONE)
279-
|| (bytecodeViewPanel1.decompiler == Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE)) {
280-
setDividerLocation(sp2, 0.5);
281-
} else if (bytecodeViewPanel1.decompiler == Decompiler.NONE) {
282-
setDividerLocation(sp2, 0);
283-
}
284-
} else {
285-
sp.setResizeWeight(1);
286-
sp2.setResizeWeight(0);
287-
setDividerLocation(sp2, 1);
258+
259+
this.sp.setResizeWeight(0.5);
260+
setDividerLocation(sp, 0.5);
261+
262+
/* If panel 1 and panel 2 are ticked but not panel 3 */
263+
if (bytecodeViewPanel1.decompiler != Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel3.decompiler == Decompiler.NONE) {
264+
this.sp.setLeftComponent(bytecodeViewPanel1);
265+
this.sp.setRightComponent(bytecodeViewPanel2);
266+
this.add(sp, BorderLayout.CENTER);
267+
} /* If panel 1 and panel 3 are ticked but not panel 2 */
268+
else if (bytecodeViewPanel1.decompiler != Decompiler.NONE && bytecodeViewPanel2.decompiler == Decompiler.NONE && bytecodeViewPanel3.decompiler != Decompiler.NONE) {
269+
this.sp.setLeftComponent(bytecodeViewPanel1);
270+
this.sp.setRightComponent(bytecodeViewPanel3);
271+
this.add(sp, BorderLayout.CENTER);
272+
} /* If panel 2 and panel 3 are ticked but not panel 1 */
273+
else if (bytecodeViewPanel1.decompiler == Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel3.decompiler != Decompiler.NONE) {
274+
this.sp.setLeftComponent(bytecodeViewPanel2);
275+
this.sp.setRightComponent(bytecodeViewPanel3);
276+
this.add(sp, BorderLayout.CENTER);
277+
}
278+
279+
// If all panels are selected, create the second split pane
280+
if (bytecodeViewPanel1.decompiler != Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel3.decompiler != Decompiler.NONE) {
281+
this.sp.setLeftComponent(bytecodeViewPanel1);
282+
this.sp.setRightComponent(bytecodeViewPanel2);
283+
this.sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp, bytecodeViewPanel3);
284+
this.sp2.setResizeWeight(0.7);
285+
this.add(sp2);
286+
}
287+
288+
/* If view panel 1 is only ticked... */
289+
if (bytecodeViewPanel1.decompiler != Decompiler.NONE && bytecodeViewPanel2.decompiler == Decompiler.NONE && bytecodeViewPanel3.decompiler == Decompiler.NONE) {
290+
this.add(bytecodeViewPanel1, BorderLayout.CENTER);
291+
} /* If view panel 2 is only ticked... */
292+
else if (bytecodeViewPanel1.decompiler == Decompiler.NONE && bytecodeViewPanel2.decompiler != Decompiler.NONE && bytecodeViewPanel3.decompiler == Decompiler.NONE) {
293+
this.add(bytecodeViewPanel2, BorderLayout.CENTER);
294+
} /* If view panel 3 is only ticked... */
295+
else if (bytecodeViewPanel1.decompiler == Decompiler.NONE && bytecodeViewPanel2.decompiler == Decompiler.NONE && bytecodeViewPanel3.decompiler != Decompiler.NONE){
296+
this.add(bytecodeViewPanel3, BorderLayout.CENTER);
288297
}
289298
});
290299
}
291-
300+
292301
/**
293302
* Whoever wrote this function, THANK YOU!
294303
*/
@@ -321,6 +330,6 @@ public void hierarchyChanged(HierarchyEvent e) {
321330
}
322331
return splitter;
323332
}
324-
333+
325334
private static final long serialVersionUID = -8650495368920680024L;
326335
}

0 commit comments

Comments
 (0)