[jsword-svn] r1384 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/book bibledesktop/src/main/resources common-swing/src/main/java/org/crosswire/common/swing

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Tue Jun 5 10:48:08 MST 2007


Author: dmsmith
Date: 2007-06-05 10:48:07 -0700 (Tue, 05 Jun 2007)
New Revision: 1384

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/book/ParallelBookPicker.properties
   trunk/bibledesktop/src/main/resources/config.properties
   trunk/bibledesktop/src/main/resources/config.xml
   trunk/common-swing/src/main/java/org/crosswire/common/swing/ActionFactory.java
Log:
A better GUI for ParallelBookPicker. With user customization.

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-05 11:18:27 UTC (rev 1383)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java	2007-06-05 17:48:07 UTC (rev 1384)
@@ -140,26 +140,19 @@
         });
         btnKey = new JButton(actions.getAction(MORE));
         btnKey.setIcon(ICON_SELECT);
-        //btnKey.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
         btnKeyGo = new JButton(actions.getAction(GO_PASSAGE));
-        //btnKeyGo.setBorder(BorderFactory.createEmptyBorder(4, 5, 4, 5));
 
         txtSearch = new JTextField();
         txtSearch.setAction(actions.getAction(SEARCH_FIELD));
         JLabel lblSearch = actions.createJLabel(SEARCH_LABEL);
         lblSearch.setLabelFor(txtSearch);
         btnSearch = new JButton(actions.getAction(GO_SEARCH));
-        //btnSearch.setBorder(BorderFactory.createEmptyBorder(4, 5, 4, 5));
 
-        JButton btnHelp = new JButton(actions.getAction(HELP));
-        //btnHelp.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));
-        btnHelp.setText(null);
+        JButton btnHelp = actions.createJButton(HELP);
         dlgHelp = new QuickHelpDialog(GuiUtil.getFrame(this), Msg.HELP_TITLE.toString(), Msg.HELP_TEXT.toString());
 
         btnAdvanced = new JButton(actions.getAction(ADVANCED));
-        //btnAdvanced.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
         btnIndex = new JButton(actions.getAction(INDEX));
-        //btnIndex.setBorder(BorderFactory.createEmptyBorder(3, 15, 3, 15));
 
         this.setLayout(new GridBagLayout());
         this.add(lblBible,    new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0));
@@ -716,9 +709,6 @@
 
     private static final ImageIcon ICON_SELECT = GuiUtil.getIcon("toolbarButtonGraphics/general/Edit16.gif"); //$NON-NLS-1$
 
-//    private static final ImageIcon ICON_MENU = GuiUtil.getIcon("toolbarButtonGraphics/general/Preferences16.gif"); //$NON-NLS-1$
-
-
     /**
      * Keep the selection up to date with indexing.
      */

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-05 11:18:27 UTC (rev 1383)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/ParallelBookPicker.java	2007-06-05 17:48:07 UTC (rev 1384)
@@ -22,7 +22,7 @@
 package org.crosswire.bibledesktop.book;
 
 import java.awt.Component;
-import java.awt.Container;
+import java.awt.FlowLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
@@ -33,7 +33,6 @@
 import java.util.Comparator;
 import java.util.List;
 
-import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JPanel;
 import javax.swing.event.EventListenerList;
@@ -70,14 +69,17 @@
      */
     private void initialize()
     {
-        selected = new ArrayList();
+        setLayout(new FlowLayout(FlowLayout.LEADING, 1, 1));
         listeners = new EventListenerList();
         actions = new ActionFactory(ParallelBookPicker.class, this);
 
+        JPanel buttonBox = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
+        buttonBox.add(actions.createJButton("RemovePicker")); //$NON-NLS-1$
+        buttonBox.add(actions.createJButton("AddPicker")); //$NON-NLS-1$
+        add(buttonBox);
 
         // Add the first picker
         doAddPicker();
-        doAddPicker();
     }
 
     /**
@@ -85,49 +87,21 @@
      */
     public void doAddPicker()
     {
-        JPanel pickerPanel = new JPanel();
-
-        int currentPickerCount = getComponentCount();
-
-        // If there is more than one picker, then we need to remove the buttons from the
-        // previous one, since we only want the last one to have the buttons.
-        Container lastPanel = null;
-        if (currentPickerCount > 0)
-        {
-            Component last = getComponent(currentPickerCount - 1);
-            if (last instanceof Container)
-            {
-                lastPanel = (Container) last;
-            }
-        }
-
         BooksComboBoxModel mdlBook = new BooksComboBoxModel(filter, comparator);
         JComboBox cboBook = new JComboBox(mdlBook);
         cboBook.setRenderer(new BookListCellRenderer(true));
-        cboBook.addItemListener(new SelectedItemListener(currentPickerCount));
+        cboBook.addItemListener(new SelectedItemListener());
         cboBook.addActionListener(new SelectedActionListener());
-        pickerPanel.add(cboBook);
-        add(pickerPanel);
-        currentPickerCount++;
+        add(cboBook);
 
-        // Before adding, we make sure that the previous entry's buttons are removed.
-        if (currentPickerCount > 1)
-        {
-            while (lastPanel.getComponentCount() > 1)
-            {
-                lastPanel.remove(1);
-            }
-        }
-
-        addButtons(pickerPanel, currentPickerCount);
-
         Book book = mdlBook.getSelectedBook();
-        selected.add(book);
         if (book != null)
         {
             cboBook.setToolTipText(book.getName());
         }
 
+        enableButtons();
+
         GuiUtil.refresh(this);
     }
 
