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}.
41 * @param info the information about the story to represent
42 * @param seeWordCount TRUE to see word counts, FALSE to see authors
44 public BookLine(BookInfo info
, boolean seeWordCount
) {
46 this.seeWordCount
= seeWordCount
;
52 * Initialise this {@link BookLine}.
54 protected void init() {
55 iconCached
= new JLabel(" ◉ ");
56 iconNotCached
= new JLabel(" ○ ");
58 iconNotCached
.setForeground(BookCoverImager
.UNCACHED_ICON_COLOR
);
59 iconCached
.setForeground(BookCoverImager
.UNCACHED_ICON_COLOR
);
60 iconCached
.setPreferredSize(iconNotCached
.getPreferredSize());
63 secondary
= new JLabel();
64 secondary
.setForeground(AUTHOR_COLOR
);
66 JLabel id
= new JLabel(info
.getMeta().getLuid());
67 id
.setPreferredSize(new JLabel(" 999 ").getPreferredSize());
68 id
.setForeground(Color
.gray
);
69 id
.setHorizontalAlignment(SwingConstants
.CENTER
);
71 JPanel idTitle
= new JPanel(new BorderLayout());
72 idTitle
.setOpaque(false);
73 idTitle
.add(id
, BorderLayout
.WEST
);
74 idTitle
.add(title
, BorderLayout
.CENTER
);
76 setLayout(new BorderLayout());
77 add(idTitle
, BorderLayout
.CENTER
);
78 add(secondary
, BorderLayout
.EAST
);
84 * The book current selection state.
86 * @return the selection state
88 public boolean isSelected() {
93 * The book current selection state,
95 * @param selected TRUE if it is selected
97 public void setSelected(boolean selected
) {
98 if (this.selected
!= selected
) {
99 this.selected
= selected
;
105 * The item mouse-hover state.
107 * @return TRUE if it is mouse-hovered
109 public boolean isHovered() {
114 * The item mouse-hover state.
116 * @param hovered TRUE if it is mouse-hovered
118 public void setHovered(boolean hovered
) {
119 if (this.hovered
!= hovered
) {
120 this.hovered
= hovered
;
126 * The secondary value content: word count or author.
128 * @return TRUE to see word counts, FALSE to see authors
130 public boolean isSeeWordCount() {
135 * The secondary value content: word count or author.
137 * @param seeWordCount TRUE to see word counts, FALSE to see authors
139 public void setSeeWordCount(boolean seeWordCount
) {
140 if (this.seeWordCount
!= seeWordCount
) {
141 this.seeWordCount
= seeWordCount
;
147 * The information about the book represented by this item.
151 public BookInfo
getInfo() {
156 * Update the title, paint the item.
159 public void paint(Graphics g
) {
165 * Update the title with the currently registered information.
167 protected void updateMeta() {
168 String main
= info
.getMainInfo();
169 String optSecondary
= info
.getSecondaryInfo(seeWordCount
);
171 // TODO: max size limit?
173 secondary
.setText(optSecondary
+ " ");
175 setBackground(BookCoverImager
.getBackground(isEnabled(), isSelected(), isHovered()));
178 remove(iconNotCached
);
179 add(getInfo().isCached() ? iconCached
: iconNotCached
, BorderLayout
.WEST
);