Instance: use getInstance()
[nikiroo-utils.git] / src / be / nikiroo / fanfix / reader / ui / GuiReaderFrame.java
index 6b0723f766ce5cade1942fab811e88d87ad5d03d..e0ef6d72f8a6b75805e3989a46591ae5e7abbbaf 100644 (file)
@@ -31,11 +31,14 @@ import be.nikiroo.fanfix.bundles.UiConfig;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.fanfix.library.BasicLibrary;
+import be.nikiroo.fanfix.library.BasicLibrary.Status;
 import be.nikiroo.fanfix.library.LocalLibrary;
 import be.nikiroo.fanfix.output.BasicOutput.OutputType;
 import be.nikiroo.fanfix.reader.BasicReader;
 import be.nikiroo.fanfix.reader.ui.GuiReaderMainPanel.FrameHelper;
-import be.nikiroo.fanfix.reader.ui.GuiReaderMainPanel.StoryRunnable;
+import be.nikiroo.fanfix.reader.ui.GuiReaderMainPanel.MetaDataRunnable;
+import be.nikiroo.fanfix.searchable.BasicSearchable;
+import be.nikiroo.fanfix.supported.SupportType;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.Version;
 import be.nikiroo.utils.ui.ConfigEditor;
@@ -90,20 +93,26 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
 
        @Override
        public JPopupMenu createBookPopup() {
+               Status status = reader.getLibrary().getStatus();
                JPopupMenu popup = new JPopupMenu();
                popup.add(createMenuItemOpenBook());
                popup.addSeparator();
                popup.add(createMenuItemExport());
-               popup.add(createMenuItemMoveTo(true));
-               popup.add(createMenuItemSetCoverForSource());
-               popup.add(createMenuItemSetCoverForAuthor());
+               if (status.isWritable()) {
+                       popup.add(createMenuItemMoveTo());
+                       popup.add(createMenuItemSetCoverForSource());
+                       popup.add(createMenuItemSetCoverForAuthor());
+               }
+               popup.add(createMenuItemDownloadToCache());
                popup.add(createMenuItemClearCache());
-               popup.add(createMenuItemRedownload());
-               popup.addSeparator();
-               popup.add(createMenuItemRename(true));
-               popup.add(createMenuItemSetAuthor(true));
-               popup.addSeparator();
-               popup.add(createMenuItemDelete());
+               if (status.isWritable()) {
+                       popup.add(createMenuItemRedownload());
+                       popup.addSeparator();
+                       popup.add(createMenuItemRename());
+                       popup.add(createMenuItemSetAuthor());
+                       popup.addSeparator();
+                       popup.add(createMenuItemDelete());
+               }
                popup.addSeparator();
                popup.add(createMenuItemProperties());
                return popup;
@@ -117,7 +126,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
        }
 
        @Override
