Skip to content

Commit d80fc55

Browse files
committed
Fix window scaling when JDA is resized
1 parent 2ad4106 commit d80fc55

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ else if (ke.getKeyCode() == KeyEvent.VK_ESCAPE)
157157

158158
public FileNavigationPane(final FileChangeNotifier fcn)
159159
{
160-
super("ClassNavigation", "File Navigator", Resources.fileNavigatorIcon);
160+
super("ClassNavigation", "File Navigator", Resources.fileNavigatorIcon, (MainViewerGUI) fcn);
161161

162162
this.fcn = fcn;
163163
tree.setRootVisible(false);

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,36 @@ public abstract class JDAWindow extends JInternalFrame implements FileChangeNoti
2323
private String windowId;
2424

2525
public Point unmaximizedPos;
26-
public Dimension unmaximizedSize;
26+
public Dimension unmaximizedSize; // unmaximized size for when JDA is maximized
27+
public Dimension smallUnmaxSize; // unmaximized size for when JDA is unmaximized
2728

28-
public JDAWindow(final String id, final String title, final Icon icon)
29+
protected final MainViewerGUI viewer;
30+
31+
public JDAWindow(final String id, final String title, final Icon icon, final MainViewerGUI viewer)
2932
{
3033
super(title, true, true, true, true);
3134
windowId = id;
3235
setName(title);
3336
setFrameIcon(icon);
3437
setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
38+
this.viewer = viewer;
3539

3640
unmaximizedPos = getDefaultPosition();
3741
unmaximizedSize = getDefaultSize();
42+
smallUnmaxSize = unmaximizedSize;
3843

3944
addComponentListener(new ComponentAdapter()
4045
{
4146
@Override
4247
public void componentResized(ComponentEvent e)
4348
{
4449
if (!isMaximum())
45-
unmaximizedSize = getSize();
50+
{
51+
if (viewer.isMaximized)
52+
unmaximizedSize = getSize();
53+
else
54+
smallUnmaxSize = getSize();
55+
}
4656
super.componentResized(e);
4757
}
4858

@@ -58,12 +68,28 @@ public void componentMoved(ComponentEvent e)
5868
addPropertyChangeListener(evt -> {
5969
if (isNormalState())
6070
{
61-
setSize(unmaximizedSize);
71+
setSize(viewer.isMaximized? unmaximizedSize : smallUnmaxSize);
6272
setLocation(unmaximizedPos);
6373
}
6474
});
6575
}
6676

77+
public void onJDAResized() {
78+
smallUnmaxSize = new Dimension(unmaximizedSize);
79+
Dimension d = getDesktopPane().getSize();
80+
if (unmaximizedPos.getX() + smallUnmaxSize.width > d.width)
81+
smallUnmaxSize.width = d.width - (int) unmaximizedPos.getX();
82+
if (unmaximizedPos.getY() + smallUnmaxSize.height > d.height)
83+
smallUnmaxSize.height = d.height - (int) unmaximizedPos.getY();
84+
if (isNormalState())
85+
setSize(smallUnmaxSize);
86+
}
87+
88+
public void onJDAMaximized() {
89+
if (isNormalState())
90+
setSize(unmaximizedSize);
91+
}
92+
6793
@Override
6894
public abstract void openClassFile(final String name, String container, final ClassNode cn);
6995

@@ -139,6 +165,7 @@ public Dimension getPersistentSize()
139165
public void restoreSize(Dimension size)
140166
{
141167
unmaximizedSize = size;
168+
smallUnmaxSize = size;
142169
if (isNormalState())
143170
{
144171
setPreferredSize(size);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,14 @@ else if ((oldState & Frame.ICONIFIED) != 0 && (newState & Frame.ICONIFIED) == 0)
109109
if ((oldState & Frame.MAXIMIZED_BOTH) == 0 && (newState & Frame.MAXIMIZED_BOTH) != 0)
110110
{
111111
isMaximized = true;
112+
for (JDAWindow window : windows)
113+
window.onJDAMaximized();
112114
}
113115
else if ((oldState & Frame.MAXIMIZED_BOTH) != 0 && (newState & Frame.MAXIMIZED_BOTH) == 0)
114116
{
115117
setSize(unmaximizedSize);
116118
setLocation(unmaximizedPos);
119+
isMaximized = false;
117120
}
118121
}
119122
});
@@ -124,6 +127,8 @@ public void componentResized(ComponentEvent e)
124127
{
125128
if ((getExtendedState() & Frame.MAXIMIZED_BOTH) != Frame.MAXIMIZED_BOTH)
126129
unmaximizedSize = getSize();
130+
for (JDAWindow window : windows)
131+
window.onJDAResized();
127132
super.componentResized(e);
128133
}
129134

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class WorkPane extends JDAWindow implements ActionListener
3737

3838
public WorkPane(final FileChangeNotifier fcn)
3939
{
40-
super("WorkPanel", "Work Space", Resources.fileNavigatorIcon);
40+
super("WorkPanel", "Work Space", Resources.fileNavigatorIcon, (MainViewerGUI) fcn);
4141

4242
this.tabs = new JTabbedPane();
4343
this.fcn = fcn;

0 commit comments

Comments
 (0)