1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
package org.crosswire.jsword.book; |
21 | |
|
22 | |
import java.util.Map; |
23 | |
import java.util.TreeMap; |
24 | |
|
25 | |
import org.crosswire.common.config.ChoiceFactory; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public final class Defaults { |
34 | |
|
35 | |
|
36 | |
|
37 | 0 | private Defaults() { |
38 | 0 | } |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public static boolean isCurrentBible() { |
47 | 0 | return trackBible; |
48 | |
} |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public static void setCurrentBible(boolean current) { |
57 | 0 | trackBible = current; |
58 | 0 | } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public static void setCurrentBook(Book book) { |
67 | 0 | BookCategory type = book.getBookCategory(); |
68 | 0 | if (type.equals(BookCategory.BIBLE) && isCurrentBible()) { |
69 | 0 | currentBible = book; |
70 | |
} |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public static Book getCurrentBible() { |
79 | 0 | if (currentBible == null) { |
80 | 0 | return bibleDeft.getDefault(); |
81 | |
} |
82 | 0 | return currentBible; |
83 | |
} |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public static void setBible(Book book) { |
91 | 0 | bibleDeft.setDefault(book); |
92 | 0 | } |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
protected static void unsetBible() { |
98 | 0 | bibleDeft.unsetDefault(); |
99 | 0 | } |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
public static Book getBible() { |
105 | 0 | return bibleDeft.getDefault(); |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
public static String getBibleByName() { |
112 | 0 | return bibleDeft.getDefaultName(); |
113 | |
} |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
public static void setBibleByName(String name) { |
121 | 0 | bibleDeft.setDefaultByName(name); |
122 | 0 | } |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public static void setCommentary(Book book) { |
130 | 0 | commentaryDeft.setDefault(book); |
131 | 0 | } |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
protected static void unsetCommentary() { |
137 | 0 | commentaryDeft.unsetDefault(); |
138 | 0 | } |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
public static Book getCommentary() { |
144 | 0 | return commentaryDeft.getDefault(); |
145 | |
} |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public static String getCommentaryByName() { |
151 | 0 | return commentaryDeft.getDefaultName(); |
152 | |
} |
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public static void setCommentaryByName(String name) { |
160 | 0 | commentaryDeft.setDefaultByName(name); |
161 | 0 | } |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
public static void setDictionary(Book book) { |
169 | 0 | dictionaryDeft.setDefault(book); |
170 | 0 | } |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
protected static void unsetDictionary() { |
176 | 0 | dictionaryDeft.unsetDefault(); |
177 | 0 | } |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
public static Book getDictionary() { |
183 | 0 | return dictionaryDeft.getDefault(); |
184 | |
} |
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
public static String getDictionaryByName() { |
190 | 0 | return dictionaryDeft.getDefaultName(); |
191 | |
} |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
public static void setDictionaryByName(String name) { |
199 | 0 | dictionaryDeft.setDefaultByName(name); |
200 | 0 | } |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
public static void setDailyDevotional(Book book) { |
208 | 0 | dictionaryDeft.setDefault(book); |
209 | 0 | } |
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
protected static void unsetDailyDevotional() { |
215 | 0 | dailyDevotionalDeft.unsetDefault(); |
216 | 0 | } |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
public static Book getDailyDevotional() { |
222 | 0 | return dailyDevotionalDeft.getDefault(); |
223 | |
} |
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
public static String getDailyDevotionalByName() { |
229 | 0 | return dailyDevotionalDeft.getDefaultName(); |
230 | |
} |
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
public static void setDailyDevotionalByName(String name) { |
238 | 0 | dailyDevotionalDeft.setDefaultByName(name); |
239 | 0 | } |
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
public static void setGreekDefinitions(Book book) { |
247 | 0 | greekDefinitionsDeft.setDefault(book); |
248 | 0 | } |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
protected static void unsetGreekDefinitions() { |
254 | 0 | greekDefinitionsDeft.unsetDefault(); |
255 | 0 | } |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
public static Book getGreekDefinitions() { |
261 | 0 | return greekDefinitionsDeft.getDefault(); |
262 | |
} |
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
public static String getGreekDefinitionsByName() { |
268 | 0 | return greekDefinitionsDeft.getDefaultName(); |
269 | |
} |
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
public static void setGreekDefinitionsByName(String name) { |
277 | 0 | greekDefinitionsDeft.setDefaultByName(name); |
278 | 0 | } |
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
public static void setHebrewDefinitions(Book book) { |
286 | 0 | hebrewDefinitionsDeft.setDefault(book); |
287 | 0 | } |
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
protected static void unsetHebrewDefinitions() { |
293 | 0 | hebrewDefinitionsDeft.unsetDefault(); |
294 | 0 | } |
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
public static Book getHebrewDefinitions() { |
300 | 0 | return hebrewDefinitionsDeft.getDefault(); |
301 | |
} |
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
public static String getHebrewDefinitionsByName() { |
307 | 0 | return hebrewDefinitionsDeft.getDefaultName(); |
308 | |
} |
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
public static void setHebrewDefinitionsByName(String name) { |
316 | 0 | hebrewDefinitionsDeft.setDefaultByName(name); |
317 | 0 | } |
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
public static void setGreekParse(Book book) { |
325 | 0 | greekParseDeft.setDefault(book); |
326 | 0 | } |
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
protected static void unsetGreekParse() { |
332 | 0 | greekParseDeft.unsetDefault(); |
333 | 0 | } |
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
public static Book getGreekParse() { |
339 | 0 | return greekParseDeft.getDefault(); |
340 | |
} |
341 | |
|
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
public static String getGreekParseByName() { |
348 | 0 | return greekParseDeft.getDefaultName(); |
349 | |
} |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
public static void setGreekParseByName(String name) { |
355 | 0 | greekParseDeft.setDefaultByName(name); |
356 | 0 | } |
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
public static void setHebrewParse(Book book) { |
364 | 0 | hebrewParseDeft.setDefault(book); |
365 | 0 | } |
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
protected static void unsetHebrewParse() { |
371 | 0 | hebrewParseDeft.unsetDefault(); |
372 | 0 | } |
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
public static Book getHebrewParse() { |
378 | 0 | return hebrewParseDeft.getDefault(); |
379 | |
} |
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
public static String getHebrewParseByName() { |
385 | 0 | return hebrewParseDeft.getDefaultName(); |
386 | |
} |
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
public static void setHebrewParseByName(String name) { |
394 | 0 | hebrewParseDeft.setDefaultByName(name); |
395 | 0 | } |
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
protected static DefaultBook getDefaultBible() { |
401 | 0 | return bibleDeft; |
402 | |
} |
403 | |
|
404 | |
|
405 | |
|
406 | |
|
407 | |
protected static DefaultBook getDefaultCommentary() { |
408 | 0 | return commentaryDeft; |
409 | |
} |
410 | |
|
411 | |
|
412 | |
|
413 | |
|
414 | |
protected static DefaultBook getDefaultDictionary() { |
415 | 0 | return dictionaryDeft; |
416 | |
} |
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
protected static DefaultBook getDefaultDailyDevotional() { |
422 | 0 | return dailyDevotionalDeft; |
423 | |
} |
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
protected static DefaultBook getDefaultGreekDefinitions() { |
429 | 0 | return greekDefinitionsDeft; |
430 | |
} |
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
protected static DefaultBook getDefaultHebrewDefinitions() { |
436 | 0 | return hebrewDefinitionsDeft; |
437 | |
} |
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
protected static DefaultBook getDefaultGreekParse() { |
443 | 0 | return greekParseDeft; |
444 | |
} |
445 | |
|
446 | |
|
447 | |
|
448 | |
|
449 | |
protected static DefaultBook getDefaultHebrewParse() { |
450 | 0 | return hebrewParseDeft; |
451 | |
} |
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
public static void refreshBooks() { |
457 | |
|
458 | 0 | Map<Book, String> bnames = getBookMap(BookFilters.getOnlyBibles()); |
459 | 0 | ChoiceFactory.getDataMap().put(BIBLE_KEY, bnames); |
460 | |
|
461 | |
|
462 | 0 | Map<Book, String> cnames = getBookMap(BookFilters.getCommentaries()); |
463 | 0 | ChoiceFactory.getDataMap().put(COMMENTARY_KEY, cnames); |
464 | |
|
465 | |
|
466 | 0 | Map<Book, String> dnames = getBookMap(BookFilters.getDictionaries()); |
467 | 0 | ChoiceFactory.getDataMap().put(DICTIONARY_KEY, dnames); |
468 | |
|
469 | |
|
470 | 0 | Map<Book, String> rnames = getBookMap(BookFilters.getDailyDevotionals()); |
471 | 0 | ChoiceFactory.getDataMap().put(DAILY_DEVOTIONALS_KEY, rnames); |
472 | |
|
473 | |
|
474 | 0 | Map<Book, String> greekDef = getBookMap(BookFilters.getGreekDefinitions()); |
475 | 0 | ChoiceFactory.getDataMap().put(GREEKDEF_KEY, greekDef); |
476 | |
|
477 | |
|
478 | 0 | Map<Book, String> hebrewDef = getBookMap(BookFilters.getHebrewDefinitions()); |
479 | 0 | ChoiceFactory.getDataMap().put(HEBREWDEF_KEY, hebrewDef); |
480 | |
|
481 | |
|
482 | 0 | Map<Book, String> greekParse = getBookMap(BookFilters.getGreekParse()); |
483 | 0 | ChoiceFactory.getDataMap().put(GREEKPARSE_KEY, greekParse); |
484 | |
|
485 | |
|
486 | 0 | Map<Book, String> hebrewParse = getBookMap(BookFilters.getHebrewParse()); |
487 | 0 | ChoiceFactory.getDataMap().put(HEBREWPARSE_KEY, hebrewParse); |
488 | 0 | } |
489 | |
|
490 | |
|
491 | |
|
492 | |
|
493 | |
|
494 | |
protected static void checkAllPreferable() { |
495 | 0 | for (Book book : Books.installed().getBooks()) { |
496 | 0 | checkPreferable(book); |
497 | |
} |
498 | 0 | } |
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
|
505 | |
|
506 | |
protected static void checkPreferable(Book book) { |
507 | 0 | assert book != null; |
508 | |
|
509 | 0 | bibleDeft.setDefaultConditionally(book); |
510 | 0 | commentaryDeft.setDefaultConditionally(book); |
511 | 0 | dictionaryDeft.setDefaultConditionally(book); |
512 | 0 | dailyDevotionalDeft.setDefaultConditionally(book); |
513 | 0 | greekDefinitionsDeft.setDefaultConditionally(book); |
514 | 0 | greekParseDeft.setDefaultConditionally(book); |
515 | 0 | hebrewDefinitionsDeft.setDefaultConditionally(book); |
516 | 0 | hebrewParseDeft.setDefaultConditionally(book); |
517 | 0 | } |
518 | |
|
519 | |
|
520 | |
|
521 | |
|
522 | |
|
523 | |
|
524 | |
|
525 | |
private static Map<Book, String> getBookMap(BookFilter filter) { |
526 | 0 | Map<Book, String> books = new TreeMap<Book, String>(BookComparators.getDefault()); |
527 | |
|
528 | 0 | for (Book book : Books.installed().getBooks(filter)) { |
529 | 0 | books.put(book, book.getName()); |
530 | |
} |
531 | |
|
532 | 0 | return books; |
533 | |
} |
534 | |
|
535 | |
|
536 | |
|
537 | |
|
538 | 0 | static class DefaultsBookListener implements BooksListener { |
539 | |
|
540 | |
|
541 | |
|
542 | |
public void bookAdded(BooksEvent ev) { |
543 | 0 | Book book = ev.getBook(); |
544 | 0 | checkPreferable(book); |
545 | 0 | refreshBooks(); |
546 | 0 | } |
547 | |
|
548 | |
|
549 | |
|
550 | |
|
551 | |
public void bookRemoved(BooksEvent ev) { |
552 | 0 | Book book = ev.getBook(); |
553 | |
|
554 | 0 | getDefaultBible().unsetDefaultConditionally(book); |
555 | 0 | getDefaultCommentary().unsetDefaultConditionally(book); |
556 | 0 | getDefaultDailyDevotional().unsetDefaultConditionally(book); |
557 | 0 | getDefaultDictionary().unsetDefaultConditionally(book); |
558 | 0 | getDefaultGreekDefinitions().unsetDefaultConditionally(book); |
559 | 0 | getDefaultGreekParse().unsetDefaultConditionally(book); |
560 | 0 | getDefaultHebrewDefinitions().unsetDefaultConditionally(book); |
561 | 0 | getDefaultHebrewParse().unsetDefaultConditionally(book); |
562 | 0 | } |
563 | |
} |
564 | |
|
565 | |
private static final String BIBLE_KEY = "bible-names"; |
566 | |
private static final String COMMENTARY_KEY = "commentary-names"; |
567 | |
private static final String DICTIONARY_KEY = "dictionary-names"; |
568 | |
private static final String DAILY_DEVOTIONALS_KEY = "daily-devotional-names"; |
569 | |
private static final String GREEKDEF_KEY = "greekdef-names"; |
570 | |
private static final String HEBREWDEF_KEY = "hebrewdef-names"; |
571 | |
private static final String GREEKPARSE_KEY = "greekparse-names"; |
572 | |
private static final String HEBREWPARSE_KEY = "hebrewparse-names"; |
573 | |
|
574 | |
|
575 | |
|
576 | |
|
577 | 0 | private static boolean trackBible = true; |
578 | |
|
579 | |
|
580 | |
|
581 | |
|
582 | |
private static Book currentBible; |
583 | |
|
584 | |
|
585 | |
|
586 | |
|
587 | 0 | private static DefaultBook bibleDeft = new DefaultBook(Books.installed(), BookFilters.getOnlyBibles()); |
588 | |
|
589 | |
|
590 | |
|
591 | |
|
592 | 0 | private static DefaultBook commentaryDeft = new DefaultBook(Books.installed(), BookFilters.getCommentaries()); |
593 | |
|
594 | |
|
595 | |
|
596 | |
|
597 | 0 | private static DefaultBook dailyDevotionalDeft = new DefaultBook(Books.installed(), BookFilters.getDailyDevotionals()); |
598 | |
|
599 | |
|
600 | |
|
601 | |
|
602 | 0 | private static DefaultBook dictionaryDeft = new DefaultBook(Books.installed(), BookFilters.getDictionaries()); |
603 | |
|
604 | |
|
605 | |
|
606 | |
|
607 | 0 | private static DefaultBook greekParseDeft = new DefaultBook(Books.installed(), BookFilters.getGreekParse()); |
608 | |
|
609 | |
|
610 | |
|
611 | |
|
612 | 0 | private static DefaultBook hebrewParseDeft = new DefaultBook(Books.installed(), BookFilters.getHebrewParse()); |
613 | |
|
614 | |
|
615 | |
|
616 | |
|
617 | 0 | private static DefaultBook greekDefinitionsDeft = new DefaultBook(Books.installed(), BookFilters.getGreekDefinitions()); |
618 | |
|
619 | |
|
620 | |
|
621 | |
|
622 | 0 | private static DefaultBook hebrewDefinitionsDeft = new DefaultBook(Books.installed(), BookFilters.getHebrewDefinitions()); |
623 | |
|
624 | |
|
625 | |
|
626 | |
|
627 | |
static { |
628 | 0 | Books.installed().addBooksListener(new DefaultsBookListener()); |
629 | 0 | checkAllPreferable(); |
630 | 0 | } |
631 | |
|
632 | |
} |