-       public void createMenu(boolean libOk) {
+       public void createMenu(Status status) {
                invalidate();
 
                JMenuBar bar = new JMenuBar();
@@ -155,13 +164,15 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
 
                file.add(createMenuItemOpenBook());
                file.add(createMenuItemExport());
-               file.add(createMenuItemMoveTo(libOk));
-               file.addSeparator();
-               file.add(imprt);
-               file.add(imprtF);
-               file.addSeparator();
-               file.add(createMenuItemRename(libOk));
-               file.add(createMenuItemSetAuthor(libOk));
+               if (status.isWritable()) {
+                       file.add(createMenuItemMoveTo());
+                       file.addSeparator();
+                       file.add(imprt);
+                       file.add(imprtF);
+                       file.addSeparator();
+                       file.add(createMenuItemRename());
+                       file.add(createMenuItemSetAuthor());
+               }
                file.addSeparator();
                file.add(createMenuItemProperties());
                file.addSeparator();
@@ -174,6 +185,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
 
                edit.add(createMenuItemSetCoverForSource());
                edit.add(createMenuItemSetCoverForAuthor());
+               edit.add(createMenuItemDownloadToCache());
                edit.add(createMenuItemClearCache());
                edit.add(createMenuItemRedownload());
                edit.addSeparator();
@@ -181,6 +193,24 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
 
                bar.add(edit);
 
+               JMenu search = new JMenu(GuiReader.trans(StringIdGui.MENU_SEARCH));
+               search.setMnemonic(KeyEvent.VK_H);
+               for (final SupportType type : SupportType.values()) {
+                       BasicSearchable searchable = BasicSearchable.getSearchable(type);
+                       if (searchable != null) {
+                               JMenuItem searchItem = new JMenuItem(type.getSourceName());
+                               searchItem.addActionListener(new ActionListener() {
+                                       @Override
+                                       public void actionPerformed(ActionEvent e) {
+                                               reader.search(type, null, 1, 0, false);
+                                       }
+                               });
+                               search.add(searchItem);
+                       }
+               }
+
+               bar.add(search);
+
                JMenu view = new JMenu(GuiReader.trans(StringIdGui.MENU_VIEW));
                view.setMnemonic(KeyEvent.VK_V);
                JMenuItem vauthors = new JMenuItem(
@@ -208,8 +238,12 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                bar.add(view);
 
                Map<String, List<String>> groupedSources = new HashMap<String, List<String>>();
-               if (libOk) {
-                       groupedSources = reader.getLibrary().getSourcesGrouped();
+               if (status.isReady()) {
+                       try {
+                               groupedSources = reader.getLibrary().getSourcesGrouped();
+                       } catch (IOException e) {
+                               error(e.getLocalizedMessage(), "IOException", e);
+                       }
                }
                JMenu sources = new JMenu(GuiReader.trans(StringIdGui.MENU_SOURCES));
                sources.setMnemonic(KeyEvent.VK_S);
@@ -217,8 +251,12 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                bar.add(sources);
 
                Map<String, List<String>> goupedAuthors = new HashMap<String, List<String>>();
-               if (libOk) {
-                       goupedAuthors = reader.getLibrary().getAuthorsGrouped();
+               if (status.isReady()) {
+                       try {
+                               goupedAuthors = reader.getLibrary().getAuthorsGrouped();
+                       } catch (IOException e) {
+                               error(e.getLocalizedMessage(), "IOException", e);
+                       }
                }
                JMenu authors = new JMenu(GuiReader.trans(StringIdGui.MENU_AUTHORS));
                authors.setMnemonic(KeyEvent.VK_A);
@@ -239,20 +277,24 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                        Map<String, List<String>> groupedValues, boolean type) {
 
                // "All" and "Listing" special items first
-               JMenuItem item = new JMenuItem(GuiReader.trans(StringIdGui.MENU_XXX_ALL_GROUPED));
+               JMenuItem item = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_XXX_ALL_GROUPED));
                item.addActionListener(getActionOpenList(type, false));
                menu.add(item);
                item = new JMenuItem(GuiReader.trans(StringIdGui.MENU_XXX_ALL_LISTING));
                item.addActionListener(getActionOpenList(type, true));
                menu.add(item);
-               
+
                menu.addSeparator();
 
                for (final String value : groupedValues.keySet()) {
                        List<String> list = groupedValues.get(value);
                        if (type && list.size() == 1 && list.get(0).isEmpty()) {
                                // leaf item source/type
-                               item = new JMenuItem(value.isEmpty() ? GuiReader.trans(StringIdGui.MENU_AUTHORS_UNKNOWN) : value);
+                               item = new JMenuItem(
+                                               value.isEmpty() ? GuiReader
+                                                               .trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+                                                               : value);
                                item.addActionListener(getActionOpen(value, type));
                                menu.add(item);
                        } else {
@@ -261,14 +303,18 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                                        // only one group of authors
                                        dir = menu;
                                } else {
-                                       dir = new JMenu(value.isEmpty() ? GuiReader.trans(StringIdGui.MENU_AUTHORS_UNKNOWN) : value);
+                                       dir = new JMenu(
+                                                       value.isEmpty() ? GuiReader
+                                                                       .trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+                                                                       : value);
                                }
 
                                for (String sub : list) {
                                        // " " instead of "" for the visual height
                                        String itemName = sub;
                                        if (itemName.isEmpty()) {
-                                               itemName = type ? " " : GuiReader.trans(StringIdGui.MENU_AUTHORS_UNKNOWN);
+                                               itemName = type ? " " : GuiReader
+                                                               .trans(StringIdGui.MENU_AUTHORS_UNKNOWN);
                                        }
 
                                        String actualValue = value;
@@ -316,9 +362,13 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                        final boolean listMode) {
                return new ActionListener() {
                        @Override
-                       public void actionPerformed(ActionEvent e) {
+                       public void actionPerformed(ActionEvent ae) {
                                mainPanel.removeBookPanes();
-                               mainPanel.addBookPane(type, listMode);
+                               try {
+                                       mainPanel.addBookPane(type, listMode);
+                               } catch (IOException e) {
+                                       error(e.getLocalizedMessage(), "IOException", e);
+                               }
                                mainPanel.refreshBooks();
                        }
                };
@@ -338,11 +388,10 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                ConfigEditor<Config> ed = new ConfigEditor<Config>(
-                                               Config.class, Instance.getConfig(),
-                                               GuiReader.trans(StringIdGui.SUBTITLE_CONFIG));
+                                               Config.class, Instance.getInstance().getConfig(), GuiReader.trans(StringIdGui.SUBTITLE_CONFIG));
                                JFrame frame = new JFrame(title);
                                frame.add(ed);
-                               frame.setSize(800, 600);
+                               frame.setSize(850, 600);
                                frame.setVisible(true);
                        }
                });
@@ -364,7 +413,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                ConfigEditor<UiConfig> ed = new ConfigEditor<UiConfig>(
-                                               UiConfig.class, Instance.getUiConfig(),
+                                               UiConfig.class, Instance.getInstance().getUiConfig(),
                                                GuiReader.trans(StringIdGui.SUBTITLE_CONFIG_UI));
                                JFrame frame = new JFrame(title);
                                frame.add(ed);
@@ -385,40 +434,36 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                final JFileChooser fc = new JFileChooser();
                fc.setAcceptAllFileFilterUsed(false);
 
-               final Map<FileFilter, OutputType> filters = new HashMap<FileFilter, OutputType>();
+               // Add the "ALL" filters first, then the others
+               final Map<FileFilter, OutputType> otherFilters = new HashMap<FileFilter, OutputType>();
                for (OutputType type : OutputType.values()) {
                        String ext = type.getDefaultExtension(false);
                        String desc = type.getDesc(false);
 
                        if (ext == null || ext.isEmpty()) {
-                               filters.put(createAllFilter(desc), type);
+                               fc.addChoosableFileFilter(createAllFilter(desc));
                        } else {
-                               filters.put(new FileNameExtensionFilter(desc, ext), type);
+                               otherFilters.put(new FileNameExtensionFilter(desc, ext), type);
                        }
                }
 
-               // First the "ALL" filters, then, the extension filters
-               for (Entry<FileFilter, OutputType> entry : filters.entrySet()) {
-                       if (!(entry.getKey() instanceof FileNameExtensionFilter)) {
-                               fc.addChoosableFileFilter(entry.getKey());
-                       }
-               }
-               for (Entry<FileFilter, OutputType> entry : filters.entrySet()) {
-                       if (entry.getKey() instanceof FileNameExtensionFilter) {
-                               fc.addChoosableFileFilter(entry.getKey());
-                       }
+               for (Entry<FileFilter, OutputType> entry : otherFilters.entrySet()) {
+                       fc.addChoosableFileFilter(entry.getKey());
                }
                //
 
-               JMenuItem export = new JMenuItem(GuiReader.trans(StringIdGui.MENU_FILE_EXPORT), KeyEvent.VK_S);
+               JMenuItem export = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_FILE_EXPORT), KeyEvent.VK_S);
                export.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
                                if (selectedBook != null) {
-                                       fc.showDialog(GuiReaderFrame.this, GuiReader.trans(StringIdGui.TITLE_SAVE));
+                                       fc.showDialog(GuiReaderFrame.this,
+                                                       GuiReader.trans(StringIdGui.TITLE_SAVE));
                                        if (fc.getSelectedFile() != null) {
-                                               final OutputType type = filters.get(fc.getFileFilter());
+                                               final OutputType type = otherFilters.get(fc
+                                                               .getFileFilter());
                                                final String path = fc.getSelectedFile()
                                                                .getAbsolutePath()
                                                                + type.getDefaultExtension(false);
@@ -431,7 +476,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                                                                                        selectedBook.getInfo().getMeta()
                                                                                                        .getLuid(), type, path, pg);
                                                                } catch (IOException e) {
-                                                                       Instance.getTraceHandler().error(e);
+                                                                       Instance.getInstance().getTraceHandler().error(e);
                                                                }
                                                        }
                                                });
