pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1862652 - in /pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger: PDFDebugger.java ui/WindowPrefs.java
Date Sat, 06 Jul 2019 10:44:01 GMT
Author: tilman
Date: Sat Jul  6 10:44:01 2019
New Revision: 1862652

URL: http://svn.apache.org/viewvc?rev=1862652&view=rev
Log:
PDFBOX-2941: save and restore window settings

Added:
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/WindowPrefs.java   (with
props)
Modified:
    pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java

Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java?rev=1862652&r1=1862651&r2=1862652&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java Sat Jul
 6 10:44:01 2019
@@ -21,6 +21,7 @@ import java.awt.Component;
 import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.FileDialog;
+import java.awt.Frame;
 import java.awt.Toolkit;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
@@ -109,6 +110,7 @@ import org.apache.pdfbox.debugger.ui.Rot
 import org.apache.pdfbox.debugger.ui.TextDialog;
 import org.apache.pdfbox.debugger.ui.Tree;
 import org.apache.pdfbox.debugger.ui.ViewMenu;
+import org.apache.pdfbox.debugger.ui.WindowPrefs;
 import org.apache.pdfbox.debugger.ui.ZoomMenu;
 import org.apache.pdfbox.filter.FilterFactory;
 import org.apache.pdfbox.io.IOUtils;
@@ -150,6 +152,7 @@ public class PDFDebugger extends JFrame
     private final JPanel documentPanel = new JPanel();
     private TreeStatusPane statusPane;
     private RecentFiles recentFiles;
+    private WindowPrefs windowPrefs;
     private boolean isPageMode;
     private PDDocument document;
     private String currentFilePath;
@@ -362,10 +365,10 @@ public class PDFDebugger extends JFrame
             }
         });
 
-        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+        windowPrefs = new WindowPrefs(this.getClass());
+
         jScrollPane1.setBorder(new BevelBorder(BevelBorder.RAISED));
-        jScrollPane1.setPreferredSize(new Dimension(screenSize.width / 8, 500));
-        jSplitPane1.setDividerLocation(screenSize.width / 8);
+        jSplitPane1.setDividerLocation(windowPrefs.getDividerLocation());
         tree.addTreeSelectionListener(new TreeSelectionListener()
         {
             @Override
@@ -380,7 +383,6 @@ public class PDFDebugger extends JFrame
         jSplitPane1.setRightComponent(jScrollPane2);
         jSplitPane1.setDividerSize(3);
 
-        jScrollPane2.setPreferredSize(new Dimension(screenSize.width / 8 * 7, 500));
         jScrollPane2.setViewportView(jTextPane1);
 
         jSplitPane1.setLeftComponent(jScrollPane1);
@@ -407,7 +409,8 @@ public class PDFDebugger extends JFrame
         menuBar.add(viewMenu.getMenu());
         setJMenuBar(menuBar);
 
-        setBounds(screenSize.width / 4, screenSize.height / 4, screenSize.width / 2, screenSize.height
/ 2);
+        setExtendedState(windowPrefs.getExtendedState());
+        setBounds(windowPrefs.getBounds());
 
         // drag and drop to open files
         setTransferHandler(new TransferHandler()
@@ -1193,6 +1196,10 @@ public class PDFDebugger extends JFrame
                 throw new RuntimeException(e);
             }
         }
+        windowPrefs.setExtendedState(getExtendedState());
+        this.setExtendedState(Frame.NORMAL);
+        windowPrefs.setBounds(getBounds());
+        windowPrefs.setDividerLocation(jSplitPane1.getDividerLocation());
         performApplicationExit();
     }
 

Added: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/WindowPrefs.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/WindowPrefs.java?rev=1862652&view=auto
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/WindowPrefs.java (added)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/WindowPrefs.java Sat
Jul  6 10:44:01 2019
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.debugger.ui;
+
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.util.prefs.Preferences;
+
+/**
+ * A class to save windows position and size in preference using java Preference API.
+ *
+ * @author Tilman Hausherr
+ */
+public class WindowPrefs
+{
+    private static final String KEY = "window_prefs_";
+    private final Preferences pref;
+
+    public WindowPrefs(Class className)
+    {
+        this.pref = Preferences.userNodeForPackage(className);
+    }
+
+    public void setBounds(Rectangle rect)
+    {
+        Preferences node = pref.node(KEY);
+        node.putInt("X", rect.x);
+        node.putInt("Y", rect.y);
+        node.putInt("W", rect.width);
+        node.putInt("H", rect.height);
+    }
+
+    public Rectangle getBounds()
+    {
+        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+        Preferences node = pref.node(KEY);
+        int x = node.getInt("X", screenSize.width / 4);
+        int y = node.getInt("Y", screenSize.height / 4);
+        int w = node.getInt("W", screenSize.width / 2);
+        int h = node.getInt("H", screenSize.height / 2);
+        return new Rectangle(x, y, w, h);
+    }
+
+    public void setDividerLocation(int divider)
+    {
+        Preferences node = pref.node(KEY);
+        node.putInt("DIV", divider);
+    }
+
+    public int getDividerLocation()
+    {
+        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+        Preferences node = pref.node(KEY);
+        return node.getInt("DIV", screenSize.width / 8);
+    }
+
+    public void setExtendedState(int extendedState)
+    {
+        Preferences node = pref.node(KEY);
+        node.putInt("EXTSTATE", extendedState);
+    }
+
+    public int getExtendedState()
+    {
+        Preferences node = pref.node(KEY);
+        return node.getInt("EXTSTATE", Frame.NORMAL);
+    }
+}

Propchange: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/ui/WindowPrefs.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message