b4c6be41c7123786a9d33bfbd9bb1bfa150a8a19
1 package be
.nikiroo
.fanfix_swing
.gui
.book
;
3 import java
.awt
.BorderLayout
;
5 import java
.awt
.Dimension
;
6 import java
.awt
.Graphics
;
8 import javax
.swing
.JLabel
;
9 import javax
.swing
.JPanel
;
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() {
56 iconCached
= new JLabel(" ");
57 iconNotCached
= new JLabel(" * ");
59 iconNotCached
.setForeground(BookCoverImager
.UNCACHED_ICON_COLOR
);
60 iconCached
.setPreferredSize(iconNotCached
.getPreferredSize());
63 secondary
= new JLabel();
64 secondary
.setForeground(AUTHOR_COLOR
);
66 setLayout(new BorderLayout());
67 add(title
, BorderLayout
.CENTER
);
68 add(secondary
, BorderLayout
.EAST
);
74 * The book current selection state.
76 * @return the selection state
78 public boolean isSelected() {
83 * The book current selection state,
85 * @param selected TRUE if it is selected
87 public void setSelected(boolean selected
) {
88 if (this.selected
!= selected
) {
89 this.selected
= selected
;
95 * The item mouse-hover state.
97 * @return TRUE if it is mouse-hovered
99 public boolean isHovered() {
104 * The item mouse-hover state.
106 * @param hovered TRUE if it is mouse-hovered
108 public void setHovered(boolean hovered
) {
109 if (this.hovered
!= hovered
) {
110 this.hovered
= hovered
;
116 * The secondary value content: word count or author.
118 * @return TRUE to see word counts, FALSE to see authors
120 public boolean isSeeWordCount() {
125 * The secondary value content: word count or author.
127 * @param seeWordCount TRUE to see word counts, FALSE to see authors
129 public void setSeeWordCount(boolean seeWordCount
) {
130 if (this.seeWordCount
!= seeWordCount
) {
131 this.seeWordCount
= seeWordCount
;
137 * The information about the book represented by this item.
141 public BookInfo
getInfo() {
146 * Update the title, paint the item.
149 public void paint(Graphics g
) {
155 * Update the title with the currently registered information.
157 protected void updateMeta() {
158 String main
= info
.getMainInfo();
159 String optSecondary
= info
.getSecondaryInfo(seeWordCount
);
161 // TODO: max size limit?
163 secondary
.setText(optSecondary
+ " ");
165 setBackground(BookCoverImager
.getBackground(isEnabled(), isSelected(), isHovered()));
168 remove(iconNotCached
);
169 add(getInfo().isCached() ? iconCached
: iconNotCached
, BorderLayout
.WEST
);