@@ -472,7 +517,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
         * @return the item
         */
        private JMenuItem createMenuItemClearCache() {
-               JMenuItem refresh = new JMenuItem(GuiReader.trans(StringIdGui.MENU_EDIT_CLEAR_CACHE), KeyEvent.VK_C);
+               JMenuItem refresh = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_EDIT_CLEAR_CACHE),
+                               KeyEvent.VK_C);
                refresh.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -504,21 +551,22 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
        /**
         * Create the "move to" menu item.
         * 
-        * @param libOk
-        *            the library can be queried
-        * 
         * @return the item
         */
-       private JMenuItem createMenuItemMoveTo(boolean libOk) {
-               JMenu changeTo = new JMenu(GuiReader.trans(StringIdGui.MENU_FILE_MOVE_TO));
+       private JMenuItem createMenuItemMoveTo() {
+               JMenu changeTo = new JMenu(
+                               GuiReader.trans(StringIdGui.MENU_FILE_MOVE_TO));
                changeTo.setMnemonic(KeyEvent.VK_M);
 
                Map<String, List<String>> groupedSources = new HashMap<String, List<String>>();
-               if (libOk) {
+               try {
                        groupedSources = reader.getLibrary().getSourcesGrouped();
+               } catch (IOException e) {
+                       error(e.getLocalizedMessage(), "IOException", e);
                }
 
-               JMenuItem item = new JMenuItem(GuiReader.trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_TYPE));
+               JMenuItem item = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_TYPE));
                item.addActionListener(createMoveAction(ChangeAction.SOURCE, null));
                changeTo.add(item);
                changeTo.addSeparator();
