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
.management
.RuntimeErrorException
;
11 import javax
.swing
.JLabel
;
12 import javax
.swing
.JPanel
;
14 import be
.nikiroo
.fanfix
.data
.MetaData
;
15 import be
.nikiroo
.fanfix
.reader
.ui
.GuiReaderBook
.BookActionListener
;
16 import be
.nikiroo
.utils
.ui
.WrapLayout
;
19 * A group of {@link GuiReaderBook}s for display.
23 public class GuiReaderGroup
extends JPanel
{
24 private static final long serialVersionUID
= 1L;
25 private BookActionListener action
;
26 private Color backgroundColor
;
27 private GuiReader reader
;
28 private List
<MetaData
> stories
;
29 private List
<GuiReaderBook
> books
;
31 private boolean words
; // words or authors (secondary info on books)
34 * Create a new {@link GuiReaderGroup}.
37 * the {@link GuiReaderBook} used to probe some information about
40 * the title of this group
41 * @param backgroundColor
42 * the background colour to use (or NULL for default)
44 public GuiReaderGroup(GuiReader reader
, String title
, Color backgroundColor
) {
46 this.backgroundColor
= backgroundColor
;
48 this.pane
= new JPanel();
50 pane
.setLayout(new WrapLayout(WrapLayout
.LEADING
, 5, 5));
51 if (backgroundColor
!= null) {
52 pane
.setBackground(backgroundColor
);
53 setBackground(backgroundColor
);
56 setLayout(new BorderLayout(0, 10));
57 add(pane
, BorderLayout
.CENTER
);
60 if (title
.isEmpty()) {
64 JLabel label
= new JLabel();
65 label
.setText(String
.format("<html>"
66 + "<body style='text-align: center; color: gray;'><br><b>"
67 + "%s" + "</b></body>" + "</html>", title
));
68 label
.setHorizontalAlignment(JLabel
.CENTER
);
69 add(label
, BorderLayout
.NORTH
);
74 * Set the {@link ActionListener} that will be fired on each
75 * {@link GuiReaderBook} action.
80 public void setActionListener(BookActionListener action
) {
82 refreshBooks(stories
, words
);
86 * Refresh the list of {@link GuiReaderBook}s displayed in the control.
91 * TRUE to see word counts, FALSE to see authors
93 public void refreshBooks(List
<MetaData
> stories
, boolean seeWordcount
) {
94 this.stories
= stories
;
95 this.words
= seeWordcount
;
97 books
= new ArrayList
<GuiReaderBook
>();
102 if (stories
!= null) {
103 for (MetaData meta
: stories
) {
104 GuiReaderBook book
= new GuiReaderBook(reader
, meta
,
105 reader
.isCached(meta
.getLuid()), seeWordcount
);
106 if (backgroundColor
!= null) {
107 book
.setBackground(backgroundColor
);
112 book
.addActionListener(new BookActionListener() {
114 public void select(GuiReaderBook book
) {
115 for (GuiReaderBook abook
: books
) {
116 abook
.setSelected(abook
== book
);
121 public void popupRequested(GuiReaderBook book
, MouseEvent e
) {
125 public void action(GuiReaderBook book
) {
129 if (action
!= null) {
130 book
.addActionListener(action
);
144 * Enables or disables this component, depending on the value of the
145 * parameter <code>b</code>. An enabled component can respond to user input
146 * and generate events. Components are enabled initially by default.
148 * Disabling this component will also affect its children.
151 * If <code>true</code>, this component is enabled; otherwise
152 * this component is disabled
155 public void setEnabled(boolean b
) {
157 for (GuiReaderBook book
: books
) {