/*
* 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.EDLChunk;
import com.meapsoft.EDLFile;
import com.meapsoft.FeatChunk;
import com.meapsoft.FeatFile;
import com.meapsoft.disgraced.ColorMap;
/**
*
* @author douglas@music.columbia.edu
*
*/
public class SingleFeatureColorBarsPanel extends SingleFeaturePanel
{
private static final long serialVersionUID = 1L;
int numColors = 256;
ColorMap colormap = ColorMap.getJet(numColors);
public SingleFeatureColorBarsPanel()
{
numDrawableFeatures = -1;
}
public SingleFeatureColorBarsPanel(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 "ColorBars";
}
// 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;
//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);
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 x = 0;
int width = 0;
// keep track of our progress:
progress.setMinimum(0);
progress.setMaximum(numChunks);
progress.setValue(0);
for (int chunkNum = firstChunkToDraw; chunkNum < numChunks && x < getWidth(); chunkNum++)
{
//FeatChunk fC = getFeatChunkByNumber(chunkNum);
FeatChunk fC = (FeatChunk)events.get(chunkNum);
//if (edlFile == null)
//{
x = (int) ((fC.startTime - localFirstEventTime) * xScaler);
width = (int) (fC.length * xScaler) + 1;
//}
//else
//{
// EDLChunk eC = (EDLChunk)events.get(chunkNum);
// x = (int) ((eC.dstTime - localFirstEventTime) * xScaler);
// width = (int) (eC.length * xScaler) + 1;
//}
// adjust to zero
//double[] dataPoints = featFile.getFeatureByName(featureName, i);
double[] dataPoints = fC.getFeatureByName(featureName);
//double dataPoints[] = fC.getFeatures();// featureData[i];
if (featureSize > 1)
{
for (int j = 1; j < featureSize + 1; j++)
{
double dataPoint = dataPoints[j - 1] - lowestValue;
double colorIndex = (dataPoint / featureRange) * 255.0;
double y = j * yIncr;
// System.out.println("i: " + i + " j: " + j + " x: " + x +
// " y: " + y + " h: " + h + " yIncr: " + yIncr);
g.setColor(colormap.table[(int) colorIndex]);
g.fillRect(x, h - (int) (y), width, (int) yIncr + 1);
}
}
else
{
double dataPoint = dataPoints[0] - lowestValue;
double colorIndex = (dataPoint / featureRange) * 255.0;
g.setColor(colormap.table[(int) colorIndex]);
g.fillRect(x, 0, width, h);
}
//increment the progress
progress.setValue(progress.getValue()+1);
}
// g.setColor(this.defaultFGColor);
// g.drawString(featureName, 20, 20);
/*
* if (showSegmentTicks) drawSegmentTicks(g);
*
* if (selected) drawBorder(g);
*/
}
public static void printUsageAndExit()
{
System.out
.println("Usage: SingleFeatureColorBarsPanel [-options] features.feat FeatureName \n\n"
+ " where options include:\n"
+ getStandardUsage()
);
System.out.println();
System.exit(0);
}
public static void main(String[] args)
{
//final String argArray[] = args;
if (args.length < 1)
{
printUsageAndExit();
}
SingleFeatureColorBarsPanel sFP = new SingleFeatureColorBarsPanel(args);
if (sFP.pngOutputFileName == null)
{
JFrame frame = new JFrame("SingleFeatureColorBarsPanel");
frame.setContentPane(sFP);
frame.pack();
//frame.setBounds(100, 100, 600, 400);
frame.setVisible(true);
}
}
}