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
.fanfix
.searchable
.BasicSearchable
;
40 import be
.nikiroo
.fanfix
.supported
.SupportType
;
41 import be
.nikiroo
.utils
.Progress
;
42 import be
.nikiroo
.utils
.Version
;
43 import be
.nikiroo
.utils
.ui
.ConfigEditor
;
46 * A {@link Frame} that will show a {@link GuiReaderBook} item for each
47 * {@link Story} in the main cache ({@link Instance#getCache()}), and offer a
48 * way to copy them to the {@link GuiReader} cache (
49 * {@link BasicReader#getLibrary()}), read them, delete them...
53 class GuiReaderFrame
extends JFrame
implements FrameHelper
{
54 private static final long serialVersionUID
= 1L;
55 private GuiReader reader
;
56 private GuiReaderMainPanel mainPanel
;
59 * The different modification actions you can use on {@link Story} items.
63 private enum ChangeAction
{
64 /** Change the source/type, that is, move it to another source. */
66 /** Change its name. */
68 /** Change its author. */
73 * Create a new {@link GuiReaderFrame}.
76 * the associated {@link GuiReader} to forward some commands and
77 * access its {@link LocalLibrary}
79 * the type of {@link Story} to load, or NULL for all types
81 public GuiReaderFrame(GuiReader reader
, String type
) {
82 super(getAppTitle(reader
.getLibrary().getLibraryName()));
86 mainPanel
= new GuiReaderMainPanel(this, type
);
89 setLayout(new BorderLayout());
90 add(mainPanel
, BorderLayout
.CENTER
);
94 public JPopupMenu
createBookPopup() {
95 JPopupMenu popup
= new JPopupMenu();
96 popup
.add(createMenuItemOpenBook());
98 popup
.add(createMenuItemExport());
99 popup
.add(createMenuItemMoveTo(true));
100 popup
.add(createMenuItemSetCoverForSource());
101 popup
.add(createMenuItemSetCoverForAuthor());
102 popup
.add(createMenuItemClearCache());
103 popup
.add(createMenuItemRedownload());
104 popup
.addSeparator();
105 popup
.add(createMenuItemRename(true));
106 popup
.add(createMenuItemSetAuthor(true));
107 popup
.addSeparator();
108 popup
.add(createMenuItemDelete());
109 popup
.addSeparator();
110 popup
.add(createMenuItemProperties());
115 public JPopupMenu
createSourceAuthorPopup() {
116 JPopupMenu popup
= new JPopupMenu();
117 popup
.add(createMenuItemOpenBook());
122 public void createMenu(boolean libOk
) {
125 JMenuBar bar
= new JMenuBar();
127 JMenu file
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_FILE
));
128 file
.setMnemonic(KeyEvent
.VK_F
);
130 JMenuItem imprt
= new JMenuItem(
131 GuiReader
.trans(StringIdGui
.MENU_FILE_IMPORT_URL
),
133 imprt
.addActionListener(new ActionListener() {
135 public void actionPerformed(ActionEvent e
) {
136 mainPanel
.imprt(true);
139 JMenuItem imprtF
= new JMenuItem(
140 GuiReader
.trans(StringIdGui
.MENU_FILE_IMPORT_FILE
),
142 imprtF
.addActionListener(new ActionListener() {
144 public void actionPerformed(ActionEvent e
) {
145 mainPanel
.imprt(false);
148 JMenuItem exit
= new JMenuItem(
149 GuiReader
.trans(StringIdGui
.MENU_FILE_EXIT
), KeyEvent
.VK_X
);
150 exit
.addActionListener(new ActionListener() {
152 public void actionPerformed(ActionEvent e
) {
153 GuiReaderFrame
.this.dispatchEvent(new WindowEvent(
154 GuiReaderFrame
.this, WindowEvent
.WINDOW_CLOSING
));
158 file
.add(createMenuItemOpenBook());
159 file
.add(createMenuItemExport());
160 file
.add(createMenuItemMoveTo(libOk
));
165 file
.add(createMenuItemRename(libOk
));
166 file
.add(createMenuItemSetAuthor(libOk
));
168 file
.add(createMenuItemProperties());
174 JMenu edit
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_EDIT
));
175 edit
.setMnemonic(KeyEvent
.VK_E
);
177 edit
.add(createMenuItemSetCoverForSource());
178 edit
.add(createMenuItemSetCoverForAuthor());
179 edit
.add(createMenuItemClearCache());
180 edit
.add(createMenuItemRedownload());
182 edit
.add(createMenuItemDelete());
186 JMenu search
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_SEARCH
));
187 search
.setMnemonic(KeyEvent
.VK_H
);
188 for (SupportType type
: SupportType
.values()) {
189 BasicSearchable searchable
= BasicSearchable
.getSearchable(type
);
190 if (searchable
!= null) {
191 JMenuItem searchItem
= new JMenuItem(type
.getSourceName());
192 searchItem
.addActionListener(new ActionListener() {
194 public void actionPerformed(ActionEvent e
) {
195 // TODO: open a search window
198 search
.add(searchItem
);
202 // TODO: enable when ready
207 JMenu view
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_VIEW
));
208 view
.setMnemonic(KeyEvent
.VK_V
);
209 JMenuItem vauthors
= new JMenuItem(
210 GuiReader
.trans(StringIdGui
.MENU_VIEW_AUTHOR
));
211 vauthors
.setMnemonic(KeyEvent
.VK_A
);
212 vauthors
.addActionListener(new ActionListener() {
214 public void actionPerformed(ActionEvent e
) {
215 mainPanel
.setWords(false);
216 mainPanel
.refreshBooks();
220 JMenuItem vwords
= new JMenuItem(
221 GuiReader
.trans(StringIdGui
.MENU_VIEW_WCOUNT
));
222 vwords
.setMnemonic(KeyEvent
.VK_W
);
223 vwords
.addActionListener(new ActionListener() {
225 public void actionPerformed(ActionEvent e
) {
226 mainPanel
.setWords(true);
227 mainPanel
.refreshBooks();
233 Map
<String
, List
<String
>> groupedSources
= new HashMap
<String
, List
<String
>>();
235 groupedSources
= reader
.getLibrary().getSourcesGrouped();
237 JMenu sources
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_SOURCES
));
238 sources
.setMnemonic(KeyEvent
.VK_S
);
239 populateMenuSA(sources
, groupedSources
, true);
242 Map
<String
, List
<String
>> goupedAuthors
= new HashMap
<String
, List
<String
>>();
244 goupedAuthors
= reader
.getLibrary().getAuthorsGrouped();
246 JMenu authors
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_AUTHORS
));
247 authors
.setMnemonic(KeyEvent
.VK_A
);
248 populateMenuSA(authors
, goupedAuthors
, false);
251 JMenu options
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_OPTIONS
));
252 options
.setMnemonic(KeyEvent
.VK_O
);
253 options
.add(createMenuItemConfig());
254 options
.add(createMenuItemUiConfig());
261 private void populateMenuSA(JMenu menu
,
262 Map
<String
, List
<String
>> groupedValues
, boolean type
) {
264 // "All" and "Listing" special items first
265 JMenuItem item
= new JMenuItem(
266 GuiReader
.trans(StringIdGui
.MENU_XXX_ALL_GROUPED
));
267 item
.addActionListener(getActionOpenList(type
, false));
269 item
= new JMenuItem(GuiReader
.trans(StringIdGui
.MENU_XXX_ALL_LISTING
));
270 item
.addActionListener(getActionOpenList(type
, true));
275 for (final String value
: groupedValues
.keySet()) {
276 List
<String
> list
= groupedValues
.get(value
);
277 if (type
&& list
.size() == 1 && list
.get(0).isEmpty()) {
278 // leaf item source/type
279 item
= new JMenuItem(
280 value
.isEmpty() ? GuiReader
281 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
283 item
.addActionListener(getActionOpen(value
, type
));
287 if (!type
&& groupedValues
.size() == 1) {
288 // only one group of authors
292 value
.isEmpty() ? GuiReader
293 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
297 for (String sub
: list
) {
298 // " " instead of "" for the visual height
299 String itemName
= sub
;
300 if (itemName
.isEmpty()) {
301 itemName
= type ?
" " : GuiReader
302 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
);
305 String actualValue
= value
;
307 if (!sub
.isEmpty()) {
308 actualValue
+= "/" + sub
;
314 item
= new JMenuItem(itemName
);
315 item
.addActionListener(getActionOpen(actualValue
, type
));
327 * Return an {@link ActionListener} that will set the given source (type) as
328 * the selected/displayed one.
331 * the type (source) to select, cannot be NULL
333 * @return the {@link ActionListener}
335 private ActionListener
getActionOpen(final String source
, final boolean type
) {
336 return new ActionListener() {
338 public void actionPerformed(ActionEvent e
) {
339 mainPanel
.removeBookPanes();
340 mainPanel
.addBookPane(source
, type
);
341 mainPanel
.refreshBooks();
346 private ActionListener
getActionOpenList(final boolean type
,
347 final boolean listMode
) {
348 return new ActionListener() {
350 public void actionPerformed(ActionEvent e
) {
351 mainPanel
.removeBookPanes();
352 mainPanel
.addBookPane(type
, listMode
);
353 mainPanel
.refreshBooks();
359 * Create the Fanfix Configuration menu item.
363 private JMenuItem
createMenuItemConfig() {
364 final String title
= GuiReader
.trans(StringIdGui
.TITLE_CONFIG
);
365 JMenuItem item
= new JMenuItem(title
);
366 item
.setMnemonic(KeyEvent
.VK_F
);
368 item
.addActionListener(new ActionListener() {
370 public void actionPerformed(ActionEvent e
) {
371 ConfigEditor
<Config
> ed
= new ConfigEditor
<Config
>(
372 Config
.class, Instance
.getConfig(), GuiReader
373 .trans(StringIdGui
.SUBTITLE_CONFIG
));
374 JFrame frame
= new JFrame(title
);
376 frame
.setSize(800, 600);
377 frame
.setVisible(true);
385 * Create the UI Configuration menu item.
389 private JMenuItem
createMenuItemUiConfig() {
390 final String title
= GuiReader
.trans(StringIdGui
.TITLE_CONFIG_UI
);
391 JMenuItem item
= new JMenuItem(title
);
392 item
.setMnemonic(KeyEvent
.VK_U
);
394 item
.addActionListener(new ActionListener() {
396 public void actionPerformed(ActionEvent e
) {
397 ConfigEditor
<UiConfig
> ed
= new ConfigEditor
<UiConfig
>(
398 UiConfig
.class, Instance
.getUiConfig(), GuiReader
399 .trans(StringIdGui
.SUBTITLE_CONFIG_UI
));
400 JFrame frame
= new JFrame(title
);
402 frame
.setSize(800, 600);
403 frame
.setVisible(true);
411 * Create the export menu item.
415 private JMenuItem
createMenuItemExport() {
416 final JFileChooser fc
= new JFileChooser();
417 fc
.setAcceptAllFileFilterUsed(false);
419 // Add the "ALL" filters first, then the others
420 final Map
<FileFilter
, OutputType
> otherFilters
= new HashMap
<FileFilter
, OutputType
>();
421 for (OutputType type
: OutputType
.values()) {
422 String ext
= type
.getDefaultExtension(false);
423 String desc
= type
.getDesc(false);
425 if (ext
== null || ext
.isEmpty()) {
426 fc
.addChoosableFileFilter(createAllFilter(desc
));
428 otherFilters
.put(new FileNameExtensionFilter(desc
, ext
), type
);
432 for (Entry
<FileFilter
, OutputType
> entry
: otherFilters
.entrySet()) {
433 fc
.addChoosableFileFilter(entry
.getKey());
437 JMenuItem export
= new JMenuItem(
438 GuiReader
.trans(StringIdGui
.MENU_FILE_EXPORT
), KeyEvent
.VK_S
);
439 export
.addActionListener(new ActionListener() {
441 public void actionPerformed(ActionEvent e
) {
442 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
443 if (selectedBook
!= null) {
444 fc
.showDialog(GuiReaderFrame
.this,
445 GuiReader
.trans(StringIdGui
.TITLE_SAVE
));
446 if (fc
.getSelectedFile() != null) {
447 final OutputType type
= otherFilters
.get(fc
.getFileFilter());
448 final String path
= fc
.getSelectedFile()
450 + type
.getDefaultExtension(false);
451 final Progress pg
= new Progress();
452 mainPanel
.outOfUi(pg
, false, new Runnable() {
456 reader
.getLibrary().export(
457 selectedBook
.getInfo().getMeta()
458 .getLuid(), type
, path
, pg
);
459 } catch (IOException e
) {
460 Instance
.getTraceHandler().error(e
);
473 * Create a {@link FileFilter} that accepts all files and return the given
481 private FileFilter
createAllFilter(final String desc
) {
482 return new FileFilter() {
484 public String
getDescription() {
489 public boolean accept(File f
) {
496 * Create the refresh (delete cache) menu item.
500 private JMenuItem
createMenuItemClearCache() {
501 JMenuItem refresh
= new JMenuItem(
502 GuiReader
.trans(StringIdGui
.MENU_EDIT_CLEAR_CACHE
),
504 refresh
.addActionListener(new ActionListener() {
506 public void actionPerformed(ActionEvent e
) {
507 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
508 if (selectedBook
!= null) {
509 mainPanel
.outOfUi(null, false, new Runnable() {
512 reader
.clearLocalReaderCache(selectedBook
.getInfo()
513 .getMeta().getLuid());
514 selectedBook
.setCached(false);
515 GuiReaderCoverImager
.clearIcon(selectedBook
517 SwingUtilities
.invokeLater(new Runnable() {
520 selectedBook
.repaint();
533 * Create the "move to" menu item.
536 * the library can be queried
540 private JMenuItem
createMenuItemMoveTo(boolean libOk
) {
541 JMenu changeTo
= new JMenu(
542 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO
));
543 changeTo
.setMnemonic(KeyEvent
.VK_M
);
545 Map
<String
, List
<String
>> groupedSources
= new HashMap
<String
, List
<String
>>();
547 groupedSources
= reader
.getLibrary().getSourcesGrouped();
550 JMenuItem item
= new JMenuItem(
551 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO_NEW_TYPE
));
552 item
.addActionListener(createMoveAction(ChangeAction
.SOURCE
, null));
554 changeTo
.addSeparator();
556 for (final String type
: groupedSources
.keySet()) {
557 List
<String
> list
= groupedSources
.get(type
);
558 if (list
.size() == 1 && list
.get(0).isEmpty()) {
559 item
= new JMenuItem(type
);
560 item
.addActionListener(createMoveAction(ChangeAction
.SOURCE
,
564 JMenu dir
= new JMenu(type
);
565 for (String sub
: list
) {
566 // " " instead of "" for the visual height
567 String itemName
= sub
.isEmpty() ?
" " : sub
;
568 String actualType
= type
;
569 if (!sub
.isEmpty()) {
570 actualType
+= "/" + sub
;
573 item
= new JMenuItem(itemName
);
574 item
.addActionListener(createMoveAction(
575 ChangeAction
.SOURCE
, actualType
));
586 * Create the "set author" menu item.
589 * the library can be queried
593 private JMenuItem
createMenuItemSetAuthor(boolean libOk
) {
594 JMenu changeTo
= new JMenu(
595 GuiReader
.trans(StringIdGui
.MENU_FILE_SET_AUTHOR
));
596 changeTo
.setMnemonic(KeyEvent
.VK_A
);
599 JMenuItem newItem
= new JMenuItem(
600 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO_NEW_AUTHOR
));
601 changeTo
.add(newItem
);
602 changeTo
.addSeparator();
603 newItem
.addActionListener(createMoveAction(ChangeAction
.AUTHOR
, null));
607 Map
<String
, List
<String
>> groupedAuthors
= reader
.getLibrary()
608 .getAuthorsGrouped();
610 if (groupedAuthors
.size() > 1) {
611 for (String key
: groupedAuthors
.keySet()) {
612 JMenu group
= new JMenu(key
);
613 for (String value
: groupedAuthors
.get(key
)) {
614 JMenuItem item
= new JMenuItem(
615 value
.isEmpty() ? GuiReader
616 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
618 item
.addActionListener(createMoveAction(
619 ChangeAction
.AUTHOR
, value
));
624 } else if (groupedAuthors
.size() == 1) {
625 for (String value
: groupedAuthors
.values().iterator().next()) {
626 JMenuItem item
= new JMenuItem(
627 value
.isEmpty() ? GuiReader
628 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
630 item
.addActionListener(createMoveAction(
631 ChangeAction
.AUTHOR
, value
));
641 * Create the "rename" menu item.
644 * the library can be queried
648 private JMenuItem
createMenuItemRename(
649 @SuppressWarnings("unused") boolean libOk
) {
650 JMenuItem changeTo
= new JMenuItem(
651 GuiReader
.trans(StringIdGui
.MENU_FILE_RENAME
));
652 changeTo
.setMnemonic(KeyEvent
.VK_R
);
653 changeTo
.addActionListener(createMoveAction(ChangeAction
.TITLE
, null));
657 private ActionListener
createMoveAction(final ChangeAction what
,
659 return new ActionListener() {
661 public void actionPerformed(ActionEvent e
) {
662 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
663 if (selectedBook
!= null) {
664 boolean refreshRequired
= false;
666 if (what
== ChangeAction
.SOURCE
) {
667 refreshRequired
= mainPanel
.getCurrentType();
668 } else if (what
== ChangeAction
.TITLE
) {
669 refreshRequired
= false;
670 } else if (what
== ChangeAction
.AUTHOR
) {
671 refreshRequired
= !mainPanel
.getCurrentType();
674 String changeTo
= type
;
676 MetaData meta
= selectedBook
.getInfo().getMeta();
678 if (what
== ChangeAction
.SOURCE
) {
679 init
= meta
.getSource();
680 } else if (what
== ChangeAction
.TITLE
) {
681 init
= meta
.getTitle();
682 } else if (what
== ChangeAction
.AUTHOR
) {
683 init
= meta
.getAuthor();
686 Object rep
= JOptionPane
.showInputDialog(
688 GuiReader
.trans(StringIdGui
.SUBTITLE_MOVE_TO
),
689 GuiReader
.trans(StringIdGui
.TITLE_MOVE_TO
),
690 JOptionPane
.QUESTION_MESSAGE
, null, null, init
);
696 changeTo
= rep
.toString();
699 final String fChangeTo
= changeTo
;
700 mainPanel
.outOfUi(null, refreshRequired
, new Runnable() {
703 String luid
= selectedBook
.getInfo().getMeta()
705 if (what
== ChangeAction
.SOURCE
) {
706 reader
.changeSource(luid
, fChangeTo
);
707 } else if (what
== ChangeAction
.TITLE
) {
708 reader
.changeTitle(luid
, fChangeTo
);
709 } else if (what
== ChangeAction
.AUTHOR
) {
710 reader
.changeAuthor(luid
, fChangeTo
);
713 mainPanel
.getSelectedBook().repaint();
714 mainPanel
.unsetSelectedBook();
716 SwingUtilities
.invokeLater(new Runnable() {
730 * Create the re-download (then delete original) menu item.
734 private JMenuItem
createMenuItemRedownload() {
735 JMenuItem refresh
= new JMenuItem(
736 GuiReader
.trans(StringIdGui
.MENU_EDIT_REDOWNLOAD
),
738 refresh
.addActionListener(new ActionListener() {
740 public void actionPerformed(ActionEvent e
) {
741 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
742 if (selectedBook
!= null) {
743 final MetaData meta
= selectedBook
.getInfo().getMeta();
746 new StoryRunnable() {
748 public void run(Story story
) {
749 MetaData newMeta
= story
.getMeta();
750 if (!newMeta
.getSource().equals(
752 reader
.changeSource(newMeta
.getLuid(),
758 .trans(StringIdGui
.PROGRESS_CHANGE_SOURCE
));
767 * Create the delete menu item.
771 private JMenuItem
createMenuItemDelete() {
772 JMenuItem delete
= new JMenuItem(
773 GuiReader
.trans(StringIdGui
.MENU_EDIT_DELETE
), KeyEvent
.VK_D
);
774 delete
.addActionListener(new ActionListener() {
776 public void actionPerformed(ActionEvent e
) {
777 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
778 if (selectedBook
!= null
779 && selectedBook
.getInfo().getMeta() != null) {
781 final MetaData meta
= selectedBook
.getInfo().getMeta();
782 int rep
= JOptionPane
.showConfirmDialog(
784 GuiReader
.trans(StringIdGui
.SUBTITLE_DELETE
,
785 meta
.getLuid(), meta
.getTitle()),
786 GuiReader
.trans(StringIdGui
.TITLE_DELETE
),
787 JOptionPane
.OK_CANCEL_OPTION
);
789 if (rep
== JOptionPane
.OK_OPTION
) {
790 mainPanel
.outOfUi(null, true, new Runnable() {
793 reader
.delete(meta
.getLuid());
794 mainPanel
.unsetSelectedBook();
806 * Create the properties menu item.
810 private JMenuItem
createMenuItemProperties() {
811 JMenuItem delete
= new JMenuItem(
812 GuiReader
.trans(StringIdGui
.MENU_FILE_PROPERTIES
),
814 delete
.addActionListener(new ActionListener() {
816 public void actionPerformed(ActionEvent e
) {
817 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
818 if (selectedBook
!= null) {
819 mainPanel
.outOfUi(null, false, new Runnable() {
822 new GuiReaderPropertiesFrame(reader
.getLibrary(),
823 selectedBook
.getInfo().getMeta())
835 * Create the open menu item for a book, a source/type or an author.
839 public JMenuItem
createMenuItemOpenBook() {
840 JMenuItem open
= new JMenuItem(
841 GuiReader
.trans(StringIdGui
.MENU_FILE_OPEN
), KeyEvent
.VK_O
);
842 open
.addActionListener(new ActionListener() {
844 public void actionPerformed(ActionEvent e
) {
845 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
846 if (selectedBook
!= null) {
847 if (selectedBook
.getInfo().getMeta() == null) {
848 mainPanel
.removeBookPanes();
849 mainPanel
.addBookPane(selectedBook
.getInfo()
850 .getMainInfo(), mainPanel
.getCurrentType());
851 mainPanel
.refreshBooks();
853 mainPanel
.openBook(selectedBook
);
863 * Create the SetCover menu item for a book to change the linked source
868 private JMenuItem
createMenuItemSetCoverForSource() {
869 JMenuItem open
= new JMenuItem(
870 GuiReader
.trans(StringIdGui
.MENU_EDIT_SET_COVER_FOR_SOURCE
),
872 open
.addActionListener(new ActionListener() {
874 public void actionPerformed(ActionEvent e
) {
875 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
876 if (selectedBook
!= null) {
877 BasicLibrary lib
= reader
.getLibrary();
878 String luid
= selectedBook
.getInfo().getMeta().getLuid();
879 String source
= selectedBook
.getInfo().getMeta()
882 lib
.setSourceCover(source
, luid
);
884 GuiReaderBookInfo sourceInfo
= GuiReaderBookInfo
885 .fromSource(lib
, source
);
886 GuiReaderCoverImager
.clearIcon(sourceInfo
);
895 * Create the SetCover menu item for a book to change the linked source
900 private JMenuItem
createMenuItemSetCoverForAuthor() {
901 JMenuItem open
= new JMenuItem(
902 GuiReader
.trans(StringIdGui
.MENU_EDIT_SET_COVER_FOR_AUTHOR
),
904 open
.addActionListener(new ActionListener() {
906 public void actionPerformed(ActionEvent e
) {
907 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
908 if (selectedBook
!= null) {
909 BasicLibrary lib
= reader
.getLibrary();
910 String luid
= selectedBook
.getInfo().getMeta().getLuid();
911 String author
= selectedBook
.getInfo().getMeta()
914 lib
.setAuthorCover(author
, luid
);
916 GuiReaderBookInfo authorInfo
= GuiReaderBookInfo
917 .fromAuthor(lib
, author
);
918 GuiReaderCoverImager
.clearIcon(authorInfo
);
927 * Display an error message and log the linked {@link Exception}.
932 * the title of the error message
934 * the exception to log if any
936 public void error(final String message
, final String title
, Exception e
) {
937 Instance
.getTraceHandler().error(title
+ ": " + message
);
939 Instance
.getTraceHandler().error(e
);
942 SwingUtilities
.invokeLater(new Runnable() {
945 JOptionPane
.showMessageDialog(GuiReaderFrame
.this, message
,
946 title
, JOptionPane
.ERROR_MESSAGE
);
952 public GuiReader
getReader() {
957 * Return the title of the application.
960 * the name of the associated {@link BasicLibrary}, which can be
965 static private String
getAppTitle(String libraryName
) {
966 if (!libraryName
.isEmpty()) {
967 return GuiReader
.trans(StringIdGui
.TITLE_LIBRARY_WITH_NAME
, Version
968 .getCurrentVersion().toString(), libraryName
);
971 return GuiReader
.trans(StringIdGui
.TITLE_LIBRARY
, Version
972 .getCurrentVersion().toString());