@@ -555,46 +603,54 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
        /**
         * Create the "set author" menu item.
         * 
-        * @param libOk
-        *            the library can be queried
-        * 
         * @return the item
         */
-       private JMenuItem createMenuItemSetAuthor(boolean libOk) {
-               JMenu changeTo = new JMenu(GuiReader.trans(StringIdGui.MENU_FILE_SET_AUTHOR));
+       private JMenuItem createMenuItemSetAuthor() {
+               JMenu changeTo = new JMenu(
+                               GuiReader.trans(StringIdGui.MENU_FILE_SET_AUTHOR));
                changeTo.setMnemonic(KeyEvent.VK_A);
 
                // New author
-               JMenuItem newItem = new JMenuItem(GuiReader.trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_AUTHOR));
+               JMenuItem newItem = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_FILE_MOVE_TO_NEW_AUTHOR));
                changeTo.add(newItem);
                changeTo.addSeparator();
                newItem.addActionListener(createMoveAction(ChangeAction.AUTHOR, null));
 
                // Existing authors
-               if (libOk) {
-                       Map<String, List<String>> groupedAuthors = reader.getLibrary()
-                                       .getAuthorsGrouped();
-
-                       if (groupedAuthors.size() > 1) {
-                               for (String key : groupedAuthors.keySet()) {
-                                       JMenu group = new JMenu(key);
-                                       for (String value : groupedAuthors.get(key)) {
-                                               JMenuItem item = new JMenuItem(
-                                                               value.isEmpty() ? GuiReader.trans(StringIdGui.MENU_AUTHORS_UNKNOWN) : value);
-                                               item.addActionListener(createMoveAction(
-                                                               ChangeAction.AUTHOR, value));
-                                               group.add(item);
-                                       }
-                                       changeTo.add(group);
-                               }
-                       } else if (groupedAuthors.size() == 1) {
-                               for (String value : groupedAuthors.values().iterator().next()) {
+               Map<String, List<String>> groupedAuthors;
+
+               try {
+                       groupedAuthors = reader.getLibrary().getAuthorsGrouped();
+               } catch (IOException e) {
+                       error(e.getLocalizedMessage(), "IOException", e);
+                       groupedAuthors = new HashMap<String, List<String>>();
+
+               }
+
+               if (groupedAuthors.size() > 1) {
+                       for (String key : groupedAuthors.keySet()) {
+                               JMenu group = new JMenu(key);
+                               for (String value : groupedAuthors.get(key)) {
                                        JMenuItem item = new JMenuItem(
-                                                       value.isEmpty() ? GuiReader.trans(StringIdGui.MENU_AUTHORS_UNKNOWN) : value);
+                                                       value.isEmpty() ? GuiReader
+                                                                       .trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+                                                                       : value);
                                        item.addActionListener(createMoveAction(
                                                        ChangeAction.AUTHOR, value));
-                                       changeTo.add(item);
+                                       group.add(item);
                                }
+                               changeTo.add(group);
+                       }
+               } else if (groupedAuthors.size() == 1) {
+                       for (String value : groupedAuthors.values().iterator().next()) {
+                               JMenuItem item = new JMenuItem(
+                                               value.isEmpty() ? GuiReader
+                                                               .trans(StringIdGui.MENU_AUTHORS_UNKNOWN)
+                                                               : value);
+                               item.addActionListener(createMoveAction(ChangeAction.AUTHOR,
+                                               value));
+                               changeTo.add(item);
                        }
                }
 
@@ -604,14 +660,11 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
        /**
         * Create the "rename" menu item.
         * 
-        * @param libOk
-        *            the library can be queried
-        * 
         * @return the item
         */
-       private JMenuItem createMenuItemRename(
-                       @SuppressWarnings("unused") boolean libOk) {
-               JMenuItem changeTo = new JMenuItem(GuiReader.trans(StringIdGui.MENU_FILE_RENAME));
+       private JMenuItem createMenuItemRename() {
+               JMenuItem changeTo = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_FILE_RENAME));
                changeTo.setMnemonic(KeyEvent.VK_R);
                changeTo.addActionListener(createMoveAction(ChangeAction.TITLE, null));
                return changeTo;
@@ -647,9 +700,10 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                                                }
 
                                                Object rep = JOptionPane.showInputDialog(
-                                                               GuiReaderFrame.this, GuiReader.trans(StringIdGui.SUBTITLE_MOVE_TO),
-                                                               GuiReader.trans(StringIdGui.TITLE_MOVE_TO), JOptionPane.QUESTION_MESSAGE,
-                                                               null, null, init);
+                                                               GuiReaderFrame.this,
+                                                               GuiReader.trans(StringIdGui.SUBTITLE_MOVE_TO),
+                                                               GuiReader.trans(StringIdGui.TITLE_MOVE_TO),
+                                                               JOptionPane.QUESTION_MESSAGE, null, null, init);
 
                                                if (rep == null) {
                                                        return;
@@ -678,7 +732,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                                                        SwingUtilities.invokeLater(new Runnable() {
                                                                @Override
                                                                public void run() {
-                                                                       createMenu(true);
+                                                                       createMenu(reader.getLibrary().getStatus());
                                                                }
                                                        });
                                                }
