OSDN Git Service

画面サイズ・位置保存の再考
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / gui / MainFrame.java
index 6454553..5c50ce4 100644 (file)
@@ -516,10 +516,11 @@ public class MainFrame extends JFrame {
             setSize(windowWidth, windowHeight);
         }
 
-        // TODO 最大化した状態で終了した場合の考慮
         final int windowPosX = p.getSystemWindowPosX();
         final int windowPosY = p.getSystemWindowPosY();
-        if (windowPosX > 1024 && windowPosY > 1024) {
+        final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+        if (windowPosX + windowWidth > 0 && windowPosX < screenSize.width
+                && windowPosY + windowHeight > 0 && windowPosY < screenSize.height) {
             setLocation(windowPosX, windowPosY);
         } else {
             setLocationByPlatform(true);
@@ -835,13 +836,16 @@ public class MainFrame extends JFrame {
         public void windowClosing(WindowEvent e) {
             final Config p = Config.INSTANCE;
 
-            final Dimension size = getSize();
-            p.setSystemWindowWidth(size.width);
-            p.setSystemWindowHeight(size.height);
+            // 保存するのは最大化していない場合だけ
+            if (JFrame.NORMAL == getExtendedState()) {
+                final Dimension size = getSize();
+                p.setSystemWindowWidth(size.width);
+                p.setSystemWindowHeight(size.height);
 
-            final Point pos = getLocation();
-            p.setSystemWindowPosX(pos.x);
-            p.setSystemWindowPosY(pos.y);
+                final Point pos = getLocation();
+                p.setSystemWindowPosX(pos.x);
+                p.setSystemWindowPosY(pos.y);
+            }
 
             p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
             p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());