Instance: use getInstance()
[nikiroo-utils.git] / src / be / nikiroo / fanfix / reader / ui / GuiReaderViewerPanel.java
index 18f6aca577f760fddf4e163b1f4d120658f6bc2a..0577a0ab2f4bac5c734e5282d589f5d8004926cc 100644 (file)
@@ -18,7 +18,9 @@ import javax.swing.JScrollPane;
 import javax.swing.SwingConstants;
 
 import be.nikiroo.fanfix.Instance;
+import be.nikiroo.fanfix.bundles.StringIdGui;
 import be.nikiroo.fanfix.data.Chapter;
+import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.utils.Image;
 import be.nikiroo.utils.ui.ImageUtilsAwt;
@@ -50,14 +52,27 @@ public class GuiReaderViewerPanel extends JPanel {
         * Create a new viewer.
         * 
         * @param story
-        *            the {@link Story} to work on.
+        *            the {@link Story} to work on
         */
        public GuiReaderViewerPanel(Story story) {
+               this(story.getMeta(), story.getMeta().isImageDocument());
+       }
+
+       /**
+        * Create a new viewer.
+        * 
+        * @param meta
+        *            the {@link MetaData} of the story to show
+        * @param isImageDocument
+        *            TRUE if it is an image document, FALSE if not
+        */
+       public GuiReaderViewerPanel(MetaData meta, boolean isImageDocument) {
                super(new BorderLayout());
 
-               this.imageDocument = story.getMeta().isImageDocument();
+               this.imageDocument = isImageDocument;
 
                this.text = new JEditorPane("text/html", "");
+               text.setEditable(false);
                text.setAlignmentY(TOP_ALIGNMENT);
                htmlOutput = new GuiReaderViewerTextOutput();
 
@@ -68,6 +83,10 @@ public class GuiReaderViewerPanel extends JPanel {
                                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
                scroll.getVerticalScrollBar().setUnitIncrement(16);
 
+               // TODO:
+               // JButton up = new BasicArrowButton(BasicArrowButton.NORTH);
+               // JButton down = new BasicArrowButton(BasicArrowButton.SOUTH);
+
                if (!imageDocument) {
                        add(scroll, BorderLayout.CENTER);
                } else {
@@ -100,7 +119,7 @@ public class GuiReaderViewerPanel extends JPanel {
                        main.invalidate();
                }
 
-               setChapter(story.getMeta().getResume());
+               setChapter(meta.getResume());
        }
 
        /**
@@ -194,13 +213,17 @@ public class GuiReaderViewerPanel extends JPanel {
                }
 
                imageProgress.setValue(i);
-               imageProgress.setString(String.format("Image %d / %d", i + 1, chap
-                               .getParagraphs().size()));
+               imageProgress.setString(GuiReader.trans(StringIdGui.IMAGE_PROGRESSION,
+                               i + 1, chap.getParagraphs().size()));
 
                currentImage = i;
 
                final Image img = chap.getParagraphs().get(i).getContentImage();
 
+               // prepare the viewport to get the right sizes later on
+               image.setIcon(null);
+               scroll.setViewportView(image);
+
                new Thread(new Runnable() {
                        @Override
                        public void run() {
@@ -262,7 +285,7 @@ public class GuiReaderViewerPanel extends JPanel {
                                }
                        });
                } catch (Exception e) {
-                       Instance.getTraceHandler().error(
+                       Instance.getInstance().getTraceHandler().error(
                                        new Exception("Failed to load image into label", e));
                        EventQueue.invokeLater(new Runnable() {
                                @Override