gui: code cleanup for properties
[fanfix.git] / src / be / nikiroo / fanfix / reader / ui / GuiReaderPropertiesPane.java
1 package be.nikiroo.fanfix.reader.ui;
2
3 import java.awt.BorderLayout;
4 import java.awt.Color;
5 import java.awt.Font;
6 import java.util.Map;
7
8 import javax.swing.BorderFactory;
9 import javax.swing.BoxLayout;
10 import javax.swing.ImageIcon;
11 import javax.swing.JLabel;
12 import javax.swing.JPanel;
13 import javax.swing.JTextArea;
14
15 import be.nikiroo.fanfix.data.MetaData;
16 import be.nikiroo.fanfix.data.Story;
17 import be.nikiroo.fanfix.library.BasicLibrary;
18 import be.nikiroo.fanfix.reader.BasicReader;
19
20 /**
21 * A panel displaying properties and other information of a {@link Story}.
22 *
23 * @author niki
24 */
25 public class GuiReaderPropertiesPane extends JPanel {
26 private static final long serialVersionUID = 1L;
27 private final int space = 10;
28
29 /**
30 * Create a new {@link GuiReaderPropertiesPane}.
31 *
32 * @param lib
33 * the library to use for the cover image
34 * @param meta
35 * the meta to describe
36 */
37 public GuiReaderPropertiesPane(BasicLibrary lib, MetaData meta) {
38 // Image
39 ImageIcon img = GuiReaderCoverImager.generateCoverIcon(lib, meta);
40
41 setLayout(new BorderLayout());
42
43 // Main panel
44 JPanel mainPanel = new JPanel(new BorderLayout());
45 JPanel mainPanelKeys = new JPanel();
46 mainPanelKeys.setLayout(new BoxLayout(mainPanelKeys, BoxLayout.Y_AXIS));
47 JPanel mainPanelValues = new JPanel();
48 mainPanelValues.setLayout(new BoxLayout(mainPanelValues,
49 BoxLayout.Y_AXIS));
50
51 mainPanel.add(mainPanelKeys, BorderLayout.WEST);
52 mainPanel.add(mainPanelValues, BorderLayout.CENTER);
53
54 Map<String, String> desc = BasicReader.getMetaDesc(meta);
55
56 Color trans = new Color(0, 0, 0, 1);
57 Color base = mainPanelValues.getBackground();
58 for (String key : desc.keySet()) {
59 JTextArea jKey = new JTextArea(key);
60 jKey.setFont(new Font(jKey.getFont().getFontName(), Font.BOLD, jKey
61 .getFont().getSize()));
62 jKey.setEditable(false);
63 jKey.setLineWrap(false);
64 jKey.setBackground(trans);
65 mainPanelKeys.add(jKey);
66
67 final JTextArea jValue = new JTextArea(desc.get(key));
68 jValue.setEditable(false);
69 jValue.setLineWrap(false);
70 jValue.setBackground(base);
71 mainPanelValues.add(jValue);
72 }
73
74 // Image
75 JLabel imgLabel = new JLabel(img);
76 imgLabel.setVerticalAlignment(JLabel.TOP);
77
78 // Borders
79 mainPanelKeys.setBorder(BorderFactory.createEmptyBorder(space, space,
80 space, space));
81 mainPanelValues.setBorder(BorderFactory.createEmptyBorder(space, space,
82 space, space));
83 imgLabel.setBorder(BorderFactory.createEmptyBorder(0, space, space, 0));
84
85 // Add all
86 add(imgLabel, BorderLayout.WEST);
87 add(mainPanel, BorderLayout.CENTER);
88 }
89
90 /**
91 * The invisible border size (multiply by 2 if you need the total width or
92 * the total height).
93 *
94 * @return the invisible border thickness
95 */
96 public int getBorderThickness() {
97 return space;
98 }
99 }