[jsword-svn] r1388 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/book bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop common/src/main/java/org/crosswire/common/config

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Wed Jun 6 13:49:06 MST 2007


Author: dmsmith
Date: 2007-06-06 13:49:06 -0700 (Wed, 06 Jun 2007)
New Revision: 1388

Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/ParallelBookPicker.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
   trunk/common/src/main/java/org/crosswire/common/config/AbstractReflectedChoice.java
   trunk/common/src/main/java/org/crosswire/common/config/Choice.java
   trunk/common/src/main/java/org/crosswire/common/config/Config.java
   trunk/common/src/main/java/org/crosswire/common/config/IntOptionsChoice.java
Log:
Added the ability to listen for configuration changes and have them update the gui appropriately.
With this font changes take effect immediately.

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java	2007-06-06 20:47:21 UTC (rev 1387)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java	2007-06-06 20:49:06 UTC (rev 1388)
@@ -102,7 +102,7 @@
         };
 
         // search() and version() rely on this returning only Books indexed by verses
-        ParallelBookPicker picker = new ParallelBookPicker(BookFilters.getBibles(), BookComparators.getInitialComparator());
+        picker = new ParallelBookPicker(BookFilters.getBibles(), BookComparators.getInitialComparator());
         picker.addBookListener(this);
         selected = picker.getBooks();
         if (selected.length > 0)
@@ -368,6 +368,14 @@
         return title;
     }
 
+    /**
+     * @return the picker
+     */
+    public ParallelBookPicker getPicker()
+    {
+        return picker;
+    }
+
     public void setKey(String newKey)
     {
         if (selected == null)
@@ -723,11 +731,11 @@
     private transient ActionFactory actions;
 
     private transient Book[] selected;
-
     /*
      * GUI Components
      */
     private PassageSelectionPane dlgSelect;
+    private ParallelBookPicker picker;
     private JTextField txtKey;
     private JTextField txtSearch;
     private JButton btnAdvanced;

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/ParallelBookPicker.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/ParallelBookPicker.java	2007-06-06 20:47:21 UTC (rev 1387)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/ParallelBookPicker.java	2007-06-06 20:49:06 UTC (rev 1388)
@@ -193,12 +193,12 @@
         }
     }
 
-    private void enableButtons()
+    public void enableButtons()
     {
-        int count = getComponentCount();
-        actions.getAction("RemovePicker").setEnabled(count > 2); //$NON-NLS-1$
-        actions.getAction("AddPicker").setEnabled(count <= maxPickers); //$NON-NLS-1$
-        getComponent(0).setVisible(maxPickers >= 2);
+        int count = getComponentCount() - 1;
+        actions.getAction("RemovePicker").setEnabled(count > 1); //$NON-NLS-1$
+        actions.getAction("AddPicker").setEnabled(count < maxPickers); //$NON-NLS-1$
+        getComponent(0).setVisible(maxPickers >= 2 || count > maxPickers);
     }
 
     /**

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java	2007-06-06 20:47:21 UTC (rev 1387)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java	2007-06-06 20:49:06 UTC (rev 1388)
@@ -28,6 +28,8 @@
 import java.awt.event.ActionEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.net.MalformedURLException;
@@ -63,6 +65,7 @@
 import org.crosswire.bibledesktop.display.BookDataDisplay;
 import org.crosswire.bibledesktop.display.URIEvent;
 import org.crosswire.bibledesktop.display.URIEventListener;
+import org.crosswire.bibledesktop.display.basic.SplitBookDataDisplay;
 import org.crosswire.bibledesktop.util.ConfigurableSwingConverter;
 import org.crosswire.common.config.ChoiceFactory;
 import org.crosswire.common.config.Config;
@@ -83,7 +86,6 @@
 import org.crosswire.common.swing.desktop.event.ViewEventListener;
 import org.crosswire.common.util.CWClassLoader;
 import org.crosswire.common.util.Logger;
-import org.crosswire.common.util.LucidRuntimeException;
 import org.crosswire.common.util.OSType;
 import org.crosswire.common.util.Reporter;
 import org.crosswire.common.util.ResourceUtil;
@@ -837,17 +839,32 @@
             ExceptionPane.showExceptionDialog(null, ex);
         }
 
-        URI configUri = Project.instance().getWritablePropertiesURI("desktop"); //$NON-NLS-1$
-        try
+        config.localToApplication();
+        config.addPropertyChangeListener(new PropertyChangeListener()
         {
-            config.localToApplication();
-            config.localToPermanent(configUri);
-        }
-        catch (IOException ex)
-        {
-            throw new LucidRuntimeException(Msg.CONFIG_SAVE_FAILED, ex, new Object[] { configUri });
-        }
+            /* (non-Javadoc)
+             * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+             */
+            public void propertyChange(PropertyChangeEvent evt)
+            {
+                // When the font changes update all the visible locations using it.
+                if (evt.getPropertyName().equals("BibleDisplay.ConfigurableFont")) //$NON-NLS-1$
+                {
+                    BibleViewPane view = (BibleViewPane) getViews().getSelected();
+                    SplitBookDataDisplay da = view.getPassagePane();
+                    da.getBookDataDisplay().refresh();
 
+                    reference.refresh();
+                }
+
+                if (evt.getPropertyName().equals("BibleDisplay.MaxPickers")) //$NON-NLS-1$
+                {
+                    BibleViewPane view = (BibleViewPane) getViews().getSelected();
+                    DisplaySelectPane selector = view.getSelectPane();
+                    selector.getPicker().enableButtons();
+                }
+            }            
+        });
     }
 
     public void checkForBooks()
