1 package be
.nikiroo
.fanfix_swing
.gui
;
3 import java
.awt
.BorderLayout
;
5 import java
.awt
.Dimension
;
7 import java
.util
.concurrent
.ExecutionException
;
9 import javax
.swing
.ImageIcon
;
10 import javax
.swing
.JLabel
;
11 import javax
.swing
.JPanel
;
12 import javax
.swing
.SwingWorker
;
13 import javax
.swing
.border
.EmptyBorder
;
15 import be
.nikiroo
.fanfix
.Instance
;
16 import be
.nikiroo
.fanfix_swing
.gui
.book
.BookBlock
;
17 import be
.nikiroo
.fanfix_swing
.gui
.book
.BookInfo
;
20 * Display detailed informations about a {@link BookInfo}.
22 * Actually, just its name, the number of stories it contains and a small image
27 public class DetailsPanel
extends JPanel
{
28 private static final long serialVersionUID
= 1L;
35 * Create a new {@link DetailsPanel}.
37 public DetailsPanel() {
38 this.setLayout(new BorderLayout());
40 this.setPreferredSize(new Dimension(300, 300));
41 this.setMinimumSize(new Dimension(200, 200));
43 icon
= config(new JLabel(), Color
.black
);
44 name
= config(new JLabel(), Color
.black
);
45 opt
= config(new JLabel(), Color
.gray
);
47 JPanel panel
= new JPanel(new BorderLayout());
48 panel
.add(name
, BorderLayout
.NORTH
);
49 panel
.add(opt
, BorderLayout
.SOUTH
);
50 panel
.setBorder(new EmptyBorder(0, 0, 10, 0));
52 this.add(icon
, BorderLayout
.CENTER
);
53 this.add(panel
, BorderLayout
.SOUTH
);
59 * Configure a {@link JLabel} with the given colour.
61 * @param label the label to configure
62 * @param color the colour to use
64 * @return the (same) configured label
66 private JLabel
config(JLabel label
, Color color
) {
67 label
.setAlignmentX(CENTER_ALIGNMENT
);
68 label
.setHorizontalAlignment(JLabel
.CENTER
);
69 label
.setHorizontalTextPosition(JLabel
.CENTER
);
70 label
.setForeground(color
);
75 * Set the {@link BookInfo} you want to see displayed here.
77 * @param info the {@link BookInfo} to display
79 public void setBook(final BookInfo info
) {
85 name
.setText(info
.getMainInfo());
86 opt
.setText(info
.getSecondaryInfo(true));
87 new SwingWorker
<Image
, Void
>() {
89 protected Image
doInBackground() throws Exception
{
90 return BookBlock
.generateCoverImage(Instance
.getInstance().getLibrary(), info
);
94 protected void done() {
96 icon
.setIcon(new ImageIcon(get()));
97 } catch (InterruptedException e
) {
98 } catch (ExecutionException e
) {