/* this is applicMain   */
package digitera;
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import javax.sound.sampled.*;

import dataSeries.*;
import sun.audio.*;
import java.awt.image.MemoryImageSource;
  
import java.net.URL;  
import java.io.*;
import java.util.*;
import java.lang.Math;
import java.net.*;
import steam.*;
public class applicMain 
 {
   public static void main(String args[])
   {
     mainDigiteraFrame aFrame= new mainDigiteraFrame();
     aFrame.setTitle("progAtmos");
     aFrame.setResizable(true);
     aFrame.resize(1400,900);
     aFrame.init();
     aFrame.show();
     aFrame.repaint();
     aFrame.start();
     aFrame.repaint();
    }
 }    
class mainDigiteraFrame extends Frame implements ChMouseDown
  {
     int bW=0,bH=0;
    Image theImage=null;
    digiRiff aDigiRiff; 
    String fName;
  alphaButton  theSign;
  steamButton rot180But,mirrorBut,createBut,createOverViewBut,removeLatestMarkBut,
                      testBut;
  steamAltNameButton whatPictureBut;
  public void init()
   {  
        FileDialog aFileDialog;

        bW=size().width;bH=size().height; 
        aFileDialog=new FileDialog(this,"aRawScanningFile");
           int dotIndex;
          aFileDialog.setDirectory("c:\\muSimulations\\");
          aFileDialog.show();
          fName=aFileDialog.getFile();
          aDigiRiff=new digiRiff(aFileDialog.getDirectory()+"\\"+fName,this,10,50,bW-200,bH-100);
          aDigiRiff.getSamplePicture(100);
         
      theSign=new alphaButton("",100,bH-80,100,20);
      theSign.scaleX=20.0;theSign.scaleY=20.0;
      theSign.theText="christer juren"; 
        theSign.addButton(aDigiRiff);
     theSign.addButton(whatPictureBut=new steamAltNameButton("samplePict",bW-200+15,50,50,20,"overView"));
     whatPictureBut.theModel=new chActionDown(this);   
     whatPictureBut.theModelWhenActive=new chActionDown(this);  
     theSign.addButton(createOverViewBut=new steamButton("createOverView",bW-200+15,80,50,20));
     createOverViewBut.theModel=new chActionDown(this);   
     theSign.addButton( removeLatestMarkBut=new steamButton("removeLatestMark",bW-200+15+20,80+20,50,20));
      removeLatestMarkBut.theModel=new chActionDown(this);   
     theSign.addButton(createBut=new steamButton("CREATE",bW-200+15,200,50,20));
     createBut.theModel=new chActionDown(this);   
     theSign.addButton(rot180But=new steamButton("rot180",bW-200+15+20,200+20,50,20));
     rot180But.activeMyColor=Color.red;
     theSign.addButton(mirrorBut=new steamButton("mirrorVertical",bW-200+15+20,200+40,50,20));
     mirrorBut.activeMyColor=Color.red;
     theSign.addButton(testBut=new steamButton("TEST",bW-200+15+20,200+70,50,20));
     testBut.theModel=new chActionDown(this);   
     testBut.theModelWhenActive=new chActionDown(this);   
     testBut.activeMyColor=Color.red;
   }
 
   public void chMouseDown(Graphics g,steamButton aBut)
   {int i,j;
    if( aBut==testBut)
    {
      aDigiRiff.mirror=mirrorBut.active;aDigiRiff.rot180=rot180But.active;
     if(aBut.active)
      aDigiRiff.doTest();
     else aDigiRiff.clearTest();
    }
    else
    if( aBut==removeLatestMarkBut)
    {
      aDigiRiff.removeLatestMark();aBut.active=false;
    }
    else
     if(aBut==createOverViewBut)
     {
       aDigiRiff.createOverview();
       aBut.active=false;
       whatPictureBut.active=true;aDigiRiff.paintSample=false;
     }
    else
     if(aBut==createBut)
     {
        FileDialog aFileDialog;
        aFileDialog=new FileDialog(this,"current RawScan: "+fName);
           int dotIndex;
          aFileDialog.setDirectory("c:\\muSimulations\\");
          aFileDialog.show();
           String fName=aFileDialog.getFile();
     aDigiRiff.mirror=mirrorBut.active; aDigiRiff.rot180=rot180But.active;

     paint(g);
     aDigiRiff.createACopy(aFileDialog.getDirectory()+"\\"+fName);
     aBut.active=false;
    }
    else
    if(aBut==whatPictureBut)
    {
     aDigiRiff.paintSample=!whatPictureBut.active;
    }
   }
 public boolean mouseDown(Event e,int x,int y)
    {Graphics gg;
     int i,j,colorNaatt;
     gg=getGraphics();
     theSign.checkAllForClick(gg,x,y); 
     paint(gg);   
     gg.dispose();
     return true;
    }
public void run()
      {
      } 
 public void start()
      {
       
      }
 public void stop() {}     
 public void paint(Graphics g)
  {Graphics gg; 
      if (theImage==null)
          {
            bW=size().width;bH=size().height; theImage=createImage(bW,bH);
          }  
        gg=theImage.getGraphics();
        gg.setColor(Color.lightGray);
        gg.fillRect(0,0,bW,bH);
        gg.setColor(Color.black);
        myPaint(gg); 
        gg.dispose();
       g.drawImage(theImage,0,0,this);
   } 
public void myPaint(Graphics g)
{
        theSign.paintAll(g);
}
}