1 package be
.nikiroo
.fanfix
.reader
.ui
;
3 import java
.awt
.BorderLayout
;
5 import java
.awt
.event
.ActionEvent
;
6 import java
.awt
.event
.ActionListener
;
7 import java
.awt
.event
.KeyEvent
;
8 import java
.awt
.event
.WindowEvent
;
10 import java
.io
.IOException
;
11 import java
.util
.HashMap
;
12 import java
.util
.List
;
14 import java
.util
.Map
.Entry
;
16 import javax
.swing
.JFileChooser
;
17 import javax
.swing
.JFrame
;
18 import javax
.swing
.JMenu
;
19 import javax
.swing
.JMenuBar
;
20 import javax
.swing
.JMenuItem
;
21 import javax
.swing
.JOptionPane
;
22 import javax
.swing
.JPopupMenu
;
23 import javax
.swing
.SwingUtilities
;
24 import javax
.swing
.filechooser
.FileFilter
;
25 import javax
.swing
.filechooser
.FileNameExtensionFilter
;
27 import be
.nikiroo
.fanfix
.Instance
;
28 import be
.nikiroo
.fanfix
.bundles
.Config
;
29 import be
.nikiroo
.fanfix
.bundles
.StringIdGui
;
30 import be
.nikiroo
.fanfix
.bundles
.UiConfig
;
31 import be
.nikiroo
.fanfix
.data
.MetaData
;
32 import be
.nikiroo
.fanfix
.data
.Story
;
33 import be
.nikiroo
.fanfix
.library
.BasicLibrary
;
34 import be
.nikiroo
.fanfix
.library
.LocalLibrary
;
35 import be
.nikiroo
.fanfix
.output
.BasicOutput
.OutputType
;
36 import be
.nikiroo
.fanfix
.reader
.BasicReader
;
37 import be
.nikiroo
.fanfix
.reader
.ui
.GuiReaderMainPanel
.FrameHelper
;
38 import be
.nikiroo
.fanfix
.reader
.ui
.GuiReaderMainPanel
.StoryRunnable
;
39 import be
.nikiroo
.utils
.Progress
;
40 import be
.nikiroo
.utils
.Version
;
41 import be
.nikiroo
.utils
.ui
.ConfigEditor
;
44 * A {@link Frame} that will show a {@link GuiReaderBook} item for each
45 * {@link Story} in the main cache ({@link Instance#getCache()}), and offer a
46 * way to copy them to the {@link GuiReader} cache (
47 * {@link BasicReader#getLibrary()}), read them, delete them...
51 class GuiReaderFrame
extends JFrame
implements FrameHelper
{
52 private static final long serialVersionUID
= 1L;
53 private GuiReader reader
;
54 private GuiReaderMainPanel mainPanel
;
57 * The different modification actions you can use on {@link Story} items.
61 private enum ChangeAction
{
62 /** Change the source/type, that is, move it to another source. */
64 /** Change its name. */
66 /** Change its author. */
71 * Create a new {@link GuiReaderFrame}.
74 * the associated {@link GuiReader} to forward some commands and
75 * access its {@link LocalLibrary}
77 * the type of {@link Story} to load, or NULL for all types
79 public GuiReaderFrame(GuiReader reader
, String type
) {
80 super(getAppTitle(reader
.getLibrary().getLibraryName()));
84 mainPanel
= new GuiReaderMainPanel(this, type
);
87 setLayout(new BorderLayout());
88 add(mainPanel
, BorderLayout
.CENTER
);
92 public JPopupMenu
createBookPopup() {
93 JPopupMenu popup
= new JPopupMenu();
94 popup
.add(createMenuItemOpenBook());
96 popup
.add(createMenuItemExport());
97 popup
.add(createMenuItemMoveTo(true));
98 popup
.add(createMenuItemSetCoverForSource());
99 popup
.add(createMenuItemSetCoverForAuthor());
100 popup
.add(createMenuItemClearCache());
101 popup
.add(createMenuItemRedownload());
102 popup
.addSeparator();
103 popup
.add(createMenuItemRename(true));
104 popup
.add(createMenuItemSetAuthor(true));
105 popup
.addSeparator();
106 popup
.add(createMenuItemDelete());
107 popup
.addSeparator();
108 popup
.add(createMenuItemProperties());
113 public JPopupMenu
createSourceAuthorPopup() {
114 JPopupMenu popup
= new JPopupMenu();
115 popup
.add(createMenuItemOpenBook());
120 public void createMenu(boolean libOk
) {
123 JMenuBar bar
= new JMenuBar();
125 JMenu file
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_FILE
));
126 file
.setMnemonic(KeyEvent
.VK_F
);
128 JMenuItem imprt
= new JMenuItem(
129 GuiReader
.trans(StringIdGui
.MENU_FILE_IMPORT_URL
),
131 imprt
.addActionListener(new ActionListener() {
133 public void actionPerformed(ActionEvent e
) {
134 mainPanel
.imprt(true);
137 JMenuItem imprtF
= new JMenuItem(
138 GuiReader
.trans(StringIdGui
.MENU_FILE_IMPORT_FILE
),
140 imprtF
.addActionListener(new ActionListener() {
142 public void actionPerformed(ActionEvent e
) {
143 mainPanel
.imprt(false);
146 JMenuItem exit
= new JMenuItem(
147 GuiReader
.trans(StringIdGui
.MENU_FILE_EXIT
), KeyEvent
.VK_X
);
148 exit
.addActionListener(new ActionListener() {
150 public void actionPerformed(ActionEvent e
) {
151 GuiReaderFrame
.this.dispatchEvent(new WindowEvent(
152 GuiReaderFrame
.this, WindowEvent
.WINDOW_CLOSING
));
156 file
.add(createMenuItemOpenBook());
157 file
.add(createMenuItemExport());
158 file
.add(createMenuItemMoveTo(libOk
));
163 file
.add(createMenuItemRename(libOk
));
164 file
.add(createMenuItemSetAuthor(libOk
));
166 file
.add(createMenuItemProperties());
172 JMenu edit
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_EDIT
));
173 edit
.setMnemonic(KeyEvent
.VK_E
);
175 edit
.add(createMenuItemSetCoverForSource());
176 edit
.add(createMenuItemSetCoverForAuthor());
177 edit
.add(createMenuItemClearCache());
178 edit
.add(createMenuItemRedownload());
180 edit
.add(createMenuItemDelete());
184 JMenu view
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_VIEW
));
185 view
.setMnemonic(KeyEvent
.VK_V
);
186 JMenuItem vauthors
= new JMenuItem(
187 GuiReader
.trans(StringIdGui
.MENU_VIEW_AUTHOR
));
188 vauthors
.setMnemonic(KeyEvent
.VK_A
);
189 vauthors
.addActionListener(new ActionListener() {
191 public void actionPerformed(ActionEvent e
) {
192 mainPanel
.setWords(false);
193 mainPanel
.refreshBooks();
197 JMenuItem vwords
= new JMenuItem(
198 GuiReader
.trans(StringIdGui
.MENU_VIEW_WCOUNT
));
199 vwords
.setMnemonic(KeyEvent
.VK_W
);
200 vwords
.addActionListener(new ActionListener() {
202 public void actionPerformed(ActionEvent e
) {
203 mainPanel
.setWords(true);
204 mainPanel
.refreshBooks();
210 Map
<String
, List
<String
>> groupedSources
= new HashMap
<String
, List
<String
>>();
212 groupedSources
= reader
.getLibrary().getSourcesGrouped();
214 JMenu sources
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_SOURCES
));
215 sources
.setMnemonic(KeyEvent
.VK_S
);
216 populateMenuSA(sources
, groupedSources
, true);
219 Map
<String
, List
<String
>> goupedAuthors
= new HashMap
<String
, List
<String
>>();
221 goupedAuthors
= reader
.getLibrary().getAuthorsGrouped();
223 JMenu authors
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_AUTHORS
));
224 authors
.setMnemonic(KeyEvent
.VK_A
);
225 populateMenuSA(authors
, goupedAuthors
, false);
228 JMenu options
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_OPTIONS
));
229 options
.setMnemonic(KeyEvent
.VK_O
);
230 options
.add(createMenuItemConfig());
231 options
.add(createMenuItemUiConfig());
238 private void populateMenuSA(JMenu menu
,
239 Map
<String
, List
<String
>> groupedValues
, boolean type
) {
241 // "All" and "Listing" special items first
242 JMenuItem item
= new JMenuItem(
243 GuiReader
.trans(StringIdGui
.MENU_XXX_ALL_GROUPED
));
244 item
.addActionListener(getActionOpenList(type
, false));
246 item
= new JMenuItem(GuiReader
.trans(StringIdGui
.MENU_XXX_ALL_LISTING
));
247 item
.addActionListener(getActionOpenList(type
, true));
252 for (final String value
: groupedValues
.keySet()) {
253 List
<String
> list
= groupedValues
.get(value
);
254 if (type
&& list
.size() == 1 && list
.get(0).isEmpty()) {
255 // leaf item source/type
256 item
= new JMenuItem(
257 value
.isEmpty() ? GuiReader
258 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
260 item
.addActionListener(getActionOpen(value
, type
));
264 if (!type
&& groupedValues
.size() == 1) {
265 // only one group of authors
269 value
.isEmpty() ? GuiReader
270 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
274 for (String sub
: list
) {
275 // " " instead of "" for the visual height
276 String itemName
= sub
;
277 if (itemName
.isEmpty()) {
278 itemName
= type ?
" " : GuiReader
279 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
);
282 String actualValue
= value
;
284 if (!sub
.isEmpty()) {
285 actualValue
+= "/" + sub
;
291 item
= new JMenuItem(itemName
);
292 item
.addActionListener(getActionOpen(actualValue
, type
));
304 * Return an {@link ActionListener} that will set the given source (type) as
305 * the selected/displayed one.
308 * the type (source) to select, cannot be NULL
310 * @return the {@link ActionListener}
312 private ActionListener
getActionOpen(final String source
, final boolean type
) {
313 return new ActionListener() {
315 public void actionPerformed(ActionEvent e
) {
316 mainPanel
.removeBookPanes();
317 mainPanel
.addBookPane(source
, type
);
318 mainPanel
.refreshBooks();
323 private ActionListener
getActionOpenList(final boolean type
,
324 final boolean listMode
) {
325 return new ActionListener() {
327 public void actionPerformed(ActionEvent e
) {
328 mainPanel
.removeBookPanes();
329 mainPanel
.addBookPane(type
, listMode
);
330 mainPanel
.refreshBooks();
336 * Create the Fanfix Configuration menu item.
340 private JMenuItem
createMenuItemConfig() {
341 final String title
= GuiReader
.trans(StringIdGui
.TITLE_CONFIG
);
342 JMenuItem item
= new JMenuItem(title
);
343 item
.setMnemonic(KeyEvent
.VK_F
);
345 item
.addActionListener(new ActionListener() {
347 public void actionPerformed(ActionEvent e
) {
348 ConfigEditor
<Config
> ed
= new ConfigEditor
<Config
>(
349 Config
.class, Instance
.getConfig(), GuiReader
350 .trans(StringIdGui
.SUBTITLE_CONFIG
));
351 JFrame frame
= new JFrame(title
);
353 frame
.setSize(800, 600);
354 frame
.setVisible(true);
362 * Create the UI Configuration menu item.
366 private JMenuItem
createMenuItemUiConfig() {
367 final String title
= GuiReader
.trans(StringIdGui
.TITLE_CONFIG_UI
);
368 JMenuItem item
= new JMenuItem(title
);
369 item
.setMnemonic(KeyEvent
.VK_U
);
371 item
.addActionListener(new ActionListener() {
373 public void actionPerformed(ActionEvent e
) {
374 ConfigEditor
<UiConfig
> ed
= new ConfigEditor
<UiConfig
>(
375 UiConfig
.class, Instance
.getUiConfig(), GuiReader
376 .trans(StringIdGui
.SUBTITLE_CONFIG_UI
));
377 JFrame frame
= new JFrame(title
);
379 frame
.setSize(800, 600);
380 frame
.setVisible(true);
388 * Create the export menu item.
392 private JMenuItem
createMenuItemExport() {
393 final JFileChooser fc
= new JFileChooser();
394 fc
.setAcceptAllFileFilterUsed(false);
396 // Add the "ALL" filters first, then the others
397 final Map
<FileFilter
, OutputType
> otherFilters
= new HashMap
<FileFilter
, OutputType
>();
398 for (OutputType type
: OutputType
.values()) {
399 String ext
= type
.getDefaultExtension(false);
400 String desc
= type
.getDesc(false);
402 if (ext
== null || ext
.isEmpty()) {
403 fc
.addChoosableFileFilter(createAllFilter(desc
));
405 otherFilters
.put(new FileNameExtensionFilter(desc
, ext
), type
);
409 for (Entry
<FileFilter
, OutputType
> entry
: otherFilters
.entrySet()) {
410 fc
.addChoosableFileFilter(entry
.getKey());
414 JMenuItem export
= new JMenuItem(
415 GuiReader
.trans(StringIdGui
.MENU_FILE_EXPORT
), KeyEvent
.VK_S
);
416 export
.addActionListener(new ActionListener() {
418 public void actionPerformed(ActionEvent e
) {
419 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
420 if (selectedBook
!= null) {
421 fc
.showDialog(GuiReaderFrame
.this,
422 GuiReader
.trans(StringIdGui
.TITLE_SAVE
));
423 if (fc
.getSelectedFile() != null) {
424 final OutputType type
= otherFilters
.get(fc
.getFileFilter());
425 final String path
= fc
.getSelectedFile()
427 + type
.getDefaultExtension(false);
428 final Progress pg
= new Progress();
429 mainPanel
.outOfUi(pg
, false, new Runnable() {
433 reader
.getLibrary().export(
434 selectedBook
.getInfo().getMeta()
435 .getLuid(), type
, path
, pg
);
436 } catch (IOException e
) {
437 Instance
.getTraceHandler().error(e
);
450 * Create a {@link FileFilter} that accepts all files and return the given
458 private FileFilter
createAllFilter(final String desc
) {
459 return new FileFilter() {
461 public String
getDescription() {
466 public boolean accept(File f
) {
473 * Create the refresh (delete cache) menu item.
477 private JMenuItem
createMenuItemClearCache() {
478 JMenuItem refresh
= new JMenuItem(
479 GuiReader
.trans(StringIdGui
.MENU_EDIT_CLEAR_CACHE
),
481 refresh
.addActionListener(new ActionListener() {
483 public void actionPerformed(ActionEvent e
) {
484 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
485 if (selectedBook
!= null) {
486 mainPanel
.outOfUi(null, false, new Runnable() {
489 reader
.clearLocalReaderCache(selectedBook
.getInfo()
490 .getMeta().getLuid());
491 selectedBook
.setCached(false);
492 GuiReaderCoverImager
.clearIcon(selectedBook
494 SwingUtilities
.invokeLater(new Runnable() {
497 selectedBook
.repaint();
510 * Create the "move to" menu item.
513 * the library can be queried
517 private JMenuItem
createMenuItemMoveTo(boolean libOk
) {
518 JMenu changeTo
= new JMenu(
519 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO
));
520 changeTo
.setMnemonic(KeyEvent
.VK_M
);
522 Map
<String
, List
<String
>> groupedSources
= new HashMap
<String
, List
<String
>>();
524 groupedSources
= reader
.getLibrary().getSourcesGrouped();
527 JMenuItem item
= new JMenuItem(
528 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO_NEW_TYPE
));
529 item
.addActionListener(createMoveAction(ChangeAction
.SOURCE
, null));
531 changeTo
.addSeparator();
533 for (final String type
: groupedSources
.keySet()) {
534 List
<String
> list
= groupedSources
.get(type
);
535 if (list
.size() == 1 && list
.get(0).isEmpty()) {
536 item
= new JMenuItem(type
);
537 item
.addActionListener(createMoveAction(ChangeAction
.SOURCE
,
541 JMenu dir
= new JMenu(type
);
542 for (String sub
: list
) {
543 // " " instead of "" for the visual height
544 String itemName
= sub
.isEmpty() ?
" " : sub
;
545 String actualType
= type
;
546 if (!sub
.isEmpty()) {
547 actualType
+= "/" + sub
;
550 item
= new JMenuItem(itemName
);
551 item
.addActionListener(createMoveAction(
552 ChangeAction
.SOURCE
, actualType
));
563 * Create the "set author" menu item.
566 * the library can be queried
570 private JMenuItem
createMenuItemSetAuthor(boolean libOk
) {
571 JMenu changeTo
= new JMenu(
572 GuiReader
.trans(StringIdGui
.MENU_FILE_SET_AUTHOR
));
573 changeTo
.setMnemonic(KeyEvent
.VK_A
);
576 JMenuItem newItem
= new JMenuItem(
577 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO_NEW_AUTHOR
));
578 changeTo
.add(newItem
);
579 changeTo
.addSeparator();
580 newItem
.addActionListener(createMoveAction(ChangeAction
.AUTHOR
, null));
584 Map
<String
, List
<String
>> groupedAuthors
= reader
.getLibrary()
585 .getAuthorsGrouped();
587 if (groupedAuthors
.size() > 1) {
588 for (String key
: groupedAuthors
.keySet()) {
589 JMenu group
= new JMenu(key
);
590 for (String value
: groupedAuthors
.get(key
)) {
591 JMenuItem item
= new JMenuItem(
592 value
.isEmpty() ? GuiReader
593 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
595 item
.addActionListener(createMoveAction(
596 ChangeAction
.AUTHOR
, value
));
601 } else if (groupedAuthors
.size() == 1) {
602 for (String value
: groupedAuthors
.values().iterator().next()) {
603 JMenuItem item
= new JMenuItem(
604 value
.isEmpty() ? GuiReader
605 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
607 item
.addActionListener(createMoveAction(
608 ChangeAction
.AUTHOR
, value
));
618 * Create the "rename" menu item.
621 * the library can be queried
625 private JMenuItem
createMenuItemRename(
626 @SuppressWarnings("unused") boolean libOk
) {
627 JMenuItem changeTo
= new JMenuItem(
628 GuiReader
.trans(StringIdGui
.MENU_FILE_RENAME
));
629 changeTo
.setMnemonic(KeyEvent
.VK_R
);
630 changeTo
.addActionListener(createMoveAction(ChangeAction
.TITLE
, null));
634 private ActionListener
createMoveAction(final ChangeAction what
,
636 return new ActionListener() {
638 public void actionPerformed(ActionEvent e
) {
639 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
640 if (selectedBook
!= null) {
641 boolean refreshRequired
= false;
643 if (what
== ChangeAction
.SOURCE
) {
644 refreshRequired
= mainPanel
.getCurrentType();
645 } else if (what
== ChangeAction
.TITLE
) {
646 refreshRequired
= false;
647 } else if (what
== ChangeAction
.AUTHOR
) {
648 refreshRequired
= !mainPanel
.getCurrentType();
651 String changeTo
= type
;
653 MetaData meta
= selectedBook
.getInfo().getMeta();
655 if (what
== ChangeAction
.SOURCE
) {
656 init
= meta
.getSource();
657 } else if (what
== ChangeAction
.TITLE
) {
658 init
= meta
.getTitle();
659 } else if (what
== ChangeAction
.AUTHOR
) {
660 init
= meta
.getAuthor();
663 Object rep
= JOptionPane
.showInputDialog(
665 GuiReader
.trans(StringIdGui
.SUBTITLE_MOVE_TO
),
666 GuiReader
.trans(StringIdGui
.TITLE_MOVE_TO
),
667 JOptionPane
.QUESTION_MESSAGE
, null, null, init
);
673 changeTo
= rep
.toString();
676 final String fChangeTo
= changeTo
;
677 mainPanel
.outOfUi(null, refreshRequired
, new Runnable() {
680 String luid
= selectedBook
.getInfo().getMeta()
682 if (what
== ChangeAction
.SOURCE
) {
683 reader
.changeSource(luid
, fChangeTo
);
684 } else if (what
== ChangeAction
.TITLE
) {
685 reader
.changeTitle(luid
, fChangeTo
);
686 } else if (what
== ChangeAction
.AUTHOR
) {
687 reader
.changeAuthor(luid
, fChangeTo
);
690 mainPanel
.getSelectedBook().repaint();
691 mainPanel
.unsetSelectedBook();
693 SwingUtilities
.invokeLater(new Runnable() {
707 * Create the re-download (then delete original) menu item.
711 private JMenuItem
createMenuItemRedownload() {
712 JMenuItem refresh
= new JMenuItem(
713 GuiReader
.trans(StringIdGui
.MENU_EDIT_REDOWNLOAD
),
715 refresh
.addActionListener(new ActionListener() {
717 public void actionPerformed(ActionEvent e
) {
718 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
719 if (selectedBook
!= null) {
720 final MetaData meta
= selectedBook
.getInfo().getMeta();
723 new StoryRunnable() {
725 public void run(Story story
) {
726 MetaData newMeta
= story
.getMeta();
727 if (!newMeta
.getSource().equals(
729 reader
.changeSource(newMeta
.getLuid(),
735 .trans(StringIdGui
.PROGRESS_CHANGE_SOURCE
));
744 * Create the delete menu item.
748 private JMenuItem
createMenuItemDelete() {
749 JMenuItem delete
= new JMenuItem(
750 GuiReader
.trans(StringIdGui
.MENU_EDIT_DELETE
), KeyEvent
.VK_D
);
751 delete
.addActionListener(new ActionListener() {
753 public void actionPerformed(ActionEvent e
) {
754 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
755 if (selectedBook
!= null
756 && selectedBook
.getInfo().getMeta() != null) {
758 final MetaData meta
= selectedBook
.getInfo().getMeta();
759 int rep
= JOptionPane
.showConfirmDialog(
761 GuiReader
.trans(StringIdGui
.SUBTITLE_DELETE
,
762 meta
.getLuid(), meta
.getTitle()),
763 GuiReader
.trans(StringIdGui
.TITLE_DELETE
),
764 JOptionPane
.OK_CANCEL_OPTION
);
766 if (rep
== JOptionPane
.OK_OPTION
) {
767 mainPanel
.outOfUi(null, true, new Runnable() {
770 reader
.delete(meta
.getLuid());
771 mainPanel
.unsetSelectedBook();
783 * Create the properties menu item.
787 private JMenuItem
createMenuItemProperties() {
788 JMenuItem delete
= new JMenuItem(
789 GuiReader
.trans(StringIdGui
.MENU_FILE_PROPERTIES
),
791 delete
.addActionListener(new ActionListener() {
793 public void actionPerformed(ActionEvent e
) {
794 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
795 if (selectedBook
!= null) {
796 mainPanel
.outOfUi(null, false, new Runnable() {
799 new GuiReaderPropertiesFrame(reader
.getLibrary(),
800 selectedBook
.getInfo().getMeta())
812 * Create the open menu item for a book, a source/type or an author.
816 public JMenuItem
createMenuItemOpenBook() {
817 JMenuItem open
= new JMenuItem(
818 GuiReader
.trans(StringIdGui
.MENU_FILE_OPEN
), KeyEvent
.VK_O
);
819 open
.addActionListener(new ActionListener() {
821 public void actionPerformed(ActionEvent e
) {
822 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
823 if (selectedBook
!= null) {
824 if (selectedBook
.getInfo().getMeta() == null) {
825 mainPanel
.removeBookPanes();
826 mainPanel
.addBookPane(selectedBook
.getInfo()
827 .getMainInfo(), mainPanel
.getCurrentType());
828 mainPanel
.refreshBooks();
830 mainPanel
.openBook(selectedBook
);
840 * Create the SetCover menu item for a book to change the linked source
845 private JMenuItem
createMenuItemSetCoverForSource() {
846 JMenuItem open
= new JMenuItem(
847 GuiReader
.trans(StringIdGui
.MENU_EDIT_SET_COVER_FOR_SOURCE
),
849 open
.addActionListener(new ActionListener() {
851 public void actionPerformed(ActionEvent e
) {
852 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
853 if (selectedBook
!= null) {
854 BasicLibrary lib
= reader
.getLibrary();
855 String luid
= selectedBook
.getInfo().getMeta().getLuid();
856 String source
= selectedBook
.getInfo().getMeta()
859 lib
.setSourceCover(source
, luid
);
861 GuiReaderBookInfo sourceInfo
= GuiReaderBookInfo
862 .fromSource(lib
, source
);
863 GuiReaderCoverImager
.clearIcon(sourceInfo
);
872 * Create the SetCover menu item for a book to change the linked source
877 private JMenuItem
createMenuItemSetCoverForAuthor() {
878 JMenuItem open
= new JMenuItem(
879 GuiReader
.trans(StringIdGui
.MENU_EDIT_SET_COVER_FOR_AUTHOR
),
881 open
.addActionListener(new ActionListener() {
883 public void actionPerformed(ActionEvent e
) {
884 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
885 if (selectedBook
!= null) {
886 BasicLibrary lib
= reader
.getLibrary();
887 String luid
= selectedBook
.getInfo().getMeta().getLuid();
888 String author
= selectedBook
.getInfo().getMeta()
891 lib
.setAuthorCover(author
, luid
);
893 GuiReaderBookInfo authorInfo
= GuiReaderBookInfo
894 .fromAuthor(lib
, author
);
895 GuiReaderCoverImager
.clearIcon(authorInfo
);
904 * Display an error message and log the linked {@link Exception}.
909 * the title of the error message
911 * the exception to log if any
913 public void error(final String message
, final String title
, Exception e
) {
914 Instance
.getTraceHandler().error(title
+ ": " + message
);
916 Instance
.getTraceHandler().error(e
);
919 SwingUtilities
.invokeLater(new Runnable() {
922 JOptionPane
.showMessageDialog(GuiReaderFrame
.this, message
,
923 title
, JOptionPane
.ERROR_MESSAGE
);
929 public GuiReader
getReader() {
934 * Return the title of the application.
937 * the name of the associated {@link BasicLibrary}, which can be
942 static private String
getAppTitle(String libraryName
) {
943 if (!libraryName
.isEmpty()) {
944 return GuiReader
.trans(StringIdGui
.TITLE_LIBRARY_WITH_NAME
, Version
945 .getCurrentVersion().toString(), libraryName
);
948 return GuiReader
.trans(StringIdGui
.TITLE_LIBRARY
, Version
949 .getCurrentVersion().toString());