[jsword-svn] r1905 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/book bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop bibledesktop/src/main/resources biblemapper/src/main/java/org/crosswire/biblemapper/swing common-swing/src/main/java/org/crosswire/common/config/swing common-swing/src/main/java/org/crosswire/common/swing common-swing/src/main/java/org/crosswire/common/swing/desktop jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop jsword-limbo/src/main/java/org/crosswire/common/swing

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Thu Jul 24 20:09:06 MST 2008


Author: dmsmith
Date: 2008-07-24 20:09:06 -0700 (Thu, 24 Jul 2008)
New Revision: 1905

Added:
   trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/LayoutPersistence.java
Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/AdvancedSearchPane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/PassageSelectionPane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/InternetWarning.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java
   trunk/bibledesktop/src/main/resources/config.xml
   trunk/biblemapper/src/main/java/org/crosswire/biblemapper/swing/Mapper.java
   trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/FontChooser.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/QuickHelpDialog.java
   trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/CompareResultsPane.java
   trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/GeneratorPane.java
   trunk/jsword-limbo/src/main/java/org/crosswire/common/swing/TextViewPanel.java
Log:
Added Adam Thomas' Layout persistence changes.

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/AdvancedSearchPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/AdvancedSearchPane.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/AdvancedSearchPane.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -321,7 +321,7 @@
         dlgMain.setModal(modal);
 
         GuiUtil.restrainedPack(dlgMain, 0.5f, 0.75f);
-        GuiUtil.centerWindow(dlgMain);
+        GuiUtil.centerOnScreen(dlgMain);
         GuiUtil.applyDefaultOrientation(dlgMain);
         dlgMain.setVisible(true);
 

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/PassageSelectionPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/PassageSelectionPane.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/PassageSelectionPane.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -322,7 +322,7 @@
 
         GuiUtil.applyDefaultOrientation(dlgMain);
         GuiUtil.restrainedPack(dlgMain, 0.5f, 0.75f);
-        GuiUtil.centerWindow(dlgMain);
+        GuiUtil.centerOnScreen(dlgMain);
         dlgMain.setVisible(true);
 
         if (bailout)

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -244,7 +244,7 @@
         dlgMain.setModal(true);
 
         GuiUtil.setSize(dlgMain, new Dimension(750, 400));
-        GuiUtil.centerWindow(dlgMain);
+        GuiUtil.centerOnScreen(dlgMain);
         GuiUtil.applyDefaultOrientation(dlgMain);
         dlgMain.setVisible(true);
         dlgMain.toFront();

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/InternetWarning.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/InternetWarning.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/InternetWarning.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -109,7 +109,7 @@
         content.add(webWarning, BorderLayout.NORTH);
         content.add(buttons, BorderLayout.SOUTH);
         dialog.pack();
-        GuiUtil.centerWindow(dialog);
+        GuiUtil.centerOnScreen(dialog);
         GuiUtil.applyDefaultOrientation(dialog);
         dialog.setVisible(true);
 

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -24,7 +24,6 @@
 import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.Container;
-import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
@@ -80,6 +79,7 @@
 import org.crosswire.common.swing.FixedSplitPane;
 import org.crosswire.common.swing.GuiUtil;
 import org.crosswire.common.swing.LookAndFeelUtil;
+import org.crosswire.common.swing.desktop.LayoutPersistence;
 import org.crosswire.common.swing.desktop.LayoutType;
 import org.crosswire.common.swing.desktop.TDIViewLayout;
 import org.crosswire.common.swing.desktop.ToolBar;
@@ -382,6 +382,7 @@
 
         return toolbar;
     }
+
     /**
      * Create the file menu
      * @return the file menu
@@ -431,6 +432,7 @@
         menuGo.add(actions.getAction(DesktopActions.FORWARD)).addMouseListener(barStatus);
         return menuGo;
     }
+
     /**
      * Create the view menu.
      * @return the view menu.
@@ -548,6 +550,7 @@
         menuHelp.setToolTipText(null);
         return menuHelp;
     }
+
     /**
      * Get the size of the content panel and make that the preferred size.
      */