@@ -1177,7 +1194,7 @@
     private JSplitPane sptBlog;
     private JCheckBoxMenuItem sidebarToggle;
     private StatusBar barStatus;
-    private MultiBookPane reference;
+    protected MultiBookPane reference;
     private JSplitPane sptBooks;
     private JPanel mainPanel;
     private transient History history;

Modified: trunk/common/src/main/java/org/crosswire/common/config/AbstractReflectedChoice.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/config/AbstractReflectedChoice.java	2007-06-06 20:47:21 UTC (rev 1387)
+++ trunk/common/src/main/java/org/crosswire/common/config/AbstractReflectedChoice.java	2007-06-06 20:49:06 UTC (rev 1388)
@@ -42,7 +42,7 @@
      */
     public void init(Element option, ResourceBundle configResources) throws StartupException
     {
-        String key = option.getAttributeValue("key"); //$NON-NLS-1$
+        key = option.getAttributeValue("key"); //$NON-NLS-1$
 
         assert configResources != null;
 
@@ -130,6 +130,14 @@
     }
 
     /* (non-Javadoc)
+     * @see org.crosswire.common.config.Choice#getKey()
+     */
+    public String getKey()
+    {
+        return key;
+    }
+
+    /* (non-Javadoc)
      * @see org.crosswire.common.config.Choice#getType()
      */
     public String getType()
@@ -275,6 +283,11 @@
     }
 
     /**
+     * The key of the option.
+     */
+    private String key;
+
+    /**
      * The type that we reflect to
      */
     private Class clazz;

Modified: trunk/common/src/main/java/org/crosswire/common/config/Choice.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/config/Choice.java	2007-06-06 20:47:21 UTC (rev 1387)
+++ trunk/common/src/main/java/org/crosswire/common/config/Choice.java	2007-06-06 20:49:06 UTC (rev 1388)
@@ -47,6 +47,12 @@
     void init(Element option, ResourceBundle configResources) throws StartupException;
 
     /**
+     * The key of the option.
+     * @return String The key string as supplied in config.xml
+     */
+    String getKey();
+
+    /**
      * The full path of the option.
      * @return String The path string as supplied in config.properties
      */

