Skip to content

Commit ac0fcb0

Browse files
committed
Save window locations and sizes
Also save whether the main window is maximized or not I really don't like this code at all.
1 parent 39266f3 commit ac0fcb0

File tree

13 files changed

+213
-120
lines changed

13 files changed

+213
-120
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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.settings.Settings;
910

1011
import javax.swing.*;
1112
import javax.swing.filechooser.FileFilter;
@@ -116,6 +117,8 @@ public void run()
116117
{
117118
new ExceptionUI(e);
118119
}
120+
if (!viewer.isMaximized)
121+
viewer.unmaximizedPos = viewer.getLocation();
119122
Settings.saveGUI();
120123
cleanup();
121124
}

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

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/main/java/the/bytecode/club/jda/decompilers/CFRDecompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import org.benf.cfr.reader.util.output.*;
2020
import org.objectweb.asm.tree.ClassNode;
2121
import org.zeroturnaround.zip.ZipUtil;
22-
import the.bytecode.club.jda.DecompilerSettings;
2322
import the.bytecode.club.jda.JDA;
2423
import the.bytecode.club.jda.JarUtils;
24+
import the.bytecode.club.jda.settings.DecompilerSettings;
2525

2626
import java.io.File;
2727
import java.io.IOException;

src/main/java/the/bytecode/club/jda/decompilers/Decompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import org.objectweb.asm.ClassReader;
44
import org.objectweb.asm.ClassWriter;
55
import org.objectweb.asm.tree.ClassNode;
6-
import the.bytecode.club.jda.DecompilerSettings;
76
import the.bytecode.club.jda.JDA;
87
import the.bytecode.club.jda.api.ExceptionUI;
98
import the.bytecode.club.jda.decompilers.bytecode.ClassNodeDecompiler;
9+
import the.bytecode.club.jda.settings.DecompilerSettings;
1010

1111
import java.io.PrintWriter;
1212
import java.io.StringWriter;

src/main/java/the/bytecode/club/jda/decompilers/FernFlowerDecompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import org.jetbrains.java.decompiler.main.decompiler.PrintStreamLogger;
77
import org.jetbrains.java.decompiler.main.extern.IResultSaver;
88
import org.objectweb.asm.tree.ClassNode;
9-
import the.bytecode.club.jda.DecompilerSettings;
109
import the.bytecode.club.jda.JDA;
1110
import the.bytecode.club.jda.JarUtils;
11+
import the.bytecode.club.jda.settings.DecompilerSettings;
1212

1313
import java.io.File;
1414
import java.nio.file.Files;

src/main/java/the/bytecode/club/jda/decompilers/ProcyonDecompiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public DecompilerSettings getDecompilerSettings()
5353
JCommander jCommander = new JCommander(options);
5454
String[] args = new String[Settings.values().length * 2];
5555
int index = 0;
56-
for (the.bytecode.club.jda.DecompilerSettings.Setting setting : Settings.values())
56+
for (the.bytecode.club.jda.settings.DecompilerSettings.Setting setting : Settings.values())
5757
{
5858
args[index++] = "--" + setting.getParam();
5959
args[index++] = String.valueOf(getSettings().isSelected(setting));
@@ -262,7 +262,7 @@ private void doSaveJarDecompiled(File inFile, File outFile) throws Exception
262262
}
263263
}
264264

265-
public enum Settings implements the.bytecode.club.jda.DecompilerSettings.Setting
265+
public enum Settings implements the.bytecode.club.jda.settings.DecompilerSettings.Setting
266266
{
267267
SHOW_DEBUG_LINE_NUMBERS("debug-line-numbers", "Show Debug Line Numbers"),
268268
SIMPLIFY_MEMBER_REFERENCES("simplify-member-references", "Simplify Member References"),

src/main/java/the/bytecode/club/jda/decompilers/bytecode/ClassNodeDecompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import org.objectweb.asm.tree.FieldNode;
66
import org.objectweb.asm.tree.InnerClassNode;
77
import org.objectweb.asm.tree.MethodNode;
8-
import the.bytecode.club.jda.DecompilerSettings;
98
import the.bytecode.club.jda.FileContainer;
109
import the.bytecode.club.jda.JDA;
1110
import the.bytecode.club.jda.decompilers.Decompiler;
11+
import the.bytecode.club.jda.settings.DecompilerSettings;
1212

1313
import java.util.ArrayList;
1414
import java.util.List;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package the.bytecode.club.jda.gui;
22

33
import the.bytecode.club.jda.JDA;
4-
import the.bytecode.club.jda.Setting;
54
import the.bytecode.club.jda.api.ExceptionUI;
5+
import the.bytecode.club.jda.settings.Setting;
66

77
import javax.swing.*;
88
import javax.swing.filechooser.FileFilter;

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

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import the.bytecode.club.jda.decompilers.FernFlowerDecompiler;
1010
import the.bytecode.club.jda.decompilers.ProcyonDecompiler;
1111
import the.bytecode.club.jda.decompilers.bytecode.ClassNodeDecompiler;
12+
import the.bytecode.club.jda.settings.DecompilerSettings;
13+
import the.bytecode.club.jda.settings.Settings;
1214

1315
import javax.swing.*;
1416
import javax.swing.filechooser.FileFilter;
@@ -128,9 +130,11 @@ public boolean dispatchKeyEvent(KeyEvent e)
128130
}
129131

