Urbi SDK Remote for Java  2.7.5
SendSoundSampler.java
00001 /*
00002  * Copyright (C) 2010-2011, Gostai S.A.S.
00003  *
00004  * This software is provided "as is" without warranty of any kind,
00005  * either expressed or implied, including but not limited to the
00006  * implied warranties of fitness for a particular purpose.
00007  *
00008  * See the LICENSE file for more information.
00009  */
00010 
00011 package urbi;
00012 
00013 import javax.swing.*;
00014 import javax.swing.border.*;
00015 import java.awt.*;
00016 import java.awt.event.*;
00017 import java.io.*;
00018 import javax.sound.sampled.*;
00019 
00020 import urbi.UClient;
00021 
00022 public class    SendSoundSampler extends JFrame
00023 {
00024     private     UClient client;
00025 
00026     public              SendSoundSampler()
00027     {
00028         super("Send Sound Sampler");
00029         setDefaultCloseOperation(EXIT_ON_CLOSE);
00030         createUI();
00031         setVisible(true);
00032         pack();
00033         setVisible(true);
00034 
00035     }
00036 
00037     public              SendSoundSampler(UClient c)
00038     {
00039         super("Send Sound Sampler");
00040         client = c;
00041         setDefaultCloseOperation(EXIT_ON_CLOSE);
00042         createUI();
00043         setVisible(true);
00044         pack();
00045         setVisible(true);
00046 
00047     }
00048 
00049     public void         setClient(UClient c)
00050     {
00051         this.client = c;
00052     }
00053 
00054     public UClient      getClient()
00055     {
00056         return client;
00057     }
00058 
00059     private void        createUI()
00060     {
00061         setFont(new Font("Serif", Font.PLAIN, 12));
00062         setSize(200, 350);
00063         Container content = getContentPane();
00064 
00065         final JButton play = new JButton("Play");
00066         play.setEnabled(true);
00067         ActionListener saveListener = new ActionListener()
00068             {
00069                 public void actionPerformed(ActionEvent e)
00070                 {
00071                     FileDialog          fd = new FileDialog(SendSoundSampler.this);
00072                     fd.setVisible(true);
00073                     if (fd.getFile() == null)
00074                         return ;
00075                     String path = fd.getDirectory() + fd.getFile();
00076                     try
00077                     {
00078                         SoundUtilities.sendSound(path, client);
00079                     }
00080                     catch (IOException ie)
00081                     {
00082                     }
00083                 }
00084             };
00085         play.addActionListener(saveListener);
00086         Panel   bottom = new Panel(new GridLayout(2, 1));
00087         Panel   topBottom = new Panel();
00088         topBottom.add(play);
00089         bottom.add(topBottom);
00090         content.add(bottom, BorderLayout.CENTER);
00091 
00092         addWindowListener(new WindowAdapter()
00093             {
00094                 public void windowClosing(WindowEvent e)
00095                 {
00096                     dispose();
00097                     System.exit(0);
00098                 }
00099             });
00100     }
00101 }