/Users/lyon/j4p/src/sound/soundDemo/CapturePlaybackHack.java

1    package sound.soundDemo; 
2     
3    // sound.soundDemo.JavaSound 
4     
5    /* 
6     * Copyright 2002 Sun Microsystems, Inc. All rights reserved. 
7     * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 
8     */ 
9     
10   import javax.sound.midi.MidiSystem; 
11   import javax.sound.sampled.AudioSystem; 
12   import javax.swing.JFrame; 
13   import javax.swing.JMenu; 
14   import javax.swing.JMenuBar; 
15   import javax.swing.JPanel; 
16   import javax.swing.JTabbedPane; 
17   import java.awt.BorderLayout; 
18   import java.awt.Dimension; 
19   import java.awt.Toolkit; 
20   import java.awt.event.WindowAdapter; 
21   import java.awt.event.WindowEvent; 
22   import java.io.File; 
23    
24   /** 
25    * 
26    * @author Brian Lichtenwalter 
27    * @version @(#)JavaSound.java  1.17 02/02/06 
28    */ 
29   public class CapturePlaybackHack  { 
30       JTabbedPane tabPane = new JTabbedPane(); 
31       int width = 760, height = 500; 
32       int index; 
33       private final MyJPanel jPanel = new MyJPanel(); 
34    
35       public CapturePlaybackHack(String audioDirectory) { 
36           jPanel.setLayout(new BorderLayout()); 
37           JMenuBar menuBar = new JMenuBar(); 
38           if (JavaSoundApplet.applet == null) { 
39               JMenu fileMenu = (JMenu) menuBar.add(new JMenu("File")); 
40           } 
41           JPanel p = getCapturePlaybackPanel(); 
42           tabPane.addTab("Capture/Playback", p); 
43           jPanel.add(tabPane, BorderLayout.CENTER); 
44       } 
45    
46       public JPanel getCapturePlaybackPanel() { 
47           JPanel p = new JPanel(new BorderLayout()); 
48           CapturePlaybackPanel capturePlaybackPanel = new CapturePlaybackPanel(); 
49           p.add(capturePlaybackPanel); 
50           return p; 
51       } 
52    
53       public static void main(String[] args) { 
54           checkAudio(); 
55           String media = "media"; 
56           if (args.length > 0) { 
57               File file = new File(args[0]); 
58               if (file == null && !file.isDirectory()) { 
59                   System.out.println("usage: java JavaSound audioDirectory"); 
60               } else { 
61                   media = args[0]; 
62               } 
63           } 
64           final CapturePlaybackHack demo = new CapturePlaybackHack(media); 
65           JFrame f = new JFrame("Java Sound Demo"); 
66           f.addWindowListener(new WindowAdapter() { 
67               public void windowClosing(WindowEvent e) { 
68                   System.exit(0); 
69               } 
70    
71               public void windowDeiconified(WindowEvent e) { 
72               } 
73    
74               public void windowIconified(WindowEvent e) { 
75               } 
76           }); 
77           f.getContentPane().add("Center", demo.jPanel); 
78           f.pack(); 
79           Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); 
80           f.setLocation(d.width / 2 - demo.width / 2, d.height / 2 - demo.height / 2); 
81           f.setSize(new Dimension(demo.width, demo.height)); 
82           f.setVisible(true); 
83       } 
84    
85       private static void checkAudio() { 
86           try { 
87               if (MidiSystem.getSequencer() == null) { 
88                   System.err.println("MidiSystem Sequencer Unavailable, exiting!"); 
89                   System.exit(1); 
90               } else if (AudioSystem.getMixer(null) == null) { 
91                   System.err.println("AudioSystem Unavailable, exiting!"); 
92                   System.exit(1); 
93               } 
94           } catch (Exception ex) { 
95               ex.printStackTrace(); 
96               System.exit(1); 
97           } 
98       } 
99    
100      private class MyJPanel extends JPanel { 
101          public Dimension getPreferredSize() { 
102              return new Dimension(CapturePlaybackHack.this.width, CapturePlaybackHack.this.height); 
103          } 
104      } 
105  } 
106