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

/**
 * Title:        WaterMixApplet
 * Description:  Mixing water with Fuzzy Logic
 * Copyright:    Copyright (c) 2001
 * @author S. Robl <stefan@qdev.de>, A. Heinze <mail@aheinze.de>
 * @version 1.0
 */

public class WaterContainer 
{
  myDebug debug = new myDebug(5);
  int currentPercent=100;

  private int x, y, w, h, b;
  private int relFillRecTop; // upper pixel border of the filled water
  private Color BCol=Color.black;
  private Color WaterCol=Color.blue;
  private Color BackColor=Color.white;
  private double currentTemp=0;

  public WaterContainer(int x,int y,int w,int h,int b) 
  {
    this.x=x;
    this.y=y;
    this.w=w;
    this.h=h; 
	this.b=b;
	
    debug.Write("WaterContainer()",0);
  }

  public void setWaterColor(Color col) 
  {
    WaterCol=col;
  }
  
  public Color getWaterColor() 
  {
    return WaterCol;
  }

  public void setWaterTemp(double temperature) 
  {
    currentTemp=temperature;
    int v= (int)((temperature/100.0)*180);
    setWaterColor(new Color(255,180-v,0));
  }
  
  public double getWaterTemp() 
  {
    return currentTemp;
  }

  public int getWaterLevelPixel(boolean absolute) 
  {
    if (absolute) return y+relFillRecTop; else return relFillRecTop;
  }

  public void paint(Graphics g) 
  {
    debug.Write("WaterContainer.paint(..)",0);

    if (g==null) 
      return;

    g.setColor(BCol);
	g.fillRect(x,y,b,h);
	g.fillRect(x+w-b,y,b,h);
	g.fillRect(x,y+h-b,w,b);

    // set new water
    int fillPixel=(int)(((h-2*b)/100.0)*currentPercent);
    relFillRecTop=(h-b-fillPixel);
    debug.Write("fill(Pixel,%): " + new Integer(fillPixel).toString()+", " + currentPercent ,1);
    g.setColor(WaterCol);
    g.fillRect(x+b,y+relFillRecTop,w-2*b, fillPixel);
  }

  public void setLevel(int percent) 
  {
    currentPercent=percent;
  }

  public void setLevel(double min, double max, double current) 
  {
    if (current==0 || current<=min)
      setLevel(0);
    else if (current>=max || max<min) 
      setLevel(100);
    else
      setLevel((int)((current/(max-min))*100));
  }

  public void setBackColor(Color BackColor) 
  {
    this.BackColor=BackColor;
  }
}
