Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

MEAPsoftGUIPanel.java

00001 /*
00002  *  Copyright 2006-2007 Columbia University.
00003  *
00004  *  This file is part of MEAPsoft.
00005  *
00006  *  MEAPsoft is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License version 2 as
00008  *  published by the Free Software Foundation.
00009  *
00010  *  MEAPsoft is distributed in the hope that it will be useful, but
00011  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with MEAPsoft; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00018  *  02110-1301 USA
00019  *
00020  *  See the file "COPYING" for the text of the license.
00021  */
00022 
00023 package com.meapsoft.gui;
00024 
00025 import java.awt.*;
00026 import java.awt.event.*;
00027 import java.io.*;
00028 import java.util.*;
00029 import javax.swing.*; 
00030 
00031 import com.meapsoft.*;
00032 
00040 public abstract class MEAPsoftGUIPanel extends JPanel implements ActionListener, MouseListener
00041 {
00042     // Background color of this Panel
00043     public Color color;
00044         
00045     //
00046     protected static MEAPsoftGUI meapsoftGUI;
00047 
00048     // name of audio player to use in segmenter and synthesizer panels
00049     protected static String audioPlayerName; 
00050 
00051     // various files used my MEAPsoftGUI components
00052     public static FeatFile segmentFile = null;
00053     public static FeatFile featFile = null;
00054     public static EDLFile edlFile = null;
00055 
00056         //IO data
00057         protected static String dataDirectory;
00058         protected static String meapsoftDirectory;
00059         protected static String slash;
00060         protected static String dataBaseName = "mann";
00061         //segmenter
00062         protected static String inputSoundFileNameFull;
00063         protected static String inputSoundFileNameShort;
00064         protected static String outputSegmentsFileName = dataBaseName + ".seg";
00065         //features
00066         protected static String inputSegmentsFileName = dataBaseName + ".seg";
00067         protected static String outputFeaturesFileName = dataBaseName + ".feat";
00068         //composer
00069         protected static String inputFeaturesFileName = dataBaseName + ".feat";
00070         protected static String outputEDLFileName = dataBaseName + ".edl";
00071         //synth
00072         protected static String inputEDLFileName = dataBaseName + ".edl";
00073         protected static String outputSoundFileNameFull;
00074         protected static String outputSoundFileNameShort;
00075 
00076     // some constants that we share with MEAPsoftGUI
00077     //protected static String slash = MEAPsoftGUI.slash;
00078     
00079     
00080 //    public static int OPEN = MEAPsoftGUI.OPEN;
00081 //    public static int SAVE = MEAPsoftGUI.SAVE;
00082 //    public static int TARGET = MEAPsoftGUI.TARGET;
00083 //    public static int DIR = MEAPsoftGUI.DIR;
00084 //    public static int OPENWAV = MEAPsoftGUI.OPENWAV;
00085         
00086     //public static int FATAL_ERROR = MEAPsoftGUI.FATAL_ERROR;
00087     //public static int MESSAGE = MEAPsoftGUI.MESSAGE;
00088 
00089     // help button
00090         protected JLabel helpButton;
00091     protected String helpURL;
00092 
00093     // window title (used for help window).
00094     protected String title;
00095     
00099     public MEAPsoftGUIPanel(MEAPsoftGUI msg)
00100     { 
00101         meapsoftGUI = msg;
00102 
00103         dataDirectory = msg.dataDirectory;
00104         meapsoftDirectory = msg.meapsoftDirectory;
00105         slash = MEAPUtil.slash;
00106 
00107         if (System.getProperty("os.name").equals("Mac OS X"))
00108             audioPlayerName = "open";
00109         else if (System.getProperty("os.name").equals("Linux"))
00110             audioPlayerName = "play";
00111         else if (System.getProperty("os.name").startsWith("Windows"))
00112             audioPlayerName = 
00113                 "C:\\Program Files\\Windows Media Player\\wmplayer.exe";
00114         else
00115             audioPlayerName = null;
00116 
00117         helpButton = new JLabel("(help)");
00118                 helpButton.setForeground(Color.blue);
00119         helpButton.setAlignmentX(Component.CENTER_ALIGNMENT);
00120                 helpButton.addMouseListener(this);
00121         helpURL = "file:///" + meapsoftDirectory + slash + "doc" + slash 
00122             + "manual.html";
00123     }
00124 
00129     public abstract int run();
00130 
00135     /*
00136     protected static void ShowDialog(Exception e, String message, int status)
00137     {
00138         meapsoftGUI.ShowDialog(e,  message, status);
00139     }
00140 
00141         protected static void ShowDialog(String message, int status)
00142     {
00143         meapsoftGUI.ShowDialog(message, status);
00144     }
00145 
00146         protected static  String[] FileSelector(int mode)
00147     {
00148         return meapsoftGUI.FileSelector(mode);
00149     }
00150         */
00151     protected static void initSegmentFile()
00152     {        
00153         String fn = dataDirectory + slash + outputSegmentsFileName;
00154 
00155         if(segmentFile == null || segmentFile.filename != fn)
00156             segmentFile = new FeatFile(fn);
00157     }
00158 
00159     protected static void initFeatFile()
00160     {
00161         String fn = dataDirectory + slash + outputFeaturesFileName;
00162 
00163         if(featFile == null || featFile.filename != fn)
00164             featFile = new FeatFile(fn);
00165     }
00166 
00167     protected static void initEDLFile()
00168     {        
00169         String fn = dataDirectory + slash + outputEDLFileName;
00170 
00171         if(edlFile == null || edlFile.filename != fn)
00172             edlFile = new EDLFile(fn);
00173     }
00174 
00175     protected synchronized static void UpdateFileNames()
00176         {
00177                 //segmenter
00178                 outputSegmentsFileName = dataBaseName + ".seg";
00179                 //features
00180                 inputSegmentsFileName = dataBaseName + ".seg";
00181                 outputFeaturesFileName = dataBaseName + ".feat";
00182                 //composer
00183                 inputFeaturesFileName = dataBaseName + ".feat";
00184                 outputEDLFileName = dataBaseName + ".edl";
00185                 //synth
00186                 inputEDLFileName = dataBaseName + ".edl";
00187                 String[] outputName = new String[2];
00188                 outputName[0] = dataDirectory + slash + dataBaseName + ".MEAPED.wav";
00189                 outputName[1] = dataBaseName + ".MEAPED.wav";
00190                 SetOutputFileName(outputName);
00191         }
00192         
00193         protected synchronized static void SetInputFileName(String[] names)
00194         {
00195                 inputSoundFileNameFull = names[0];
00196                 inputSoundFileNameShort = names[1];
00197                 dataBaseName = inputSoundFileNameShort;
00198                 meapsoftGUI.segmenterPanel.inputSoundFileField.setText(inputSoundFileNameShort);
00199                 UpdateFileNames();
00200                 meapsoftGUI.UpdateInfoTexts();
00201         }
00202         
00203         protected static void SetOutputFileName(String[] names)
00204         {
00205                 outputSoundFileNameFull = names[0];
00206                 outputSoundFileNameShort = names[1];
00207                 meapsoftGUI.synthPanel.outputFileNameField.setText(outputSoundFileNameShort);
00208         }
00209 
00210         protected static void RefreshGUI()
00211     {
00212         meapsoftGUI.RefreshGUI();
00213     }
00214 
00215     protected static void PlaySoundFile(String soundFile)
00216     {
00217         try
00218         {
00219             Process p = null;
00220             if(audioPlayerName != null)
00221             {
00222                 String[] args = {audioPlayerName, soundFile};
00223 
00224                 // need a special case for OS X because native OS X
00225                 // applications are actually stored as directories...
00226                 if(System.getProperty("os.name").equals("Mac OS X")
00227                    && new File(audioPlayerName).isDirectory())
00228                 {
00229                                         String[] tmp = {"open", "-a", audioPlayerName, soundFile};
00230                     args = tmp;
00231                 }
00232 
00233                 p = Runtime.getRuntime().exec(args);
00234             }
00235             else
00236                 GUIUtils.ShowDialog(
00237                                         "I don't know what program to use to play audio on your platform.  Please check your preferences.", 
00238                                         GUIUtils.MESSAGE, null);
00239         }
00240         catch (IOException e)
00241         {
00242             GUIUtils.ShowDialog(e, "Problem opening soundfile.", GUIUtils.MESSAGE, null);
00243         }
00244     }
00245 
00246 
00247         public void actionPerformed(ActionEvent arg0)
00248     {
00249     }
00250 
00251     public void mouseClicked(MouseEvent arg0)
00252         {               
00253                 HelpWindow help = new HelpWindow(helpURL, title+" Help", color);
00254         }
00255 
00256         public void mousePressed(MouseEvent arg0)
00257         {
00258         }
00259 
00260         public void mouseReleased(MouseEvent arg0)
00261         {
00262         }
00263 
00264         public void mouseEntered(MouseEvent arg0)
00265         {
00266         }
00267 
00268         public void mouseExited(MouseEvent arg0)
00269         {
00270         }
00271 }

Generated on Tue Feb 6 19:02:27 2007 for MEAPsoft by doxygen1.2.18