@@ -557,7 +560,7 @@
         if (contentPane instanceof JComponent)
         {
             ((JComponent) contentPane).setPreferredSize(contentPane.getSize());
-            log.warn("The size of the contentpane is: " + contentPane.getSize()); //$NON-NLS-1$
+            //log.warn("The size of the contentpane is: " + contentPane.getSize()); //$NON-NLS-1$
         }
     }
 
@@ -900,7 +903,7 @@
         if (bibles.size() == 0)
         {
             int reply = CWOptionPane.showConfirmDialog(this, Msg.NO_BIBLES_MESSAGE, Msg.NO_BIBLES_TITLE.toString(), JOptionPane.OK_CANCEL_OPTION,
-                            JOptionPane.QUESTION_MESSAGE);
+                                                       JOptionPane.QUESTION_MESSAGE);
             if (reply == JOptionPane.OK_OPTION)
             {
                 actions.doBooks();
@@ -1007,53 +1010,6 @@
     }
 
     /**
-     * @param maxHeight The maxHeight to set.
-     */
-    public static void setMaxHeight(int maxHeight)
-    {
-        defaultSize.height = maxHeight;
-    }
-
-    /**
-     * @return Returns the maxHeight.
-     */
-    public static int getMaxHeight()
-    {
-        return defaultSize.height;
-    }
-
-    /**
-     * @return Returns the maxWidth.
-     */
-    public static int getMaxWidth()
-    {
-        return defaultSize.width;
-    }
-
-    /**
-     * @param maxWidth The maxWidth to set.
-     */
-    public static void setMaxWidth(int maxWidth)
-    {
-        defaultSize.width = maxWidth;
-    }
-    /**
-     * @return Returns the defaultSize.
-     */
-    public static Dimension getDefaultSize()
-    {
-        return defaultSize;
-    }
-
-    /**
-     * @param newDefaultSize The defaultSize to set.
-     */
-    public static void setDefaultSize(Dimension newDefaultSize)
-    {
-        defaultSize = newDefaultSize;
-    }
-
-    /**
      * Setup the choices so that the options dialog knows what there is to
      * select from.
      */
@@ -1168,12 +1124,20 @@
             LookAndFeelUtil.initialize();
 
             Splash splash = new Splash();
-
             Desktop desktop = new Desktop();
 
-            // change the size and location before showing the application.
-            GuiUtil.setSize(desktop, getDefaultSize());
-            GuiUtil.centerWindow(desktop);
+            // Restore window size, position, and layout if previously opened,
+            // otherwise use defaults.
+            LayoutPersistence layoutPersistence = LayoutPersistence.instance();
+            if (layoutPersistence.isLayoutPersisted(desktop))
+            {
+                layoutPersistence.restoreLayout(desktop);
+            }
+            else
+            {
+                GuiUtil.defaultDesktopSize(desktop);
+                GuiUtil.centerOnScreen(desktop);
+            }
 
             // Now bring up the app and offer to install books if the user has none.
             SwingUtilities.invokeLater(new DesktopRunner(desktop, splash));
@@ -1208,93 +1172,88 @@
         }
 
         private Desktop desktop;
-        private Splash splash;
+        private Splash  splash;
     }
 
-    private boolean hasRefBooks;
+    private boolean                    hasRefBooks;
 
     // Strings for the names of property files.
-    private static final String SPLASH_PROPS = "splash"; //$NON-NLS-1$
+    private static final String        SPLASH_PROPS          = "splash";                                    //$NON-NLS-1$
 
     // Strings for URL protocols/URI schemes