Modified: trunk/common/src/main/java/org/crosswire/common/config/Config.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/config/Config.java	2007-06-06 20:47:21 UTC (rev 1387)
+++ trunk/common/src/main/java/org/crosswire/common/config/Config.java	2007-06-06 20:49:06 UTC (rev 1388)
@@ -21,6 +21,9 @@
  */
 package org.crosswire.common.config;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -85,6 +88,10 @@
     public Config(String title)
     {
         this.title = title;
+        keys = new ArrayList();
+        models = new ArrayList();
+        local = new Properties();
+        listenerList = new EventListenerList();
     }
 
     /**
@@ -310,6 +317,10 @@
                 try
                 {
                     choice.setString(newValue);
+                    if (changeListeners != null)
+                    {
+                        changeListeners.firePropertyChange(new PropertyChangeEvent(choice, choice.getKey(), oldValue, newValue));
+                    }
                 }
                 catch (LucidException ex)
                 {
@@ -500,6 +511,69 @@
     }
 
     /**
+     * Add a PropertyChangeListener to the listener list.
+     * The listener is registered for all properties.
+     *
+     * @param listener  The PropertyChangeListener to be added
+     */
+    public void addPropertyChangeListener(PropertyChangeListener listener)
+    {
+        if (changeListeners == null)
+        {
+            changeListeners = new PropertyChangeSupport(this);
+        }
+        changeListeners.addPropertyChangeListener(listener);
+    }
+
+    /**
+     * Remove a PropertyChangeListener from the listener list.
+     * This removes a PropertyChangeListener that was registered
+     * for all properties.
+     *
+     * @param listener  The PropertyChangeListener to be removed
+     */
+    public void removePropertyChangeListener(PropertyChangeListener listener)
+    {
+        if (changeListeners != null)
+        {
+            changeListeners.removePropertyChangeListener(listener);
+        }
+    }
+
+    /**
+     * Add a PropertyChangeListener for a specific property.  The listener
+     * will be invoked only when a call on firePropertyChange names that
+     * specific property.
+     *
+     * @param propertyName  The name of the property to listen on.
+     * @param listener  The PropertyChangeListener to be added
+     */
+
+    public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
+    {
+        if (changeListeners == null)
+        {
+            changeListeners = new PropertyChangeSupport(this);
+        }
+        changeListeners.addPropertyChangeListener(propertyName, listener);
+    }
+
+    /**
+     * Remove a PropertyChangeListener for a specific property.
+     *
+     * @param propertyName  The name of the property that was listened on.
+     * @param listener  The PropertyChangeListener to be removed
+     */
+
+    public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
+    {
+        if (changeListeners != null)
+        {
+            changeListeners.removePropertyChangeListener(propertyName, listener);
+        }
+    }
+
+    /**
      * Add an Exception listener to the list of things wanting
      * to know whenever we capture an Exception
      */
@@ -568,11 +642,6 @@
     }
 
     /**
-     * The log stream
-     */
-    private static final Logger log = Logger.getLogger(Config.class);
-
-    /**
      * The name for dialog boxes and properties files
      */
     protected String title;
@@ -593,7 +662,18 @@
     protected Properties local = new Properties();
 
     /**
+     * The set of property change listeners.
+     */
+    protected PropertyChangeSupport changeListeners;
+
+    /**
      * The list of listeners
      */
     protected EventListenerList listenerList = new EventListenerList();
+
+    /**
+     * The log stream
+     */
+    private static final Logger log = Logger.getLogger(Config.class);
+
 }

Modified: trunk/common/src/main/java/org/crosswire/common/config/IntOptionsChoice.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/config/IntOptionsChoice.java	2007-06-06 20:47:21 UTC (rev 1387)
+++ trunk/common/src/main/java/org/crosswire/common/config/IntOptionsChoice.java	2007-06-06 20:49:06 UTC (rev 1388)
@@ -48,7 +48,7 @@
 
         super.init(option, configResources);
 
-        String prefix = option.getAttributeValue("key") + ".alternative."; //$NON-NLS-1$  //$NON-NLS-2$
+        String prefix = getKey() + ".alternative."; //$NON-NLS-1$
 
         List list = new ArrayList();
         Iterator iter = option.getChildren("alternative").iterator(); //$NON-NLS-1$




More information about the jsword-svn mailing list