[jsword-svn] r1410 - in trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop: book desktop display display/basic passage
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Fri Jun 15 14:59:12 MST 2007
Author: dmsmith
Date: 2007-06-15 14:59:12 -0700 (Fri, 15 Jun 2007)
New Revision: 1410
Modified:
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModel.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleViewPane.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BookSelectEvent.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BooksListModel.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectEvent.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/ParallelBookPicker.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/BookDataDisplay.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/ProxyBookDataDisplay.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/ScrolledBookDataDisplay.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/SplitBookDataDisplay.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TabbedBookDataDisplay.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeySidebar.java
Log:
QA changes (checkstyle, findbugs, pmd, ...)
Fixed bugs.
Used BookProvider interface.
Simplified BookDataDisplay usage.
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModel.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModel.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModel.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -271,7 +271,7 @@
/**
* What is currently selected?
*/
- private Object selected;
+ private transient Object selected;
/**
* Are we a book, chapter or verse selector
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleViewPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleViewPane.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleViewPane.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -104,7 +104,7 @@
*/
public void bookChosen(DisplaySelectEvent ev)
{
- pnlPassg.setBookData(ev.getBooks(), ev.getKey());
+ pnlPassg.setBookData(ev.getBookProvider().getBooks(), ev.getKey());
}
});
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BookSelectEvent.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BookSelectEvent.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BookSelectEvent.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -23,7 +23,7 @@
import java.util.EventObject;
-import org.crosswire.jsword.book.Book;
+import org.crosswire.jsword.book.BookProvider;
/**
* A BookSelectEvent happens whenever a user selects a book.
@@ -39,36 +39,21 @@
* @param source The thing that started this off
* @param books The selected books
*/
- public BookSelectEvent(Object source, Book[] books)
+ public BookSelectEvent(BookProvider source)
{
super(source);
- this.books = books;
}
/**
* Get all the books.
* @return the books
*/
- public Book[] getBooks()
+ public BookProvider getBookProvider()
{
- return books;
+ return (BookProvider) getSource();
}
/**
- * Get the first book.
- * @return the first book
- */
- public Book getFirstBook()
- {
- return books != null && books.length > 0 ? books[0] : null;
- }
-
- /**
- * The new list of Books
- */
- private transient Book[] books;
-
- /**
* Serialization ID
*/
private static final long serialVersionUID = 6018474028417993389L;
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BooksListModel.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BooksListModel.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BooksListModel.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -251,7 +251,7 @@
/**
* The sort algorithm to use.
*/
- protected Comparator comparator;
+ protected transient Comparator comparator;
/**
* The log stream
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectEvent.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectEvent.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectEvent.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -23,7 +23,7 @@
import java.util.EventObject;
-import org.crosswire.jsword.book.Book;
+import org.crosswire.jsword.book.BookProvider;
import org.crosswire.jsword.passage.Key;
/**
@@ -39,14 +39,12 @@
* For when a command has been made
* @param source The thing that started this off
* @param key The selected Key
- * @param book The selected book
*/
- public DisplaySelectEvent(Object source, Key key, Book[] books)
+ public DisplaySelectEvent(BookProvider source, Key key)
{
super(source);
this.key = key;
- this.books = books;
}
/**
@@ -62,9 +60,9 @@
* Get the type of command
* @return The type of command
*/
- public Book[] getBooks()
+ public BookProvider getBookProvider()
{
- return books;
+ return (BookProvider) getSource();
}
/**
@@ -73,11 +71,6 @@
private Key key;
/**
- * The new Book
- */
- private transient Book[] books;
-
- /**
* Serialization ID
*/
private static final long serialVersionUID = 3689068456540910136L;
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-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DisplaySelectPane.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -56,6 +56,7 @@
import org.crosswire.jsword.book.BookComparators;
import org.crosswire.jsword.book.BookException;
import org.crosswire.jsword.book.BookFilters;
+import org.crosswire.jsword.book.BookProvider;
import org.crosswire.jsword.index.IndexStatus;
import org.crosswire.jsword.index.IndexStatusEvent;
import org.crosswire.jsword.index.IndexStatusListener;
@@ -79,7 +80,7 @@
* @author Joe Walker [joe at eireneh dot com]
* @author DM Smith [dmsmith555 at yahoo dot com]
*/
-public class DisplaySelectPane extends JPanel implements KeyChangeListener, BookSelectListener
+public class DisplaySelectPane extends JPanel implements KeyChangeListener, BookSelectListener, BookProvider
{
/**
* General constructor
@@ -218,7 +219,7 @@
*/
public Book[] getBooks()
{
- return selected;
+ return (Book[]) selected.clone();
}
/**
@@ -405,7 +406,7 @@
return;
}
- fireCommandMade(new DisplaySelectEvent(this, key, selected));
+ fireCommandMade(new DisplaySelectEvent(this, key));
}
/**
@@ -602,10 +603,10 @@
*/
public void booksChosen(BookSelectEvent ev)
{
- Book[] books = ev.getBooks();
+ Book[] books = ev.getBookProvider().getBooks();
assert books.length > 0;
- Book newSelected = ev.getFirstBook();
+ Book newSelected = ev.getBookProvider().getFirstBook();
if (selected.length > 0 && selected[0] != newSelected)
{
@@ -623,7 +624,7 @@
return;
}
- fireVersionChanged(new DisplaySelectEvent(this, key, selected));
+ fireVersionChanged(new DisplaySelectEvent(this, key));
}
/* (non-Javadoc)
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -45,6 +45,7 @@
import org.crosswire.bibledesktop.display.BookDataDisplay;
import org.crosswire.bibledesktop.display.BookDataDisplayFactory;
import org.crosswire.bibledesktop.display.URIEventListener;
+import org.crosswire.bibledesktop.passage.KeyChangeListener;
import org.crosswire.bibledesktop.passage.KeyListListModel;
import org.crosswire.bibledesktop.passage.KeyTreeCellRenderer;
import org.crosswire.bibledesktop.passage.KeyTreeModel;
@@ -171,6 +172,22 @@
}
/* (non-Javadoc)
+ * @see org.crosswire.bibledesktop.display.BookDataDisplay#addKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+ */
+ public void addKeyChangeListener(KeyChangeListener listener)
+ {
+ display.addKeyChangeListener(listener);
+ }
+
+ /* (non-Javadoc)
+ * @see org.crosswire.bibledesktop.display.BookDataDisplay#removeKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+ */
+ public void removeKeyChangeListener(KeyChangeListener listener)
+ {
+ display.removeKeyChangeListener(listener);
+ }
+
+ /* (non-Javadoc)
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent evt)
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-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/ParallelBookPicker.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -41,6 +41,7 @@
import org.crosswire.common.swing.GuiUtil;
import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.book.BookFilter;
+import org.crosswire.jsword.book.BookProvider;
/**
* A picker of more than one book at a time.
@@ -49,7 +50,7 @@
* The copyright to this program is held by it's authors.
* @author DM Smith [dmsmith555 at yahoo dot com]
*/
-public class ParallelBookPicker extends JPanel
+public class ParallelBookPicker extends JPanel implements BookProvider
{
/**
@@ -90,7 +91,7 @@
BooksComboBoxModel mdlBook = new BooksComboBoxModel(filter, comparator);
JComboBox cboBook = new JComboBox(mdlBook);
cboBook.setRenderer(new BookListCellRenderer(true));
- cboBook.addItemListener(new SelectedItemListener());
+ cboBook.addItemListener(new SelectedItemListener(this));
cboBook.addActionListener(new SelectedActionListener());
add(cboBook);
@@ -102,7 +103,7 @@
enableButtons();
GuiUtil.refresh(this);
- fireBooksChosen(new BookSelectEvent(this, getBooks()));
+ fireBooksChosen(new BookSelectEvent(this));
}
/**
@@ -118,13 +119,13 @@
remove(size - 1);
enableButtons();
GuiUtil.refresh(this);
- fireBooksChosen(new BookSelectEvent(this, getBooks()));
+ fireBooksChosen(new BookSelectEvent(this));
}
}
- /**
- * What are the currently selected Books?
+ /* (non-Javadoc)
+ * @see org.crosswire.jsword.book.BookProvider#getBooks()
*/
public Book[] getBooks()
{
@@ -142,6 +143,24 @@
return (Book[]) books.toArray(new Book[books.size()]);
}
+ /* (non-Javadoc)
+ * @see org.crosswire.jsword.book.BookProvider#getFirstBook()
+ */
+ public Book getFirstBook()
+ {
+ int count = getComponentCount();
+ for (int i = 1; i < count; i++)
+ {
+ Component comp = getComponent(i);
+ if (comp instanceof JComboBox)
+ {
+ JComboBox combo = (JComboBox) comp;
+ return (Book) combo.getSelectedItem();
+ }
+ }
+ return null;
+ }
+
/**
* @return the maxPickers
*/
@@ -211,6 +230,7 @@
private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException
{
listeners = new EventListenerList();
+ actions = new ActionFactory(ParallelBookPicker.class, this);
is.defaultReadObject();
}
@@ -218,8 +238,13 @@
/**
* An ItemListener for a particular combo box that tracks it's selected item.
*/
- final class SelectedItemListener implements ItemListener
+ final class SelectedItemListener implements ItemListener, BookProvider
{
+ SelectedItemListener(ParallelBookPicker picker)
+ {
+ this.picker = picker;
+ }
+
/* (non-Javadoc)
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
*/
@@ -231,11 +256,28 @@
Book selected = (Book) combo.getSelectedItem();
- fireBooksChosen(new BookSelectEvent(this, getBooks()));
+ fireBooksChosen(new BookSelectEvent(this));
combo.setToolTipText(selected.getName());
}
}
+ /* (non-Javadoc)
+ * @see org.crosswire.jsword.book.BookProvider#getBooks()
+ */
+ public Book[] getBooks()
+ {
+ return picker.getBooks();
+ }
+
+ /* (non-Javadoc)
+ * @see org.crosswire.jsword.book.BookProvider#getFirstBook()
+ */
+ public Book getFirstBook()
+ {
+ return picker.getFirstBook();
+ }
+
+ private ParallelBookPicker picker;
}
/**
@@ -259,17 +301,17 @@
/**
* The filter to apply
*/
- private BookFilter filter;
+ private transient BookFilter filter;
/**
* The comparator to order the books.
*/
- private Comparator comparator;
+ private transient Comparator comparator;
/**
* Allow for adding and removing pickers.
*/
- private ActionFactory actions;
+ private transient ActionFactory actions;
/**
* Who is interested in things this DisplaySelectPane does
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-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -813,10 +813,51 @@
fillChoiceFactory();
config = new Config(Msg.CONFIG_TITLE.toString());
- Document xmlconfig = null;
try
{
- xmlconfig = XMLUtil.getDocument(CONFIG_KEY);
+ Document xmlconfig = XMLUtil.getDocument(CONFIG_KEY);
+
+ Locale defaultLocale = Locale.getDefault();
+ ResourceBundle configResources = ResourceBundle.getBundle(CONFIG_KEY, defaultLocale, CWClassLoader.instance(Desktop.class));
+
+ config.add(xmlconfig, configResources);
+
+ try
+ {
+ config.setProperties(ResourceUtil.getProperties(DESKTOP_KEY));
+ }
+ catch (IOException ex)
+ {
+ ex.printStackTrace(System.err);
+ ExceptionPane.showExceptionDialog(null, ex);
+ }
+
+ config.localToApplication();
+ config.addPropertyChangeListener(new PropertyChangeListener()
+ {
+ /* (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.getBiblePicker().enableButtons();
+ }
+ }
+ });
}
// Something went wrong before we've managed to get on our feet.
// so we want the best possible shot at working out what failed.
@@ -831,47 +872,6 @@
ExceptionPane.showExceptionDialog(null, e);
}
- Locale defaultLocale = Locale.getDefault();
- ResourceBundle configResources = ResourceBundle.getBundle(CONFIG_KEY, defaultLocale, CWClassLoader.instance(Desktop.class));
-
- config.add(xmlconfig, configResources);
-
- try
- {
- config.setProperties(ResourceUtil.getProperties(DESKTOP_KEY));
- }
- catch (IOException ex)
- {
- ex.printStackTrace(System.err);
- ExceptionPane.showExceptionDialog(null, ex);
- }
-
- config.localToApplication();
- config.addPropertyChangeListener(new PropertyChangeListener()
- {
- /* (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.getBiblePicker().enableButtons();
- }
- }
- });
}
public void checkForBooks()
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/BookDataDisplay.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/BookDataDisplay.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/BookDataDisplay.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -24,7 +24,9 @@
import java.awt.Component;
import java.beans.PropertyChangeListener;
+import org.crosswire.bibledesktop.passage.KeyChangeListener;
import org.crosswire.jsword.book.Book;
+import org.crosswire.jsword.book.BookProvider;
import org.crosswire.jsword.passage.Key;
/**
@@ -34,7 +36,7 @@
* The copyright to this program is held by it's authors.
* @author Joe Walker [joe at eireneh dot com]
*/
-public interface BookDataDisplay extends PropertyChangeListener
+public interface BookDataDisplay extends BookProvider, PropertyChangeListener
{
/**
* Used by property change listeners to listen for when books should be compared.
@@ -42,66 +44,69 @@
String COMPARE_BOOKS = "ComparingBooks"; //$NON-NLS-1$
/**
- * Copy the selection to the clipboard
+ * Clear any BookData that is displayed. This is equivalent to:
+ * <code>setBookData(null, null)</code>.
*/
- void copy();
+ void clearBookData();
/**
- * Add a listener for when someone clicks on a browser 'link'
- * @param listener The listener to add
+ * Set the BookData to be displayed.
+ * The data to be displayed is specified as a books and key rather than the
+ * more obvious BookData (the result of reading books using a key)
+ * since some displays may wish so split up the display and only look up
+ * smaller sections at a time.
+ * @param books The Books to read data from
+ * @param key The key to read from the given book
*/
- void addURIEventListener(URIEventListener listener);
+ void setBookData(Book[] books, Key key);
/**
- * Remove a listener for when someone clicks on a browser 'link'
- * @param listener The listener to remove
+ * The Book Key that we are displaying, or null if we are not displaying
+ * anything
+ * @return The current key
*/
- void removeURIEventListener(URIEventListener listener);
+ Key getKey();
/**
- * Accessor for the Swing component
+ * Cause the BookData to be re-displayed.
*/
- Component getComponent();
+ void refresh();
/**
- * Clear any BookData that is displayed.
+ * Copy the selection to the clipboard
*/
- void clearBookData();
+ void copy();
/**
- * Set the BookData to be displayed.
- * The data to be displayed is specified as a books and key rather than the
- * more obvious BookData (the result of reading books using a key)
- * since some displays may wish so split up the display and only look up
- * smaller sections at a time.
- * @param books The Books to read data from
- * @param key The key to read from the given book
+ * Add a listener for when the key changes.
+ *
+ * @param listener
*/
- void setBookData(Book[] books, Key key);
+ void addKeyChangeListener(KeyChangeListener listener);
/**
- * Cause the BookData to be re-displayed.
+ * Remove a listener for when the key changes.
+ *
+ * @param listener
*/
- void refresh();
+ void removeKeyChangeListener(KeyChangeListener listener);
/**
- * The Book Key that we are displaying, or null if we are not displaying
- * anything
- * @return The current key
+ * Add a listener for when someone clicks on a browser 'link'
+ * @param listener The listener to add
*/
- Key getKey();
+ void addURIEventListener(URIEventListener listener);
/**
- * Accessor for the Books used in the current display, or null if we are not
- * displaying anything.
- * @return The current books
+ * Remove a listener for when someone clicks on a browser 'link'
+ * @param listener The listener to remove
*/
- Book[] getBooks();
+ void removeURIEventListener(URIEventListener listener);
+
/**
- * Accessor for the first Book used in the current display, or null if we are not
- * displaying anything.
- * @return The current books
+ * Accessor for the Swing component
*/
- Book getFirstBook();
+ Component getComponent();
+
}
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/ProxyBookDataDisplay.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/ProxyBookDataDisplay.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/ProxyBookDataDisplay.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -24,6 +24,7 @@
import java.awt.Component;
import java.beans.PropertyChangeEvent;
+import org.crosswire.bibledesktop.passage.KeyChangeListener;
import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.passage.Key;
@@ -57,6 +58,22 @@
}
/* (non-Javadoc)
+ * @see org.crosswire.bibledesktop.display.BookDataDisplay#addKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+ */
+ public void addKeyChangeListener(KeyChangeListener listener)
+ {
+ proxy.addKeyChangeListener(listener);
+ }
+
+ /* (non-Javadoc)
+ * @see org.crosswire.bibledesktop.display.BookDataDisplay#removeKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+ */
+ public void removeKeyChangeListener(KeyChangeListener listener)
+ {
+ proxy.removeKeyChangeListener(listener);
+ }
+
+ /* (non-Javadoc)
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent evt)
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/ScrolledBookDataDisplay.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/ScrolledBookDataDisplay.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/ScrolledBookDataDisplay.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -45,7 +45,6 @@
super(child);
scrView = new CWScrollPane(getProxy().getComponent());
scrView.getViewport().setPreferredSize(new Dimension(500, 400));
-// scrView.getViewport().add(getProxy().getComponent(), null);
}
/* (non-Javadoc)
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/SplitBookDataDisplay.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/SplitBookDataDisplay.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/SplitBookDataDisplay.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -23,30 +23,31 @@
import java.awt.BorderLayout;
import java.awt.Component;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Arrays;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
+import javax.swing.event.EventListenerList;
import org.crosswire.bibledesktop.display.BookDataDisplay;
-import org.crosswire.bibledesktop.passage.KeyChangeEvent;
import org.crosswire.bibledesktop.passage.KeyChangeListener;
import org.crosswire.bibledesktop.passage.KeySidebar;
import org.crosswire.common.swing.FixedSplitPane;
import org.crosswire.common.util.Logger;
+import org.crosswire.common.util.StringUtil;
import org.crosswire.jsword.book.Book;
+import org.crosswire.jsword.book.BookProvider;
import org.crosswire.jsword.passage.Key;
/**
- * A quick Swing Bible display pane.
+ * A SplitBookDataDisplay consists of a KeySidebar and a BookDataDisplay in a SplitPane.
*
* @see gnu.gpl.License for license details.
* The copyright to this program is held by it's authors.
* @author Joe Walker [joe at eireneh dot com]
* @author DM Smith [dmsmith555 at yahoo dot com]
*/
-public class SplitBookDataDisplay extends JPanel
+public class SplitBookDataDisplay extends JPanel implements BookProvider
{
/**
* Initialize the SplitBookDataDisplay
@@ -55,14 +56,8 @@
{
this.child = child;
this.sidebar = sidebar;
- init();
- }
+ listenerList = new EventListenerList();
- /**
- * Create the GUI
- */
- private void init()
- {
split = new FixedSplitPane();
split.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
split.setLeftComponent(sidebar);
@@ -97,25 +92,22 @@
*/
public void setBookData(Book[] books, Key key)
{
- boolean keyChanged = this.key == null || !this.key.equals(key);
- boolean bookChanged = this.books == null || !this.books.equals(books);
+ boolean keyChanged = child.getKey() == null || !child.getKey().equals(key);
+ boolean bookChanged = child.getBooks() == null || !Arrays.equals(child.getBooks(), books);
- this.books = books;
- this.key = key;
-
- // Only set the passage if it has changed
+ // Only set the passage if it has changed
if (keyChanged)
{
log.debug("new passage chosen: " + key.getName()); //$NON-NLS-1$
- fireKeyChanged(new KeyChangeEvent(this, key));
}
+ if (bookChanged)
+ {
+ log.debug("new book(s) chosen: " + StringUtil.toString(books)); //$NON-NLS-1$
+ }
+
if (bookChanged || keyChanged)
{
- if (bookChanged)
- {
- log.debug("new bible chosen: " + books); //$NON-NLS-1$
- }
child.setBookData(books, key);
}
}
@@ -144,13 +136,12 @@
validate();
}
-
/**
* @return the key
*/
public Key getKey()
{
- return key;
+ return child.getKey();
}
/**
@@ -158,7 +149,7 @@
*/
public Book[] getBooks()
{
- return books;
+ return child.getBooks();
}
/**
@@ -166,7 +157,7 @@
*/
public Book getFirstBook()
{
- return books != null && books.length > 0 ? books[0] : null;
+ return child.getFirstBook();
}
/**
@@ -178,70 +169,26 @@
}
/**
- * Add a command listener
+ * Add a listener for changes in the Key.
+ *
+ * @param listener the listener to add
*/
public synchronized void addKeyChangeListener(KeyChangeListener listener)
{
- List temp = new ArrayList(2);
-
- if (keyChangeListeners != null)
- {
- temp.addAll(keyChangeListeners);
- }
-
- if (!temp.contains(listener))
- {
- temp.add(listener);
- keyChangeListeners = temp;
- }
+ child.addKeyChangeListener(listener);
}
/**
- * Remove a command listener
+ * Remove a listener for changes in the Key.
+ *
+ * @param listener the listener to remove
*/
public synchronized void removeKeyChangeListener(KeyChangeListener listener)
{
- if (keyChangeListeners != null && keyChangeListeners.contains(listener))
- {
- List temp = new ArrayList();
- temp.addAll(keyChangeListeners);
-
- temp.remove(listener);
- keyChangeListeners = temp;
- }
+ child.removeKeyChangeListener(listener);
}
/**
- * Inform the command keyChangeListeners
- */
- protected synchronized void fireKeyChanged(KeyChangeEvent ev)
- {
- if (keyChangeListeners != null)
- {
- for (int i = 0; i < keyChangeListeners.size(); i++)
- {
- KeyChangeListener listener = (KeyChangeListener) keyChangeListeners.get(i);
- listener.keyChanged(ev);
- }
- }
- }
-
- /**
- * The whole passage that we are viewing
- */
- private Key key;
-
- /**
- * The listener for KeyChangeEvents
- */
- private transient List keyChangeListeners;
-
- /**
- * What books are we currently viewing?
- */
- private transient Book[] books;
-
- /**
* The log stream
*/
private static final Logger log = Logger.getLogger(SplitBookDataDisplay.class);
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TabbedBookDataDisplay.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TabbedBookDataDisplay.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TabbedBookDataDisplay.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -39,8 +39,9 @@
import org.crosswire.bibledesktop.display.BookDataDisplay;
import org.crosswire.bibledesktop.display.BookDataDisplayFactory;
-import org.crosswire.bibledesktop.display.ScrolledBookDataDisplay;
import org.crosswire.bibledesktop.display.URIEventListener;
+import org.crosswire.bibledesktop.passage.KeyChangeListener;
+import org.crosswire.common.swing.CWScrollPane;
import org.crosswire.common.swing.GuiUtil;
import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.passage.Key;
@@ -64,19 +65,14 @@
*/
public TabbedBookDataDisplay()
{
- pnlView = createInnerDisplayPane();
+ views = new HashMap();
+ displays = new ArrayList();
+ pnlMore = new JPanel();
+ pnlMain = new JPanel();
- init();
+ bookDataDisplay = createInnerDisplayPane();
- center = pnlView.getComponent();
- pnlMain.add(center, BorderLayout.CENTER);
- }
-
- /**
- * GUI creation
- */
- private void init()
- {
+ tabMain = new JTabbedPane();
tabMain.setTabPlacement(SwingConstants.BOTTOM);
tabMain.addChangeListener(new ChangeListener()
{
@@ -87,6 +83,10 @@
});
pnlMain.setLayout(new BorderLayout());
+
+ center = bookDataDisplay.getComponent();
+ scrMain = new CWScrollPane(center);
+ pnlMain.add(scrMain, BorderLayout.CENTER);
}
/* (non-Javadoc)
@@ -110,14 +110,14 @@
*/
public void setBookData(Book[] books, Key newkey)
{
- this.books = books;
+ this.books = books == null ? null : (Book[]) books.clone();
this.key = KeyUtil.getPassage(newkey);
// Tabbed view or not we should clear out the old tabs
tabMain.removeAll();
views.clear();
displays.clear();
- displays.add(pnlView);
+ displays.add(bookDataDisplay);
// So use purely Keys and not Passage, create a utility to cut up
// a key into a number of keys.
@@ -150,22 +150,23 @@
pnlNew.setBookData(books, first);
Component display = pnlNew.getComponent();
- views.put(display, pnlNew);
+ JScrollPane scrView = new CWScrollPane(display);
+ views.put(scrView, pnlNew);
- tabMain.add(getTabName(first), display);
+ tabMain.add(getTabName(first), scrView);
tabMain.add(Msg.MORE.toString(), pnlMore);
setCenterComponent(tabMain);
}
else
{
- pnlView.setBookData(books, key);
+ bookDataDisplay.setBookData(books, key);
- setCenterComponent(pnlView.getComponent());
+ setCenterComponent(bookDataDisplay.getComponent());
}
// Since we changed the contents of the page we need to cause it to repaint
- GuiUtil.refresh(center);
+ GuiUtil.refresh(scrMain);
GuiUtil.refresh(pnlMain);
}
@@ -197,7 +198,7 @@
*/
public Book[] getBooks()
{
- return books;
+ return books == null ? null : (Book[]) books.clone();
}
/* (non-Javadoc)
@@ -217,6 +218,60 @@
}
/* (non-Javadoc)
+ * @see org.crosswire.bibledesktop.display.BookDataDisplay#addKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+ */
+ public void addKeyChangeListener(KeyChangeListener listener)
+ {
+ // First add to our list of listeners so when we add a new tab
+ // we can add this new listener to the new tab
+ List temp = new ArrayList();
+ if (keyEventListeners == null)
+ {
+ temp.add(listener);
+ keyEventListeners = temp;
+ }
+ else
+ {
+ temp.addAll(keyEventListeners);
+
+ if (!temp.contains(listener))
+ {
+ temp.add(listener);
+ keyEventListeners = temp;
+ }
+ }
+
+ Iterator iter = displays.iterator();
+ while (iter.hasNext())
+ {
+ BookDataDisplay bdd = (BookDataDisplay) iter.next();
+ bdd.addKeyChangeListener(listener);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.crosswire.bibledesktop.display.BookDataDisplay#removeKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+ */
+ public void removeKeyChangeListener(KeyChangeListener listener)
+ {
+ // First remove from the list of listeners
+ if (keyEventListeners != null && keyEventListeners.contains(listener))
+ {
+ List temp = new ArrayList();
+ temp.addAll(keyEventListeners);
+ temp.remove(listener);
+ keyEventListeners = temp;
+ }
+
+ Iterator iter = displays.iterator();
+ while (iter.hasNext())
+ {
+ BookDataDisplay bdd = (BookDataDisplay) iter.next();
+ bdd.removeKeyChangeListener(listener);
+ }
+ }
+
+ /* (non-Javadoc)
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent evt)
@@ -235,22 +290,22 @@
*/
public synchronized void addURIEventListener(URIEventListener listener)
{
- // First add to our list of listeners so when we get more event syncs
- // we can add this new listener to the new sync
+ // First add to our list of listeners so when we add a new tab
+ // we can add this new listener to the new tab
List temp = new ArrayList();
- if (hyperlis == null)
+ if (uriEventListeners == null)
{
temp.add(listener);
- hyperlis = temp;
+ uriEventListeners = temp;
}
else
{
- temp.addAll(hyperlis);
+ temp.addAll(uriEventListeners);
if (!temp.contains(listener))
{
temp.add(listener);
- hyperlis = temp;
+ uriEventListeners = temp;
}
}
@@ -269,12 +324,12 @@
public synchronized void removeURIEventListener(URIEventListener listener)
{
// First remove from the list of listeners
- if (hyperlis != null && hyperlis.contains(listener))
+ if (uriEventListeners != null && uriEventListeners.contains(listener))
{
List temp = new ArrayList();
- temp.addAll(hyperlis);
+ temp.addAll(uriEventListeners);
temp.remove(listener);
- hyperlis = temp;
+ uriEventListeners = temp;
}
// Now remove from all the known syncs
@@ -291,12 +346,28 @@
*/
private void setCenterComponent(Component comp)
{
- // And show it is needed
+ // We are currently viewing either a set of tabs (tabMain)
+ // or a single page (bookDataDisplay.getComponent()).
+ // The new center component is either tabMain
+ // or something that should be wrapped with a scroller.
+ //
+ // So when we go from tabMain, we need to remove center
+ // and when we go from a single page we need to remove the scroller
+ //
+
if (center != comp)
{
- pnlMain.remove(center);
+ pnlMain.removeAll();
center = comp;
- pnlMain.add(center, BorderLayout.CENTER);
+ if (center == tabMain)
+ {
+ pnlMain.add(tabMain, BorderLayout.CENTER);
+ }
+ else
+ {
+ pnlMain.add(scrMain, BorderLayout.CENTER);
+ //scrMain.setViewportView(center);
+ }
}
}
@@ -322,10 +393,10 @@
BookDataDisplay pnlNew = createInnerDisplayPane();
pnlNew.setBookData(books, next);
- Component display = pnlNew.getComponent();
- views.put(display, pnlNew);
+ JScrollPane scrView = new CWScrollPane(pnlNew.getComponent());
+ views.put(scrView, pnlNew);
- tabMain.add(getTabName(next), display);
+ tabMain.add(getTabName(next), scrView);
// Do we need a new more tab
if (waiting != null)
@@ -334,7 +405,7 @@
}
// Select the real new tab in place of any more tabs
- tabMain.setSelectedComponent(display);
+ tabMain.setSelectedComponent(scrView);
}
/**
@@ -348,7 +419,7 @@
JScrollPane sp = (JScrollPane) o;
return (BookDataDisplay) views.get(sp);
}
- return pnlView;
+ return bookDataDisplay;
}
/**
@@ -356,13 +427,13 @@
*/
private synchronized BookDataDisplay createInnerDisplayPane()
{
- BookDataDisplay display = new ScrolledBookDataDisplay(BookDataDisplayFactory.createBookDataDisplay());
+ BookDataDisplay display = BookDataDisplayFactory.createBookDataDisplay();
displays.add(display);
// Add all the known listeners to this new BookDataDisplay
- if (hyperlis != null)
+ if (uriEventListeners != null)
{
- Iterator iter = hyperlis.iterator();
+ Iterator iter = uriEventListeners.iterator();
while (iter.hasNext())
{
URIEventListener li = (URIEventListener) iter.next();
@@ -370,6 +441,17 @@
}
}
+ // Add all the known listeners to this new BookDataDisplay
+ if (keyEventListeners != null)
+ {
+ Iterator iter = keyEventListeners.iterator();
+ while (iter.hasNext())
+ {
+ KeyChangeListener li = (KeyChangeListener) iter.next();
+ display.addKeyChangeListener(li);
+ }
+ }
+
return display;
}
@@ -419,9 +501,14 @@
/**
* A list of all the URIEventListeners
*/
- private List hyperlis;
+ private List uriEventListeners;
/**
+ * A list of all the keyEventListeners
+ */
+ private List keyEventListeners;
+
+ /**
* The passage that we are displaying (in one or more tabs)
*/
private Passage key;
@@ -444,22 +531,22 @@
/**
* If we are using tabs, this is the main view
*/
- private JTabbedPane tabMain = new JTabbedPane();
+ private JTabbedPane tabMain;
/**
* If we are not using tabs, this is the main view
*/
- private BookDataDisplay pnlView;
+ private BookDataDisplay bookDataDisplay;
/**
* An map of compnents to their views
*/
- private Map views = new HashMap();
+ private Map views;
/**
* A list of all the InnerDisplayPanes so we can control listeners
*/
- private List displays = new ArrayList();
+ private List displays;
/**
* Pointer to whichever of the above is currently in use
@@ -469,10 +556,15 @@
/**
* Blank thing for the "More..." button
*/
- private JPanel pnlMore = new JPanel();
+ private JPanel pnlMore;
/**
* The top level component
*/
- private JPanel pnlMain = new JPanel();
+ private JPanel pnlMain;
+
+ /**
+ * The top level component
+ */
+ private JScrollPane scrMain;
}
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -30,6 +30,7 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.text.MessageFormat;
+import java.util.Arrays;
import javax.swing.JTextPane;
import javax.swing.event.EventListenerList;
@@ -45,6 +46,7 @@
import org.crosswire.bibledesktop.display.BookDataDisplay;
import org.crosswire.bibledesktop.display.URIEvent;
import org.crosswire.bibledesktop.display.URIEventListener;
+import org.crosswire.bibledesktop.passage.KeyChangeListener;
import org.crosswire.common.swing.AntiAliasedTextPane;
import org.crosswire.common.util.Logger;
import org.crosswire.common.util.NetUtil;
@@ -101,14 +103,12 @@
*/
public void setBookData(Book[] books, Key key)
{
- this.books = books;
- this.key = key;
-
+
if (books == null || books.length == 0 || books[0] == null || key == null)
{
bdata = null;
}
- else if (bdata == null || !books.equals(bdata.getBooks()) || !key.equals(bdata.getKey()))
+ else if (bdata == null || !Arrays.equals(books, bdata.getBooks()) || !key.equals(bdata.getKey()))
{
bdata = new BookData(books, key, compareBooks);
}
@@ -313,8 +313,9 @@
return new String[] { protocol, data };
}
- /**
- * Accessor for the Swing component
+
+ /* (non-Javadoc)
+ * @see org.crosswire.bibledesktop.display.BookDataDisplay#getComponent()
*/
public Component getComponent()
{
@@ -330,6 +331,22 @@
}
/* (non-Javadoc)
+ * @see org.crosswire.bibledesktop.display.BookDataDisplay#addKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+ */
+ public synchronized void addKeyChangeListener(KeyChangeListener listener)
+ {
+ listenerList.add(KeyChangeListener.class, listener);
+ }
+
+ /* (non-Javadoc)
+ * @see org.crosswire.bibledesktop.display.BookDataDisplay#removeKeyChangeListener(org.crosswire.bibledesktop.passage.KeyChangeListener)
+ */
+ public synchronized void removeKeyChangeListener(KeyChangeListener listener)
+ {
+ listenerList.remove(KeyChangeListener.class, listener);
+ }
+
+ /* (non-Javadoc)
* @see org.crosswire.bibledesktop.display.BookDataDisplay#addURIEventListener(org.crosswire.bibledesktop.display.URIEventListener)
*/
public synchronized void addURIEventListener(URIEventListener listener)
@@ -429,7 +446,7 @@
*/
public Key getKey()
{
- return key;
+ return bdata.getKey();
}
/* (non-Javadoc)
@@ -437,7 +454,7 @@
*/
public Book[] getBooks()
{
- return books;
+ return bdata.getBooks();
}
/* (non-Javadoc)
@@ -445,7 +462,7 @@
*/
public Book getFirstBook()
{
- return books != null && books.length > 0 ? books[0] : null;
+ return bdata.getFirstBook();
}
// Strings for hyperlinks
@@ -465,16 +482,6 @@
private BookData bdata;
/**
- * The current books
- */
- private Book[] books;
-
- /**
- * The current key
- */
- private Key key;
-
- /**
* Whether the books should be compared.
*/
private boolean compareBooks;
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeySidebar.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeySidebar.java 2007-06-15 21:57:17 UTC (rev 1409)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeySidebar.java 2007-06-15 21:59:12 UTC (rev 1410)
@@ -61,7 +61,7 @@
*/
public KeySidebar(Book[] books)
{
- this.books = books;
+ this.books = books == null ? null : (Book[]) books.clone();
init();
setActive();
}
@@ -309,7 +309,7 @@
*/
public void bookChosen(DisplaySelectEvent ev)
{
- books = ev.getBooks();
+ books = ev.getBookProvider().getBooks();
}
/* (non-Javadoc)
More information about the jsword-svn
mailing list