update chanelog
[nikiroo-utils.git] / src / be / nikiroo / fanfix / reader / ui / GuiReaderPropertiesFrame.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.List;
7 import java.util.Map.Entry;
8
9 import javax.swing.BorderFactory;
10 import javax.swing.BoxLayout;
11 import javax.swing.ImageIcon;
12 import javax.swing.JFrame;
13 import javax.swing.JLabel;
14 import javax.swing.JPanel;
15 import javax.swing.JTextArea;
16
17 import be.nikiroo.fanfix.data.MetaData;
18 import be.nikiroo.fanfix.data.Story;
19 import be.nikiroo.fanfix.reader.BasicReader;
20 import be.nikiroo.fanfix.reader.Reader;
21
22 /**
23 * A frame displaying properties and other information of a {@link Story}.
24 *
25 * @author niki
26 */
27 public class GuiReaderPropertiesFrame extends JFrame {
28 private static final long serialVersionUID = 1L;
29
30 /**
31 * Create a new {@link GuiReaderPropertiesFrame}.
32 *
33 * @param reader
34 * the linked reader
35 * @param meta
36 * the meta to describe
37 */
38 public GuiReaderPropertiesFrame(Reader reader, MetaData meta) {
39 // Borders
40 int top = 20;
41 int space = 10;
42
43 // Image
44 ImageIcon img = GuiReaderCoverImager.generateCoverIcon(
45 reader.getLibrary(), meta);
46
47 // frame
48 setTitle(meta.getLuid() + ": " + meta.getTitle());
49
50 setSize(800, img.getIconHeight() + 2 * top);
51 setLayout(new BorderLayout());
52
53 // Main panel
54 JPanel mainPanel = new JPanel(new BorderLayout());
55 JPanel mainPanelKeys = new JPanel();
56 mainPanelKeys.setLayout(new BoxLayout(mainPanelKeys, BoxLayout.Y_AXIS));
57 JPanel mainPanelValues = new JPanel();
58 mainPanelValues.setLayout(new BoxLayout(mainPanelValues,
59 BoxLayout.Y_AXIS));
60
61 mainPanel.add(mainPanelKeys, BorderLayout.WEST);
62 mainPanel.add(mainPanelValues, BorderLayout.CENTER);
63
64 List<Entry<String, String>> infos = BasicReader.getMetaDesc(meta);
65
66 Color trans = new Color(0, 0, 0, 1);
67 for (Entry<String, String> info : infos) {
68 JTextArea key = new JTextArea(info.getKey());
69 key.setFont(new Font(key.getFont().getFontName(), Font.BOLD, key
70 .getFont().getSize()));
71 key.setEditable(false);
72 key.setLineWrap(false);
73 key.setBackground(trans);
74 mainPanelKeys.add(key);
75
76 JTextArea value = new JTextArea(info.getValue());
77 value.setEditable(false);
78 value.setLineWrap(false);
79 value.setBackground(trans);
80 mainPanelValues.add(value);
81 }
82
83 // Image
84 JLabel imgLabel = new JLabel(img);
85 imgLabel.setVerticalAlignment(JLabel.TOP);
86
87 // Borders
88 mainPanelKeys.setBorder(BorderFactory.createEmptyBorder(top, space, 0,
89 0));
90 mainPanelValues.setBorder(BorderFactory.createEmptyBorder(top, space,
91 0, 0));
92 imgLabel.setBorder(BorderFactory.createEmptyBorder(0, space, 0, 0));
93
94 // Add all
95 add(imgLabel, BorderLayout.WEST);
96 add(mainPanel, BorderLayout.CENTER);
97 }
98 }