@@ -136,16 +110,13 @@
      */
     public void doRemovePicker()
     {
+        // There should always be 2 components present:
+        // the first picker and the panel holding the add/remove buttons
         int size = getComponentCount();
-        if (size > 1)
+        if (size > 2)
         {
             remove(size - 1);
-            size = getComponentCount();
-            Component comp = getComponent(size - 1);
-            if (comp instanceof JPanel)
-            {
-                addButtons((JPanel) comp, size - 1); 
-            }
+            enableButtons();
             GuiUtil.refresh(this);
         }
 
@@ -156,10 +127,37 @@
      */
     public Book[] getBooks()
     {
-        return (Book[]) selected.toArray(new Book[selected.size()]);
+        List books = new ArrayList();
+        int count = getComponentCount();
+        for (int i = 1; i < count; i++)
+        {
+            Component comp = getComponent(i);
+            if (comp instanceof JComboBox)
+            {
+                JComboBox combo = (JComboBox) comp;
+                books.add(combo.getSelectedItem());
+            }
+        }
+        return (Book[]) books.toArray(new Book[books.size()]);
     }
 
     /**
+     * @return the maxPickers
+     */
+    public static int getMaxPickers()
+    {
+        return maxPickers;
+    }
+
+    /**
+     * @param maxPickers the maxPickers to set
+     */
+    public static void setMaxPickers(int maxPickers)
+    {
+        ParallelBookPicker.maxPickers = maxPickers;
+    }
+
+    /**
      * Add a BookSelectListener listener
      */
     public synchronized void addBookListener(BookSelectListener li)
@@ -194,19 +192,12 @@
         }
     }
 
-    private void addButtons(JPanel pickerPanel, int currentPickerCount)
+    private void enableButtons()
     {
-        // If there are more than one picker, we allow a user to remove a picker
-        if (currentPickerCount > 0)
-        {
-            pickerPanel.add(new JButton(actions.getAction("RemovePicker"))); //$NON-NLS-1$
-        }
-
-        // Only allow the user to add a certain amount of pickers.
-        if (currentPickerCount < MAX_PICKERS)
-        {
-            pickerPanel.add(new JButton(actions.getAction("AddPicker"))); //$NON-NLS-1$
-        }
+        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);
     }
 
     /**
@@ -218,9 +209,6 @@
      */
     private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException
     {
-        // We don't serialize views
-        selected = null;
-
         listeners = new EventListenerList();
 
         is.defaultReadObject();
@@ -231,15 +219,6 @@
      */
     final class SelectedItemListener implements ItemListener
     {
-        /**
-         * Track the selected item in the combo box indicated by index.
-         * @param index
-         */
-        public SelectedItemListener(int index)
-        {
-            this.index = index;
-        }
-
         /* (non-Javadoc)
          * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
          */
@@ -249,14 +228,13 @@
             {
                 JComboBox combo = (JComboBox) ev.getSource();
                 
-                selected.set(index, combo.getSelectedItem());
+                Book selected = (Book) combo.getSelectedItem();
 
                 fireBooksChosen(new BookSelectEvent(this, getBooks()));
-                combo.setToolTipText(selected.toString());
+                combo.setToolTipText(selected.getName());
             }
         }
 
-        private int index;
     }
 
     /**
@@ -288,11 +266,6 @@
     private Comparator comparator;
 
     /**
-     * The selected items in each combo.
-     */
-    protected transient List selected;
-
-    /**
      * Allow for adding and removing pickers.
      */
     private ActionFactory actions;
