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
;
10 import be
.nikiroo
.fanfix
.data
.Story
;
11 import be
.nikiroo
.fanfix_swing
.gui
.BooksPanel
;
14 * A book item presented in a {@link BooksPanel}.
16 * Can be a story, or a comic or... a group.
20 public class BookLine
extends JPanel
{
21 private static final long serialVersionUID
= 1L;
23 /** Colour used for the seconday item (author/word count). */
24 protected static final Color AUTHOR_COLOR
= new Color(128, 128, 128);
26 private boolean selected
;
27 private boolean hovered
;
29 private BookInfo info
;
30 private boolean seeWordCount
;
33 private JLabel secondary
;
34 private JLabel iconCached
;
35 private JLabel iconNotCached
;
38 * Create a new {@link BookLine} item for the given {@link Story}.
40 * @param info the information about the story to represent
41 * @param seeWordCount TRUE to see word counts, FALSE to see authors
43 public BookLine(BookInfo info
, boolean seeWordCount
) {
45 this.seeWordCount
= seeWordCount
;
51 * Initialise this {@link BookLine}.
53 protected void init() {
55 iconCached
= new JLabel(" ");
56 iconNotCached
= new JLabel(" * ");
59 secondary
= new JLabel();
60 secondary
.setForeground(AUTHOR_COLOR
);
62 setLayout(new BorderLayout());
63 add(title
, BorderLayout
.CENTER
);
64 add(secondary
, BorderLayout
.EAST
);
70 * The book current selection state.
72 * @return the selection state
74 public boolean isSelected() {
79 * The book current selection state,
81 * @param selected TRUE if it is selected
83 public void setSelected(boolean selected
) {
84 if (this.selected
!= selected
) {
85 this.selected
= selected
;
91 * The item mouse-hover state.
93 * @return TRUE if it is mouse-hovered
95 public boolean isHovered() {
100 * The item mouse-hover state.
102 * @param hovered TRUE if it is mouse-hovered
104 public void setHovered(boolean hovered
) {
105 if (this.hovered
!= hovered
) {
106 this.hovered
= hovered
;
112 * The secondary value content: word count or author.
114 * @return TRUE to see word counts, FALSE to see authors
116 public boolean isSeeWordCount() {
121 * The secondary value content: word count or author.
123 * @param seeWordCount TRUE to see word counts, FALSE to see authors
125 public void setSeeWordCount(boolean seeWordCount
) {
126 if (this.seeWordCount
!= seeWordCount
) {
127 this.seeWordCount
= seeWordCount
;
133 * The information about the book represented by this item.
137 public BookInfo
getInfo() {
142 * Update the title, paint the item.
145 public void paint(Graphics g
) {
151 * Update the title with the currently registered information.
153 protected void updateMeta() {
154 String main
= info
.getMainInfo();
155 String optSecondary
= info
.getSecondaryInfo(seeWordCount
);
157 //TODO: max size limit?
159 secondary
.setText(optSecondary
+ " ");
161 setBackground(BookCoverImager
.getBackground(isEnabled(), isSelected(), isHovered()));
164 remove(iconNotCached
);
165 add(getInfo().isCached() ? iconCached
: iconNotCached
, BorderLayout
.WEST
);