1
22 package org.crosswire.bibledesktop.display.basic;
23
24 import java.awt.BorderLayout;
25 import java.awt.Component;
26 import java.io.IOException;
27 import java.io.ObjectInputStream;
28 import java.util.Arrays;
29
30 import javax.swing.JPanel;
31 import javax.swing.JSplitPane;
32 import javax.swing.event.EventListenerList;
33
34 import org.crosswire.bibledesktop.display.BookDataDisplay;
35 import org.crosswire.bibledesktop.passage.KeyChangeListener;
36 import org.crosswire.bibledesktop.passage.KeySidebar;
37 import org.crosswire.common.swing.FixedSplitPane;
38 import org.crosswire.common.util.Logger;
39 import org.crosswire.jsword.book.Book;
40 import org.crosswire.jsword.book.BookProvider;
41 import org.crosswire.jsword.passage.Key;
42
43
52 public class SplitBookDataDisplay extends JPanel implements BookProvider {
53
56 public SplitBookDataDisplay(KeySidebar sidebar, BookDataDisplay child) {
57 this.child = child;
58 this.sidebar = sidebar;
59 listenerList = new EventListenerList();
60
61 split = new FixedSplitPane();
62 split.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
63 split.setLeftComponent(sidebar);
64 split.setRightComponent(child.getComponent());
65 split.setOneTouchExpandable(true);
66 split.setDividerLocation(0.0D);
67 split.setBorder(null);
68 split.setDividerSize(8);
69
70 setLayout(new BorderLayout());
71 add(split, BorderLayout.CENTER);
72 }
73
74
77 public KeySidebar getSidebar() {
78 return sidebar;
79 }
80
81
84 public BookDataDisplay getBookDataDisplay() {
85 return child;
86 }
87
88
94 public void setBookData(Book[] books, Key key) {
95 boolean keyChanged = child.getKey() == null || !child.getKey().equals(key);
96 boolean bookChanged = child.getBooks() == null || !Arrays.equals(child.getBooks(), books);
97
98 if (keyChanged) {
100 log.debug("new passage chosen: " + key.getName());
101 }
102
103 if (bookChanged) {
104 log.debug("new book(s) chosen: " + Arrays.toString(books));
105 }
106
107 if (bookChanged || keyChanged) {
108 child.setBookData(books, key);
109 }
110 }
111
112
118 public void showSidebar(boolean show) {
119 Component childComponent = child.getComponent();
120 if (show) {
121 remove(childComponent);
122 split.add(childComponent, JSplitPane.RIGHT);
123 add(split);
124 } else {
125 remove(split);
126 split.remove(childComponent);
127 add(childComponent);
128 }
129
130 validate();
132 }
133
134
137 public Key getKey() {
138 return child.getKey();
139 }
140
141
144 public Book[] getBooks() {
145 return child.getBooks();
146 }
147
148
151 public Book getFirstBook() {
152 return child.getFirstBook();
153 }
154
155
158 public void copy() {
159 child.copy();
160 }
161
162
168 public synchronized void addKeyChangeListener(KeyChangeListener listener) {
169 child.addKeyChangeListener(listener);
170 }
171
172
178 public synchronized void removeKeyChangeListener(KeyChangeListener listener) {
179 child.removeKeyChangeListener(listener);
180 }
181
182
189 private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException {
190 child = null;
192 is.defaultReadObject();
193 }
194
195
198 private static final Logger log = Logger.getLogger(SplitBookDataDisplay.class);
199
200
203 private KeySidebar sidebar;
204 private JSplitPane split;
205 private transient BookDataDisplay child;
206
207
210 private static final long serialVersionUID = 3257283643176202806L;
211 }
212