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
);
204 JMenu view
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_VIEW
));
205 view
.setMnemonic(KeyEvent
.VK_V
);
206 JMenuItem vauthors
= new JMenuItem(
207 GuiReader
.trans(StringIdGui
.MENU_VIEW_AUTHOR
));
208 vauthors
.setMnemonic(KeyEvent
.VK_A
);
209 vauthors
.addActionListener(new ActionListener() {
211 public void actionPerformed(ActionEvent e
) {
212 mainPanel
.setWords(false);
213 mainPanel
.refreshBooks();
217 JMenuItem vwords
= new JMenuItem(
218 GuiReader
.trans(StringIdGui
.MENU_VIEW_WCOUNT
));
219 vwords
.setMnemonic(KeyEvent
.VK_W
);
220 vwords
.addActionListener(new ActionListener() {
222 public void actionPerformed(ActionEvent e
) {
223 mainPanel
.setWords(true);
224 mainPanel
.refreshBooks();
230 Map
<String
, List
<String
>> groupedSources
= new HashMap
<String
, List
<String
>>();
232 groupedSources
= reader
.getLibrary().getSourcesGrouped();
234 JMenu sources
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_SOURCES
));
235 sources
.setMnemonic(KeyEvent
.VK_S
);
236 populateMenuSA(sources
, groupedSources
, true);
239 Map
<String
, List
<String
>> goupedAuthors
= new HashMap
<String
, List
<String
>>();
241 goupedAuthors
= reader
.getLibrary().getAuthorsGrouped();
243 JMenu authors
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_AUTHORS
));
244 authors
.setMnemonic(KeyEvent
.VK_A
);
245 populateMenuSA(authors
, goupedAuthors
, false);
248 JMenu options
= new JMenu(GuiReader
.trans(StringIdGui
.MENU_OPTIONS
));
249 options
.setMnemonic(KeyEvent
.VK_O
);
250 options
.add(createMenuItemConfig());
251 options
.add(createMenuItemUiConfig());
258 private void populateMenuSA(JMenu menu
,
259 Map
<String
, List
<String
>> groupedValues
, boolean type
) {
261 // "All" and "Listing" special items first
262 JMenuItem item
= new JMenuItem(
263 GuiReader
.trans(StringIdGui
.MENU_XXX_ALL_GROUPED
));
264 item
.addActionListener(getActionOpenList(type
, false));
266 item
= new JMenuItem(GuiReader
.trans(StringIdGui
.MENU_XXX_ALL_LISTING
));
267 item
.addActionListener(getActionOpenList(type
, true));
272 for (final String value
: groupedValues
.keySet()) {
273 List
<String
> list
= groupedValues
.get(value
);
274 if (type
&& list
.size() == 1 && list
.get(0).isEmpty()) {
275 // leaf item source/type
276 item
= new JMenuItem(
277 value
.isEmpty() ? GuiReader
278 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
280 item
.addActionListener(getActionOpen(value
, type
));
284 if (!type
&& groupedValues
.size() == 1) {
285 // only one group of authors
289 value
.isEmpty() ? GuiReader
290 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
294 for (String sub
: list
) {
295 // " " instead of "" for the visual height
296 String itemName
= sub
;
297 if (itemName
.isEmpty()) {
298 itemName
= type ?
" " : GuiReader
299 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
);
302 String actualValue
= value
;
304 if (!sub
.isEmpty()) {
305 actualValue
+= "/" + sub
;
311 item
= new JMenuItem(itemName
);
312 item
.addActionListener(getActionOpen(actualValue
, type
));
324 * Return an {@link ActionListener} that will set the given source (type) as
325 * the selected/displayed one.
328 * the type (source) to select, cannot be NULL
330 * @return the {@link ActionListener}
332 private ActionListener
getActionOpen(final String source
, final boolean type
) {
333 return new ActionListener() {
335 public void actionPerformed(ActionEvent e
) {
336 mainPanel
.removeBookPanes();
337 mainPanel
.addBookPane(source
, type
);
338 mainPanel
.refreshBooks();
343 private ActionListener
getActionOpenList(final boolean type
,
344 final boolean listMode
) {
345 return new ActionListener() {
347 public void actionPerformed(ActionEvent e
) {
348 mainPanel
.removeBookPanes();
349 mainPanel
.addBookPane(type
, listMode
);
350 mainPanel
.refreshBooks();
356 * Create the Fanfix Configuration menu item.
360 private JMenuItem
createMenuItemConfig() {
361 final String title
= GuiReader
.trans(StringIdGui
.TITLE_CONFIG
);
362 JMenuItem item
= new JMenuItem(title
);
363 item
.setMnemonic(KeyEvent
.VK_F
);
365 item
.addActionListener(new ActionListener() {
367 public void actionPerformed(ActionEvent e
) {
368 ConfigEditor
<Config
> ed
= new ConfigEditor
<Config
>(
369 Config
.class, Instance
.getConfig(), GuiReader
370 .trans(StringIdGui
.SUBTITLE_CONFIG
));
371 JFrame frame
= new JFrame(title
);
373 frame
.setSize(800, 600);
374 frame
.setVisible(true);
382 * Create the UI Configuration menu item.
386 private JMenuItem
createMenuItemUiConfig() {
387 final String title
= GuiReader
.trans(StringIdGui
.TITLE_CONFIG_UI
);
388 JMenuItem item
= new JMenuItem(title
);
389 item
.setMnemonic(KeyEvent
.VK_U
);
391 item
.addActionListener(new ActionListener() {
393 public void actionPerformed(ActionEvent e
) {
394 ConfigEditor
<UiConfig
> ed
= new ConfigEditor
<UiConfig
>(
395 UiConfig
.class, Instance
.getUiConfig(), GuiReader
396 .trans(StringIdGui
.SUBTITLE_CONFIG_UI
));
397 JFrame frame
= new JFrame(title
);
399 frame
.setSize(800, 600);
400 frame
.setVisible(true);
408 * Create the export menu item.
412 private JMenuItem
createMenuItemExport() {
413 final JFileChooser fc
= new JFileChooser();
414 fc
.setAcceptAllFileFilterUsed(false);
416 // Add the "ALL" filters first, then the others
417 final Map
<FileFilter
, OutputType
> otherFilters
= new HashMap
<FileFilter
, OutputType
>();
418 for (OutputType type
: OutputType
.values()) {
419 String ext
= type
.getDefaultExtension(false);
420 String desc
= type
.getDesc(false);
422 if (ext
== null || ext
.isEmpty()) {
423 fc
.addChoosableFileFilter(createAllFilter(desc
));
425 otherFilters
.put(new FileNameExtensionFilter(desc
, ext
), type
);
429 for (Entry
<FileFilter
, OutputType
> entry
: otherFilters
.entrySet()) {
430 fc
.addChoosableFileFilter(entry
.getKey());
434 JMenuItem export
= new JMenuItem(
435 GuiReader
.trans(StringIdGui
.MENU_FILE_EXPORT
), KeyEvent
.VK_S
);
436 export
.addActionListener(new ActionListener() {
438 public void actionPerformed(ActionEvent e
) {
439 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
440 if (selectedBook
!= null) {
441 fc
.showDialog(GuiReaderFrame
.this,
442 GuiReader
.trans(StringIdGui
.TITLE_SAVE
));
443 if (fc
.getSelectedFile() != null) {
444 final OutputType type
= otherFilters
.get(fc
.getFileFilter());
445 final String path
= fc
.getSelectedFile()
447 + type
.getDefaultExtension(false);
448 final Progress pg
= new Progress();
449 mainPanel
.outOfUi(pg
, false, new Runnable() {
453 reader
.getLibrary().export(
454 selectedBook
.getInfo().getMeta()
455 .getLuid(), type
, path
, pg
);
456 } catch (IOException e
) {
457 Instance
.getTraceHandler().error(e
);
470 * Create a {@link FileFilter} that accepts all files and return the given
478 private FileFilter
createAllFilter(final String desc
) {
479 return new FileFilter() {
481 public String
getDescription() {
486 public boolean accept(File f
) {
493 * Create the refresh (delete cache) menu item.
497 private JMenuItem
createMenuItemClearCache() {
498 JMenuItem refresh
= new JMenuItem(
499 GuiReader
.trans(StringIdGui
.MENU_EDIT_CLEAR_CACHE
),
501 refresh
.addActionListener(new ActionListener() {
503 public void actionPerformed(ActionEvent e
) {
504 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
505 if (selectedBook
!= null) {
506 mainPanel
.outOfUi(null, false, new Runnable() {
509 reader
.clearLocalReaderCache(selectedBook
.getInfo()
510 .getMeta().getLuid());
511 selectedBook
.setCached(false);
512 GuiReaderCoverImager
.clearIcon(selectedBook
514 SwingUtilities
.invokeLater(new Runnable() {
517 selectedBook
.repaint();
530 * Create the "move to" menu item.
533 * the library can be queried
537 private JMenuItem
createMenuItemMoveTo(boolean libOk
) {
538 JMenu changeTo
= new JMenu(
539 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO
));
540 changeTo
.setMnemonic(KeyEvent
.VK_M
);
542 Map
<String
, List
<String
>> groupedSources
= new HashMap
<String
, List
<String
>>();
544 groupedSources
= reader
.getLibrary().getSourcesGrouped();
547 JMenuItem item
= new JMenuItem(
548 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO_NEW_TYPE
));
549 item
.addActionListener(createMoveAction(ChangeAction
.SOURCE
, null));
551 changeTo
.addSeparator();
553 for (final String type
: groupedSources
.keySet()) {
554 List
<String
> list
= groupedSources
.get(type
);
555 if (list
.size() == 1 && list
.get(0).isEmpty()) {
556 item
= new JMenuItem(type
);
557 item
.addActionListener(createMoveAction(ChangeAction
.SOURCE
,
561 JMenu dir
= new JMenu(type
);
562 for (String sub
: list
) {
563 // " " instead of "" for the visual height
564 String itemName
= sub
.isEmpty() ?
" " : sub
;
565 String actualType
= type
;
566 if (!sub
.isEmpty()) {
567 actualType
+= "/" + sub
;
570 item
= new JMenuItem(itemName
);
571 item
.addActionListener(createMoveAction(
572 ChangeAction
.SOURCE
, actualType
));
583 * Create the "set author" menu item.
586 * the library can be queried
590 private JMenuItem
createMenuItemSetAuthor(boolean libOk
) {
591 JMenu changeTo
= new JMenu(
592 GuiReader
.trans(StringIdGui
.MENU_FILE_SET_AUTHOR
));
593 changeTo
.setMnemonic(KeyEvent
.VK_A
);
596 JMenuItem newItem
= new JMenuItem(
597 GuiReader
.trans(StringIdGui
.MENU_FILE_MOVE_TO_NEW_AUTHOR
));
598 changeTo
.add(newItem
);
599 changeTo
.addSeparator();
600 newItem
.addActionListener(createMoveAction(ChangeAction
.AUTHOR
, null));
604 Map
<String
, List
<String
>> groupedAuthors
= reader
.getLibrary()
605 .getAuthorsGrouped();
607 if (groupedAuthors
.size() > 1) {
608 for (String key
: groupedAuthors
.keySet()) {
609 JMenu group
= new JMenu(key
);
610 for (String value
: groupedAuthors
.get(key
)) {
611 JMenuItem item
= new JMenuItem(
612 value
.isEmpty() ? GuiReader
613 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
615 item
.addActionListener(createMoveAction(
616 ChangeAction
.AUTHOR
, value
));
621 } else if (groupedAuthors
.size() == 1) {
622 for (String value
: groupedAuthors
.values().iterator().next()) {
623 JMenuItem item
= new JMenuItem(
624 value
.isEmpty() ? GuiReader
625 .trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
)
627 item
.addActionListener(createMoveAction(
628 ChangeAction
.AUTHOR
, value
));
638 * Create the "rename" menu item.
641 * the library can be queried
645 private JMenuItem
createMenuItemRename(
646 @SuppressWarnings("unused") boolean libOk
) {
647 JMenuItem changeTo
= new JMenuItem(
648 GuiReader
.trans(StringIdGui
.MENU_FILE_RENAME
));
649 changeTo
.setMnemonic(KeyEvent
.VK_R
);
650 changeTo
.addActionListener(createMoveAction(ChangeAction
.TITLE
, null));
654 private ActionListener
createMoveAction(final ChangeAction what
,
656 return new ActionListener() {
658 public void actionPerformed(ActionEvent e
) {
659 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
660 if (selectedBook
!= null) {
661 boolean refreshRequired
= false;
663 if (what
== ChangeAction
.SOURCE
) {
664 refreshRequired
= mainPanel
.getCurrentType();
665 } else if (what
== ChangeAction
.TITLE
) {
666 refreshRequired
= false;
667 } else if (what
== ChangeAction
.AUTHOR
) {
668 refreshRequired
= !mainPanel
.getCurrentType();
671 String changeTo
= type
;
673 MetaData meta
= selectedBook
.getInfo().getMeta();
675 if (what
== ChangeAction
.SOURCE
) {
676 init
= meta
.getSource();
677 } else if (what
== ChangeAction
.TITLE
) {
678 init
= meta
.getTitle();
679 } else if (what
== ChangeAction
.AUTHOR
) {
680 init
= meta
.getAuthor();
683 Object rep
= JOptionPane
.showInputDialog(
685 GuiReader
.trans(StringIdGui
.SUBTITLE_MOVE_TO
),
686 GuiReader
.trans(StringIdGui
.TITLE_MOVE_TO
),
687 JOptionPane
.QUESTION_MESSAGE
, null, null, init
);
693 changeTo
= rep
.toString();
696 final String fChangeTo
= changeTo
;
697 mainPanel
.outOfUi(null, refreshRequired
, new Runnable() {
700 String luid
= selectedBook
.getInfo().getMeta()
702 if (what
== ChangeAction
.SOURCE
) {
703 reader
.changeSource(luid
, fChangeTo
);
704 } else if (what
== ChangeAction
.TITLE
) {
705 reader
.changeTitle(luid
, fChangeTo
);
706 } else if (what
== ChangeAction
.AUTHOR
) {
707 reader
.changeAuthor(luid
, fChangeTo
);
710 mainPanel
.getSelectedBook().repaint();
711 mainPanel
.unsetSelectedBook();
713 SwingUtilities
.invokeLater(new Runnable() {
727 * Create the re-download (then delete original) menu item.
731 private JMenuItem
createMenuItemRedownload() {
732 JMenuItem refresh
= new JMenuItem(
733 GuiReader
.trans(StringIdGui
.MENU_EDIT_REDOWNLOAD
),
735 refresh
.addActionListener(new ActionListener() {
737 public void actionPerformed(ActionEvent e
) {
738 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
739 if (selectedBook
!= null) {
740 final MetaData meta
= selectedBook
.getInfo().getMeta();
743 new StoryRunnable() {
745 public void run(Story story
) {
746 MetaData newMeta
= story
.getMeta();
747 if (!newMeta
.getSource().equals(
749 reader
.changeSource(newMeta
.getLuid(),
755 .trans(StringIdGui
.PROGRESS_CHANGE_SOURCE
));
764 * Create the delete menu item.
768 private JMenuItem
createMenuItemDelete() {
769 JMenuItem delete
= new JMenuItem(
770 GuiReader
.trans(StringIdGui
.MENU_EDIT_DELETE
), KeyEvent
.VK_D
);
771 delete
.addActionListener(new ActionListener() {
773 public void actionPerformed(ActionEvent e
) {
774 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
775 if (selectedBook
!= null
776 && selectedBook
.getInfo().getMeta() != null) {
778 final MetaData meta
= selectedBook
.getInfo().getMeta();
779 int rep
= JOptionPane
.showConfirmDialog(
781 GuiReader
.trans(StringIdGui
.SUBTITLE_DELETE
,
782 meta
.getLuid(), meta
.getTitle()),
783 GuiReader
.trans(StringIdGui
.TITLE_DELETE
),
784 JOptionPane
.OK_CANCEL_OPTION
);
786 if (rep
== JOptionPane
.OK_OPTION
) {
787 mainPanel
.outOfUi(null, true, new Runnable() {
790 reader
.delete(meta
.getLuid());
791 mainPanel
.unsetSelectedBook();
803 * Create the properties menu item.
807 private JMenuItem
createMenuItemProperties() {
808 JMenuItem delete
= new JMenuItem(
809 GuiReader
.trans(StringIdGui
.MENU_FILE_PROPERTIES
),
811 delete
.addActionListener(new ActionListener() {
813 public void actionPerformed(ActionEvent e
) {
814 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
815 if (selectedBook
!= null) {
816 mainPanel
.outOfUi(null, false, new Runnable() {
819 new GuiReaderPropertiesFrame(reader
.getLibrary(),
820 selectedBook
.getInfo().getMeta())
832 * Create the open menu item for a book, a source/type or an author.
836 public JMenuItem
createMenuItemOpenBook() {
837 JMenuItem open
= new JMenuItem(
838 GuiReader
.trans(StringIdGui
.MENU_FILE_OPEN
), KeyEvent
.VK_O
);
839 open
.addActionListener(new ActionListener() {
841 public void actionPerformed(ActionEvent e
) {
842 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
843 if (selectedBook
!= null) {
844 if (selectedBook
.getInfo().getMeta() == null) {
845 mainPanel
.removeBookPanes();
846 mainPanel
.addBookPane(selectedBook
.getInfo()
847 .getMainInfo(), mainPanel
.getCurrentType());
848 mainPanel
.refreshBooks();
850 mainPanel
.openBook(selectedBook
);
860 * Create the SetCover menu item for a book to change the linked source
865 private JMenuItem
createMenuItemSetCoverForSource() {
866 JMenuItem open
= new JMenuItem(
867 GuiReader
.trans(StringIdGui
.MENU_EDIT_SET_COVER_FOR_SOURCE
),
869 open
.addActionListener(new ActionListener() {
871 public void actionPerformed(ActionEvent e
) {
872 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
873 if (selectedBook
!= null) {
874 BasicLibrary lib
= reader
.getLibrary();
875 String luid
= selectedBook
.getInfo().getMeta().getLuid();
876 String source
= selectedBook
.getInfo().getMeta()
879 lib
.setSourceCover(source
, luid
);
881 GuiReaderBookInfo sourceInfo
= GuiReaderBookInfo
882 .fromSource(lib
, source
);
883 GuiReaderCoverImager
.clearIcon(sourceInfo
);
892 * Create the SetCover menu item for a book to change the linked source
897 private JMenuItem
createMenuItemSetCoverForAuthor() {
898 JMenuItem open
= new JMenuItem(
899 GuiReader
.trans(StringIdGui
.MENU_EDIT_SET_COVER_FOR_AUTHOR
),
901 open
.addActionListener(new ActionListener() {
903 public void actionPerformed(ActionEvent e
) {
904 final GuiReaderBook selectedBook
= mainPanel
.getSelectedBook();
905 if (selectedBook
!= null) {
906 BasicLibrary lib
= reader
.getLibrary();
907 String luid
= selectedBook
.getInfo().getMeta().getLuid();
908 String author
= selectedBook
.getInfo().getMeta()
911 lib
.setAuthorCover(author
, luid
);
913 GuiReaderBookInfo authorInfo
= GuiReaderBookInfo
914 .fromAuthor(lib
, author
);
915 GuiReaderCoverImager
.clearIcon(authorInfo
);
924 * Display an error message and log the linked {@link Exception}.
929 * the title of the error message
931 * the exception to log if any
933 public void error(final String message
, final String title
, Exception e
) {
934 Instance
.getTraceHandler().error(title
+ ": " + message
);
936 Instance
.getTraceHandler().error(e
);
939 SwingUtilities
.invokeLater(new Runnable() {
942 JOptionPane
.showMessageDialog(GuiReaderFrame
.this, message
,
943 title
, JOptionPane
.ERROR_MESSAGE
);
949 public GuiReader
getReader() {
954 * Return the title of the application.
957 * the name of the associated {@link BasicLibrary}, which can be
962 static private String
getAppTitle(String libraryName
) {
963 if (!libraryName
.isEmpty()) {
964 return GuiReader
.trans(StringIdGui
.TITLE_LIBRARY_WITH_NAME
, Version
965 .getCurrentVersion().toString(), libraryName
);
968 return GuiReader
.trans(StringIdGui
.TITLE_LIBRARY
, Version
969 .getCurrentVersion().toString());