329c714e200c8f3b04aac2b2736a5e9b76867c0c
1 package be
.nikiroo
.fanfix_swing
.gui
.book
;
3 import java
.awt
.BorderLayout
;
4 import java
.awt
.Dimension
;
5 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
.library
.BasicLibrary
;
13 import be
.nikiroo
.fanfix_swing
.gui
.BooksPanel
;
16 * A book item presented in a {@link BooksPanel}.
18 * Can be a story, or a comic or... a group.
22 public class BookBlock
extends BookLine
{
23 static private final long serialVersionUID
= 1L;
24 static private Image empty
= BookCoverImager
.generateCoverImage(null,
28 private Image coverImage
;
31 * Create a new {@link BookBlock} item for the given {@link Story}.
34 * the information about the story to represent
36 * TRUE to see word counts, FALSE to see authors
38 public BookBlock(BookInfo info
, boolean seeWordCount
) {
39 super(info
, seeWordCount
);
43 protected void init() {
48 JPanel filler
= new JPanel();
49 filler
.setPreferredSize(new Dimension(BookCoverImager
.getCoverWidth(),
50 BookCoverImager
.getCoverHeight()));
51 filler
.setOpaque(false);
53 setLayout(new BorderLayout(10, 10));
54 add(filler
, BorderLayout
.CENTER
);
55 add(title
, BorderLayout
.SOUTH
);
59 * the cover image to use a base (see
60 * {@link BookCoverImager#generateCoverImage(BasicLibrary, BookInfo)})
65 public void setCoverImage(Image coverImage
) {
66 this.coverImage
= coverImage
;
70 public void paint(Graphics g
) {
72 g
.drawImage(coverImage
,
73 BookCoverImager
.TEXT_WIDTH
- BookCoverImager
.COVER_WIDTH
, 0,
75 BookCoverImager
.paintOverlay(g
, isEnabled(), isSelected(), isHovered(),
76 getInfo().isCached());
80 protected void updateMeta() {
81 String main
= getMainInfoDisplay();
82 String optSecondary
= getSecondaryInfoDisplay(isSeeWordCount());
83 String color
= String
.format("#%X%X%X", AUTHOR_COLOR
.getRed(),
84 AUTHOR_COLOR
.getGreen(), AUTHOR_COLOR
.getBlue());
85 title
.setText(String
.format("<html>"
86 + "<body style='width: %d px; height: %d px; text-align: center;'>"
87 + "%s" + "<br>" + "<span style='color: %s;'>" + "%s" + "</span>"
88 + "</body>" + "</html>", BookCoverImager
.TEXT_WIDTH
,
89 BookCoverImager
.TEXT_HEIGHT
, main
, color
, optSecondary
));
91 setBackground(BookCoverImager
.getBackground(isEnabled(), isSelected(),
96 * Generate a cover icon based upon the given {@link BookInfo}.
99 * the library the meta comes from
101 * the {@link BookInfo}
105 static public java
.awt
.Image
generateCoverImage(BasicLibrary lib
,
107 return BookCoverImager
.generateCoverImage(lib
, info
);