package crushtools.plot;
/*******************************************************************************
 * Copyright (c) 2014 Attila Kovacs <attila[AT]sigmyne.com>.
 * All rights reserved. 
 * 
 * This file is part of crushtools.
 * 
 *     crushtools 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.
 * 
 *     crushtools 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 crushtools.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Contributors:
 *     Attila Kovacs <attila[AT]sigmyne.com> - initial API and implementation
 ******************************************************************************/
// (C)2007 Attila Kovacs <attila[AT]sigmyne.com>

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

public class ColorScalePanel extends ColorMapPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 460851913543807978L;

	public int width;
	public double zerolevel;
	public int size = 300;

	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);
	}
}