@@ -308,6 +281,11 @@
     private static final int MAX_PICKERS = 5;
 
     /**
+     * The maximum number of pickers.
+     */
+    private static int maxPickers = MAX_PICKERS;
+
+    /**
      * Serialization ID
      */
     private static final long serialVersionUID = 1633401996774729671L;

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/ParallelBookPicker.properties
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/ParallelBookPicker.properties	2007-06-05 11:18:27 UTC (rev 1383)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/ParallelBookPicker.properties	2007-06-05 17:48:07 UTC (rev 1384)
@@ -2,8 +2,8 @@
 AddPicker.Name=+
 AddPicker.ShortDescription=Add a parallel Bible
 AddPicker.LongDescription=Add a parallel Bible.
-AddPicker.SmallIcon=
-AddPicker.LargeIcon=
+AddPicker.SmallIcon=images/add-13.png
+AddPicker.LargeIcon=images/add-13.png
 AddPicker.MnemonicKey=
 AddPicker.AcceleratorKey=
 AddPicker.AcceleratorKey.Modifiers=
@@ -12,8 +12,8 @@
 RemovePicker.Name=-
 RemovePicker.ShortDescription=Remove a parallel Bible
 RemovePicker.LongDescription=Remove a parallel Bible.
-RemovePicker.SmallIcon=
-RemovePicker.LargeIcon=
+RemovePicker.SmallIcon=images/subtract-13.png
+RemovePicker.LargeIcon=images/subtract-13.png
 RemovePicker.MnemonicKey=
 RemovePicker.AcceleratorKey=
 RemovePicker.AcceleratorKey.Modifiers=

Modified: trunk/bibledesktop/src/main/resources/config.properties
===================================================================
--- trunk/bibledesktop/src/main/resources/config.properties	2007-06-05 11:18:27 UTC (rev 1383)
+++ trunk/bibledesktop/src/main/resources/config.properties	2007-06-05 17:48:07 UTC (rev 1384)
@@ -22,6 +22,8 @@
 Bibles.DefaultHebrewParse.help=Which of the available Hebrew Morphology/Parsing Guides is the default.
 BibleDisplay.Reuse.path=Bible Display.Open links in same Bible View
 BibleDisplay.Reuse.help=Reuse Bible View for links.
+BibleDisplay.MaxPickers.path=Bible Display.Parallel Bible Limit
+BibleDisplay.MaxPickers.help=Limit the number of Bibles to show at once
 BibleDisplay.Commentaries.path=Bible Display.List Commentaries with Bibles
 BibleDisplay.Commentaries.help=List Commentaries with Bibles
 BibleDisplay.Sidebar.path=Bible Display.Show the Passage Sidebar

Modified: trunk/bibledesktop/src/main/resources/config.xml
===================================================================
--- trunk/bibledesktop/src/main/resources/config.xml	2007-06-05 11:18:27 UTC (rev 1383)
+++ trunk/bibledesktop/src/main/resources/config.xml	2007-06-05 17:48:07 UTC (rev 1384)
@@ -132,6 +132,10 @@
     <introspect class="org.crosswire.bibledesktop.desktop.Desktop" property="BibleViewReused"/>
   </option>
 
+  <option key="BibleDisplay.MaxPickers" type="number">
+    <introspect class="org.crosswire.bibledesktop.book.ParallelBookPicker" property="MaxPickers"/>
+  </option>
+
   <option key="BibleDisplay.Commentaries" type="boolean">
     <introspect class="org.crosswire.jsword.book.BookFilters" property="CommentariesWithBibles"/>
   </option>

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/ActionFactory.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/ActionFactory.java	2007-06-05 11:18:27 UTC (rev 1383)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/ActionFactory.java	2007-06-05 17:48:07 UTC (rev 1384)
@@ -21,6 +21,7 @@
  */
 package org.crosswire.common.swing;
 
+import java.awt.Insets;
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -36,6 +37,7 @@
 
 import javax.swing.Action;
 import javax.swing.Icon;
+import javax.swing.JButton;
 import javax.swing.JLabel;
 import javax.swing.KeyStroke;
 
@@ -191,6 +193,20 @@
     }
 
     /**
+     * Build a button from an action that consist solely of the icon.
+     * @param key
+     * @return
+     */
+    public JButton createJButton(String key)
+    {
+        JButton button = new JButton(getAction(key));
+        button.setBorderPainted(false);
+        button.setText(null);
+        button.setMargin(new Insets(0, 0, 0, 0));
+        return button;
+    }
+
+    /**
      * Build the map of actions from resources
      */
     private void buildActionMap(Class basis)




More information about the jsword-svn mailing list