751e37f511c5ed58fda8a7f7aa1885495755e5ea
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;
34 private BookInfo info
;
37 * Create a new {@link DetailsPanel}.
39 public DetailsPanel() {
40 this.setLayout(new BorderLayout());
42 this.setPreferredSize(new Dimension(300, 300));
43 this.setMinimumSize(new Dimension(200, 200));
45 icon
= config(new JLabel(), Color
.black
);
46 name
= config(new JLabel(), Color
.black
);
47 opt
= config(new JLabel(), Color
.gray
);
49 JPanel panel
= new JPanel(new BorderLayout());
50 panel
.add(name
, BorderLayout
.NORTH
);
51 panel
.add(opt
, BorderLayout
.SOUTH
);
52 panel
.setBorder(new EmptyBorder(0, 0, 10, 0));
54 this.add(icon
, BorderLayout
.CENTER
);
55 this.add(panel
, BorderLayout
.SOUTH
);
61 * Configure a {@link JLabel} with the given colour.
63 * @param label the label to configure
64 * @param color the colour to use
66 * @return the (same) configured label
68 private JLabel
config(JLabel label
, Color color
) {
69 label
.setAlignmentX(CENTER_ALIGNMENT
);
70 label
.setHorizontalAlignment(JLabel
.CENTER
);
71 label
.setHorizontalTextPosition(JLabel
.CENTER
);
72 label
.setForeground(color
);
77 * Set the {@link BookInfo} you want to see displayed here.
79 * @param info the {@link BookInfo} to display
81 public void setBook(final BookInfo info
) {
88 } else if (info
.getMainInfo() == null) {
89 name
.setText("All the " + info
.getType().toString().toLowerCase() + "s");
90 opt
.setText(info
.getSecondaryInfo(true));
92 final String myId
= info
.getId();
94 name
.setText(info
.getMainInfo());
95 opt
.setText(info
.getSecondaryInfo(true));
97 new SwingWorker
<Image
, Void
>() {
99 protected Image
doInBackground() throws Exception
{
102 BookInfo current
= DetailsPanel
.this.info
;
103 if (current
!= null && current
.getId().equals(myId
)) {
104 return BookBlock
.generateCoverImage(Instance
.getInstance().getLibrary(), info
);
111 protected void done() {
112 BookInfo current
= DetailsPanel
.this.info
;
113 if (current
!= null && current
.getId().equals(myId
)) {
117 icon
.setIcon(new ImageIcon(img
));
118 } catch (InterruptedException e
) {
119 } catch (ExecutionException e
) {