1 package be
.nikiroo
.fanfix
.reader
.ui
;
3 import java
.awt
.BorderLayout
;
5 import java
.awt
.event
.ActionListener
;
6 import java
.awt
.event
.MouseEvent
;
7 import java
.util
.ArrayList
;
10 import javax
.swing
.JLabel
;
11 import javax
.swing
.JPanel
;
13 import be
.nikiroo
.fanfix
.bundles
.StringIdGui
;
14 import be
.nikiroo
.fanfix
.reader
.ui
.GuiReaderBook
.BookActionListener
;
15 import be
.nikiroo
.utils
.ui
.WrapLayout
;
18 * A group of {@link GuiReaderBook}s for display.
22 public class GuiReaderGroup
extends JPanel
{
23 private static final long serialVersionUID
= 1L;
24 private BookActionListener action
;
25 private Color backgroundColor
;
26 private GuiReader reader
;
27 private List
<GuiReaderBookInfo
> infos
;
28 private List
<GuiReaderBook
> books
;
30 private boolean words
; // words or authors (secondary info on books)
33 * Create a new {@link GuiReaderGroup}.
36 * the {@link GuiReaderBook} used to probe some information about
39 * the title of this group
40 * @param backgroundColor
41 * the background colour to use (or NULL for default)
43 public GuiReaderGroup(GuiReader reader
, String title
, Color backgroundColor
) {
45 this.backgroundColor
= backgroundColor
;
47 this.pane
= new JPanel();
49 pane
.setLayout(new WrapLayout(WrapLayout
.LEADING
, 5, 5));
50 if (backgroundColor
!= null) {
51 pane
.setBackground(backgroundColor
);
52 setBackground(backgroundColor
);
55 setLayout(new BorderLayout(0, 10));
56 add(pane
, BorderLayout
.CENTER
);
59 if (title
.isEmpty()) {
60 title
= GuiReader
.trans(StringIdGui
.MENU_AUTHORS_UNKNOWN
);
63 JLabel label
= new JLabel();
64 label
.setText(String
.format("<html>"
65 + "<body style='text-align: center; color: gray;'><br><b>"
66 + "%s" + "</b></body>" + "</html>", title
));
67 label
.setHorizontalAlignment(JLabel
.CENTER
);
68 add(label
, BorderLayout
.NORTH
);
73 * Set the {@link ActionListener} that will be fired on each
74 * {@link GuiReaderBook} action.
79 public void setActionListener(BookActionListener action
) {
81 refreshBooks(infos
, words
);
85 * Refresh the list of {@link GuiReaderBook}s displayed in the control.
88 * the new list of infos
90 * TRUE to see word counts, FALSE to see authors
92 public void refreshBooks(List
<GuiReaderBookInfo
> infos
, boolean seeWordcount
) {
94 refreshBooks(seeWordcount
);
98 * Refresh the list of {@link GuiReaderBook}s displayed in the control.
100 * Will not change the current stories.
102 * @param seeWordcount
103 * TRUE to see word counts, FALSE to see authors
105 public void refreshBooks(boolean seeWordcount
) {
106 this.words
= seeWordcount
;
108 books
= new ArrayList
<GuiReaderBook
>();
114 for (GuiReaderBookInfo info
: infos
) {
115 boolean isCached
= false;
116 if (info
.getMeta() != null) {
117 isCached
= reader
.isCached(info
.getMeta().getLuid());
120 GuiReaderBook book
= new GuiReaderBook(reader
, info
, isCached
,
122 if (backgroundColor
!= null) {
123 book
.setBackground(backgroundColor
);
128 book
.addActionListener(new BookActionListener() {
130 public void select(GuiReaderBook book
) {
131 for (GuiReaderBook abook
: books
) {
132 abook
.setSelected(abook
== book
);
137 public void popupRequested(GuiReaderBook book
, MouseEvent e
) {
141 public void action(GuiReaderBook book
) {
145 if (action
!= null) {
146 book
.addActionListener(action
);
160 * Enables or disables this component, depending on the value of the
161 * parameter <code>b</code>. An enabled component can respond to user input
162 * and generate events. Components are enabled initially by default.
164 * Disabling this component will also affect its children.
167 * If <code>true</code>, this component is enabled; otherwise
168 * this component is disabled
171 public void setEnabled(boolean b
) {
173 for (GuiReaderBook book
: books
) {