View Javadoc

1   /*
2    *  XNap
3    *
4    *  A peer-to-peer and file sharing client.
5    *
6    *  Copyright Kazaam 2002-2003.
7    *
8    *  This program is free software; you can redistribute it and/or modify
9    *  it under the terms of the GNU General Public License as published by
10   *  the Free Software Foundation; either version 2 of the License, or
11   *  (at your option) any later version.
12   *
13   *  This program is distributed in the hope that it will be useful,
14   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   *  GNU General Public License for more details.
17   *
18   *  You should have received a copy of the GNU General Public License
19   *  along with this program; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   *
22   */
23  /*
24   * Modified by Steffen Pingel for XNap 3. 
25   *  - replaced JTabbedPane by JPanel
26   *  - removed InformationPanel
27   *  - removed Kazaam Logo
28   *  - removed setIconTextGap() calls (to avoid Java 1.4 dependency)
29   *  - removed setFont() calls
30   *  - removed parentFrame
31   *  - added l10n
32   */
33  package org.xnap.plugin.viewer.jmfplayer;
34  
35  import java.awt.Color;
36  import java.io.File;
37  
38  import javax.swing.JLabel;
39  import javax.swing.JPanel;
40  
41  import org.xnap.XNap;
42  import org.xnap.gui.XNapFrame;
43  import org.xnap.gui.util.IconHelper;
44  
45  /*
46   * KazaamPreviewerDemo.java
47   *
48   * Created on December 29, 2002
49   * @author  joker10000y
50   */
51  public class JMFPlayerPanel extends JPanel {
52      
53      /*** Creates new form KazaamMediaPreview */
54      public JMFPlayerPanel() 
55      {
56          initComponents();
57      }
58  
59      /*** This method is called from within the constructor to
60       * initialize the form.
61       * WARNING: Do NOT modify this code. The content of this method is
62       * always regenerated by the Form Editor.
63       */
64      private void initComponents() {
65          PlayerToolbar = new javax.swing.JToolBar();
66          JButtonStop = new javax.swing.JButton();
67          JButtonFullScreenMode = new javax.swing.JButton();
68          RepeatPlaybackCheckbox = new javax.swing.JCheckBox();
69          ContentArea = new javax.swing.JPanel();
70          addHierarchyBoundsListener(new java.awt.event.HierarchyBoundsListener() {
71  				public void ancestorMoved(java.awt.event.HierarchyEvent evt) {
72  				}
73  				public void ancestorResized(java.awt.event.HierarchyEvent evt) {
74  					formAncestorResized(evt);
75  				}
76  			});
77  		setToolTipText("Media Preview");
78          setLayout(new java.awt.BorderLayout());
79  
80  
81  		JButtonStop.setIcon(IconHelper.getToolBarIcon("noatunstop.png"));
82          JButtonStop.setToolTipText(XNap.tr("Stop Media Playback"));
83          JButtonStop.setBorderPainted(false);
84          JButtonStop.setMargin(new java.awt.Insets(0, 0, 0, 0));
85  		JButtonStop.setEnabled(false);
86          JButtonStop.addActionListener(new java.awt.event.ActionListener() 
87  			{
88  				public void actionPerformed(java.awt.event.ActionEvent evt)
89  				{
90  					JButtonStopActionPerformed(evt);
91  				}
92  			});
93          PlayerToolbar.add(JButtonStop);
94  
95  		JButtonFullScreenMode.setIcon(IconHelper.getToolBarIcon("fullscreen.png"));
96          JButtonFullScreenMode.setToolTipText(XNap.tr("Play Media in Full Screen Mode"));
97          JButtonFullScreenMode.setBorderPainted(false);
98          JButtonFullScreenMode.setMargin(new java.awt.Insets(0, 0, 0, 0));
99          JButtonFullScreenMode.addActionListener(new java.awt.event.ActionListener() 
100 			{
101 				public void actionPerformed(java.awt.event.ActionEvent evt)
102 				{
103 					JButtonFullScreenModeActionPerformed(evt);
104 				}
105 			});
106         PlayerToolbar.add(JButtonFullScreenMode);
107 
108 
109         RepeatPlaybackCheckbox.setText(XNap.tr("Continuous Playback"));
110         RepeatPlaybackCheckbox.setToolTipText(XNap.tr("Continuously Repeat Playback of the Media File"));
111         RepeatPlaybackCheckbox.setMargin(new java.awt.Insets(0, 0, 0, 0));
112         RepeatPlaybackCheckbox.setRolloverEnabled(true);
113         RepeatPlaybackCheckbox.addActionListener(new java.awt.event.ActionListener() 
114 			{
115 				public void actionPerformed(java.awt.event.ActionEvent evt) {
116 					RepeatPlaybackCheckboxActionPerformed(evt);
117 				}
118 			});
119         PlayerToolbar.add(RepeatPlaybackCheckbox);
120 
121         add(PlayerToolbar, java.awt.BorderLayout.SOUTH);
122 
123         ContentArea.setLayout(new java.awt.BorderLayout());
124 
125         ContentArea.setBackground(new java.awt.Color(0, 0, 0));
126         ContentArea.setForeground(new java.awt.Color(255, 255, 255));
127 		// add dummy component to fill the area
128         ContentArea.add(new JLabel(), java.awt.BorderLayout.CENTER);
129 
130         add(ContentArea, java.awt.BorderLayout.CENTER);
131     }
132 
133    
134     private void RepeatPlaybackCheckboxActionPerformed(java.awt.event.ActionEvent evt) 
135 	{
136 		if(RepeatPlaybackCheckbox.isSelected()==true)
137 			{
138 				KazaamMediaPlayer.setLoopPlayback(true);
139 			}
140 		else if(RepeatPlaybackCheckbox.isSelected()==false)
141 			{
142 				KazaamMediaPlayer.setLoopPlayback(false);
143 			}
144 	
145     }
146 
147     public void setOpenFile(File theMediaFile)
148     {
149 		if(KazaamMediaPlayer.isStarted()==true)
150 			{
151 				stopPlayer();
152 			}
153         try
154 			{
155                 myPlayerPanel = new KazaamMediaPlayer();  
156                 //myPlayerPanel.setLayout(new java.awt.BorderLayout());
157                 myPlayerPanel.setBackground(Color.black);
158                 myPlayerPanel.setDoubleBuffered(true);
159                 add(myPlayerPanel,"Center");
160                 myPlayerPanel.setPlayFile(theMediaFile); 
161                 JButtonStop.setEnabled(true);
162 			}
163         catch(Exception e)
164 			{
165                 System.out.println(e);
166 			}
167 		//MyPlayerPanel.setSize(MyPlayerPanel.getMaximumSize());
168     }
169     
170     private void JButtonStopActionPerformed(java.awt.event.ActionEvent evt) {
171 		// Add your handling code here:
172 		try
173 			{
174 				stopPlayer();
175 			}
176 		catch(Exception e){}
177 
178 	}
179 	public void stopPlayer()
180 	{
181 		try
182 			{
183 				JButtonStop.setEnabled(false);
184 				myPlayerPanel.stop(); 
185 				remove(myPlayerPanel);
186 				myPlayerPanel=null;
187 				//repaintAll();
188 			}
189 		catch(Exception e){}
190 	}
191     
192     private void JButtonPauseActionPerformed(java.awt.event.ActionEvent evt) {
193 		// Add your handling code here:
194 		myPlayerPanel.pause(); 
195 	}
196 
197     
198     private void JButtonFullScreenModeActionPerformed(java.awt.event.ActionEvent evt) 
199 	{
200 		myPlayerPanel.setFullScreen(true, XNapFrame.getInstance());			
201 	}
202 
203     /*** Exit the Application */
204     private void exitForm(java.awt.event.WindowEvent evt) {
205         System.exit(0);
206     }
207         
208 	private void formAncestorResized(java.awt.event.HierarchyEvent evt) {
209 
210         //repaintAll();
211     }
212    
213 //  	private void repaintAll()
214 //  	{
215 //  		getRootPane().repaint(new Rectangle(theParentFrame.getBounds()));
216 //  	}    
217     
218     // Variables declaration - do not modify
219     private javax.swing.JButton JButtonFullScreenMode;
220     private javax.swing.JToolBar PlayerToolbar;
221     private javax.swing.JPanel ContentArea;
222     private javax.swing.JButton JButtonStop;
223     private javax.swing.JCheckBox RepeatPlaybackCheckbox;
224     private KazaamMediaPlayer myPlayerPanel;
225 
226     // End of variables declaration
227     
228 }