1 package be
.nikiroo
.fanfix
.reader
.ui
;
3 import java
.awt
.BorderLayout
;
5 import java
.awt
.LayoutManager
;
6 import java
.awt
.event
.ActionEvent
;
7 import java
.awt
.event
.ActionListener
;
9 import javax
.swing
.BorderFactory
;
10 import javax
.swing
.BoxLayout
;
11 import javax
.swing
.JFrame
;
12 import javax
.swing
.JLabel
;
13 import javax
.swing
.JPanel
;
14 import javax
.swing
.SwingConstants
;
16 import be
.nikiroo
.fanfix
.bundles
.StringIdGui
;
17 import be
.nikiroo
.fanfix
.data
.Chapter
;
18 import be
.nikiroo
.fanfix
.data
.MetaData
;
19 import be
.nikiroo
.fanfix
.data
.Story
;
20 import be
.nikiroo
.fanfix
.library
.BasicLibrary
;
23 * An internal, Swing-based {@link Story} viewer.
25 * Works on both text and image document (see {@link MetaData#isImageDocument()}
30 public class GuiReaderViewer
extends JFrame
{
31 private static final long serialVersionUID
= 1L;
34 private MetaData meta
;
36 private GuiReaderPropertiesPane descPane
;
37 private GuiReaderViewerPanel mainPanel
;
38 private GuiReaderNavBar navbar
;
41 * Create a new {@link Story} viewer.
44 * the {@link BasicLibrary} to load the cover from
46 * the {@link Story} to display
48 public GuiReaderViewer(BasicLibrary lib
, Story story
) {
49 setTitle(GuiReader
.trans(StringIdGui
.TITLE_STORY
, story
.getMeta()
50 .getLuid(), story
.getMeta().getTitle()));
55 this.meta
= story
.getMeta();
64 * Initialise the base panel with everything but the navigation buttons.
67 * the {@link BasicLibrary} to use to retrieve the cover image in
68 * the description panel
70 private void initGuiBase(BasicLibrary lib
) {
71 setLayout(new BorderLayout());
74 title
.setFont(new Font(Font
.SERIF
, Font
.BOLD
,
75 title
.getFont().getSize() * 3));
76 title
.setText(meta
.getTitle());
77 title
.setHorizontalAlignment(SwingConstants
.CENTER
);
78 title
.setBorder(BorderFactory
.createEmptyBorder(10, 10, 10, 10));
79 add(title
, BorderLayout
.NORTH
);
81 JPanel contentPane
= new JPanel(new BorderLayout());
82 add(contentPane
, BorderLayout
.CENTER
);
84 descPane
= new GuiReaderPropertiesPane(lib
, meta
);
85 contentPane
.add(descPane
, BorderLayout
.NORTH
);
87 mainPanel
= new GuiReaderViewerPanel(story
);
88 contentPane
.add(mainPanel
, BorderLayout
.CENTER
);
92 * Create the 4 navigation buttons in {@link GuiReaderViewer#navButtons} and
95 private void initGuiNavButtons() {
96 navbar
= new GuiReaderNavBar(-1, story
.getChapters().size() - 1) {
97 private static final long serialVersionUID
= 1L;
100 protected String
computeLabel(int index
, int min
, int max
) {
104 chap
= meta
.getResume();
105 descPane
.setVisible(true);
107 chap
= story
.getChapters().get(chapter
);
108 descPane
.setVisible(false);
111 String chapterDisplay
= GuiReader
.trans(
112 StringIdGui
.CHAPTER_HTML_UNNAMED
, chap
.getNumber(),
113 story
.getChapters().size());
114 if (chap
.getName() != null && !chap
.getName().trim().isEmpty()) {
115 chapterDisplay
= GuiReader
.trans(
116 StringIdGui
.CHAPTER_HTML_NAMED
, chap
.getNumber(),
117 story
.getChapters().size(), chap
.getName());
120 return "<HTML>" + chapterDisplay
+ "</HTML>";
124 navbar
.addActionListener(new ActionListener() {
126 public void actionPerformed(ActionEvent e
) {
127 setChapter(navbar
.getIndex());
131 JPanel navButtonsPane
= new JPanel();
132 LayoutManager layout
= new BoxLayout(navButtonsPane
, BoxLayout
.X_AXIS
);
133 navButtonsPane
.setLayout(layout
);
135 add(navbar
, BorderLayout
.SOUTH
);
139 * Set the current chapter, 0-based.
141 * Chapter -1 is reserved for the description page.
144 * the chapter number to set
146 private void setChapter(int chapter
) {
149 chap
= meta
.getResume();
150 descPane
.setVisible(true);
152 chap
= story
.getChapters().get(chapter
);
153 descPane
.setVisible(false);
156 mainPanel
.setChapter(chap
);