Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

Visualizer.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 /*
00024  * Created on Nov 17, 2006
00025  *
00026  */
00027 package com.meapsoft.visualizer;
00028 
00029 import java.awt.BorderLayout;
00030 import java.awt.Color;
00031 import java.awt.Component;
00032 import java.awt.Font;
00033 import java.awt.Point;
00034 import java.awt.Rectangle;
00035 import java.awt.event.ActionEvent;
00036 import java.awt.event.ActionListener;
00037 import java.awt.event.ComponentEvent;
00038 import java.awt.event.ComponentListener;
00039 import java.awt.event.MouseEvent;
00040 import java.awt.event.MouseListener;
00041 import java.awt.event.MouseMotionListener;
00042 import java.io.File;
00043 import java.io.IOException;
00044 import java.text.DecimalFormat;
00045 import java.util.Vector;
00046 
00047 import javax.swing.BorderFactory;
00048 import javax.swing.BoxLayout;
00049 import javax.swing.ButtonGroup;
00050 import javax.swing.JButton;
00051 import javax.swing.JComboBox;
00052 import javax.swing.JFrame;
00053 import javax.swing.JLabel;
00054 import javax.swing.JPanel;
00055 import javax.swing.JRadioButton;
00056 import javax.swing.JCheckBox;
00057 import javax.swing.JScrollPane;
00058 
00059 import javax.swing.border.EtchedBorder;
00060 import javax.swing.border.TitledBorder;
00061 
00062 import com.meapsoft.Chunk;
00063 import com.meapsoft.EDLChunk;
00064 import com.meapsoft.EDLFile;
00065 import com.meapsoft.FeatChunk;
00066 import com.meapsoft.FeatFile;
00067 import com.meapsoft.MEAPUtil;
00068 import com.meapsoft.Synthesizer;
00069 import com.meapsoft.gui.GUIUtils;
00070 import com.meapsoft.gui.HelpWindow;
00071 
00076 public class Visualizer implements ActionListener, MouseListener, MouseMotionListener, ComponentListener
00077 {       
00078         String meapsoftDirectory;
00079         String dataDirectory;
00080         String slash;;
00081         
00082         EDLFile eDLInputFile;
00083         FeatFile featInputFile;
00084         
00085         EDLFile eDLOutputFile;
00086         FeatFile featOutputFile;
00087         
00088         DrawingPanel drawingPanel;
00089         private JScrollPane scroller;
00090         
00091         JPanel metaControlPanel;
00092         JLabel featInputFileLabel;
00093         JLabel eDLInputFileLabel;
00094         
00095         JComboBox rendererSelector;
00096         
00097         JLabel sourceLabel;
00098         JLabel featureNameLabel;
00099         JLabel featureRangeLabel;
00100         JLabel featureValueLabel;
00101         JLabel startTimeLabel;
00102         JLabel endTimeLabel;
00103         JLabel lengthLabel;
00104         JLabel destTimeLabel;
00105         JLabel chunksSelectedLabel;
00106         
00107         DecimalFormat fiveFiveNumberFormat = new java.text.DecimalFormat(); 
00108         DecimalFormat fiveTwoNumberFormat = new java.text.DecimalFormat(); 
00109         
00110         JPanel localControlPanel;
00111         //JLabel featureNameLabel;
00112 
00113         JPanel guiPanel;
00114         JFrame mainWindow;
00115         
00116         Color metaControlsColor;
00117         Color localControlsColor;
00118         Color drawingBackgroundColor;
00119 
00120     private JRadioButton playFeatChunksButton;
00121     private JRadioButton playEDLChunksButton;
00122     private JCheckBox playAddBlipsButton;
00123 
00124         private Point dragStart;
00125         private Point dragEnd;
00126         private boolean dragShift = false;
00127         
00128     private Thread playThread = null;
00129 
00130     private String helpURL;
00131 
00132         public Visualizer(FeatFile featFile, EDLFile eDLFile)
00133         {
00134                 String paths[] = MEAPUtil.getPaths();
00135                 if (paths != null)
00136                 {
00137                         meapsoftDirectory = paths[0];
00138                         dataDirectory = paths[1];
00139                 }
00140                 else
00141                         System.exit(-1);
00142                 
00143                 slash = MEAPUtil.slash;
00144                         
00145                 this.eDLInputFile = eDLFile;
00146                 this.featInputFile = featFile;
00147                 
00148                 if (this.featInputFile == null)
00149                         selectFeatInputFile();
00150                 else if (this.featInputFile.chunks.size() == 0)
00151                         selectFeatInputFile();
00152 
00153                 fiveFiveNumberFormat.setMaximumIntegerDigits(5);
00154                 fiveFiveNumberFormat.setMaximumFractionDigits(5);
00155                 
00156                 fiveTwoNumberFormat.setMaximumIntegerDigits(5);
00157                 fiveTwoNumberFormat.setMaximumFractionDigits(2);
00158                 
00159                 setupGUI();
00160         }
00161         
00162         private void setupGUI()
00163         {
00164                 mainWindow = new JFrame("MEAPsoft Visualizer");
00165                 mainWindow.setSize(1024, 768);
00166                 
00167                 guiPanel = new JPanel();
00168                 guiPanel.setLayout(new BorderLayout());
00169                 guiPanel.setSize(1024, 768);
00170                 mainWindow.setContentPane(guiPanel);
00171                 
00172                 metaControlsColor = new Color((int)(Math.random() * 127 + 127),
00173                                         (int)(Math.random() * 127 + 127),
00174                                         (int)(Math.random() * 127 + 127));
00175 
00176                 localControlsColor = new Color((int)(Math.random() * 127 + 127),
00177                                         (int)(Math.random() * 127 + 127),
00178                                         (int)(Math.random() * 127 + 127));
00179                                         
00180                 setupMetaControlsGUI();
00181                 setupDrawingPanel();    
00182                 setupLocalControlsGUI();                        
00183 
00184                 mainWindow.show();
00185         }
00186         
00187         private void setupMetaControlsGUI()
00188         {
00189                 metaControlPanel = new JPanel();
00190                 metaControlPanel.setLayout(new BoxLayout(metaControlPanel, BoxLayout.Y_AXIS));
00191                 metaControlPanel.setBackground(metaControlsColor);
00192 
00193                 /*
00194                  * select type of visualization
00195                  */
00196                 
00197                 JPanel visTypesPanel = new JPanel();
00198                 visTypesPanel.setLayout(new BoxLayout(visTypesPanel, BoxLayout.Y_AXIS));
00199                 visTypesPanel.setAlignmentX(0.0f);
00200                 visTypesPanel.setBackground(metaControlsColor);
00201                 TitledBorder t1 = BorderFactory.createTitledBorder(
00202                         BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), 
00203                         "visualization type");
00204                 t1.setTitleJustification(TitledBorder.CENTER);
00205                 visTypesPanel.setBorder(t1);
00206                 
00207                 String[] rendererStrings = {"segment order", "scatterplot", "bar graph", "line graph"};
00208 
00209                 rendererSelector = new JComboBox(rendererStrings);
00210                 rendererSelector.setMaximumSize(rendererSelector.getPreferredSize());
00211                 rendererSelector.setBackground(metaControlsColor);
00212                 rendererSelector.setActionCommand("rendererSelector");
00213                 rendererSelector.addActionListener(this);
00214                 
00215                 visTypesPanel.add(rendererSelector);
00216                 
00217                 metaControlPanel.add(visTypesPanel);
00218 
00219                 /*
00220                  * load files
00221                  */
00222                  
00223                 JPanel fileIOPanel = new JPanel();
00224                 fileIOPanel.setLayout(new BoxLayout(fileIOPanel, BoxLayout.Y_AXIS));
00225                 fileIOPanel.setAlignmentX(0.0f);
00226                 fileIOPanel.setBackground(metaControlsColor);
00227                 TitledBorder t2 = BorderFactory.createTitledBorder(
00228                         BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), 
00229                         "file I/O");
00230                 t2.setTitleJustification(TitledBorder.CENTER);
00231                 fileIOPanel.setBorder(t2);
00232 
00233                 featInputFileLabel = new JLabel("no file loaded");
00234                 featInputFileLabel.setBackground(metaControlsColor);
00235                 fileIOPanel.add(featInputFileLabel);
00236 
00237                 eDLInputFileLabel = new JLabel("no file loaded");
00238                 eDLInputFileLabel.setBackground(metaControlsColor);
00239                 fileIOPanel.add(eDLInputFileLabel);
00240                 
00241                 JButton selectFeatsButton = new JButton("load files");
00242                 selectFeatsButton.setBackground(metaControlsColor);
00243                 selectFeatsButton.setActionCommand("selectFiles");
00244                 selectFeatsButton.addActionListener(this);
00245                 fileIOPanel.add(selectFeatsButton);
00246 
00247                 JLabel featOutputFileLabel = 
00248                         new JLabel("save selected chunks");
00249                 featOutputFileLabel.setBackground(metaControlsColor);
00250                 fileIOPanel.add(featOutputFileLabel);
00251                 
00252                 JButton selectFeatOutputButton = new JButton("save .feat");
00253                 selectFeatOutputButton.setBackground(metaControlsColor);
00254                 selectFeatOutputButton.setActionCommand("saveFeatFile");
00255                 selectFeatOutputButton.addActionListener(this);
00256                 fileIOPanel.add(selectFeatOutputButton);
00257                 
00258                 JButton selectEDLOutputButton = new JButton("save .edl");
00259                 selectEDLOutputButton.setBackground(metaControlsColor);
00260                 selectEDLOutputButton.setActionCommand("saveEDLFile");
00261                 selectEDLOutputButton.addActionListener(this);
00262                 fileIOPanel.add(selectEDLOutputButton);
00263                 
00264                 metaControlPanel.add(fileIOPanel);
00265                 
00266                 /*
00267                  * audio playback
00268                  */
00269         JPanel audioPanel = new JPanel();
00270                 audioPanel.setLayout(new BoxLayout(audioPanel, BoxLayout.Y_AXIS));
00271                 audioPanel.setAlignmentX(0.0f);
00272                 audioPanel.setBackground(metaControlsColor);
00273                 TitledBorder t3 = BorderFactory.createTitledBorder(
00274                         BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), 
00275                         "synthesizer");
00276                 t3.setTitleJustification(TitledBorder.CENTER);
00277         audioPanel.setBorder(t3);
00278 
00279         playFeatChunksButton = new JRadioButton("play feat chunks");
00280         playFeatChunksButton.setBackground(metaControlsColor);
00281         playFeatChunksButton.setSelected(true);
00282         playFeatChunksButton.setEnabled(false);
00283         audioPanel.add(playFeatChunksButton);
00284         playEDLChunksButton = new JRadioButton("play edl chunks");
00285         playEDLChunksButton.setBackground(metaControlsColor);
00286         playEDLChunksButton.setEnabled(false);
00287         audioPanel.add(playEDLChunksButton);
00288         playAddBlipsButton = new JCheckBox("add blips");
00289         playAddBlipsButton.setBackground(metaControlsColor);
00290         playAddBlipsButton.setEnabled(true);
00291         audioPanel.add(playAddBlipsButton);
00292         
00293         ButtonGroup playTypeBG = new ButtonGroup();
00294         playTypeBG.add(playFeatChunksButton);
00295         playTypeBG.add(playEDLChunksButton);
00296 
00297         JButton playButton = new JButton("play selected");
00298         playButton.setBackground(metaControlsColor);
00299         playButton.setActionCommand("playChunks");
00300         playButton.addActionListener(this);
00301         audioPanel.add(playButton);
00302         JButton stopButton = new JButton("stop");
00303         stopButton.setBackground(metaControlsColor);
00304         stopButton.setActionCommand("stopPlayback");
00305         stopButton.addActionListener(this);
00306         audioPanel.add(stopButton);
00307 
00308                 metaControlPanel.add(audioPanel);
00309 
00310                 updateFileNameLabels();
00311 
00312                 /*
00313                  * standard info display
00314                  */
00315                 
00316                 JPanel infoDisplayPanel = new JPanel();
00317                 infoDisplayPanel.setLayout(new BoxLayout(infoDisplayPanel, BoxLayout.Y_AXIS));
00318                 infoDisplayPanel.setBackground(metaControlsColor);
00319                 infoDisplayPanel.setBounds(visTypesPanel.getBounds());
00320                 
00321                 TitledBorder t4 = BorderFactory.createTitledBorder(
00322                         BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), 
00323                         "chunk data");
00324                 t4.setTitleJustification(TitledBorder.CENTER);
00325                 infoDisplayPanel.setBorder(t4);
00326                 
00327                 JLabel iL1 = new JLabel("file name:");
00328                 infoDisplayPanel.add(iL1);
00329 
00330                 sourceLabel = new JLabel("unknown");
00331                 Font font = sourceLabel.getFont();
00332                 sourceLabel.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
00333                 infoDisplayPanel.add(sourceLabel);
00334                 
00335                 JLabel iL2 = new JLabel("feature name:");
00336                 infoDisplayPanel.add(iL2);
00337                 
00338                 featureNameLabel = new JLabel("unknown feature...");
00339                 featureNameLabel.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
00340                 infoDisplayPanel.add(featureNameLabel);
00341 
00342                 JLabel iL3 = new JLabel("feature range:");
00343                 infoDisplayPanel.add(iL3);
00344                 
00345                 featureRangeLabel = new JLabel("unknown range");
00346                 featureRangeLabel.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
00347                 infoDisplayPanel.add(featureRangeLabel);
00348 
00349                 JLabel iL4 = new JLabel("feature value:");
00350                 infoDisplayPanel.add(iL4);
00351                 
00352                 featureValueLabel = new JLabel("unknown value");
00353                 featureValueLabel.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
00354                 infoDisplayPanel.add(featureValueLabel);
00355                 
00356                 JLabel iL5 = new JLabel("start time:");
00357                 infoDisplayPanel.add(iL5);
00358                 
00359                 startTimeLabel = new JLabel("???");
00360                 startTimeLabel.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
00361                 infoDisplayPanel.add(startTimeLabel);
00362 
00363                 JLabel iL6 = new JLabel("length:");
00364                 infoDisplayPanel.add(iL6);
00365                 
00366                 lengthLabel = new JLabel("???");
00367                 lengthLabel.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
00368                 infoDisplayPanel.add(lengthLabel);
00369 
00370                 JLabel iL7 = new JLabel("dest time:");
00371                 infoDisplayPanel.add(iL7);
00372                 
00373                 destTimeLabel = new JLabel("???");
00374                 destTimeLabel.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
00375                 infoDisplayPanel.add(destTimeLabel);
00376                                 
00377                 chunksSelectedLabel = new JLabel("0 selected");
00378                 chunksSelectedLabel.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
00379                 infoDisplayPanel.add(chunksSelectedLabel);
00380                 
00381                 //ARRRRG! This is such a kludge. 
00382                 //If I don't do this then the freaking infoDisplayPanel jumps
00383                 //all over tarnation every time a value changes...!!!
00384                 JPanel dummyPanel = new JPanel();
00385                 dummyPanel.setBackground(metaControlsColor);
00386                 dummyPanel.setBounds(0,0,visTypesPanel.getWidth(), 0);
00387                 infoDisplayPanel.add(dummyPanel);
00388                 
00389                 metaControlPanel.add(infoDisplayPanel);
00390 
00391         JButton helpButton = new JButton("help");
00392                 helpButton.setForeground(Color.blue);
00393                 helpButton.setBackground(metaControlsColor);
00394         //helpButton.setAlignmentX(Component.CENTER_ALIGNMENT);
00395                 helpButton.setActionCommand("help");
00396                 helpButton.addActionListener(this);
00397         helpURL = "file:///" + meapsoftDirectory + slash + "doc" + slash 
00398             + "manual.html#Visualizer";
00399         metaControlPanel.add(helpButton);
00400         
00401         guiPanel.add(metaControlPanel, BorderLayout.LINE_START);
00402         }
00403         
00404         private void setupDrawingPanel()
00405         {
00406                 //we default to point-to-point
00407                 SegmentOrderRenderer pTPV = new SegmentOrderRenderer(featInputFile, eDLInputFile);
00408                 drawingPanel = new DrawingPanel(pTPV, this);
00409                 pTPV.setDrawingPanel(drawingPanel);
00410                 drawingPanel.setSize(800, 600);
00411                 drawingPanel.addMouseListener(this);
00412                 drawingPanel.addMouseMotionListener(this);
00413 
00414                 drawingPanel.addComponentListener(this);
00415                 
00416                 scroller = new JScrollPane(drawingPanel);
00417                 drawingPanel.setScroller(scroller);
00418                 guiPanel.add(scroller, BorderLayout.CENTER);
00419         }
00420         
00421         private void setupLocalControlsGUI()
00422         {
00423                 localControlPanel = drawingPanel.renderer.buildGUI(localControlsColor);
00424                 guiPanel.add(localControlPanel, BorderLayout.PAGE_END);
00425         }
00426         
00427         public void selectEDLInputFile()
00428         {
00429                 String names[] = GUIUtils.FileSelector(GUIUtils.OPENEDL, dataDirectory, mainWindow);
00430                         
00431                 if (names[0] == null)
00432                         return;
00433                                 
00434                 //System.out.println("you selected EDLFile: " + names[0]);
00435                 eDLInputFile = new EDLFile(names[0]);
00436                 try
00437                 {
00438                         eDLInputFile.readFile();
00439                 }
00440                 catch(Exception e)
00441                 {
00442                         e.printStackTrace();
00443                         System.exit(1);
00444                 }
00445         }
00446         
00447         public void selectFeatInputFile()
00448         {               
00449                 String names[] = GUIUtils.FileSelector(GUIUtils.OPENFEAT, dataDirectory, mainWindow);
00450                         
00451                 if (names[0] == null)
00452                         return;
00453 
00454                 featInputFile = new FeatFile(names[0]);
00455                 try
00456                 {
00457                         featInputFile.readFile();
00458                 }
00459                 catch(Exception e)
00460                 {
00461                         e.printStackTrace();
00462                         System.exit(1);
00463                 }
00464         }
00465         
00466         public void saveEDLOutputFile()
00467         {
00468                 String names[] = GUIUtils.FileSelector(GUIUtils.SAVEEDL, dataDirectory, mainWindow);
00469                         
00470                 if (names[0] == null)
00471                         return;
00472                 
00473                 eDLOutputFile = new EDLFile(names[0]);
00474                 
00475                 Vector selectedChunks = drawingPanel.renderer.getSelectedEDLChunks();
00476                 
00477                 double currentTime = 0.0;
00478                 
00479                 for (int i = 0; i < selectedChunks.size(); i++)
00480                 {
00481                         EDLChunk oldChunk = (EDLChunk)selectedChunks.elementAt(i);
00482                 
00483                         EDLChunk newChunk = 
00484                                 new EDLChunk(oldChunk.srcFile, oldChunk.startTime, oldChunk.length, currentTime);
00485                         newChunk.addFeature(oldChunk.getFeatures());
00486                         eDLOutputFile.chunks.add(newChunk);
00487                         
00488                         currentTime += oldChunk.length;
00489                 }
00490 
00491                 try
00492                 {
00493                         eDLOutputFile.writeFile();
00494                 }
00495                 catch (IOException e)
00496                 {
00497                         System.out.println("can't write .edl file!");
00498                         e.printStackTrace();
00499                 }
00500         }
00501 
00502         public void saveFeatOutputFile()
00503         {
00504                 String names[] = GUIUtils.FileSelector(GUIUtils.SAVEFEAT, dataDirectory, mainWindow);
00505                         
00506                 if (names[0] == null)
00507                         return;
00508                 
00509                 featOutputFile = new FeatFile(names[0]);
00510                 
00511                 Vector selectedChunks = drawingPanel.renderer.getSelectedFeatChunks();
00512                 
00513                 double currentTime = 0.0;
00514                 
00515                 for (int i = 0; i < selectedChunks.size(); i++)
00516                 {
00517                         //featOutputFile.chunks.add(selectedChunks.elementAt(i));
00518                         FeatChunk oldChunk = (FeatChunk)selectedChunks.elementAt(i);
00519                 
00520                         FeatChunk newChunk = 
00521                                 new FeatChunk(oldChunk.srcFile, currentTime, oldChunk.length);
00522                         newChunk.addFeature(oldChunk.getFeatures());
00523                         featOutputFile.chunks.add(newChunk);
00524                         currentTime += oldChunk.length;
00525                 }
00526 
00527                 int numFeatDescs = featInputFile.featureDescriptions.size();
00528                 
00529                 for (int i = 0; i < numFeatDescs; i++)
00530                 {
00531                         String desc = 
00532                                 (String)(featInputFile.featureDescriptions.elementAt(i)) + " ";
00533                         featOutputFile.featureDescriptions.add(desc);
00534                 }
00535                 
00536                 try
00537                 {
00538                         featOutputFile.writeFile();
00539                 }
00540                 catch (IOException e)
00541                 {
00542                         System.out.println("can't write .feat file!");
00543                         e.printStackTrace();
00544                 }
00545         }
00546 
00547         public void updateFileNameLabels()
00548         {       
00549                 if (featInputFile != null)
00550                 {
00551                         String fileNameFull = featInputFile.filename;
00552             // this doesn't work in windows since the slash character
00553             // is the same as the Java regular expression escape
00554             // character
00555             // String[] stringChunks = fileNameFull.split(slash);
00556                         
00557                         String shortName = new File(fileNameFull).getName();
00558                         featInputFileLabel.setText(shortName);
00559                         playFeatChunksButton.setEnabled(true);
00560                 }
00561                 else
00562                 {
00563                         featInputFileLabel.setText("no file loaded");
00564             playFeatChunksButton.setEnabled(false);
00565                 }
00566                 
00567                 if (eDLInputFile != null)
00568                 {
00569                         String fileNameFull = eDLInputFile.filename;
00570             // this doesn't work in windows since the slash character
00571             // is the same as the Java regular expression escape
00572             // character
00573                         // String[] stringChunks = fileNameFull.split(slash);
00574                         
00575                         String shortName = new File(fileNameFull).getName();
00576                         
00577                         eDLInputFileLabel.setText(shortName);
00578             playEDLChunksButton.setEnabled(true);
00579                 }
00580                 else
00581                 {
00582                         eDLInputFileLabel.setText("no file loaded");
00583             playEDLChunksButton.setEnabled(false);
00584                 }
00585                 /*
00586                 if (eDLOutputFile != null)
00587                 {
00588                         String fileNameFull = eDLOutputFile.filename;
00589                         String[] stringChunks = fileNameFull.split(slash);
00590                         
00591                         int numStrings = stringChunks.length;
00592                         
00593                         String shortName = stringChunks[numStrings - 1];
00594                         
00595                         eDLOutputFileLabel.setText(shortName);
00596                 }
00597                 else
00598                 {
00599                         eDLOutputFileLabel.setText("no file specified");
00600                 }
00601                 */
00602         }
00603         
00604         public void updateNumChunksSelectedLabel(int nCS)
00605         {
00606                 chunksSelectedLabel.setText(nCS + " selected");
00607         }
00608         
00609         public void updateDataLabels(String sN, String fN, double low, 
00610                 double high, double fV, double sT, double l, double dT)
00611         {               
00612                 sourceLabel.setText(sN);
00613                 if (fN.length() > 16)
00614                         fN = fN.substring(0,15);
00615                 featureNameLabel.setText(fN);
00616                 featureRangeLabel.setText(fiveTwoNumberFormat.format(low) + " : " + fiveTwoNumberFormat.format(high));
00617                 featureValueLabel.setText(fiveFiveNumberFormat.format(fV));
00618                 startTimeLabel.setText(fiveFiveNumberFormat.format(sT));
00619                 lengthLabel.setText(fiveFiveNumberFormat.format(l));
00620                 destTimeLabel.setText(fiveFiveNumberFormat.format(dT));
00621         }
00622 
00623         public void updateInfoLabelsForPoint(Point p)
00624         {
00625                 Vector chunks = drawingPanel.renderer.getChunkVisInfosForPoint(p);
00626                 if (chunks.size() == 0)
00627                         return;
00628                 
00629                 //just use first one
00630                 ChunkVisInfo cVI = (ChunkVisInfo)chunks.elementAt(0);
00631 
00632                 String sF = new File(cVI.srcFile).getName();
00633                 
00634                 String fN = drawingPanel.renderer.getFeatureNameForPoint(p);
00635                 double fV = drawingPanel.renderer.getFeatureValueForPoint(p);
00636                 int featNum = drawingPanel.renderer.getFeatureNumberForPoint(p);
00637                 double low = 0.0;
00638                 double high = 0.0;
00639                 
00640                 //kludge alert!!!
00641                 if (fN.equals("start time") || fN.equals("dest time"))
00642                 {
00643                         low = 0.0;
00644                         high = drawingPanel.renderer.lastStartTime;
00645                 }
00646                 else if (fN.equals("length"))
00647                 {
00648                         low = drawingPanel.renderer.shortestChunk;
00649                         high = drawingPanel.renderer.longestChunk;
00650                 }
00651                 else if (featNum == -1)
00652                 {
00653                         low = 0.0;
00654                         high = 0.0;
00655                 }
00656                 else
00657                 {
00658                         low = drawingPanel.renderer.lowestFeatureValue[featNum];
00659                         high = drawingPanel.renderer.highestFeatureValue[featNum];
00660                 }
00661                 
00662                 updateDataLabels(sF, fN, low, high, fV, cVI.startTime, cVI.length, 
00663                         cVI.dstTime);
00664         }
00665         
00666     public void playSelectedChunks(boolean addBlips)
00667     {
00668         EDLFile edl = new EDLFile("temp file");
00669 
00670         boolean playFeatChunks = playFeatChunksButton.isSelected();
00671         Vector selectedChunks = null;
00672 
00673         String blipWav = dataDirectory + System.getProperty("file.separator") + "blip.wav"; 
00674         double blipDuration = 0.1;
00675 
00676         if(playFeatChunks)
00677             selectedChunks = drawingPanel.renderer.getSelectedFeatChunks();
00678         else
00679             selectedChunks = drawingPanel.renderer.getSelectedEDLChunks();
00680                 
00681         double currentTime = 0.0;
00682                 
00683         for (int i = 0; i < selectedChunks.size(); i++)
00684             {
00685                 Chunk oldChunk = null;
00686                 if(playFeatChunks)
00687                     oldChunk = (FeatChunk)selectedChunks.elementAt(i);
00688                 else
00689                     oldChunk = (EDLChunk)selectedChunks.elementAt(i);
00690 
00691                 EDLChunk newChunk = new EDLChunk(oldChunk.srcFile, 
00692                                              oldChunk.startTime, 
00693                                              oldChunk.length, currentTime);
00694 
00695                 // do some fading by default so it doesn't sound so bad
00696                 newChunk.commands.add("fade");
00697                 
00698                 edl.chunks.add(newChunk);
00699 
00700                 if (addBlips) {
00701                     EDLChunk blip = new EDLChunk(blipWav, 0, blipDuration, currentTime);
00702                     edl.chunks.add(blip);
00703                 }
00704                 
00705                 currentTime += oldChunk.length;
00706             }
00707         edl.haveReadFile = true;
00708 
00709         Synthesizer synth = new Synthesizer(edl, null);
00710         playThread = new Thread(synth, "synthesizer");
00711         playThread.start();
00712     }
00713 
00714     public static void main(String[] args)
00715     {           
00716         EDLFile eDLFile = null;
00717         FeatFile featFile = null;
00718                 
00719                 if (args.length == 1)
00720                 {
00721                         featFile = new FeatFile(args[0]);
00722                 }
00723                 else if (args.length == 2)
00724                 {
00725                         featFile = new FeatFile(args[0]);
00726                         eDLFile = new EDLFile(args[1]);
00727                 }
00728                 else
00729                 {
00730                         System.out.println("I don't understand your command line arguments.");
00731                         System.exit(-1);
00732                 }
00733 
00734                 try
00735                 {
00736                         if (featFile != null)
00737                                 featFile.readFile();
00738                                 
00739                         if (eDLFile != null)
00740                                 eDLFile.readFile();
00741                 }
00742                 catch(Exception e)
00743                 {
00744                         e.printStackTrace();
00745                         System.exit(1);
00746                 }
00747         
00748         Visualizer sV = new Visualizer(featFile, eDLFile);
00749         }
00750 
00751         public void actionPerformed(ActionEvent arg0)
00752         {
00753                 String command = arg0.getActionCommand();
00754                 
00755                 if (command.equals("rendererSelector"))
00756                 {                       
00757                         if (rendererSelector.getSelectedIndex() == 0)
00758                         {
00759                                 mainWindow.hide();
00760                                 drawingPanel.resetZoom();
00761                                 SegmentOrderRenderer pTPV;
00762         
00763                                 if (drawingPanel.renderer != null)
00764                                         pTPV = new SegmentOrderRenderer(drawingPanel.renderer);                 
00765                                 else 
00766                                         pTPV = new SegmentOrderRenderer(featInputFile, eDLInputFile);
00767                                 drawingPanel.setRenderer(pTPV);
00768                                 pTPV.setDrawingPanel(drawingPanel);
00769                                 guiPanel.remove(localControlPanel);
00770                                 localControlPanel = drawingPanel.renderer.buildGUI(Color.orange);
00771                                 guiPanel.add(localControlPanel, BorderLayout.PAGE_END);
00772                                 guiPanel.repaint();
00773                                 mainWindow.show();
00774                         }
00775                         else if (rendererSelector.getSelectedIndex() == 1)
00776                         {
00777                                 mainWindow.hide();
00778                                 drawingPanel.resetZoom();
00779                                 ScatterPlotRenderer sPV;
00780                                 if (drawingPanel.renderer != null)
00781                                         sPV = new ScatterPlotRenderer(drawingPanel.renderer);                   
00782                                 else 
00783                                         sPV = new ScatterPlotRenderer(featInputFile, eDLInputFile);
00784                                 drawingPanel.setRenderer(sPV);
00785                                 sPV.setDrawingPanel(drawingPanel);
00786                                 guiPanel.remove(localControlPanel);
00787                                 localControlPanel = drawingPanel.renderer.buildGUI(Color.orange);
00788                                 guiPanel.add(localControlPanel, BorderLayout.PAGE_END);
00789                                 guiPanel.repaint();
00790                                 mainWindow.show();
00791                         }
00792                         else if (rendererSelector.getSelectedIndex() == 2)
00793                         {
00794                                 mainWindow.hide();
00795                                 drawingPanel.resetZoom();
00796                                 BarGraphRenderer bGV;
00797                                 if (drawingPanel.renderer != null)
00798                                         bGV = new BarGraphRenderer(drawingPanel.renderer);                      
00799                                 else 
00800                                         bGV = new BarGraphRenderer(featInputFile, eDLInputFile);
00801                                 drawingPanel.setRenderer(bGV);
00802                                 bGV.setDrawingPanel(drawingPanel);
00803                                 guiPanel.remove(localControlPanel);
00804                                 localControlPanel = drawingPanel.renderer.buildGUI(Color.orange);
00805                                 guiPanel.add(localControlPanel, BorderLayout.PAGE_END);
00806                                 guiPanel.repaint();
00807                                 mainWindow.show();
00808                         }
00809                         else if (rendererSelector.getSelectedIndex() == 3)
00810                         {
00811                                 mainWindow.hide();
00812                                 drawingPanel.resetZoom();
00813                                 LineGraphRenderer lGV;
00814                                 if (drawingPanel.renderer != null)
00815                                         lGV = new LineGraphRenderer(drawingPanel.renderer);                     
00816                                 else 
00817                                         lGV = new LineGraphRenderer(featInputFile, eDLInputFile);
00818                                 drawingPanel.setRenderer(lGV);
00819                                 lGV.setDrawingPanel(drawingPanel);
00820                                 guiPanel.remove(localControlPanel);
00821                                 localControlPanel = drawingPanel.renderer.buildGUI(Color.orange);
00822                                 guiPanel.add(localControlPanel, BorderLayout.PAGE_END);
00823                                 guiPanel.repaint();
00824                                 mainWindow.show();
00825                         }
00826                 }
00827                 else if (command.equals("numChunksSelectedChanged"))
00828                 {
00829                         updateNumChunksSelectedLabel(drawingPanel.renderer.numChunksSelected());
00830                 }
00831                 else if (command.equals("selectFiles"))
00832                 {
00833                         selectFeatInputFile();
00834                         //updateFileNameLabels();
00835                         //drawingPanel.renderer.setFiles(featInputFile, eDLInputFile);
00836                         //drawingPanel.repaint();
00837                         
00838                         selectEDLInputFile();
00839                         updateFileNameLabels();
00840                         drawingPanel.renderer.setFiles(featInputFile, eDLInputFile);
00841                         drawingPanel.repaint();
00842                 }
00843                 /*
00844                 else if (command.equals("selectEDL"))
00845                 {
00846                         selectEDLInputFile();
00847                         updateFileNameLabels();
00848                         drawingPanel.renderer.setFiles(featInputFile, eDLInputFile);
00849                         drawingPanel.repaint();
00850                 }
00851                 else if (command.equals("selectFeats"))
00852                 {
00853                         selectFeatInputFile();
00854                         updateFileNameLabels();
00855                         drawingPanel.renderer.setFiles(featInputFile, eDLInputFile);
00856                         drawingPanel.repaint();
00857                 }
00858                 */
00859                 else if (command.equals("saveFeatFile"))
00860                 {
00861                         saveFeatOutputFile();
00862                 }
00863                 else if (command.equals("saveEDLFile"))
00864                 {
00865                         saveEDLOutputFile();
00866                 }
00867                 else if (command.equals("updateFiles"))
00868                 {
00869                         drawingPanel.renderer.setFiles(featInputFile, eDLInputFile);
00870                         drawingPanel.repaint();
00871                 }
00872         else if (command.equals("playChunks"))
00873         {
00874             // stop any already existing threads
00875             if(playThread != null)
00876             {
00877                 playThread.interrupt();
00878                 playThread.stop();
00879             }
00880 
00881             playSelectedChunks(playAddBlipsButton.isSelected());
00882         }
00883         else if (command.equals("stopPlayback"))
00884         {
00885             if(playThread != null)
00886             {
00887                 playThread.interrupt();
00888                 playThread.stop();
00889                 playThread = null;
00890             }
00891         }
00892         else if (command.equals("help"))
00893         {
00894             HelpWindow help = new HelpWindow(helpURL, "Visualizer Help", Color.WHITE);
00895         }
00896         }
00897 
00898 
00899         public void mouseClicked(MouseEvent arg0)
00900         {
00901                 Point p = arg0.getPoint();
00902 
00903                 drawingPanel.renderer.toggleSelectedForPoint(p);
00904                 updateNumChunksSelectedLabel(drawingPanel.renderer.numChunksSelected());
00905                 drawingPanel.repaint();
00906         }
00907 
00908         public void mousePressed(MouseEvent arg0)
00909         {
00910                 
00911         }
00912 
00913 
00914         public void mouseReleased(MouseEvent arg0)
00915         {
00916                 if (dragStart != null)
00917                 {
00918                         dragEnd = arg0.getPoint();
00919                         
00920                         //System.out.println(dragStart.toString() + " " + dragEnd.toString());
00921                         
00922                         int xDist = dragEnd.x - dragStart.x;
00923                         int yDist = dragEnd.y - dragStart.y;
00924                         int x = dragStart.x;
00925                         int y = dragStart.y;
00926                         
00927                         if (xDist < 0)
00928                                 x = dragEnd.x;
00929                         
00930                         if (yDist < 0)
00931                                 y = dragEnd.y;  
00932                         
00933                         drawingPanel.renderer.setDragRect(new Rectangle(x, y, Math.abs(xDist), Math.abs(yDist)), dragShift);
00934                         
00935                         updateNumChunksSelectedLabel(drawingPanel.renderer.numChunksSelected());
00936 
00937                         dragStart = null;
00938                         dragEnd = null;
00939                         dragShift = false;
00940                 }
00941         }
00942 
00943 
00944         public void mouseEntered(MouseEvent arg0)
00945         {
00946 
00947         }
00948 
00949 
00950         public void mouseExited(MouseEvent arg0)
00951         {
00952 
00953         }
00954 
00955 
00956         public void mouseDragged(MouseEvent arg0)
00957         {
00958                 if (dragStart == null)
00959                 {
00960                         dragStart = arg0.getPoint();
00961 
00962                         if ((arg0.getModifiers() & MouseEvent.SHIFT_MASK) == MouseEvent.SHIFT_MASK)
00963                                 dragShift = true;
00964                 }
00965                 else
00966                 {
00967                         dragEnd = arg0.getPoint();
00968                         
00969                         //System.out.println(dragStart.toString() + " " + dragEnd.toString());
00970                         
00971                         int xDist = dragEnd.x - dragStart.x;
00972                         int yDist = dragEnd.y - dragStart.y;
00973                         int x = dragStart.x;
00974                         int y = dragStart.y;
00975                         
00976                         if (xDist < 0)
00977                                 x = dragEnd.x;
00978                         
00979                         if (yDist < 0)
00980                                 y = dragEnd.y;  
00981                         
00982                         drawingPanel.renderer.updateDragRect(new Rectangle(x, y, Math.abs(xDist), Math.abs(yDist)), dragShift);
00983                 }
00984         }
00985 
00986 
00987         public void mouseMoved(MouseEvent arg0)
00988         {
00989                 Point p = arg0.getPoint();
00990 
00991                 updateInfoLabelsForPoint(p);
00992         }
00993 
00994         public void componentResized(ComponentEvent arg0)
00995         {               
00996                 if (!drawingPanel.iJustZoomed)
00997                 {
00998                 
00999                         drawingPanel.setOrigWH(drawingPanel.getWidth(), drawingPanel.getHeight());
01000                         //System.out.println("cR...");
01001                 }
01002                 drawingPanel.iJustZoomed = false;
01003         }
01004 
01005         public void componentMoved(ComponentEvent arg0)
01006         {
01007         }
01008 
01009         public void componentShown(ComponentEvent arg0)
01010         {
01011         }
01012 
01013         public void componentHidden(ComponentEvent arg0)
01014         {
01015         }
01016 }

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