package com.teppefall.subpixel;

/**
 * @author janerik
 * 
 * ColorIcon.java
 * 
 * Creates a toolbar icon based on Color, String ID or both. Used by ColorAction.
 */

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.GradientPaint;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;

public class ColorIcon extends ImageIcon {

	public static String COLORICON = "colorIcon";//, SPLITICON = "splitIcon", GRADIENTICON = "gradienticon";
	String type;
	Color color;
	int size = 10;

	public ColorIcon(Color color) {
		this(color, COLORICON);
	}
	
	public ColorIcon(String type) {
		this(new JMenuItem().getForeground(), type);
		size = 18;
	}

	public ColorIcon(Color color, String type) {
		this.color = color;
		this.type = type;
	}

	public int getIconHeight() {
		return size;
	}
	
	public int getIconWidth() {
		return size;
	}

	public synchronized void paintIcon(Component c, Graphics g, int insetsx, int insetsy) {
		g.setColor(color);
		if(type.equals(COLORICON)) {
			g.fillRect(insetsx, insetsy, size, size);
		}
		else if(type.equals(PaintAction.SPLIT)) {
			g.drawRect(insetsx, insetsy, size, size);
			g.drawLine(insetsx+size/2, insetsy, size/2, size);
		}
		else if(type.equals(PaintAction.GRADIENT)) {
			GradientPaint gradient = new GradientPaint(0, 0, Color.WHITE, size, size, Color.BLACK);
	        //g.setPaint(gradient);
			g.drawRect(insetsx, insetsy, size, size);
		}
	}
	
}

