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.videoinfo;
21  
22  import java.awt.GridBagLayout;
23  import java.io.File;
24  
25  import javax.swing.JLabel;
26  import javax.swing.JPanel;
27  
28  import org.xnap.XNap;
29  import org.xnap.gui.StatusBar;
30  import org.xnap.gui.util.GUIHelper;
31  import org.xnap.gui.util.GridBagHelper;
32  import org.xnap.util.Formatter;
33  
34  /***
35   * VideoInfoPanel displays the length and resolution of avi and mpg files.
36   */
37  public class VideoInfoPanel extends JPanel
38  {
39  
40      //--- Constant(s) ---
41      
42      //--- Data field(s) ---
43  
44  	private JLabel jlInfo = new JLabel();
45      
46      //--- Constructor(s) ---
47  
48      public VideoInfoPanel() 
49      {
50  		super(new GridBagLayout());
51  		jlInfo.setBorder(GUIHelper.createDefaultBorder(XNap.tr("Video Info")));
52  		GridBagHelper.add(this, jlInfo);
53  		GridBagHelper.addVerticalSpacer(this);
54      }
55  
56      //--- Method(s) ---
57  
58      public void display(File file)
59      {
60  		jlInfo.setText("");
61  	
62  		VideoFile vf = new VideoFile(file);
63  
64  		if (vf.parse()) {
65  			StringBuffer sb = new StringBuffer();
66  			sb.append("<html><table>");
67  			sb.append(GUIHelper.tableRow(XNap.tr("Filename"),
68  										 file.getName()));
69  			sb.append
70  				(GUIHelper.tableRow(XNap.tr("Length"),
71  									Formatter.formatLength(vf.getLength())));
72  			sb.append(GUIHelper.tableRow(XNap.tr("Height"), 
73  										 vf.getHeight() + ""));
74  			
75  			sb.append(GUIHelper.tableRow(XNap.tr("Width"),
76  										 vf.getWidth() + ""));
77  			sb.append("</table></html>");
78  			jlInfo.setText(sb.toString());
79  		}
80  		else {
81  			StatusBar.setText(XNap.tr("Not a valid video file"));
82  		}
83      }
84  }