Package com.meapsoft.visualizer

Source Code of com.meapsoft.visualizer.SingleFeatureBarGraphPanel

/*
*  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.Graphics;

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

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

/**
*
* @author douglas@music.columbia.edu
*
*/

public class SingleFeatureBarGraphPanel extends SingleFeaturePanel
{
  private static final long serialVersionUID = 1L;

  public SingleFeatureBarGraphPanel()
  {
    super();

    numDrawableFeatures = 1;
  }

  public SingleFeatureBarGraphPanel(String[] args)
  {
    super();
   
    parseCommands(args);
   
    numDrawableFeatures = 1;
    setProgress(new DefaultBoundedRangeModel());
   
    String fileName = args[args.length - 2];
    FeatFile fF = null;
    EDLFile eF = null;
   
    String featName = args[args.length-1];
   
    try
    {
      fF = new FeatFile(fileName);
      fF.readFile();
     
      if (edlFileName != null)
      {
        System.out.println("making EDLFile from " + edlFileName);
        eF = new EDLFile(edlFileName);
        eF.readFile();
      }
       
    }
    catch(Exception e)
    {
      e.printStackTrace();
      return;
    }

    if (initialize(fF, eF, featName) == -1)
    {
      System.out.println("hmm, something wrong, bailing.");
      return;
    }
   
    repaint();
   
    if (pngOutputFileName != null)
    {
      writeImageToPNG(pngOutputFileName);
      System.exit(0);
    }
  }
 
  public String getDisplayType()
  {
    return "BarGraph";
  }

  // 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 h = this.getHeight();
    double yScaler = h / featureRange;

    double xScaler = w / timeRange;
    //System.out.println("w: " + w + " h: " + h);
    //System.out.println("xScaler: " + xScaler + " yScaler: " + yScaler);
    //System.out.println("numChunks: " + numChunks);

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

    g.setColor(fGColor);

    double localFirstEventTime = ((FeatChunk) events
        .get(firstChunkToDraw)).startTime;
    int x = 0;

    for (int i = firstChunkToDraw; i < numChunks && x < getWidth(); i++)
    {
      FeatChunk fC = (FeatChunk) events.get(i);
      x = (int) ((fC.startTime - localFirstEventTime) * xScaler);
      int width = (int) (fC.length * xScaler) + 1;

      //double[] features = featFile.getFeatureByName(featureName, i);
      double[] features = fC.getFeatureByName(featureName);
     
      //we can just use features[0] because we know that bar graph panel only
      //draws one dimensional features!
      // adjust to zero
      double dataPoint = features[0] - lowestValue;
      // featureData[i][0] - lowestValue;
      int y = (int) (dataPoint * yScaler);

      // g.drawLine(xPrev, yPrev, x, y);
      g.fillRect(x, h - y, width, y);
    }

  }

  public static void printUsageAndExit()
  {
    System.out
        .println("Usage: SingleFeatureBarGraphPanel [-options] featuresFile.feat FeatureName \n\n"
            + "  where options include:\n"
            + getStandardUsage()
            );
    System.out.println();
    System.exit(0);
  }
 
  public static void main(String[] args)
  {
    if (args.length < 2)
    {
      printUsageAndExit();
    }
   
    SingleFeatureBarGraphPanel sFP = new SingleFeatureBarGraphPanel(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.SingleFeatureBarGraphPanel

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.