-    private static final String BIBLE_PROTOCOL = "bible"; //$NON-NLS-1$
-    private static final String DICTIONARY_PROTOCOL = "dict"; //$NON-NLS-1$
-    private static final String GREEK_DEF_PROTOCOL = "gdef"; //$NON-NLS-1$
-    private static final String HEBREW_DEF_PROTOCOL = "hdef"; //$NON-NLS-1$
-    private static final String GREEK_MORPH_PROTOCOL = "gmorph"; //$NON-NLS-1$
-    private static final String HEBREW_MORPH_PROTOCOL = "hmorph"; //$NON-NLS-1$
-    private static final String COMMENTARY_PROTOCOL = "comment"; //$NON-NLS-1$
+    private static final String        BIBLE_PROTOCOL        = "bible";                                     //$NON-NLS-1$
+    private static final String        DICTIONARY_PROTOCOL   = "dict";                                      //$NON-NLS-1$
+    private static final String        GREEK_DEF_PROTOCOL    = "gdef";                                      //$NON-NLS-1$
+    private static final String        HEBREW_DEF_PROTOCOL   = "hdef";                                      //$NON-NLS-1$
+    private static final String        GREEK_MORPH_PROTOCOL  = "gmorph";                                    //$NON-NLS-1$
+    private static final String        HEBREW_MORPH_PROTOCOL = "hmorph";                                    //$NON-NLS-1$
+    private static final String        COMMENTARY_PROTOCOL   = "comment";                                   //$NON-NLS-1$
 
     // Empty String
-    private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+    private static final String        EMPTY_STRING          = "";                                          //$NON-NLS-1$
 
     // Various other strings used as keys
-    private static final String CONFIG_KEY = "config"; //$NON-NLS-1$
-    private static final String DESKTOP_KEY = "desktop"; //$NON-NLS-1$
-    private static final String CONV_KEY = "converters"; //$NON-NLS-1$
-    private static final String CSWING_KEY = "cswing-styles"; //$NON-NLS-1$
+    private static final String        CONFIG_KEY            = "config";                                    //$NON-NLS-1$
+    private static final String        DESKTOP_KEY           = "desktop";                                   //$NON-NLS-1$
+    private static final String        CONV_KEY              = "converters";                                //$NON-NLS-1$
+    private static final String        CSWING_KEY            = "cswing-styles";                             //$NON-NLS-1$
 
     /**
      * The configuration engine
      */
-    private transient Config config;
+    private transient Config           config;
 
     /**
      * Whether to show the Key Sidebar at startup
      */
-    private static boolean sidebarShowing;
+    private static boolean             sidebarShowing;
 
     /**
      * Whether to show the view source in the menu at startup
      */
-    private static boolean viewSourceShowing;
+    private static boolean             viewSourceShowing;
 
     /**
      * Whether to show differences between versions of the Bible
      */
-    private static boolean compareShowing;
+    private static boolean             compareShowing;
 
     /**
      * Whether to show the web journal at startup
      */
-    private static boolean webJournalShowing = true;
+    private static boolean             webJournalShowing     = true;
 
     /**
      * Whether to current BibleView should be used for links
      */
-    private static boolean reuseBibleView = true;
+    private static boolean             reuseBibleView        = true;
 
     /**
-     * The default dimension for this frame
-     */
-    private static Dimension defaultSize = new Dimension(1280, 960);
-
-    /**
      * The log stream
      */
-    protected static final Logger log = Logger.getLogger(Desktop.class);
+    protected static final Logger      log                   = Logger.getLogger(Desktop.class);
 
     protected transient DesktopActions actions;
 
     /**
      * The application icon
      */
-    private static final ImageIcon ICON_APP = GuiUtil.getIcon("images/BibleDesktop16.png"); //$NON-NLS-1$
+    private static final ImageIcon     ICON_APP              = GuiUtil.getIcon("images/BibleDesktop16.png"); //$NON-NLS-1$
 
