1 package be
.nikiroo
.fanfix_swing
.gui
.book
;
3 import java
.awt
.BorderLayout
;
5 import java
.awt
.Graphics
;
7 import javax
.swing
.JLabel
;
8 import javax
.swing
.JPanel
;
9 import javax
.swing
.SwingConstants
;
11 import be
.nikiroo
.fanfix
.data
.Story
;
12 import be
.nikiroo
.fanfix_swing
.gui
.BooksPanel
;
15 * A book item presented in a {@link BooksPanel}.
17 * Can be a story, or a comic or... a group.
21 public class BookLine
extends JPanel
{
22 private static final long serialVersionUID
= 1L;
24 /** Colour used for the seconday item (author/word count). */
25 protected static final Color AUTHOR_COLOR
= new Color(128, 128, 128);
27 private boolean selected
;
28 private boolean hovered
;
30 private BookInfo info
;
31 private boolean seeWordCount
;
34 private JLabel secondary
;
35 private JLabel iconCached
;
36 private JLabel iconNotCached
;
39 * Create a new {@link BookLine} item for the given {@link Story}.
42 * the information about the story to represent
44 * TRUE to see word counts, FALSE to see authors
46 public BookLine(BookInfo info
, boolean seeWordCount
) {
48 this.seeWordCount
= seeWordCount
;
54 * Initialise this {@link BookLine}.
56 protected void init() {
57 iconCached
= new JLabel(" ◉ ");
58 iconNotCached
= new JLabel(" ○ ");
60 iconNotCached
.setForeground(BookCoverImager
.UNCACHED_ICON_COLOR
);
61 iconCached
.setForeground(BookCoverImager
.UNCACHED_ICON_COLOR
);
62 iconCached
.setPreferredSize(iconNotCached
.getPreferredSize());
65 secondary
= new JLabel();
66 secondary
.setForeground(AUTHOR_COLOR
);
68 JLabel id
= new JLabel(info
.getMeta().getLuid());
69 id
.setPreferredSize(new JLabel(" 999 ").getPreferredSize());
70 id
.setForeground(Color
.gray
);
71 id
.setHorizontalAlignment(SwingConstants
.CENTER
);
73 JPanel idTitle
= new JPanel(new BorderLayout());
74 idTitle
.setOpaque(false);
75 idTitle
.add(id
, BorderLayout
.WEST
);
76 idTitle
.add(title
, BorderLayout
.CENTER
);
78 setLayout(new BorderLayout());
79 add(idTitle
, BorderLayout
.CENTER
);
80 add(secondary
, BorderLayout
.EAST
);
86 * The book current selection state.
88 * @return the selection state
90 public boolean isSelected() {
95 * The book current selection state,
98 * TRUE if it is selected
100 public void setSelected(boolean selected
) {
101 if (this.selected
!= selected
) {
102 this.selected
= selected
;
108 * The item mouse-hover state.
110 * @return TRUE if it is mouse-hovered
112 public boolean isHovered() {
117 * The item mouse-hover state.
120 * TRUE if it is mouse-hovered
122 public void setHovered(boolean hovered
) {
123 if (this.hovered
!= hovered
) {
124 this.hovered
= hovered
;
130 * The secondary value content: word count or author.
132 * @return TRUE to see word counts, FALSE to see authors
134 public boolean isSeeWordCount() {
139 * The secondary value content: word count or author.
141 * @param seeWordCount
142 * TRUE to see word counts, FALSE to see authors
144 public void setSeeWordCount(boolean seeWordCount
) {
145 if (this.seeWordCount
!= seeWordCount
) {
146 this.seeWordCount
= seeWordCount
;
152 * The information about the book represented by this item.
156 public BookInfo
getInfo() {
161 * Update the title, paint the item.
164 public void paint(Graphics g
) {
170 * Update the title with the currently registered information.
172 protected void updateMeta() {
173 String main
= info
.getMainInfo();
174 String optSecondary
= info
.getSecondaryInfo(seeWordCount
);
176 // TODO: max size limit?
178 secondary
.setText(optSecondary
+ " ");
180 setBackground(BookCoverImager
.getBackground(isEnabled(), isSelected(),
184 remove(iconNotCached
);
185 add(getInfo().isCached() ? iconCached
: iconNotCached
,