1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.bitzi;
21
22 import java.awt.Color;
23 import java.util.Iterator;
24 import java.util.Properties;
25
26 import javax.swing.BoxLayout;
27 import javax.swing.JLabel;
28 import javax.swing.JPanel;
29
30 import net.n3.nanoxml.IXMLElement;
31
32 import org.apache.log4j.Logger;
33 import org.xnap.XNap;
34 import org.xnap.gui.util.GUIHelper;
35
36 /***
37 * BitziItemPanel
38 */
39 public class BitziItemPanel extends JPanel {
40
41 private static final Logger logger = Logger.getLogger(BitziItemPanel.class);
42 private static Properties namesByKey = new Properties();
43 static {
44 namesByKey.setProperty("bz:fileLength", XNap.tr("Filesize"));
45 namesByKey.setProperty("bz:fileGoodness", XNap.tr("Goodness"));
46 namesByKey.setProperty("bz:fileJudgement", XNap.tr("Judgement"));
47 namesByKey.setProperty("bz:format", XNap.tr("File format"));
48 namesByKey.setProperty("mm:duration", XNap.tr("Track duration (ms)"));
49 namesByKey.setProperty("bz:audioBitrate", XNap.tr("Bitrate (kilobits/second)"));
50 namesByKey.setProperty("bz:audioSamplerate", XNap.tr("Samplerate (Hz)"));
51 namesByKey.setProperty("bz:audioChannels", XNap.tr("Channels"));
52 namesByKey.setProperty("dc:title", XNap.tr("Title"));
53 namesByKey.setProperty("dc:creator", XNap.tr("Creator"));
54 namesByKey.setProperty("bz:albumName", XNap.tr("Album name"));
55 namesByKey.setProperty("mm:trackNum", XNap.tr("Album track number"));
56 namesByKey.setProperty("dc:date", XNap.tr("Date"));
57 }
58
59 private String filename;
60
61 public BitziItemPanel()
62 {
63 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
64 setBorder(GUIHelper.createEmptyBorder(10));
65 setBackground(Color.white);
66 }
67
68 public BitziItemPanel(String filename, IXMLElement bits)
69 {
70 this();
71 setFilename(filename);
72 setBitziInfo(bits);
73 }
74
75 public void setFilename(String filename)
76 {
77 this.filename = filename;
78 }
79
80 public void setBitziInfo(IXMLElement bits)
81 {
82 removeAll();
83 if (bits == null) {
84 add(new JLabel(XNap.tr("Could not retrieve meta data for {0}", filename)));
85 }
86 else {
87 add(new JLabel(XNap.tr("Bitzi Lookup for {0}", filename)));
88 add(createSummaryLabel(bits));
89 add(createAltFilenamesLabel(bits));
90 }
91 }
92
93 private JLabel createSummaryLabel(IXMLElement bits)
94 {
95 IXMLElement desc = bits.getFirstChildNamed("Description", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
96 Properties data = new Properties(desc.getAttributes());
97 if (desc.getFirstChildNamed("dc:description") != null) {
98 data.putAll(desc.getFirstChildNamed("dc:description").getAttributes());
99 }
100
101 StringBuffer sb = new StringBuffer();
102 sb.append("<html><h3>");
103 sb.append(XNap.tr("Summary for {0}", filename));
104 sb.append("</h3>");
105
106 sb.append(renderProperty("bz:fileGoodness", data));
107 sb.append(renderProperty("bz:fileJudgement", data));
108
109 sb.append(renderProperty("dc:title", data));
110 sb.append(renderProperty("dc:creator", data));
111 sb.append(renderProperty("bz:albumName", data));
112 sb.append(renderProperty("mm:trackNum", data));
113 sb.append(renderProperty("dc:date", data));
114
115 sb.append(renderProperty("bz:fileLength", data));
116 sb.append(renderProperty("bz:format", data));
117 sb.append(renderProperty("mm:duration", data));
118 sb.append(renderProperty("bz:audioBitrate", data));
119
120 sb.append(renderProperty("bz:audioSamplerate", data));
121 sb.append(renderProperty("bz:audioChannels", data));
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136 return new JLabel(sb.toString());
137 }
138
139 private String renderProperty(String key, Properties p)
140 {
141 if (p.getProperty(key) == null) {
142 return "";
143 }
144
145 String str = "<b>" + namesByKey.getProperty(key, key) + ": </b>"
146 + p.getProperty(key) + "<br>";
147 p.remove(key);
148 return str;
149 }
150
151 private JLabel createAltFilenamesLabel(IXMLElement bits)
152 {
153 StringBuffer sb = new StringBuffer();
154
155 IXMLElement desc = bits.getFirstChildNamed("Description", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
156
157 Iterator it = desc.getChildrenNamed("bz:fileName").iterator();
158 sb.append("<html><h3>").append(XNap.tr("Alternative Filenames")).append("</h3>");
159 while (it.hasNext()) {
160 IXMLElement f = (IXMLElement)it.next();
161 sb.append(f.getAttribute("dc:title", ""));
162 if (it.hasNext()) {
163 sb.append("<br>");
164 }
165 }
166
167 return new JLabel(sb.toString());
168 }
169 }