@@ -694,31 +748,53 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
         * @return the item
         */
        private JMenuItem createMenuItemRedownload() {
-               JMenuItem refresh = new JMenuItem(GuiReader.trans(StringIdGui.MENU_EDIT_REDOWNLOAD), KeyEvent.VK_R);
+               JMenuItem refresh = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_EDIT_REDOWNLOAD),
+                               KeyEvent.VK_R);
                refresh.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
                                if (selectedBook != null) {
                                        final MetaData meta = selectedBook.getInfo().getMeta();
-                                       mainPanel.imprt(meta.getUrl(), new StoryRunnable() {
+                                       mainPanel.imprt(meta.getUrl(), new MetaDataRunnable() {
                                                @Override
-                                               public void run(Story story) {
-                                                       reader.delete(meta.getLuid());
-                                                       mainPanel.unsetSelectedBook();
-                                                       MetaData newMeta = story.getMeta();
+                                               public void run(MetaData newMeta) {
                                                        if (!newMeta.getSource().equals(meta.getSource())) {
                                                                reader.changeSource(newMeta.getLuid(),
                                                                                meta.getSource());
                                                        }
                                                }
-                                       }, GuiReader.trans(StringIdGui.PROGRESS_REDOWNLOAD_REMOVE_OLD_COPY));
+                                       }, GuiReader.trans(StringIdGui.PROGRESS_CHANGE_SOURCE));
                                }
                        }
                });
 
                return refresh;
        }
