Package com.meapsoft.visualizer

Source Code of com.meapsoft.visualizer.SingleFeatureCrissCrossPanel

/*
*  Copyright 2006-2007 Columbia University.
*
*  This file is part of MEAPsoft.
*
*  MEAPsoft is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License version 2 as
*  published by the Free Software Foundation.
*
*  MEAPsoft is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*  General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with MEAPsoft; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
*  02110-1301 USA
*
*  See the file "COPYING" for the text of the license.
*/

package com.meapsoft.visualizer;

import java.awt.Color;
import java.awt.Graphics;
import java.util.List;
import java.util.Vector;

import javax.swing.DefaultBoundedRangeModel;
import javax.swing.JFrame;

import com.meapsoft.EDLChunk;
import com.meapsoft.EDLFile;
import com.meapsoft.FeatChunk;
import com.meapsoft.FeatFile;

/**
*
* @author douglas@music.columbia.edu
*
* This panel just draws crisscrosses to show how the chunks
* in a feat file are related to the chunks in an edl file.
*/

public class SingleFeatureCrissCrossPanel extends SingleFeaturePanel
{
  private static final long serialVersionUID = 1L;
 
  List edlEvents = new Vector();

  public SingleFeatureCrissCrossPanel()
  {
    numDrawableFeatures = -1;
  }

  public SingleFeatureCrissCrossPanel(String[] args)
  {
    super();

    parseCommands(args);
   
    numDrawableFeatures = -1;
    setProgress(new DefaultBoundedRangeModel());
   
    String featFileName = args[args.length - 3];
    FeatFile fF = new FeatFile(featFileName);
   
    String edlFileName = args[args.length - 2];
    EDLFile eF = new EDLFile(edlFileName);
   
    String featName = args[args.length-1];
   
    try
    {
      fF.readFile();
      eF.readFile();
    }
    catch(Exception e)
    {
      e.printStackTrace();
      return;
    }

    //we don't want to process the edl file in this one!
    //if (initialize(fF, eF, featName) == -1)
    if (initialize(fF, null, featName) == -1)
    {
      System.out.println("hmm, something wrong, bailing.");
      return;
    }

    edlEvents = eF.chunks;
   
    repaint();
   
    if (pngOutputFileName != null)
    {
      writeImageToPNG(pngOutputFileName);
      System.exit(0);
    }
  }

  public String getDisplayType()
  {
    return "CrissCross";
  }

  // stub class, implemented from abstract parent class
  public void updateData()
  {

  }

  public void drawData(Graphics g)
  {
    double zoomMulti = (zoomLevel * 4.0) / 4.0;
    int w = (int) (this.getWidth() * zoomMulti);
    // int w = this.getWidth();
    int h = this.getHeight();
    //double yScaler = h / featureRange;

    double xScaler = w / timeRange;

    g.setColor(bgColor);
    g.fillRect(0, 0, w, h);

    g.setColor(Color.black);
    //double yIncr = (double) h / featureSize;
    //System.out.println("yIncr: " + yIncr);

    double localFirstEventTime = 0.0;
   
    //if (edlFile == null)
      localFirstEventTime = ((FeatChunk)events.get(firstChunkToDraw)).startTime;
    //else
      //localFirstEventTime = ((EDLChunk)events.get(firstChunkToDraw)).dstTime;
   
    int xFeat = 0;
    int xEDL = 0;
    //int width = 0;
   
    for (int chunkNum = firstChunkToDraw; chunkNum < numChunks && xFeat < getWidth() && xEDL < getWidth(); chunkNum++)
    {     
      //FeatChunk fC = getFeatChunkByNumber(chunkNum);
      //EDLChunk eC = (EDLChunk)events.get(chunkNum);
      FeatChunk fC = (FeatChunk)events.get(chunkNum);
      //EDLChunk eC = (EDLChunk)edlEvents.get(chunkNum);
      EDLChunk eC = null;
     
      for (int i = 0; i < numChunks; i++)
      {
        EDLChunk edlC = (EDLChunk)edlEvents.get(i);
        if (fC.compareTo(edlC) == 0)
        {
          eC = edlC;
        }
      }
     
      xFeat = (int)(((fC.startTime - localFirstEventTime) + (fC.length/2.0)) * xScaler);
      xEDL = (int) (((eC.dstTime - localFirstEventTime) + (eC.length/2.0)) * xScaler);
      //width = (int) (eC.length * xScaler) + 1;

      g.drawLine(xFeat, 0, xEDL, h);

    }
  }

  public static void printUsageAndExit()
  {
    System.out
        .println("Usage: SingleFeatureCrissCrossPanel [-options] featuresFile.feat edlFile.edl FeatureName \n\n"
            + "  where options include:\n"
            + getStandardUsage()
            );
    System.out.println();
    System.exit(0);
  }
 
  public static void main(String[] args)
  { 
    if (args.length < 3)
    {
      printUsageAndExit();
    }
   
    SingleFeatureCrissCrossPanel sFP = new SingleFeatureCrissCrossPanel(args);

    if (sFP.pngOutputFileName == null)
    {
      JFrame frame = new JFrame("SingleFeatureBarGraphPanel");
      frame.setContentPane(sFP);
      frame.pack();
      //frame.setBounds(100, 100, 600, 400);
      frame.setVisible(true);
    }
  }
}
TOP

Related Classes of com.meapsoft.visualizer.SingleFeatureCrissCrossPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.