fix(gui): detect if a window is opened inside a visible screen (PR #521)

This commit is contained in:
Ahmed Ashour
2019-03-26 17:43:23 +01:00
committed by skylot
parent 9557f04fe7
commit 3537f849ef
@@ -1,6 +1,9 @@
package jadx.gui.settings;
import java.awt.*;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -142,14 +145,25 @@ public class JadxSettings extends JadxCLIArgs {
public boolean loadWindowPos(Window window) {
WindowLocation pos = windowPos.get(window.getClass().getSimpleName());
if (pos == null) {
if (pos == null || !isContainedInAnyScreen(pos)) {
return false;
}
window.setLocation(pos.getX(), pos.getY());
window.setSize(pos.getWidth(), pos.getHeight());
return true;
}
private static boolean isContainedInAnyScreen(WindowLocation pos) {
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
if (gd.getDefaultConfiguration().getBounds().contains(
pos.getX(), pos.getY(), pos.getWidth(), pos.getHeight())) {
return true;
}
}
return false;
}
public boolean isShowHeapUsageBar() {
return showHeapUsageBar;
}