+       
+       /**
+        * Create the download to cache menu item.
+        * 
+        * @return the item
+        */
+       private JMenuItem createMenuItemDownloadToCache() {
+               JMenuItem refresh = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_EDIT_DOWNLOAD_TO_CACHE),
+                               KeyEvent.VK_T);
+               refresh.addActionListener(new ActionListener() {
+                       @Override
+                       public void actionPerformed(ActionEvent e) {
+                               final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
+                               if (selectedBook != null) {
+                                       mainPanel.prefetchBook(selectedBook);
+                               }
+                       }
+               });
+
+               return refresh;
+       }
+
 
        /**
         * Create the delete menu item.
@@ -726,7 +802,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
         * @return the item
         */
        private JMenuItem createMenuItemDelete() {
-               JMenuItem delete = new JMenuItem(GuiReader.trans(StringIdGui.MENU_EDIT_DELETE), KeyEvent.VK_D);
+               JMenuItem delete = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_EDIT_DELETE), KeyEvent.VK_D);
                delete.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -737,8 +814,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                                        final MetaData meta = selectedBook.getInfo().getMeta();
                                        int rep = JOptionPane.showConfirmDialog(
                                                        GuiReaderFrame.this,
-                                                       GuiReader.trans(StringIdGui.SUBTITLE_DELETE, meta.getLuid(),
-                                                                       meta.getTitle()), GuiReader.trans(StringIdGui.TITLE_DELETE),
+                                                       GuiReader.trans(StringIdGui.SUBTITLE_DELETE,
+                                                                       meta.getLuid(), meta.getTitle()),
+                                                       GuiReader.trans(StringIdGui.TITLE_DELETE),
                                                        JOptionPane.OK_CANCEL_OPTION);
 
                                        if (rep == JOptionPane.OK_OPTION) {
@@ -763,7 +841,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
         * @return the item
         */
        private JMenuItem createMenuItemProperties() {
-               JMenuItem delete = new JMenuItem(GuiReader.trans(StringIdGui.MENU_FILE_PROPERTIES), KeyEvent.VK_P);
+               JMenuItem delete = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_FILE_PROPERTIES),
+                               KeyEvent.VK_P);
                delete.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -790,7 +870,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
         * @return the item
         */
        public JMenuItem createMenuItemOpenBook() {
-               JMenuItem open = new JMenuItem(GuiReader.trans(StringIdGui.MENU_FILE_OPEN), KeyEvent.VK_O);
+               JMenuItem open = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_FILE_OPEN), KeyEvent.VK_O);
                open.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
