1 package be
.nikiroo
.fanfix
.reader
;
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
.data
.MetaData
;
14 import be
.nikiroo
.fanfix
.reader
.LocalReaderBook
.BookActionListener
;
15 import be
.nikiroo
.utils
.ui
.WrapLayout
;
18 * A group of {@link LocalReaderBook}s for display.
22 public class LocalReaderGroup
extends JPanel
{
23 private static final long serialVersionUID
= 1L;
24 private BookActionListener action
;
25 private Color backgroundColor
;
26 private LocalReader reader
;
27 private List
<MetaData
> stories
;
28 private List
<LocalReaderBook
> books
;
30 private boolean words
; // words or authors (secondary info on books)
33 * Create a new {@link LocalReaderGroup}.
36 * the {@link LocalReaderBook} used to probe some information
39 * the title of this group
40 * @param backgroundColor
41 * the background colour to use (or NULL for default)
43 public LocalReaderGroup(LocalReader reader
, String title
,
44 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 LocalReaderBook} action.
80 public void setActionListener(BookActionListener action
) {
82 refreshBooks(stories
, words
);
86 * Refresh the list of {@link LocalReaderBook}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
<LocalReaderBook
>();
102 if (stories
!= null) {
103 for (MetaData meta
: stories
) {
104 LocalReaderBook book
= new LocalReaderBook(meta
,
105 reader
.isCached(meta
.getLuid()), seeWordcount
);
106 if (backgroundColor
!= null) {
107 book
.setBackground(backgroundColor
);
112 book
.addActionListener(new BookActionListener() {
113 public void select(LocalReaderBook book
) {
114 for (LocalReaderBook abook
: books
) {
115 abook
.setSelected(abook
== book
);
119 public void popupRequested(LocalReaderBook book
,
123 public void action(LocalReaderBook book
) {
127 if (action
!= null) {
128 book
.addActionListener(action
);
142 * Enables or disables this component, depending on the value of the
143 * parameter <code>b</code>. An enabled component can respond to user input
144 * and generate events. Components are enabled initially by default.
146 * Disabling this component will also affect its children.
149 * If <code>true</code>, this component is enabled; otherwise
150 * this component is disabled
153 public void setEnabled(boolean b
) {
155 for (LocalReaderBook book
: books
) {