/*
 *  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.awt.event.MouseEvent;
import java.util.Iterator;

import javax.swing.JFrame;

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

public class SingleFeatureSegmentsOnlyPanel extends SingleFeaturePanel
{	
	private static final long serialVersionUID = 1L;
	
	public SingleFeatureSegmentsOnlyPanel(FeatFile featFile, String featureName) 
	{
		super(featFile, featureName);
		
		 numDrawableFeatures = 1;
	}

	public String getDisplayType() 
	{
		return "SegmentsOnly";
	}
	
	public void drawData(Graphics g) 
	{	
		double zoomMulti = (zoomLevel * 4.0)/4.0;
		int w = (int)(this.getWidth() * zoomMulti);
		int h = this.getHeight();

		g.setColor(bgColor);
		g.fillRect(0, 0, w, h);
		
		//g.setColor(fGColor);
		
		//g.drawString("no data", 100, 100);
		
	}

/*
	//we override this to draw ticks all the way up the display	
	void drawSegmentTicks(Graphics g)
	{
		int w = (int)(this.getWidth() * zoomLevel);
		int h = this.getHeight();
		//size of ticks
		//int ySize = (int)(h * 0.05);
		
		double xScaler = w/timeRange;
		
		g.setColor(segmentTicksColor);
		
		double localFirstEventTime = ((FeatChunk)events.elementAt(firstChunkToDraw)).startTime;
		
		Iterator it = events.iterator();
		
		for (int i = 0; i < firstChunkToDraw; i++)
			it.next();
		
		int x = 0;
		
		while (it.hasNext () && x < getWidth())
		{
			FeatChunk fC = (FeatChunk)it.next();
			double startTime = fC.startTime - localFirstEventTime;
			
			x = (int)(startTime * xScaler);
			g.drawLine(x, 0, x, h);
			//g.drawLine(x, h, x, h - ySize);
			
		}
	}
*/
	public void mouseClicked(MouseEvent arg0) 
	{		
		//System.out.println(featureName + ": thanks for clicking in me!");
	}

	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
	public static void main(String[] args)
	{
		if (args.length < 2)
		{
			System.out.println("usage: SingleFeatureBarGraphPanel myfilename myfeaturename\n");
			System.exit(-1);
		}

		final String fileName = args[0];
		final String featureName = args[1];
		final FeatFile fF = new FeatFile(fileName);
		//Schedule a job for the event-dispatching thread:
		//creating and showing this application's GUI.
		javax.swing.SwingUtilities.invokeLater(new Runnable() 
		{
			public void run() 
			{
				JFrame frame = new JFrame("SingleFeatureBarGraphPanel");
				
				try
				{
					fF.readFile();
				}
				catch(Exception e)
				{
					e.printStackTrace();
					System.exit(-1);
				}
				SingleFeaturePanel sFP = new SingleFeatureSegmentsOnlyPanel(fF, featureName);
				if (sFP.initialize() == -1)
				{
					System.out.println("hmm, something wrong, bailing.");
					System.exit(-1);
				}
				sFP.setSize(600, 400);
				
				frame.setContentPane(sFP);
				frame.pack();
				frame.setVisible(true);
				frame.setBounds(100, 100, 600, 400);

				sFP.repaint();
			}
		});
	}
}
