import java.io.File;

/**
 * Contain macro to access to the PDF
 * @author JPR
 *
 */
public class MacroMethods 
{

	public static void openPdf(File file)
    {
        
        try
        {            
            String[] cmd = new String[3];
            cmd[0] = "cmd.exe" ;
            cmd[1] = "/C" ;
            cmd[2] = file.getAbsolutePath();
            
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec(cmd);
            proc.waitFor();     
        }
        catch (Throwable t)
        {
        	t.printStackTrace();
        }
    }
	
	/**
	 * open the PDF corresponding to the File in parameter
	 * @param job
	 *//*
	public static Process openPdf(File file)
	{
		Process p = null;
		
		try
		{
			String fileName = file.getAbsolutePath();
			if ((new File(fileName)).exists()) {
				p=Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + fileName);
			} else {
				System.out.println("File is not exists");
			}
			waitLowProcessor();
			waitLowProcessor();		
			waitLowProcessor();		
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		return p;
	}*/

	/**
	 * wait while the page is not loaded
	 *//*
	public static void waitLowProcessor() throws ErrorException
	{
		float cpu[] = new float[10];
		do {
			int cpttry = 0;
			try 
			{
				CPUController cc = new CPUController();
				for(int i = 0; i < 10 ; i++)
				{
					Thread.sleep(500L);
					cpu[i]=cc.cpuController(1);
				}
				cpttry++;
			}
			catch(InterruptedException e)
			{
				throw new ErrorException("05 : "+e.getMessage(), 1);
			}
			if(cpttry == 10)throw new ErrorException("04 : page chargement is too long", 1);
			//TODO si on attend plus de 10 minutes, alors killer le process accrobat et passer à la page suivante (destroyProcess)
			//cf process qui a ouvert le stamp et destroyProcess
		} while ((cpu[0] > 0.12f) || (cpu[1] > 0.12f) || (cpu[2] > 0.12f) || (cpu[3] > 0.12f) || (cpu[4] > 0.12f) || (cpu[5] > 0.12f) || (cpu[6] > 0.12f) || (cpu[7] > 0.12f) || (cpu[8] > 0.12f) || (cpu[9] > 0.12f) );
	}*/


}