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, (BookInfo
) null);
27 private Image coverImage
;
30 * Create a new {@link BookBlock} item for the given {@link Story}.
32 * @param info the information about the story to represent
33 * @param seeWordCount TRUE to see word counts, FALSE to see authors
35 public BookBlock(BookInfo info
, boolean seeWordCount
) {
36 super(info
, seeWordCount
);
40 protected void init() {
45 JPanel filler
= new JPanel();
46 filler
.setPreferredSize(new Dimension(BookCoverImager
.getCoverWidth(), BookCoverImager
.getCoverHeight()));
47 filler
.setOpaque(false);
49 setLayout(new BorderLayout(10, 10));
50 add(filler
, BorderLayout
.CENTER
);
51 add(title
, BorderLayout
.SOUTH
);
55 * the cover image to use a base (see
56 * {@link BookCoverImager#generateCoverImage(BasicLibrary, BookInfo)})
58 * @param coverImage the image
60 public void setCoverImage(Image coverImage
) {
61 this.coverImage
= coverImage
;
65 public void paint(Graphics g
) {
67 g
.drawImage(coverImage
, BookCoverImager
.TEXT_WIDTH
- BookCoverImager
.COVER_WIDTH
, 0, null);
68 BookCoverImager
.paintOverlay(g
, isEnabled(), isSelected(), isHovered(), getInfo().isCached());
72 protected void updateMeta() {
73 String main
= getInfo().getMainInfo();
74 String optSecondary
= getInfo().getSecondaryInfo(isSeeWordCount());
75 String color
= String
.format("#%X%X%X", AUTHOR_COLOR
.getRed(), AUTHOR_COLOR
.getGreen(), AUTHOR_COLOR
.getBlue());
76 title
.setText(String
.format(
77 "<html>" + "<body style='width: %d px; height: %d px; text-align: center;'>" + "%s" + "<br>"
78 + "<span style='color: %s;'>" + "%s" + "</span>" + "</body>" + "</html>",
79 BookCoverImager
.TEXT_WIDTH
, BookCoverImager
.TEXT_HEIGHT
, main
, color
, optSecondary
));
81 setBackground(BookCoverImager
.getBackground(isEnabled(), isSelected(), isHovered()));
85 * Generate a cover icon based upon the given {@link BookInfo}.
87 * @param lib the library the meta comes from
88 * @param info the {@link BookInfo}
92 static public java
.awt
.Image
generateCoverImage(BasicLibrary lib
, BookInfo info
) {
93 return BookCoverImager
.generateCoverImage(lib
, info
);