Skip to content

Commit 39266f3

Browse files
committed
Fix window sizes
Ughhh.
1 parent 3740690 commit 39266f3

File tree

6 files changed

+135
-57
lines changed

6 files changed

+135
-57
lines changed

src/main/java/the/bytecode/club/jda/JDA.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import the.bytecode.club.jda.api.ExceptionUI;
77
import the.bytecode.club.jda.gui.FileNavigationPane;
88
import the.bytecode.club.jda.gui.MainViewerGUI;
9-
import the.bytecode.club.jda.gui.WorkPane;
109

1110
import javax.swing.*;
1211
import javax.swing.filechooser.FileFilter;
@@ -76,7 +75,7 @@ public static void main(String[] args)
7675
Settings.loadGUI();
7776
viewer = new MainViewerGUI();
7877
Boot.boot();
79-
JDA.boot(args, false);
78+
JDA.boot(args);
8079
}
8180
catch (Exception e)
8281
{
@@ -98,10 +97,8 @@ public void run()
9897

9998
/**
10099
* Boot after all of the libraries have been loaded
101-
*
102-
* @param cli is it running CLI mode or not
103100
*/
104-
public static void boot(String[] args, boolean cli)
101+
public static void boot(String[] args)
105102
{
106103
cleanup();
107104
Runtime.getRuntime().addShutdownHook(new Thread()
@@ -124,23 +121,22 @@ public void run()
124121
}
125122
});
126123

127-
viewer.calledAfterLoad();
128124
resetRecentFilesMenu();
129125

130126
if (viewer.mntmUpdateCheck.isSelected())
131127
versionChecker.start();
132128

133-
if (!cli)
134-
viewer.setVisible(true);
129+
viewer.setVisible(true);
130+
131+
viewer.calledAfterLoad();
135132

136133
System.out.println("Start up took " + ((System.currentTimeMillis() - start) / 1000) + " seconds");
137134

138-
if (!cli)
139-
if (args.length >= 1)
140-
for (String s : args)
141-
{
142-
openFiles(new File[] { new File(s) }, true);
143-
}
135+
if (args.length >= 1)
136+
for (String s : args)
137+
{
138+
openFiles(new File[] { new File(s) }, true);
139+
}
144140
}
145141

