1 package be
.nikiroo
.fanfix
.reader
.ui
;
3 import java
.awt
.BorderLayout
;
6 import java
.awt
.LayoutManager
;
7 import java
.awt
.event
.ActionEvent
;
8 import java
.awt
.event
.ActionListener
;
10 import javax
.swing
.BorderFactory
;
11 import javax
.swing
.BoxLayout
;
12 import javax
.swing
.JButton
;
13 import javax
.swing
.JFrame
;
14 import javax
.swing
.JLabel
;
15 import javax
.swing
.JPanel
;
16 import javax
.swing
.JScrollPane
;
17 import javax
.swing
.SwingConstants
;
19 import be
.nikiroo
.fanfix
.data
.Chapter
;
20 import be
.nikiroo
.fanfix
.data
.MetaData
;
21 import be
.nikiroo
.fanfix
.data
.Story
;
22 import be
.nikiroo
.fanfix
.library
.BasicLibrary
;
24 public class GuiReaderTextViewer
extends JFrame
{
25 private static final long serialVersionUID
= 1L;
28 private MetaData meta
;
31 private JLabel chapterLabel
;
32 private GuiReaderPropertiesPane descPane
;
33 private int currentChapter
= -42; // cover = -1
34 private GuiReaderTextViewerOutput htmlOutput
= new GuiReaderTextViewerOutput();
36 public GuiReaderTextViewer(BasicLibrary lib
, Story story
) {
37 super(story
.getMeta().getLuid() + ": " + story
.getMeta().getTitle());
42 this.meta
= story
.getMeta();
50 private void initGuiBase(BasicLibrary lib
) {
51 setLayout(new BorderLayout());
54 title
.setFont(new Font(Font
.SERIF
, Font
.BOLD
,
55 title
.getFont().getSize() * 3));
56 title
.setText(meta
.getTitle());
57 title
.setHorizontalAlignment(SwingConstants
.CENTER
);
58 title
.setBorder(BorderFactory
.createEmptyBorder(10, 10, 10, 10));
59 add(title
, BorderLayout
.NORTH
);
61 JPanel contentPane
= new JPanel(new BorderLayout());
62 add(contentPane
, BorderLayout
.CENTER
);
64 descPane
= new GuiReaderPropertiesPane(lib
, meta
);
65 contentPane
.add(descPane
, BorderLayout
.NORTH
);
68 text
.setAlignmentY(TOP_ALIGNMENT
);
70 // TODO: why is it broken?
71 // text.setPreferredSize(new Dimension(500, 500));
73 JScrollPane scroll
= new JScrollPane(text
);
74 scroll
.getVerticalScrollBar().setUnitIncrement(16);
75 contentPane
.add(scroll
, BorderLayout
.CENTER
);
78 private void initGuiNavButtons() {
79 JPanel navButtons
= new JPanel();
80 LayoutManager layout
= new BoxLayout(navButtons
, BoxLayout
.X_AXIS
);
81 navButtons
.setLayout(layout
);
83 navButtons
.add(createNavButton("<<", new ActionListener() {
85 public void actionPerformed(ActionEvent e
) {
89 navButtons
.add(createNavButton(" < ", new ActionListener() {
91 public void actionPerformed(ActionEvent e
) {
92 setChapter(currentChapter
- 1);
95 navButtons
.add(createNavButton(" > ", new ActionListener() {
97 public void actionPerformed(ActionEvent e
) {
98 setChapter(currentChapter
+ 1);
101 navButtons
.add(createNavButton(">>", new ActionListener() {
103 public void actionPerformed(ActionEvent e
) {
104 setChapter(story
.getChapters().size() - 1);
108 add(navButtons
, BorderLayout
.SOUTH
);
110 chapterLabel
= new JLabel("");
111 navButtons
.add(chapterLabel
);
114 private JButton
createNavButton(String text
, ActionListener action
) {
115 JButton navButton
= new JButton(text
);
116 navButton
.addActionListener(action
);
117 navButton
.setForeground(Color
.BLUE
);
121 private void setChapter(int chapter
) {
122 if (chapter
>= -1 && chapter
< story
.getChapters().size()
123 && chapter
!= currentChapter
) {
124 currentChapter
= chapter
;
128 chap
= meta
.getResume();
131 chap
= story
.getChapters().get(chapter
);
132 descPane
.setVisible(false);
135 chapterLabel
.setText("<HTML> <B>Chapter "
136 + chap
.getNumber() + "</B>: " + chap
.getName() + "</HTML>");
138 text
.setText(htmlOutput
.convert(chap
));
142 private void setCoverPage() {
143 descPane
.setVisible(true);