@@ -818,10 +899,12 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
         * @return the item
         */
        private JMenuItem createMenuItemSetCoverForSource() {
-               JMenuItem open = new JMenuItem(GuiReader.trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_SOURCE), KeyEvent.VK_C);
+               JMenuItem open = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_SOURCE),
+                               KeyEvent.VK_C);
                open.addActionListener(new ActionListener() {
                        @Override
-                       public void actionPerformed(ActionEvent e) {
+                       public void actionPerformed(ActionEvent ae) {
                                final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
                                if (selectedBook != null) {
                                        BasicLibrary lib = reader.getLibrary();
@@ -829,7 +912,11 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                                        String source = selectedBook.getInfo().getMeta()
                                                        .getSource();
 
-                                       lib.setSourceCover(source, luid);
+                                       try {
+                                               lib.setSourceCover(source, luid);
+                                       } catch (IOException e) {
+                                               error(e.getLocalizedMessage(), "IOException", e);
+                                       }
 
                                        GuiReaderBookInfo sourceInfo = GuiReaderBookInfo
                                                        .fromSource(lib, source);
@@ -848,10 +935,12 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
         * @return the item
         */
        private JMenuItem createMenuItemSetCoverForAuthor() {
-               JMenuItem open = new JMenuItem(GuiReader.trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_AUTHOR), KeyEvent.VK_A);
+               JMenuItem open = new JMenuItem(
+                               GuiReader.trans(StringIdGui.MENU_EDIT_SET_COVER_FOR_AUTHOR),
+                               KeyEvent.VK_A);
                open.addActionListener(new ActionListener() {
                        @Override
-                       public void actionPerformed(ActionEvent e) {
+                       public void actionPerformed(ActionEvent ae) {
                                final GuiReaderBook selectedBook = mainPanel.getSelectedBook();
                                if (selectedBook != null) {
                                        BasicLibrary lib = reader.getLibrary();
@@ -859,7 +948,11 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                                        String author = selectedBook.getInfo().getMeta()
                                                        .getAuthor();
 
-                                       lib.setAuthorCover(author, luid);
+                                       try {
+                                               lib.setAuthorCover(author, luid);
+                                       } catch (IOException e) {
+                                               error(e.getLocalizedMessage(), "IOException", e);
+                                       }
 
                                        GuiReaderBookInfo authorInfo = GuiReaderBookInfo
                                                        .fromAuthor(lib, author);
@@ -882,9 +975,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
         *            the exception to log if any
         */
        public void error(final String message, final String title, Exception e) {
-               Instance.getTraceHandler().error(title + ": " + message);
+               Instance.getInstance().getTraceHandler().error(title + ": " + message);
                if (e != null) {
-                       Instance.getTraceHandler().error(e);
+                       Instance.getInstance().getTraceHandler().error(e);
                }
 
                SwingUtilities.invokeLater(new Runnable() {
@@ -916,7 +1009,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                                        .getCurrentVersion().toString(), libraryName);
                }
 
-               return GuiReader.trans(StringIdGui.TITLE_LIBRARY, Version.getCurrentVersion()
-                               .toString());
+               return GuiReader.trans(StringIdGui.TITLE_LIBRARY, Version
+                               .getCurrentVersion().toString());
        }
 }