146142
/**
@@ -437,8 +433,7 @@ public static void resetWorkSpace(boolean ask)
437433
if (!ask)
438434
{
439435
files.clear();
440-
MainViewerGUI.getComponent(FileNavigationPane.class).resetWorkspace();
441-
MainViewerGUI.getComponent(WorkPane.class).resetWorkspace();
436+
viewer.resetWorkspace();
442437
the.bytecode.club.jda.api.BytecodeViewer.getClassNodeLoader().clear();
443438
}
444439
else
@@ -457,8 +452,7 @@ public static void resetWorkSpace(boolean ask)
457452
if (result == 0)
458453
{
459454
files.clear();
460-
MainViewerGUI.getComponent(FileNavigationPane.class).resetWorkspace();
461-
MainViewerGUI.getComponent(WorkPane.class).resetWorkspace();
455+
viewer.resetWorkspace();
462456
the.bytecode.club.jda.api.BytecodeViewer.getClassNodeLoader().clear();
463457
}
464458
}

src/main/java/the/bytecode/club/jda/gui/FileNavigationPane.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class FileNavigationPane extends VisibleComponent implements FileDrop.Lis
3737
MyTreeNode treeRoot = new MyTreeNode("Loaded Files:");
3838
MyTree tree = new MyTree(treeRoot);
3939
final JTextField quickSearch = new JTextField(quickSearchText);
40+
4041
public transient KeyAdapter search = new KeyAdapter()
4142
{
4243
@Override
@@ -160,6 +161,7 @@ public FileNavigationPane(final FileChangeNotifier fcn)
160161
tree.setShowsRootHandles(true);
161162
quickSearch.setForeground(Color.gray);
162163
setTitle("Files");
164+
setMinimumSize(new Dimension(200, 50));
163165

164166
this.open.addActionListener(e -> {
165167
final TreeNode root = (TreeNode) tree.getModel().getRoot();
@@ -253,6 +255,30 @@ public void focusLost(final FocusEvent arg0)
253255
new FileDrop(this, this);
254256
}
255257

258+
@Override
259+
public void openClassFile(String name, String container, ClassNode cn)
260+
{
261+
}
262+
263+
@Override
264+
public void openFile(String name, String container, byte[] contents)
265+
{
266+
}
267+
268+
public static Dimension defaultDimension = new Dimension(200, -1);
269+
public static Point defaultPosition = new Point(0, 0);
270+
@Override
271+
public Dimension getDefaultDimensions()
272+
{
273+
return defaultDimension;
274+
}
275+
276+
@Override
277+
public Point getDefaultPosition()
278+
{
279+
return defaultPosition;
280+
}
281+
256282
public void openClassFileToWorkSpace(final String name, final String container, final ClassNode node)
257283
{
258284
fcn.openClassFile(name, container, node);

src/main/java/the/bytecode/club/jda/gui/MainViewerGUI.java

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
*/
2626
public class MainViewerGUI extends JFrame implements FileChangeNotifier
2727
{
28-
public void java()
29-
{
30-
new FileChooser(Settings.JAVA_LOCATION, "Java Executable (Requires JRE/JDK 'C:/Program Files/Java/jre_xx/bin/java.exe')").run();
31-
}
32-
3328
public void setOptionalLibrary()
3429
{
3530
final JTextField text = new JTextField();
@@ -115,6 +110,13 @@ private JMenu generatePane(int id)
115110
return menu;
116111
}
117112

113+
public void resetWorkspace()
114+
{
115+
navigator.resetWorkspace();
116+
workPane.resetWorkspace();
117+
resetWindows();
118+
}
119+
118120
public class Test implements KeyEventDispatcher
119121
{
120122
@Override
@@ -129,7 +131,7 @@ public boolean dispatchKeyEvent(KeyEvent e)
129131

130132
public JDesktopPane desktop;
131133
static ArrayList<VisibleComponent> rfComps = new ArrayList<>();
132-
public FileNavigationPane cn;
134+
public FileNavigationPane navigator;
133135
public WorkPane workPane;
134136

135137
public AboutWindow aboutWindow = new AboutWindow();
@@ -160,6 +162,8 @@ public boolean dispatchKeyEvent(KeyEvent e)
160162

161163
public MainViewerGUI()
162164
{
165+
initializeWindows();
166+
163167
Decompiler.ensureInitted();
164168
allDecompilers.put(panelGroup1, new HashMap<>());
165169
allDecompilers.put(panelGroup2, new HashMap<>());
@@ -312,37 +316,11 @@ else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_B
312316

313317
menuBar.add(spinnerMenu);
314318

315-
// TODO: save window location and maximized/not maximized
316-
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
317-
size = new Dimension(size.width * 3 / 4, size.height * 2 / 3);
318-
setPreferredSize(size);
319-
pack();
320-
size = getContentPane().getSize();
321-
322319
if (JDA.previewCopy)
323320
setTitle("JDA v" + JDA.version + " Preview");
324321
else
325322
setTitle("JDA v" + JDA.version);
326323

327-
cn = new FileNavigationPane(this);
328-
cn.setMinimumSize(new Dimension(200, 50));
329-
cn.setMaximumSize(new Dimension(200, Integer.MAX_VALUE));
330-
cn.setPreferredSize(new Dimension(200, size.height));
331-
cn.pack();
332-
333-
workPane = new WorkPane(this);
334-
workPane.setPreferredSize(new Dimension(size.width - 200, size.height));
335-
workPane.setLocation(200, 0);
336-
workPane.pack();
337-
338-
desktop = new JDesktopPane();
339-
setContentPane(desktop);
340-
desktop.add(cn);
341-
desktop.add(workPane);
342-
343-
rfComps.add(cn);
344-
rfComps.add(workPane);
345-
346324
fontSpinner.setPreferredSize(new Dimension(42, 20));
347325
fontSpinner.setSize(new Dimension(42, 20));
348326
fontSpinner.setModel(new SpinnerNumberModel(12, 1, null, 1));
@@ -374,6 +352,44 @@ else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_B
374352
this.setLocationRelativeTo(null);
375353
}
376354

355+
private void initializeWindows()
356+
{
357+
// TODO: save window location and maximized/not maximized
358+
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
359+
setPreferredSize(new Dimension(size.width * 3 / 4, size.height * 2 / 3));
360+
361+
navigator = new FileNavigationPane(this);
362+
workPane = new WorkPane(this);
363+
364+
desktop = new JDesktopPane();
365+
setContentPane(desktop);
366+
desktop.add(navigator);
367+
desktop.add(workPane);
368+
desktop.setDesktopManager(new WorkspaceDesktopManager());
369+
pack();
370+
371+
rfComps.add(navigator);
372+
rfComps.add(workPane);
373+
}
374+
375+
public void resetWindows()
376+
{
377+
Dimension clientSize = desktop.getSize();
378+
379+
for (VisibleComponent f : rfComps)
380+
{
381+
Dimension size = f.getDefaultDimensions();
382+
if (size.width < 0 || size.height < 0)
383+
size = new Dimension(
384+
size.width < 0 ? clientSize.width + size.width : size.width,
385+
size.height < 0 ? clientSize.height + size.height : size.height);
386+
f.setPreferredSize(size);
387+
f.pack();
388+
Point pos = f.getDefaultPosition();
389+
desktop.getDesktopManager().resizeFrame(f, pos.x, pos.y, size.width, size.height);
390+
}
391+
}
392+
377393
public JSpinner fontSpinner = new JSpinner();
378394
private JMenuItem spinnerMenu = new JMenuItem("");
379395

@@ -399,6 +415,7 @@ public void setIcon(final boolean busy)
399415

400416
public void calledAfterLoad()
401417
{
418+
resetWindows();
402419
}
403420

404421
@Override

src/main/java/the/bytecode/club/jda/gui/VisibleComponent.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import the.bytecode.club.jda.FileChangeNotifier;
55

66
import javax.swing.*;
7+
import java.awt.*;
78

89
/**
910
* Used to represent all the panes inside of Bytecode Viewer, this is temp code
@@ -15,13 +16,13 @@
1516

1617
public abstract class VisibleComponent extends JInternalFrame implements FileChangeNotifier
1718
{
18-
1919
private static final long serialVersionUID = -6453413772343643526L;
2020

2121
public VisibleComponent(final String title)
2222
{
2323
super(title, false, false, false, false);
2424
this.setFrameIcon(null);
25+
setResizable(true);
2526
}
2627

2728
@SuppressWarnings("unused")
@@ -32,13 +33,14 @@ private VisibleComponent()
3233
}
3334

3435
@Override
35-
public void openClassFile(final String name, String container, final ClassNode cn)
36-
{
37-
}
36+
public abstract void openClassFile(final String name, String container, final ClassNode cn);
3837

3938
@Override
40-
public void openFile(final String name, String container, byte[] contents)
41-
{
42-
}
39+
public abstract void openFile(final String name, String container, byte[] contents);
40+
41+
protected static Dimension defaultDimensions;
42+
protected static Point defaultPosition;
4343

44+
public abstract Dimension getDefaultDimensions();
45+
public abstract Point getDefaultPosition();
4446
}

src/main/java/the/bytecode/club/jda/gui/WorkPane.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ public void componentRemoved(final ContainerEvent e)
8787

8888
}
8989

90+
public static Dimension defaultDimension = new Dimension(-FileNavigationPane.defaultDimension.width, -1);
91+
public static Point defaultPosition = new Point(FileNavigationPane.defaultDimension.width, 0);
92+
@Override
93+
public Dimension getDefaultDimensions()
94+
{
95+
return defaultDimension;
96+
}
97+
98+
@Override
99+
public Point getDefaultPosition()
100+
{
101+
return defaultPosition;
102+
}
103+
90104
int tabCount = 0;
91105

92106
public void addWorkingFile(final String name, String container, final ClassNode cn)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package the.bytecode.club.jda.gui;
2+
3+
import javax.swing.*;
4+
import java.awt.*;
5+
6+
public class WorkspaceDesktopManager extends DefaultDesktopManager
7+
{
8+
@Override
9+
public void dragFrame(JComponent f, int x, int y)
10+
{
11+
if (f instanceof VisibleComponent)
12+
{
13+
VisibleComponent frame = (VisibleComponent) f;
14+
JDesktopPane desk = frame.getDesktopPane();
15+
Dimension d = desk.getSize();
16+
if (x < 5)
17+
x = 0;
18+
else if (x + frame.getWidth() > d.width - 5)
19+
x = d.width - frame.getWidth();
20+
if (y < 5)
21+
y = 0;
22+
}
23+
super.dragFrame(f, x, y);
24+
}
25+
}

0 commit comments

Comments
 (0)