-    private transient ViewManager views;
-    private JPanel corePanel;
-//    private BlogClientFrame blogPanel;
-    private JSplitPane sptBlog;
-    private JCheckBoxMenuItem sidebarToggle;
-    private StatusBar barStatus;
-    protected MultiBookPane reference;
-    private JSplitPane sptBooks;
-    private JPanel mainPanel;
-    private transient History history;
-    private PropertyChangeSupport changeSupport;
+    private transient ViewManager      views;
+    private JPanel                     corePanel;
+//    private BlogClientFrame            blogPanel;
+    private JSplitPane                 sptBlog;
+    private JCheckBoxMenuItem          sidebarToggle;
+    private StatusBar                  barStatus;
+    protected MultiBookPane            reference;
+    private JSplitPane                 sptBooks;
+    private JPanel                     mainPanel;
+    private transient History          history;
+    private PropertyChangeSupport      changeSupport;
 
     /**
      * Serialization ID
      */
-    private static final long serialVersionUID = 3977014029116191800L;
+    private static final long          serialVersionUID      = 3977014029116191800L;
 }

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/DesktopActions.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -41,6 +41,7 @@
 import org.crosswire.common.swing.ActionFactory;
 import org.crosswire.common.swing.Actionable;
 import org.crosswire.common.swing.CWOptionPane;
+import org.crosswire.common.swing.desktop.LayoutPersistence;
 import org.crosswire.common.swing.desktop.ViewVisitor;
 import org.crosswire.common.util.CWProject;
 import org.crosswire.common.util.ClassUtil;
@@ -235,6 +236,7 @@
      */
     public void doExit()
     {
+        LayoutPersistence.instance().saveLayout(desktop);
         System.exit(0);
     }
 

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -243,7 +243,7 @@
         frame.getContentPane().add(this, BorderLayout.CENTER);
 
         GuiUtil.setSize(frame, new Dimension(750, 500));
-        GuiUtil.centerWindow(frame);
+        GuiUtil.centerOnScreen(frame);
         frame.setVisible(true);
     }
 

Modified: trunk/bibledesktop/src/main/resources/config.xml
===================================================================
--- trunk/bibledesktop/src/main/resources/config.xml	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/bibledesktop/src/main/resources/config.xml	2008-07-25 03:09:06 UTC (rev 1905)
@@ -212,14 +212,6 @@
     <alternative number="1"/>
   </option>
 
-  <option key="Application.MaxWidth" type="number">
-    <introspect class="org.crosswire.bibledesktop.desktop.Desktop" property="MaxWidth"/>
-  </option>
-
-  <option key="Application.MaxHeight" type="number">
-    <introspect class="org.crosswire.bibledesktop.desktop.Desktop" property="MaxHeight"/>
-  </option>
-
   <option key="Application.UIFont" type="font">
     <introspect class="org.crosswire.common.swing.LookAndFeelUtil" property="Font"/>
   </option>

Modified: trunk/biblemapper/src/main/java/org/crosswire/biblemapper/swing/Mapper.java
===================================================================
--- trunk/biblemapper/src/main/java/org/crosswire/biblemapper/swing/Mapper.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/biblemapper/src/main/java/org/crosswire/biblemapper/swing/Mapper.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -101,7 +101,7 @@
         Mapper mapper = new Mapper(args);
 
         mapper.pack();
-        GuiUtil.centerWindow(mapper);
+        GuiUtil.centerOnScreen(mapper);
         mapper.setVisible(true);
     }
 

Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -114,7 +114,7 @@
         // size and position
         dialog.setSize(800, 500);
         dialog.pack();
-        GuiUtil.centerWindow(dialog);
+        GuiUtil.centerOnScreen(dialog);
         dialog.setModal(true);
 
         GuiUtil.applyDefaultOrientation(dialog);

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -244,7 +244,7 @@
         pane.okBox.add(ok);
         dialog.getRootPane().setDefaultButton(ok);
 
-        GuiUtil.centerWindow(dialog);
+        GuiUtil.centerOnScreen(dialog);
         GuiUtil.applyDefaultOrientation(dialog);
         dialog.pack();
         dialog.setVisible(true);

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/FontChooser.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/FontChooser.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/FontChooser.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -146,7 +146,7 @@
         fontc.dialog.getContentPane().add(buttons, BorderLayout.SOUTH);
         fontc.dialog.setSize(800, 500);
         fontc.dialog.pack();
