/*******************************************************************************
 * Copyright (c) 2010 Attila Kovacs <attila_kovacs@post.harvard.edu>.
 * All rights reserved. 
 * 
 * This file is part of crush.
 * 
 *     crush is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     crush 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 crush.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Contributors:
 *     Attila Kovacs <attila_kovacs@post.harvard.edu> - initial API and implementation
 ******************************************************************************/
// Copyright (c) 2007 Attila Kovacs 

package crush.gui;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

public class ColorScalePanel extends ColorMapPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 460851913543807978L;
	int width;
	double zerolevel;
	int size = 100;

	public ColorScalePanel(int Width) {	
		spacing=0;

		width=Width;

		setPreferredSize(new Dimension(width, size));

		data = new double[size][1];

		for(int i=0; i<size; i++) data[i][0] = 1.0 - 1.0 / size * i;

		Border border = BorderFactory.createLineBorder(Color.BLACK);
		setBorder(border);
	}

	public void invert() {
		double[][] inverted = new double[size][1];
		for(int i=0; i<size; i++) inverted[i][0] = data[size-1-i][0];
		data = inverted;
		repaint();
	}

	public void Draw(Graphics g) {
		super.draw(g);
		int height=getHeight()-2*borderheight;
		int y=(int) (zerolevel*height) + borderwidth;

		g.setColor(Color.black);
		g.drawLine(borderwidth, y, width-borderwidth-1, y);
	}
}

