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
.reader
.ui
.GuiReaderBook
.BookActionListener
;
14 import be
.nikiroo
.utils
.ui
.WrapLayout
;
17 * A group of {@link GuiReaderBook}s for display.
21 public class GuiReaderGroup
extends JPanel
{
22 private static final long serialVersionUID
= 1L;
23 private BookActionListener action
;
24 private Color backgroundColor
;
25 private GuiReader reader
;
26 private List
<GuiReaderBookInfo
> infos
;
27 private List
<GuiReaderBook
> books
;
29 private boolean words
; // words or authors (secondary info on books)
32 * Create a new {@link GuiReaderGroup}.
35 * the {@link GuiReaderBook} used to probe some information about
38 * the title of this group
39 * @param backgroundColor
40 * the background colour to use (or NULL for default)
42 public GuiReaderGroup(GuiReader reader
, String title
, Color backgroundColor
) {
44 this.backgroundColor
= backgroundColor
;
46 this.pane
= new JPanel();
48 pane
.setLayout(new WrapLayout(WrapLayout
.LEADING
, 5, 5));
49 if (backgroundColor
!= null) {
50 pane
.setBackground(backgroundColor
);
51 setBackground(backgroundColor
);
54 setLayout(new BorderLayout(0, 10));
55 add(pane
, BorderLayout
.CENTER
);
58 if (title
.isEmpty()) {
62 JLabel label
= new JLabel();
63 label
.setText(String
.format("<html>"
64 + "<body style='text-align: center; color: gray;'><br><b>"
65 + "%s" + "</b></body>" + "</html>", title
));
66 label
.setHorizontalAlignment(JLabel
.CENTER
);
67 add(label
, BorderLayout
.NORTH
);
72 * Set the {@link ActionListener} that will be fired on each
73 * {@link GuiReaderBook} action.
78 public void setActionListener(BookActionListener action
) {
80 refreshBooks(infos
, words
);
84 * Refresh the list of {@link GuiReaderBook}s displayed in the control.
87 * the new list of stories
89 * TRUE to see word counts, FALSE to see authors
91 public void refreshBooks(List
<GuiReaderBookInfo
> infos
, boolean seeWordcount
) {
93 refreshBooks(seeWordcount
);
97 * Refresh the list of {@link GuiReaderBook}s displayed in the control.
99 * Will not change the current stories.
101 * @param seeWordcount
102 * TRUE to see word counts, FALSE to see authors
104 public void refreshBooks(boolean seeWordcount
) {
105 this.words
= seeWordcount
;
107 books
= new ArrayList
<GuiReaderBook
>();
113 for (GuiReaderBookInfo info
: infos
) {
114 boolean isCached
= false;
115 if (info
.getMeta() != null) {
116 isCached
= reader
.isCached(info
.getMeta().getLuid());
119 GuiReaderBook book
= new GuiReaderBook(reader
, info
, isCached
,
121 if (backgroundColor
!= null) {
122 book
.setBackground(backgroundColor
);
127 book
.addActionListener(new BookActionListener() {
129 public void select(GuiReaderBook book
) {
130 for (GuiReaderBook abook
: books
) {
131 abook
.setSelected(abook
== book
);
136 public void popupRequested(GuiReaderBook book
, MouseEvent e
) {
140 public void action(GuiReaderBook book
) {
144 if (action
!= null) {
145 book
.addActionListener(action
);
159 * Enables or disables this component, depending on the value of the
160 * parameter <code>b</code>. An enabled component can respond to user input
161 * and generate events. Components are enabled initially by default.
163 * Disabling this component will also affect its children.
166 * If <code>true</code>, this component is enabled; otherwise
167 * this component is disabled
170 public void setEnabled(boolean b
) {
172 for (GuiReaderBook book
: books
) {