View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin.viewer.vorbisviewer;
21  
22  import java.awt.GridBagLayout;
23  import java.io.File;
24  import java.io.FileInputStream;
25  import java.io.IOException;
26  import java.util.Iterator;
27  
28  import javax.swing.JLabel;
29  import javax.swing.JPanel;
30  
31  import org.apache.log4j.Logger;
32  import org.xnap.XNap;
33  import org.xnap.gui.StatusBar;
34  import org.xnap.gui.util.GUIHelper;
35  import org.xnap.gui.util.GridBagHelper;
36  import org.xnap.util.StringHelper;
37  
38  public class VorbisViewerPanel extends JPanel
39  {
40  	//--- Constant(s) ---
41  
42  	//--- Data field(s) ---
43  
44  	private JLabel jlInfo = new JLabel();
45  
46      private static Logger logger = Logger.getLogger(VorbisViewerPanel.class);
47  	
48  	//--- Constructor(s) ---
49  
50      public VorbisViewerPanel()
51  	{
52  		super(new GridBagLayout());
53  		
54  		jlInfo.setBorder
55  			(GUIHelper.createDefaultBorder(XNap.tr("Ogg Vorbis Info")));
56  		GridBagHelper.add(this, jlInfo);
57  		GridBagHelper.addVerticalSpacer(this);
58  	}
59  
60      //--- Method(s) ---
61  
62  	public void display(File f)
63  	{
64  		jlInfo.setText("");
65  
66  		try {
67  			VorbisInfo vi = new VorbisInfo(new FileInputStream(f));
68  			
69  			StringBuffer sb = new StringBuffer();
70  			sb.append("<html><table>");
71  			sb.append(GUIHelper.tableRow(XNap.tr("Filename"), f.getName()));
72  			sb.append(GUIHelper.tableRow(XNap.tr("Bitrate"),
73  										 vi.getBitrate() + ""));
74  			sb.append(GUIHelper.tableRow(XNap.tr("Number of Channels"),
75  										 vi.getChannels() + ""));
76  			sb.append(GUIHelper.tableRow(XNap.tr("Sample Rate"),
77  										 vi.getRate() + ""));
78  			
79  			for (Iterator i = vi.getFields().iterator(); i.hasNext();) {
80  				String name = (String)i.next();
81  				String values = StringHelper.toString(vi.getComments(name),
82  													  ", ");
83  				sb.append(GUIHelper.tableRow
84  						  (StringHelper.toFirstUpper(name),
85  						   values.substring(0, values.length() - 2)));
86  			}
87  			sb.append("</html></table>");
88  			jlInfo.setText(sb.toString());
89  		}
90  		catch (IOException ie) {
91  			logger.debug("Error reading vorbis file", ie);
92  			StatusBar.setText(ie.getLocalizedMessage());
93  		}
94  	}
95  }