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
426 final String path
= fc
.getSelectedFile()
428 + type
.getDefaultExtension(false);
429 final Progress pg
= new Progress();
430 mainPanel
.outOfUi(pg
, false, new Runnable() {
434 reader
.getLibrary().export(
435 selectedBook
.getInfo().getMeta()
436 .getLuid(), type
, path
, pg
);
437 } catch (IOException e
) {
438 Instance
.getTraceHandler().error(e
);
451 * Create a {@link FileFilter} that accepts all files and return the given
459 private FileFilter
createAllFilter(final String desc
) {
460 return new FileFilter() {
462 public String
getDescription() {
467 public boolean accept(File f
) {
474 * Create the refresh (delete cache) menu item.
478 private JMenuItem
createMenuItemClearCache() {
479 JMenuItem refresh
= new JMenuItem(
480 GuiReader
.trans(StringIdGui
.MENU_EDIT_CLEAR_CACHE
),
482 refresh
.addActionListener(new ActionListener() {
484 public void actionPerformed(ActionEvent e
) {
488 "Delete the disk cache?\n(This operation can be very long!)",
489 "Cache", JOptionPane
.YES_NO_OPTION
) == JOptionPane
.YES_OPTION
) {
491 Instance
.PATCH_emptyCache();
492 } catch (Exception err
) {
493 Instance
.getTraceHandler().error(err
);
497 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
498 if (selectedBook
!= null) {
499 mainPanel
.outOfUi(null, false, new Runnable() {
502 GuiReaderBookInfo info
= selectedBook
.getInfo();
504 MetaData meta
= info
.getMeta();
506 reader
.clearLocalReaderCache(meta
.getLuid());
507 selectedBook
.setCached(false);
508 GuiReaderCoverImager
.clearIcon(selectedBook
510 SwingUtilities
.invokeLater(new Runnable() {
513 selectedBook
.repaint();
528 * Create the "move to" menu item.
531 * the library can be queried
535 private JMenuItem
createMenuItemMoveTo(boolean libOk
) {
536 JMenu changeTo
= new JMenu(
537 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO
));
538 changeTo
.setMnemonic(KeyEvent
.VK_M
);
540 Map
<String
, List
<String
>> groupedSources
= new HashMap
<String
, List
<String
>>();
542 groupedSources
= reader
.getLibrary().getSourcesGrouped();
545 JMenuItem item
= new JMenuItem(
546 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO_NEW_TYPE
));
547 item
.addActionListener(createMoveAction(ChangeAction
.SOURCE
, null));
549 changeTo
.addSeparator();
551 for (final String type
: groupedSources
.keySet()) {
552 List
<String
> list
= groupedSources
.get(type
);
553 if (list
.size() == 1 && list
.get(0).isEmpty()) {
554 item
= new JMenuItem(type
);
555 item
.addActionListener(createMoveAction(ChangeAction
.SOURCE
,
559 JMenu dir
= new JMenu(type
);
560 for (String sub
: list
) {
561 // " " instead of "" for the visual height
562 String itemName
= sub
.isEmpty() ?
" " : sub
;
563 String actualType
= type
;
564 if (!sub
.isEmpty()) {
565 actualType
+= "/" + sub
;
568 item
= new JMenuItem(itemName
);
569 item
.addActionListener(createMoveAction(
570 ChangeAction
.SOURCE
, actualType
));
581 * Create the "set author" menu item.
584 * the library can be queried
588 private JMenuItem
createMenuItemSetAuthor(boolean libOk
) {
589 JMenu changeTo
= new JMenu(
590 GuiReader
.trans(StringIdGui
.MENU_FILE_SET_AUTHOR
));
591 changeTo
.setMnemonic(KeyEvent
.VK_A
);
594 JMenuItem newItem
= new JMenuItem(
595 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO_NEW_AUTHOR
));
596 changeTo
.add(newItem
);
597 changeTo
.addSeparator();
598 newItem
.addActionListener(createMoveAction(ChangeAction
.AUTHOR
, null));
602 Map
<String
, List
<String
>> groupedAuthors
= reader
.getLibrary()
603 .getAuthorsGrouped();
605 if (groupedAuthors
.size() > 1) {
606 for (String key
: groupedAuthors
.keySet()) {
607 JMenu group
= new JMenu(key
);
608 for (String value
: groupedAuthors
.get(key
)) {
609 JMenuItem item
= new JMenuItem(
610 value
.isEmpty() ? GuiReader
611 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
613 item
.addActionListener(createMoveAction(
614 ChangeAction
.AUTHOR
, value
));
619 } else if (groupedAuthors
.size() == 1) {
620 for (String value
: groupedAuthors
.values().iterator().next()) {
621 JMenuItem item
= new JMenuItem(
622 value
.isEmpty() ? GuiReader
623 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
625 item
.addActionListener(createMoveAction(
626 ChangeAction
.AUTHOR
, value
));
636 * Create the "rename" menu item.
639 * the library can be queried
643 private JMenuItem
createMenuItemRename(
644 @SuppressWarnings("unused") boolean libOk
) {
645 JMenuItem changeTo
= new JMenuItem(
646 GuiReader
.trans(StringIdGui
.MENU_FILE_RENAME
));
647 changeTo
.setMnemonic(KeyEvent
.VK_R
);
648 changeTo
.addActionListener(createMoveAction(ChangeAction
.TITLE
, null));
652 private ActionListener
createMoveAction(final ChangeAction what
,
654 return new ActionListener() {
656 public void actionPerformed(ActionEvent e
) {
657 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
658 if (selectedBook
!= null) {
659 boolean refreshRequired
= false;
661 if (what
== ChangeAction
.SOURCE
) {
662 refreshRequired
= mainPanel
.getCurrentType();
663 } else if (what
== ChangeAction
.TITLE
) {
664 refreshRequired
= false;
665 } else if (what
== ChangeAction
.AUTHOR
) {
666 refreshRequired
= !mainPanel
.getCurrentType();
669 String changeTo
= type
;
671 MetaData meta
= selectedBook
.getInfo().getMeta();
673 if (what
== ChangeAction
.SOURCE
) {
674 init
= meta
.getSource();
675 } else if (what
== ChangeAction
.TITLE
) {
676 init
= meta
.getTitle();
677 } else if (what
== ChangeAction
.AUTHOR
) {
678 init
= meta
.getAuthor();
681 Object rep
= JOptionPane
.showInputDialog(
683 GuiReader
.trans(StringIdGui
.SUBTITLE_MOVE_TO
),
684 GuiReader
.trans(StringIdGui
.TITLE_MOVE_TO
),
685 JOptionPane
.QUESTION_MESSAGE
, null, null, init
);
691 changeTo
= rep
.toString();
694 final String fChangeTo
= changeTo
;
695 mainPanel
.outOfUi(null, refreshRequired
, new Runnable() {
698 String luid
= selectedBook
.getInfo().getMeta()
700 if (what
== ChangeAction
.SOURCE
) {
701 reader
.changeSource(luid
, fChangeTo
);
702 } else if (what
== ChangeAction
.TITLE
) {
703 reader
.changeTitle(luid
, fChangeTo
);
704 } else if (what
== ChangeAction
.AUTHOR
) {
705 reader
.changeAuthor(luid
, fChangeTo
);
708 mainPanel
.getSelectedBook().repaint();
709 mainPanel
.unsetSelectedBook();
711 SwingUtilities
.invokeLater(new Runnable() {
725 * Create the re-download (then delete original) menu item.
729 private JMenuItem
createMenuItemRedownload() {
730 JMenuItem refresh
= new JMenuItem(
731 GuiReader
.trans(StringIdGui
.MENU_EDIT_REDOWNLOAD
),
733 refresh
.addActionListener(new ActionListener() {
735 public void actionPerformed(ActionEvent e
) {
736 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
737 if (selectedBook
!= null) {
738 final MetaData meta
= selectedBook
.getInfo().getMeta();
739 mainPanel
.imprt(meta
.getUrl(), new StoryRunnable() {
741 public void run(Story story
) {
742 MetaData newMeta
= story
.getMeta();
743 if (!newMeta
.getSource().equals(meta
.getSource())) {
744 reader
.changeSource(newMeta
.getLuid(),
748 }, GuiReader
.trans(StringIdGui
.PROGRESS_CHANGE_SOURCE
));
757 * Create the delete menu item.
761 private JMenuItem
createMenuItemDelete() {
762 JMenuItem delete
= new JMenuItem(
763 GuiReader
.trans(StringIdGui
.MENU_EDIT_DELETE
), KeyEvent
.VK_D
);
764 delete
.addActionListener(new ActionListener() {
766 public void actionPerformed(ActionEvent e
) {
767 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
768 if (selectedBook
!= null
769 && selectedBook
.getInfo().getMeta() != null) {
771 final MetaData meta
= selectedBook
.getInfo().getMeta();
772 int rep
= JOptionPane
.showConfirmDialog(
774 GuiReader
.trans(StringIdGui
.SUBTITLE_DELETE
,
775 meta
.getLuid(), meta
.getTitle()),
776 GuiReader
.trans(StringIdGui
.TITLE_DELETE
),
777 JOptionPane
.OK_CANCEL_OPTION
);
779 if (rep
== JOptionPane
.OK_OPTION
) {
780 mainPanel
.outOfUi(null, true, new Runnable() {
783 reader
.delete(meta
.getLuid());
784 mainPanel
.unsetSelectedBook();
796 * Create the properties menu item.
800 private JMenuItem
createMenuItemProperties() {
801 JMenuItem delete
= new JMenuItem(
802 GuiReader
.trans(StringIdGui
.MENU_FILE_PROPERTIES
),
804 delete
.addActionListener(new ActionListener() {
806 public void actionPerformed(ActionEvent e
) {
807 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
808 if (selectedBook
!= null) {
809 mainPanel
.outOfUi(null, false, new Runnable() {
812 new GuiReaderPropertiesFrame(reader
.getLibrary(),
813 selectedBook
.getInfo().getMeta())
825 * Create the open menu item for a book, a source/type or an author.
829 public JMenuItem
createMenuItemOpenBook() {
830 JMenuItem open
= new JMenuItem(
831 GuiReader
.trans(StringIdGui
.MENU_FILE_OPEN
), KeyEvent
.VK_O
);
832 open
.addActionListener(new ActionListener() {
834 public void actionPerformed(ActionEvent e
) {
835 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
836 if (selectedBook
!= null) {
837 if (selectedBook
.getInfo().getMeta() == null) {
838 mainPanel
.removeBookPanes();
839 mainPanel
.addBookPane(selectedBook
.getInfo()
840 .getMainInfo(), mainPanel
.getCurrentType());
841 mainPanel
.refreshBooks();
843 mainPanel
.openBook(selectedBook
);
853 * Create the SetCover menu item for a book to change the linked source
858 private JMenuItem
createMenuItemSetCoverForSource() {
859 JMenuItem open
= new JMenuItem(
860 GuiReader
.trans(StringIdGui
.MENU_EDIT_SET_COVER_FOR_SOURCE
),
862 open
.addActionListener(new ActionListener() {
864 public void actionPerformed(ActionEvent e
) {
865 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
866 if (selectedBook
!= null) {
867 BasicLibrary lib
= reader
.getLibrary();
868 String luid
= selectedBook
.getInfo().getMeta().getLuid();
869 String source
= selectedBook
.getInfo().getMeta()
872 lib
.setSourceCover(source
, luid
);
874 GuiReaderBookInfo sourceInfo
= GuiReaderBookInfo
875 .fromSource(lib
, source
);
876 GuiReaderCoverImager
.clearIcon(sourceInfo
);
885 * Create the SetCover menu item for a book to change the linked source
890 private JMenuItem
createMenuItemSetCoverForAuthor() {
891 JMenuItem open
= new JMenuItem(
892 GuiReader
.trans(StringIdGui
.MENU_EDIT_SET_COVER_FOR_AUTHOR
),
894 open
.addActionListener(new ActionListener() {
896 public void actionPerformed(ActionEvent e
) {
897 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
898 if (selectedBook
!= null) {
899 BasicLibrary lib
= reader
.getLibrary();
900 String luid
= selectedBook
.getInfo().getMeta().getLuid();
901 String author
= selectedBook
.getInfo().getMeta()
904 lib
.setAuthorCover(author
, luid
);
906 GuiReaderBookInfo authorInfo
= GuiReaderBookInfo
907 .fromAuthor(lib
, author
);
908 GuiReaderCoverImager
.clearIcon(authorInfo
);
917 * Display an error message and log the linked {@link Exception}.
922 * the title of the error message
924 * the exception to log if any
926 public void error(final String message
, final String title
, Exception e
) {
927 Instance
.getTraceHandler().error(title
+ ": " + message
);
929 Instance
.getTraceHandler().error(e
);
932 SwingUtilities
.invokeLater(new Runnable() {
935 JOptionPane
.showMessageDialog(GuiReaderFrame
.this, message
,
936 title
, JOptionPane
.ERROR_MESSAGE
);
942 public GuiReader
getReader() {
947 * Return the title of the application.
950 * the name of the associated {@link BasicLibrary}, which can be
955 static private String
getAppTitle(String libraryName
) {
956 if (!libraryName
.isEmpty()) {
957 return GuiReader
.trans(StringIdGui
.TITLE_LIBRARY_WITH_NAME
, Version
958 .getCurrentVersion().toString(), libraryName
);
961 return GuiReader
.trans(StringIdGui
.TITLE_LIBRARY
, Version
962 .getCurrentVersion().toString());