Instance: use getInstance()
[nikiroo-utils.git] / src / be / nikiroo / fanfix / reader / ui / GuiReaderFrame.java
index c0e8ec6fc430444788f26f03263d696e580d7744..e0ef6d72f8a6b75805e3989a46591ae5e7abbbaf 100644 (file)
@@ -36,7 +36,7 @@ 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;
@@ -103,6 +103,7 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                        popup.add(createMenuItemSetCoverForSource());
                        popup.add(createMenuItemSetCoverForAuthor());
                }
+               popup.add(createMenuItemDownloadToCache());
                popup.add(createMenuItemClearCache());
                if (status.isWritable()) {
                        popup.add(createMenuItemRedownload());
@@ -184,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();
@@ -386,8 +388,7 @@ 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(850, 600);
@@ -412,8 +413,8 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                ConfigEditor<UiConfig> ed = new ConfigEditor<UiConfig>(
-                                               UiConfig.class, Instance.getUiConfig(), GuiReader
-                                                               .trans(StringIdGui.SUBTITLE_CONFIG_UI));
+                                               UiConfig.class, Instance.getInstance().getUiConfig(),
+                                               GuiReader.trans(StringIdGui.SUBTITLE_CONFIG_UI));
                                JFrame frame = new JFrame(title);
                                frame.add(ed);
                                frame.setSize(800, 600);
@@ -475,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);
                                                                }
                                                        }
                                                });
@@ -756,10 +757,9 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
                                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) {
-                                                       MetaData newMeta = story.getMeta();
+                                               public void run(MetaData newMeta) {
                                                        if (!newMeta.getSource().equals(meta.getSource())) {
                                                                reader.changeSource(newMeta.getLuid(),
                                                                                meta.getSource());
@@ -772,6 +772,29 @@ class GuiReaderFrame extends JFrame implements FrameHelper {
 
                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.
@@ -952,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() {