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 panFuzzyGraphic extends JPanel 
{
  private myDebug debug = new myDebug(5);
  private FuzzyCollection fc;
  private boolean typeinput;
  private int currentPercent=100;
  private Graphics currentG;
  private String title="";

  public panFuzzyGraphic() 
  {
    try 
    {
      jbInit();
    }
    catch(Exception ex) 
    {
      ex.printStackTrace();
    }
  }

  public void setFuzzyCollection(FuzzyCollection fc, boolean input) 
  {
    this.fc=fc;
    this.typeinput=input;
  }

  public void setTitle(String title) 
  {
    this.title=title;
  }

  public panFuzzyGraphic(FuzzyCollection fc, boolean input) 
  {
    debug.Write("panFuzzyGraphic(..)",0);
    
    this.fc=fc;
    this.typeinput=input;
    
    try 
    {
      jbInit();
    }
    catch(Exception ex) 
    {
      ex.printStackTrace();
    }
  }

  void jbInit() throws Exception 
  {
    this.setLayout(null);
  }

  public void paint(Graphics g) 
  {
    debug.Write("panFuzzyGraphic.paint(..)" ,0);
    
    if (g==null)
      return;
    
    if (fc!=null) 
    {
      this.setForeground(Color.black);
      g.drawRect(0,0,this.getWidth()-1,this.getHeight()-1);

      if (typeinput)
        fc.drawInputGraph(g,1,1,this.getWidth()-2,this.getHeight()-2);
      else
        fc.drawOutputGraph(g,1,1,this.getWidth()-2,this.getHeight()-2);
      
      if (title.length()>0) 
      {
        g.setColor(Color.black);
        g.setFont(new Font("Arial",0,10));
        g.drawString(title,this.getWidth()-g.getFontMetrics().stringWidth(title)-4,this.getHeight()-4);
      }
    } 
    else 
    {
      this.setBackground(Color.green);
      this.setForeground(Color.black);
      g.drawRect(0,0,this.getWidth()-1,this.getHeight()-1);
    }
  }
}