-        GuiUtil.centerWindow(fontc.dialog);
+        GuiUtil.centerOnScreen(fontc.dialog);
         GuiUtil.applyDefaultOrientation(fontc.dialog);
         fontc.dialog.setVisible(true);
 

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -202,7 +202,7 @@
     {
         Component temp = com;
 
-        while (!(temp instanceof Dialog))
+        while ( !(temp instanceof Dialog))
         {
             temp = temp.getParent();
             if (temp == null)
@@ -221,34 +221,9 @@
      *
      * @param win The window to be moved
      */
-    public static void centerWindow(Window win)
+    public static void centerOnScreen(Window win)
     {
-        Toolkit tk = Toolkit.getDefaultToolkit();
-
-        // If the window is maximized then we can't center it
-        if (win instanceof Frame)
-        {
-            Frame frame = (Frame) win;
-            if ((frame.getExtendedState() & Frame.MAXIMIZED_BOTH) != 0)
-            {
-                return;
-            }
-        }
-
-        Dimension screenDim = tk.getScreenSize();
-        Dimension windowDim = win.getSize();
-
-        // If the window is not maximized but is the entire size of the screen
-        // then we can't center it.
-        if (windowDim.equals(screenDim))
-        {
-            return;
-        }
-
-        // Center Frame, Dialogue or Window on screen
-        int x = (screenDim.width - win.getSize().width) / 2;
-        int y = (screenDim.height - win.getSize().height) / 2;
-        win.setLocation(x, y);
+        win.setLocationRelativeTo(null);
     }
 
     /**
@@ -327,6 +302,33 @@
     }
 
     /**
+     * Set the window size relative to the current screen size.
+     * @param win The window to resize
+     * @percentOfScreen The amount of space that the window should take up
+     */
+    public static void setSize(Window win, float percentOfScreen)
+    {
+        Toolkit tk = win.getToolkit();
+        Dimension screenSize = tk.getScreenSize();
+
+        int width = new Float(screenSize.width * percentOfScreen).intValue();
+        int height = new Float(screenSize.height * percentOfScreen).intValue();
+        Dimension winSize = new Dimension(width, height);
+
+        win.setSize(winSize);
+    }
+
+    /**
+     * Set the size of the main window to a default size.
+     * @param win The window to resize
+     */
+    public static void defaultDesktopSize(Window win)
+    {
+        float defaultPercent = 0.75F;
+        setSize(win, defaultPercent);
+    }
+
+    /**
      * Maximize the specified window. It would be good if we could detect
      * where the taskbar was and not obscure it ...
      * @param win The window to be moved
@@ -604,4 +606,5 @@
      * The log stream
      */
     private static final Logger log = Logger.getLogger(GuiUtil.class);
+
 }

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/QuickHelpDialog.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/QuickHelpDialog.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/QuickHelpDialog.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -124,7 +124,7 @@
     {
         if (visible)
         {
-            GuiUtil.centerWindow(this);
+            GuiUtil.centerOnScreen(this);
         }
 
         super.setVisible(visible);

Added: trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/LayoutPersistence.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/LayoutPersistence.java	                        (rev 0)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/desktop/LayoutPersistence.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -0,0 +1,241 @@
+/**
+ * Distribution License:
+ * BibleDesktop is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, version 2 as published by
+ * the Free Software Foundation. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * The License is available on the internet at:
+ *       http://www.gnu.org/copyleft/gpl.html
+ * or by writing to:
+ *      Free Software Foundation, Inc.
+ *      59 Temple Place - Suite 330
+ *      Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2007
+ *     The copyright to this program is held by it's authors.
+ *
+ * ID: $Id: org.eclipse.jdt.ui.prefs 1178 2006-11-06 12:48:02Z dmsmith $
+ */
+
+package org.crosswire.common.swing.desktop;
+
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Point;
+import java.awt.Window;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Properties;
+
+import org.crosswire.common.util.CWProject;
+import org.crosswire.common.util.Logger;
+import org.crosswire.common.util.NetUtil;
+import org.crosswire.common.util.ResourceUtil;
+
+/**
+ * Window layout persistence mechanism. Intended to be flexible enough to allow
+ * persisting size, position, layout of multiple windows.
+ *
+ * @see gnu.gpl.License for license details.
+ *      The copyright to this program is held by it's authors.
+ * @author Adam Thomas [adam-thomas at cox dot net]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class LayoutPersistence
+{
+
+    /**
+     * Creates the singleton persistence object capable of storing and retrieving layout
+     * information on behalf windows.
+     */
+    private LayoutPersistence()
+    {
+        try
+        {
+            settings = ResourceUtil.getProperties(getClass());
+        }
+        catch (IOException e)
+        {
+            settings = new Properties();
+        }
+    }
+
+    /**
+     * All access to LayoutPersistence is through this single instance.
+     * 
+     * @return the singleton instance
+     */
+    public static LayoutPersistence instance()
+    {
+        return instance;
+    }
+
+    /**
+     * Indicates whether the window passed to the constructor has had layout
+     * information persisted.
+     * 
+     * @param window the window to persist
+     * @return Returns true is layout information for the current window has
+     * been persisted, otherwise returns false
+     */
+    public synchronized boolean isLayoutPersisted(Window window)
+    {
+        String winName = window.getName();
+        String stateKey = winName + LayoutPersistence.STATE_KEY_SUFFIX;
+        return settings.containsKey(stateKey);
+    }
+
+    /**
+     * Stores the current window's layout information.
+     * 
+     * @param window the window to persist
+     */
+    public synchronized void saveLayout(Window window)
+    {
+        String winName = window.getName();
+        String stateKey = winName + LayoutPersistence.STATE_KEY_SUFFIX;
+        String widthKey = winName + LayoutPersistence.WIDTH_KEY_SUFFIX;
+        String heightKey = winName + LayoutPersistence.HEIGHT_KEY_SUFFIX;
+        String locationXKey = winName + LayoutPersistence.LOCATION_X_KEY_SUFFIX;
+        String locationYKey = winName + LayoutPersistence.LOCATION_Y_KEY_SUFFIX;
+
+        Frame frame = null;
+        int state = Frame.NORMAL;
+        if (window instanceof Frame)
+        {
+            frame = (Frame) window;
+            state = frame.getExtendedState();
+        }
+        settings.setProperty(stateKey, String.valueOf(state));
+
+        int width = window.getWidth();
+        settings.setProperty(widthKey, String.valueOf(width));
+
+        int height = window.getHeight();
+        settings.setProperty(heightKey, String.valueOf(height));
+
+        int locationX = window.getX();
+        settings.setProperty(locationXKey, String.valueOf(locationX));
+
+        int locationY = window.getY();
+        settings.setProperty(locationYKey, String.valueOf(locationY));
+
+        try
+        {
+            URI outputURI = CWProject.instance().getWritablePropertiesURI(getClass().getName());
+            NetUtil.storeProperties(settings, outputURI, "Persistent Window properties"); //$NON-NLS-1$
+        }
+        catch (IOException ex)
+        {
+            log.error(ex.getLocalizedMessage(), ex);
+        }
+    }
+
+    /**
+     * Loads and restores the layout to the window that was passed to the constructor.
+     * 
+     * @param window the window to persist
+     */
+    public synchronized void restoreLayout(Window window)
+    {
+        String winName = window.getName();
+        String stateKey = winName + LayoutPersistence.STATE_KEY_SUFFIX;
+        String widthKey = winName + LayoutPersistence.WIDTH_KEY_SUFFIX;
+        String heightKey = winName + LayoutPersistence.HEIGHT_KEY_SUFFIX;
+        String locationXKey = winName + LayoutPersistence.LOCATION_X_KEY_SUFFIX;
+        String locationYKey = winName + LayoutPersistence.LOCATION_Y_KEY_SUFFIX;
+
+        if (window instanceof Frame)
+        {
+            Frame frame = (Frame) window;
+            int state = getState(stateKey);
+            frame.setExtendedState(state);
+        }
+
+        Dimension sizeDimension = getSize(widthKey, heightKey);
+        window.setSize(sizeDimension);
+
+        Point locationPoint = getLocation(locationXKey, locationYKey);
+        window.setLocation(locationPoint);
+    }
+
+    /**
+     * Reads persisted window state data
+     * @param stateKey the properties key for state data
+     * @return Window state data
+     */
+    private int getState(String stateKey)
+    {
+        return Integer.parseInt(settings.getProperty(stateKey));
+    }
+
+    /**
+     * Reads persisted window size data
+     * @param widthKey the properties key for width
+     * @param heightKey the properties key for height
+     * @return Window size data
+     */
+    private Dimension getSize(String widthKey, String heightKey)
+    {
+        int width = Integer.parseInt(settings.getProperty(widthKey));
+        int height = Integer.parseInt(settings.getProperty(heightKey));
+        return new Dimension(width, height);
+    }
+
+    /**
+     * Reads persisted window location data
+     * @param locationXKey the properties key for x
+     * @param locationYKey the properties key for y
+     * @return Window location data
+     */
+    private Point getLocation(String locationXKey, String locationYKey)
+    {
+        int x = Integer.parseInt(settings.getProperty(locationXKey));
+        int y = Integer.parseInt(settings.getProperty(locationYKey));
+        return new Point(x, y);
+    }
+
+    /**
+     * Provide class logging capabilities
+     */
+    private static final Logger log                   = Logger.getLogger(LayoutPersistence.class);
+
+    /**
+     * The persistence storage and retrieval object
+     */
+    private Properties   settings;
+
+    /**
+     * Suffix for window state key
+     */
+    private static final String STATE_KEY_SUFFIX      = ".WindowState";                           //$NON-NLS-1$
+
+    /**
+     * Suffix for window width key
+     */
+    private static final String WIDTH_KEY_SUFFIX      = ".Width";                                 //$NON-NLS-1$
+
+    /**
+     * Suffix for window height key
+     */
+    private static final String HEIGHT_KEY_SUFFIX     = ".Height";                                //$NON-NLS-1$
+
+    /**
+     * Suffix for window location x key
+     */
+    private static final String LOCATION_X_KEY_SUFFIX = ".LocationX";                             //$NON-NLS-1$
+
+    /**
+     * Suffix for window location y key
+     */
+    private static final String LOCATION_Y_KEY_SUFFIX = ".LocationY";                             //$NON-NLS-1$
+
+    /**
+     * The singleton instance of this class.
+     */
+    private static LayoutPersistence instance = new LayoutPersistence();
+
+}

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/CompareResultsPane.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/CompareResultsPane.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/CompareResultsPane.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -147,7 +147,7 @@
         frame.getContentPane().add(this, BorderLayout.CENTER);
 
         frame.pack();
-        GuiUtil.centerWindow(frame);
+        GuiUtil.centerOnScreen(frame);
         frame.setVisible(true);
     }
 

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/GeneratorPane.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/GeneratorPane.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/desktop/GeneratorPane.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -187,7 +187,7 @@
         frame.getContentPane().add(this, BorderLayout.CENTER);
 
         frame.pack();
-        GuiUtil.centerWindow(frame);
+        GuiUtil.centerOnScreen(frame);
         frame.setVisible(true);
     }
 

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/common/swing/TextViewPanel.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/common/swing/TextViewPanel.java	2008-07-24 20:45:11 UTC (rev 1904)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/common/swing/TextViewPanel.java	2008-07-25 03:09:06 UTC (rev 1905)
@@ -169,7 +169,7 @@
         frame.getContentPane().add(this, BorderLayout.CENTER);
 
         frame.pack();
-        GuiUtil.centerWindow(frame);
+        GuiUtil.centerOnScreen(frame);
         frame.setVisible(true);
     }
 




More information about the jsword-svn mailing list