/*                                                                           *\
        file: EAF.java
       class: EAF
        date: 02/05/1996
      author: Jeroen, Arthur
 description: Put the CostDrivers window from Intermediate COCOMO on the 
              screen.
\*                                                                           */

import java.awt.*;

public class EAF extends Frame 
{
  /* scrollbars for monitoring shifts */
  private Scrollbar scrollbars[];
  private CocomoTool main;
  private final double multables[]={0.75,0.88,1.00,1.15,1.40,1.40,
                                    0.94,0.94,1.00,1.08,1.16,1.16,
                                    0.70,0.85,1.00,1.15,1.30,1.65,
                                    1.00,1.00,1.00,1.11,1.30,1.66,
                                    1.00,1.00,1.00,1.06,1.21,1.56,
                                    0.87,0.87,1.00,1.15,1.30,1.30,
                                    0.87,0.87,1.00,1.07,1.15,1.15,
                                    1.46,1.19,1.00,0.86,0.71,0.71,
                                    1.29,1.13,1.00,0.91,0.82,0.82,
                                    1.42,1.17,1.00,0.86,0.70,0.70,
                                    1.21,1.10,1.00,0.90,0.90,0.90,
                                    1.14,1.07,1.00,0.95,0.95,0.95,
                                    1.24,1.10,1.00,0.91,0.82,0.82,
                                    1.24,1.10,1.00,0.91,0.83,0.83,
                                    1.23,1.08,1.00,1.04,1.10,1.10};

  /* returns the value set at the slides */
  public double getEAF()
  {
    int i,j;
    double d=1.0,e;
    for(i=0;i<15;i++)
    {
      e=5.0*(double)scrollbars[i].getValue()/20.0;
      j=(int)Math.floor(e);
      if(j<0)
        d*=multables[i*6];
      else if(j>=5)
        d*=multables[i*6+5];
      else
      {
        e-=(double)j;
        d*=(multables[i*6+j+1]-multables[i*6+j])*e+multables[i*6+j];
      }
    }
    return d;
  }

  /* contructor */
  public EAF(CocomoTool m) 
  {
    main=m;
    int i;

    scrollbars=new Scrollbar[15];

    /* define scrollbars */
    for(i=0;i<15;i++)
      scrollbars[i]=new Scrollbar(Scrollbar.HORIZONTAL,8,1,0,20);

    Panel header=new Panel();
    header.setLayout(new GridLayout(1,2));
    header.add(new Label("Very Low",Label.LEFT));
    header.add(new Label("Extra High",Label.RIGHT));

    Panel center=new Panel(); 
    center.setLayout(new GridLayout(19,2));
    center.add(new Label("Product attributes"));
    center.add(header);

    center.add(new Label(" - Required software reliability :"));
    center.add(scrollbars[0]);
    center.add(new Label(" - Size of application database :"));
    center.add(scrollbars[1]);
    center.add(new Label(" - Complexity of the product :"));
    center.add(scrollbars[2]);

    center.add(new Label("Hardware attributes"));
    center.add(new Label(""));
    center.add(new Label(" - Run-time performance constrains :"));
    center.add(scrollbars[3]);
    center.add(new Label(" - Memory contrains :"));
    center.add(scrollbars[4]);
    center.add(new Label(" - Volatility of the virtual machine environment :"));    
    center.add(scrollbars[5]);
    center.add(new Label(" - Required turnabout time :"));
    center.add(scrollbars[6]);    

    center.add(new Label("Personel attributes"));
    center.add(new Label(""));
    center.add(new Label(" - Analyst capability :"));
    center.add(scrollbars[7]);
    center.add(new Label(" - Software engineer capability :"));
    center.add(scrollbars[8]);
    center.add(new Label(" - Applications experience :"));
    center.add(scrollbars[9]);
    center.add(new Label(" - Virtual machine experience :"));
    center.add(scrollbars[10]);
    center.add(new Label(" - Programming language experience :"));
    center.add(scrollbars[11]);

    center.add(new Label("Project attributes"));
    center.add(new Label(" "));
    center.add(new Label(" - Use of software tools :"));
    center.add(scrollbars[12]);
    center.add(new Label(" - Application of software engineering methods :"));
    center.add(scrollbars[13]);
    center.add(new Label(" - Required development schedule :"));
    center.add(scrollbars[14]);
    setLayout(new BorderLayout());
    add("Center",center);
    add("South",new Button("Close"));
    setTitle("Cost Drivers");
    pack();
  }

  public boolean handleEvent(Event evt) 
  {
    if((evt.id==Event.WINDOW_ICONIFY)||(evt.id==Event.WINDOW_DESTROY))
    {
      hide();
      main.update();
      return true;
    }
    else if(evt.target instanceof Scrollbar)
    {
      main.update();
      return true;
    }
    else if((evt.target instanceof Button)&&(evt.id==Event.ACTION_EVENT)&&(((Button)evt.target).getLabel()=="Close"))
    
    {
      hide();
      main.update();
      return true;
    }
    return false;
  }
}