130132
public boolean isMaximized = false;
133+
public Point unmaximizedPos;
134+
public Dimension unmaximizedSize;
131135

132136
public JDesktopPane desktop;
133-
static ArrayList<VisibleComponent> rfComps = new ArrayList<>();
137+
public static ArrayList<VisibleComponent> rfComps = new ArrayList<>();
134138
public FileNavigationPane navigator;
135139
public WorkPane workPane;
136140

@@ -199,9 +203,30 @@ else if ((oldState & Frame.ICONIFIED) != 0 && (newState & Frame.ICONIFIED) == 0)
199203
else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_BOTH) == 0)
200204
{
201205
isMaximized = false;
206+
setSize(unmaximizedSize);
207+
setLocation(unmaximizedPos);
202208
}
203209
}
204210
});
211+
addComponentListener(new ComponentAdapter()
212+
{
213+
@Override
214+
public void componentResized(ComponentEvent e)
215+
{
216+
if ((getExtendedState() & Frame.MAXIMIZED_BOTH) != Frame.MAXIMIZED_BOTH)
217+
unmaximizedSize = getSize();
218+
super.componentResized(e);
219+
}
220+
221+
@Override
222+
public void componentMoved(ComponentEvent e)
223+
{
224+
if ((getExtendedState() & Frame.MAXIMIZED_BOTH) != Frame.MAXIMIZED_BOTH)
225+
unmaximizedPos = getLocation();
226+
super.componentMoved(e);
227+
}
228+
});
229+
205230
this.setIconImages(Resources.iconList);
206231

207232
JMenuBar menuBar = new JMenuBar();
@@ -210,7 +235,7 @@ else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_B
210235
JMenu settingsMenu = new JMenu("Settings");
211236
setJMenuBar(menuBar);
212237

213-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
238+
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
214239

215240
menuBar.add(fileMenu);
216241

@@ -321,6 +346,13 @@ else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_B
321346
else
322347
setTitle("JDA v" + JDA.version);
323348

349+
Dimension windowSize = Toolkit.getDefaultToolkit().getScreenSize();
350+
windowSize = new Dimension(windowSize.width * 3 / 4, windowSize.height * 2 / 3);
351+
setPreferredSize(windowSize);
352+
pack();
353+
unmaximizedSize = getSize();
354+
unmaximizedPos = getLocation();
355+
324356
fontSpinner.setPreferredSize(new Dimension(42, 20));
325357
fontSpinner.setSize(new Dimension(42, 20));
326358
fontSpinner.setModel(new SpinnerNumberModel(12, 1, null, 1));
@@ -354,10 +386,6 @@ else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_B
354386

355387
private void initializeWindows()
356388
{
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-
361389
navigator = new FileNavigationPane(this);
362390
workPane = new WorkPane(this);
363391

@@ -366,7 +394,6 @@ private void initializeWindows()
366394
desktop.add(navigator);
367395
desktop.add(workPane);
368396
desktop.setDesktopManager(new WorkspaceDesktopManager());
369-
pack();
370397

371398
rfComps.add(navigator);
372399
rfComps.add(workPane);
@@ -386,6 +413,7 @@ public void resetWindows()
386413
f.setPreferredSize(size);
387414
f.pack();
388415
Point pos = f.getDefaultPosition();
416+
f.setLocation(pos);
389417
desktop.getDesktopManager().resizeFrame(f, pos.x, pos.y, size.width, size.height);
390418
}
391419
}
@@ -416,33 +444,28 @@ public void setIcon(final boolean busy)
416444
public void calledAfterLoad()
417445
{
418446
resetWindows();
447+
Settings.loadWindows();
419448
}
420449

421450
@Override
422451
public void openClassFile(final String name, String container, final ClassNode cn)
423452
{
424453
for (final VisibleComponent vc : rfComps)
425-
{
426454
vc.openClassFile(name, container, cn);
427-
}
428455
}
429456

430457
@Override
431458
public void openFile(final String name, String container, byte[] content)
432459
{
433460
for (final VisibleComponent vc : rfComps)
434-
{
435461
vc.openFile(name, container, content);
436-
}
437462
}
438463

439464
public static <T> T getComponent(final Class<T> clazz)
440465
{
441466
for (final VisibleComponent vc : rfComps)
442-
{
443467
if (vc.getClass() == clazz)
444468
return clazz.cast(vc);
445-
}
446469
return null;
447470
}
448471

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,16 @@
1616

1717
public abstract class VisibleComponent extends JInternalFrame implements FileChangeNotifier
1818
{
19-
private static final long serialVersionUID = -6453413772343643526L;
19+
private String windowId;
2020

2121
public VisibleComponent(final String title)
2222
{
2323
super(title, false, false, false, false);
24+
windowId = title;
2425
this.setFrameIcon(null);
2526
setResizable(true);
2627
}
2728

28-
@SuppressWarnings("unused")
29-
private VisibleComponent()
30-
{ // because we want to enforce the title
31-
// argument
32-
33-
}
34-
3529
@Override
3630
public abstract void openClassFile(final String name, String container, final ClassNode cn);
3731

@@ -43,4 +37,9 @@ private VisibleComponent()
4337

4438
public abstract Dimension getDefaultDimensions();
4539
public abstract Point getDefaultPosition();
40+
41+
public String getWindowId()
42+
{
43+
return windowId;
44+
}
4645
}

0 commit comments

Comments
 (0)