package rainbowPackage;

//import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javafx.application.Platform;
//import java.io.PrintWriter;

//import javax.imageio.ImageIO;
import javax.swing.JFileChooser;

//import org.bytedeco.javacv.*;
//import org.bytedeco.ffmpeg.global.avcodec;
//import org.bytedeco.javacv.FFmpegFrameRecorder.*;
//import org.bytedeco.ffmpeg.global.avutil.*;
//import org.bytedeco.javacpp.*;
//import org.bytedeco.ffmpeg.global.avutil;
//import org.bytedeco.ffmpeg.presets.avutil;

//import static org.bytedeco.javacpp.avcodec.*;
//import static org.bytedeco.javacpp.avutil.*;

import org.apache.commons.io.FileUtils;
/*import org.jcodec.api.SequenceEncoder;
import org.jcodec.api.awt.AWTSequenceEncoder;
import org.jcodec.common.io.SeekableByteChannel;
import org.jcodec.common.model.Rational;// */
import org.jcodec.common.io.NIOUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
//import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.WebDriver.*;
//import org.openqa.selenium.WebElement;
//import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.support.ui.ExpectedConditions;
//import org.openqa.selenium.support.ui.WebDriverWait;
//import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;

//import java.io.*;

//import java.awt.*;
//import java.awt.image.*;


import org.jcodec.api.awt.AWTSequenceEncoder;
import org.jcodec.common.io.SeekableByteChannel;
import org.jcodec.common.model.Rational;
//import org.jcodec.common.io.NIOUtils;
/*import org.jcodec.api.SequenceEncoder;
import org.jcodec.api.SequenceEncoder.*;
import org.jcodec.scale.AWTUtil;
import org.jcodec.api.*;
import org.jcodec.*;//Keep For .mp4 Video Creation
import org.jcodec.common.Codec;
import org.jcodec.common.Format;
import javafx.*;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.embed.swing.SwingFXUtils; // */
//import javafx.event.EventHandler;

//import java.nio.channels.*;//Dangerous For JCodec
//import java.nio.channels.SeekableByteChannel;//Dangerous For JCodec

import javafx.geometry.Rectangle2D;
//import javafx.scene.control.Button;
import javafx.scene.control.Label;
//import javafx.scene.control.ProgressBar;
//import javafx.scene.control.TextField;
import javafx.scene.*;
//import javafx.scene.image.*;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
//import javafx.scene.input.KeyCombination.Modifier;
import javafx.scene.input.KeyEvent;
//import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
//import javafx.scene.Node.*;
import javafx.scene.paint.Color;
//import javafx.scene.web.WebEngine;
//import javafx.scene.web.WebView;
import javafx.stage.Screen;
import javafx.stage.Stage;

//import javafx.fxml.FXMLLoader;
//import java.net.URL;

public class RainbowSetup
{
	static private RainbowSystem rainbowSystem = new RainbowSystem();
	public final String browserURL = "http://www.fwaacademy.com/School/FwaAcademyGenericLogo.html";//http://www.fwaacademy.com/School/ ForThisLine BlankWebPage.html RainbowFirmWaterMarkForProduction.html RainbowFirmWaterMarkForProductionUHD.html FwaAcademyGenericLogo.html {Fwa}FreeWorldAllianceWebRingFreeWareStatusDeclarationUHD.html RainbowFirmDescription&DemonstrationForProductionUHD.html WhyToGetHighForProductionUHD.html FwaSynopsis.html PixiesPatentDentonForProductionBlack+White.html PixiesPatent.html EdibleNutritionGuideForSinssSexToys.html 
	private long browserUserWaitTime = 2780;
	
	public void Setup( Stage primaryStage, /*Thread primaryThread,*/ Parent primaryRoot ) throws IOException, FileNotFoundException
	{
		System.out.println("Got To Setup");
		Platform.runLater( () -> { try { Thread.sleep(3689);//tertiaryThread.sleep(2489);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		} } ) ;// */
		/*primaryStage.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>()
		{
			@Override
			public void handle(MouseEvent event) 
			{
				System.exit(0);
			}
		});// */
		//fRateDivisor = 6 Will Show Video For Initial Video Testing Quickest, 24 For Mid-Testing, 192 For Quick Demonstrations Taking An Hour To Complete, And More For FreeWare Goodies
		double fRateDivisor = 6;//1 For Initial Frame Testing, 0 For .fxml 24{With 24 Complete PrintScreen .png s Multiples Of 24 For All 24 Print Screens//6//7//8//144//192-ForAnyFullQuickTest//288//384//432//456//480//576 = 24^2//288//555//666//888//MagiEliteDoubleSlider:1152 1.5x:1728 2x:2304 3x:3456 4x:4608 For Buddhism Testing: 4;//10;//48//192//69;//124;//2;//10;//22<- 444 468 888 HERE HERE HERE DETERMINES FRAME RATE AND RAINBOW MOVEMENT RATE For Rainbow Lights
		final int basisImageViewIndex = 26, framesPerSecond = 4;// basisImageViewIndex = 0 -> 24 Only -1 For 1&only1 Commented Code Above// 0: Buddhism. 1: MagiElite. 2: FwaSplashLogo. 3: FwaFlagSplashLogo. 4: RainbowHorizontal. 5: Diagnostics. 6: RainbowClock. 7: RainbowRing. 8: RainbowStrobe. 9: RainbowSpiral. 10: Cheap Rainbow Fractal. 11: RainbowPattern2D 12: RainbowExponentiator 13: RainbowDoubleExponentiator
		final boolean useRainbowPattern2Ddiagnostics = false;
		//14: RainbowSplashAndPostPattern2D 15: RainbowPattern2Ddiagnostics 16: FullSelectable ColorMovement Pattern2Ddynamics 17: FullSelectable StillMovement Pattern2Ddynamics 18: FullSelectable DoubleMovement Pattern2Ddynamics 19: GlobalSelectorDiagnostics 20: GlobalSelector 21: RainbowFlasher 22: PostPattern2Ddiagnostics 23: PostPattern2D.Selector 24: FwaFlagLogo 25: PostPattern2D.RainbowFanOutClock 26: ?
		//24: FwaFlagLogo. 25: FwaFanOutClock/Kaladascoppe See Relevant Pattern2D Comments To Switch 26: FullPattern2Ddynamics
		//1-6-24-192-Temp: 480
		primaryStage.setTitle("www.RainbowFirm.com");
		Image iconImage = new Image("http://www.pixies.zone/Pictures/PentagramRainbow.png");//"Pictures/PentagramRainbow.png" When From RainbowSoft Folder Not RainbowFirm-the-Project Or Normally scr Folder Under Project
		primaryStage.getIcons().add(iconImage);

		// This is how you know how much screen you can write to.
		Screen primaryScreen = Screen.getPrimary();
		Rectangle2D primaryBounds = primaryScreen.getVisualBounds();
		System.out.println(primaryBounds);

		//primaryStage.initStyle(StageStyle.DECORATED);
		//primaryStage.setX(-100);
		//primaryStage.setY(100);
		primaryStage.setMinWidth(primaryBounds.getWidth());
		primaryStage.setMinHeight(primaryBounds.getHeight());
		primaryStage.setMaxWidth(primaryBounds.getWidth());
		primaryStage.setMaxHeight(primaryBounds.getHeight());
		primaryStage.setWidth(primaryBounds.getWidth());
		primaryStage.setHeight(primaryBounds.getHeight());// */
		
		boolean primaryIsFullScreened = true;
		primaryStage.setFullScreen(primaryIsFullScreened);
		primaryStage.setResizable(false);
		
		//primaryStage.setX(0);
		//primaryStage.setY(0);
		KeyCodeCombination fullScreenedKeyCodeCombination = new KeyCodeCombination(KeyCode.ENTER, KeyCombination.ALT_DOWN);
		primaryStage.setFullScreenExitHint("Alt-Enter To Toggle Full-Screened Mode");
		primaryStage.setFullScreenExitKeyCombination(fullScreenedKeyCodeCombination);

		String vidoePath = "C:\\RainbowFirm\\TestVideo.mp4";//, text = "Sky.Netarianism";//"C:\\TestImage.png"//"C:\\TestVideo.mp4"//"C:\\TEMP_Sonnet.mp4";
		File selectedFile = new File (vidoePath);
		JFileChooser jFileChooser = new JFileChooser();
		if ( fRateDivisor >= 6 )
		{
			jFileChooser.setSelectedFile(selectedFile);
			int returnValue = jFileChooser.showSaveDialog(null);
			if (returnValue == JFileChooser.APPROVE_OPTION)
			{
				selectedFile = jFileChooser.getSelectedFile();
				vidoePath = selectedFile.getPath();
				System.out.println(selectedFile.getName());
				System.out.println(selectedFile.getPath());
			}
		}
		//primaryStage.setMaximized(primaryIsFullScreened);

		//primaryStage.show();
		try { Thread.sleep(4400);//primaryThread.sleep(1000);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}// */

		//primaryIsFullScreened = primaryStage.isFullScreen();

		//primaryStage.initStyle(StageStyle.DECORATED);
		//primaryStage.setX(-100);
		//primaryStage.setY(100);
		/*primaryStage.setMinWidth(primaryBounds.getWidth());
		primaryStage.setMinHeight(primaryBounds.getHeight());
		primaryStage.setMaxWidth(primaryBounds.getWidth());
		primaryStage.setMaxHeight(primaryBounds.getHeight());
		primaryStage.setWidth(primaryBounds.getWidth());
		primaryStage.setHeight(primaryBounds.getHeight());// */

		/*primaryStage.setResizable(false);
		//primaryStage.setFullScreen(true);
		try { Thread.sleep(1500);//primaryThread.sleep(250);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}
		primaryStage.show();// */
		/*System.out.println("Press Alt-Enter.");
		try { primaryThread.sleep(4000);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}// */
		primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
			if (fullScreenedKeyCodeCombination.match(event)) {
				primaryStage.setFullScreen(!primaryStage.isFullScreen());
			}
		});
		/*primaryStage.setMaximized(true);
		primaryStage.setFullScreen(primaryIsFullScreened);
		primaryStage.show();//*/
		//primaryStage.setMaximized(true);
		/*try { primaryThread.sleep(2400); } catch(InterruptedException e) {
		    System.out.println("got interrupted!");
		}//*/
		/*
		primaryStage.show();
		primaryStage.setFullScreen(primaryIsFullScreened);


		if ( primaryIsFullScreened == false )
		{

		primaryStage.setWidth( 666 ); //666
		primaryStage.setHeight( 888 ); //888

		}
		else
		{
			primaryStage.setWidth( primaryBounds.getWidth() );
			primaryStage.setHeight( primaryBounds.getHeight() );
		}

		primaryStage.setMaximized(true);
		primaryStage.setFullScreen(primaryIsFullScreened);
		primaryStage.show();

		primaryStage.fullScreenProperty().addListener((observable, oldValue, newValue) -> {
			if ( newValue != primaryStage.isFullScreen() )
			{  	primaryStage.setFullScreen(primaryIsFullScreened);
			primaryStage.setWidth( primaryBounds.getWidth() );
			primaryStage.setHeight( primaryBounds.getHeight() );	}
			else
				return;
		}); // */
		//primaryStage.show();

		/*Dimension dimension = new Dimension( (int)bounds.getWidth(), (int)bounds.getHeight() );
		dimension.width = (int)bounds.getWidth();
		dimension.height = (int)bounds.getHeight() + 40;
		Dimension Dim = dimension;//*/

		//FXMLLoader loader = new FXMLLoader(Sonnet.class.getResource("main.fxml"));

		StackPane primaryStackPaneForBasis = new StackPane();//[(int)(fRateDivisor + 2)];
		StackPane primaryStackPaneForBackground = new StackPane();
		StackPane primaryStackPaneForBrowser = new StackPane();
		StackPane primaryStackPaneForMeasurement[] = new StackPane[2];
		primaryStackPaneForMeasurement[0] = new StackPane();
		primaryStackPaneForMeasurement[1] = new StackPane();
		//stackPane = new StackPane();
		primaryStackPaneForBasis.setPrefSize( primaryBounds.getWidth(), primaryBounds.getHeight() ); //+ 40 );//stackPane.setPrefSize(1920, 1080);//stackPane.setPrefSize(960, 540);
		primaryStackPaneForBackground.setPrefSize( primaryBounds.getWidth(), primaryBounds.getHeight() );
		primaryStackPaneForBrowser.setPrefSize( primaryBounds.getWidth(), primaryBounds.getHeight() );
		primaryStackPaneForMeasurement[0].setPrefSize( primaryBounds.getWidth(), primaryBounds.getHeight() );
		primaryStackPaneForMeasurement[1].setPrefSize( primaryBounds.getWidth(), primaryBounds.getHeight() );
		//Image image = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");

		//Scene primaryScene[] = new Scene[1]; //For Potential .fxml Testing
		Scene primaryScene = new Scene(primaryRoot);//[(int)(fRateDivisor + 2)]; //HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE
		//primaryScene[0] = new Scene(primaryRoot);

		//ProgressBar progressBar = new ProgressBar();
		//Button goButton = new Button("Go!");
		Label stateLabel = new Label();
		//TextField addressBar = new TextField();
		//addressBar.setText("http://www.google.com");
		//addressBar.setText("http://www.pixies.zone/PixiesTest.html");
		System.out.println("Got To Browser Initialization");
		//WebView browser = new WebView();
		//browser.setPrefSize(primaryBounds.getWidth(), primaryBounds.getHeight());
		//browser.resize(primaryBounds.getWidth(), primaryBounds.getHeight() );
		//browser.setMinSize(primaryBounds.getWidth(), primaryBounds.getHeight() );
		//browser.setPrefSize( primaryBounds.getWidth(), primaryBounds.getHeight() + 10 ); // Important For Full Screened
		try { Thread.sleep(1500);//primaryThread.sleep(1500);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}// */
		//System.setProperty("webdriver.chrome.driver", "External_JARs\\selenium-4.29.0\\selenium-chrome-driver-4.29.0.jar"); // Replace with your path
		//ChromeOptions options = new ChromeOptions();
		//options.addArguments("--start-maximized");
		//options.addArguments("--start-fullscreen");
		WebDriver driver = new FirefoxDriver();//options);
		//driver.manage().deleteAllCookies();//http://www.pixies.zone/SilkRoadOutPostDotComHeader.html PixiesAreSexysBeyondSexSlaves.html
		//driver.quit();//http://www.pixies.zone/School/%7bFwa%7dFreeWorldAllianceWebRingFreeWareStatusDeclaration.html {Fwa}FreeWorldAllianceWebRingFreeWareStatusDeclarationUHD.html EitherMakeupLikeAZombieCuntOrMedicine&GeishaCreamLikeAnElf.html //RainbowFirmWaterMarkForProduction.html RainbowFirmWaterMarkForProductionUHD.html FwaWatermarks.html RainbowFirmDescription&DemonstrationForProductionHD.html RainbowFirmDescription&DemonstrationForProductionUHD.html RainbowFirmDescription+License+ColorCodeInfoForProduction.html PixiesPatentDentonForProductionBlack+White.html School/Pictures/Beck'sTradeWindCoHD.html PixiesGetYourStuffNowUHD.html WhyToGetHighForProductionUHD.html FwaConstitution.html FwaSynopsis.html USG-RankDeterminer.html USG-RankChainOfCommand.html FwaGoods+Supplies+Armaments+Pixies.html
		//driver = new FirefoxDriver();//RainbowFirmDescription&DemonstrationForProductionMagentaPixelBlend.html//RainbowFirmDescription&DemonstrationForProductionMagentaPixelBlendNoBackgroundImage.html
		driver.get( browserURL );//http://www.pixies.zone/School/PixiesHomeForProduction.html//RainbowFirmDescription&DemonstrationForProductionMagentaPixelBlend.html
		driver.manage().window().fullscreen();//http://www.pixies.zone/School/Pictures/PixiesReligionForProduction.html PixiesReligionForProductionUHD.html GuideToGoodSyncFwaDataBartering.html
		try { Thread.sleep(browserUserWaitTime);//10000+//primaryThread.sleep(750);
		} catch (InterruptedException e) {//http://www.pixies.zone/BlankWebPage.html http://www.pixies.zone/School/BlankWebPage.html
			System.out.println("Interrupted.");
		}// */
		/*while ( driver.execute_script("return document.readyState") != "complete" )
			try { Thread.sleep(1000);//primaryThread.sleep(750);
			} catch (InterruptedException e) {
				System.out.println("Interrupted.");
			}; break;// */
		//WebDriverWait wait = new WebDriverWait(webDriver, 10);
		//WebElement e = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div[ng-show='errors']")));
		//System.out.println(e.getText());
		try {
			File screenShotFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
			File destinationFile = new File("C:\\RainbowFirm\\FireFoxScreenShot.png");
	        // Copy the screenshot file to the destination
	        FileUtils.copyFile(screenShotFile, destinationFile);
	        System.out.println("Screenshot saved successfully: " + destinationFile.getAbsolutePath());
		} catch (FileNotFoundException eFireFoxScreenShot1) {
			// TODO Auto-generated catch block
			eFireFoxScreenShot1.printStackTrace();
		}
		//WebEngine webEngine = browser.getEngine();
		//webEngine.load("https://news.google.com/news/?ned=us&hl=en&gl=US");
		/*try { Thread.sleep(250);//primaryThread.sleep(750);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}// */
		//webEngine.reload();
		/*try { Thread.sleep(450);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}// */ ///http://www.pixies.zone/PixiesPatentDentonX-LargeTextForProduction.html //http://www.pixies.zone/School/RainbowFirmDescription&DemonstrationForProduction.html ///http://www.pixies.zone/School/Pictures/PixiePatentBestTextRead/PixiesPatentProperTextRead/PixiesPatentDentonX-LargeTextForProductionTimesNewRomanRestrictedLogoFixPentagram.html
		//Platform.runLater( () -> webEngine.load( "http://www.pixies.zone/School/PixiesPatentDentonX-LargeTextForProduction.html" ) );// /School/RainbowFirmDescription&DemonstrationForProduction.html /School/RainbowFirmDescription&DemonstrationForProductionMagentaPixelBlend "http://www.pixies.zone/PixiesPatentTimes.html" PixiesPatentDentonShortForProduction.html PixiesPatentRexliaForProduction.html SpellCastingTextForProduction.html http://www.pixies.zone/BuddhistTextForProduction.html http://www.pixies.zone/BuddhistText.html http://www.pixies.zone/DictionaryTextForProduction.html //http://www.pixies.zone/BlankWebPage.html FwaSealForProduction.html "http://www.pixies.zone/PixiesTest%20-%20Copy%20(4).html" PixiesTest%20-%20Copy%20(2).html");// PixiesTest%20-%20Copy.html");  // ASDF For Rainbow Browser		
		//webEngine.reload();//http://www.pixies.zone/School/WhyToGetHighForProduction.html PixiesHomeForProduction.html PixiesRUSForProduction.html
		try { Thread.sleep(3458);//Thread.sleep(458);//primaryThread.sleep(858); //http://www.pixies.zone/KeyToBuddhismForProduction.html http://www.pixies.zone/School/Pictures/PixiePatentBestTextRead/PixiesPatentDentonX-LargeTextForProductionTimesNewRomanRestrictedLogoFixPentagram.html
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}// */
		System.out.println("Got Past WebEngine Load");
		/*try { webEngine.wait(1000);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}*/	

		//while ()
		/*try { primaryThread.sleep(10000);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		}// */
		//webEngine.load("http://www.pixies.zone/PixiesTest.html");
		//primaryStackPane[0].getChildren().add(origionalImageView);
		//stackPane[0].getChildren().add(browser);
		Image origionalBasisImage[] = new Image[5];//http://www.pixies.zone/Pictures/ // http://www.pixies.zone/School/Pictures/
		origionalBasisImage[0] = new Image("http://www.pixies.zone/Pictures/BuddhismTemplateHD.png");//BuddhismTemplateHD.png//FwaUHDFlagLogoBasisImage.png//SciMagOrderMagiEliteFullHDSkyBlueFunctionTest.png//SciMagOrderMagiEliteFullHDGreenBacking.png//KnightsOfTheSciMagOrderNewPre1.png//FwaLogoBasisImage.png//SciMagOrderMagiEliteFullHD.png
		origionalBasisImage[1] = new Image("http://www.pixies.zone/Pictures/SciMagOrderBasisUHD.png");//SciMagOrderMagiEliteFullHD.png
		origionalBasisImage[2] = new Image("http://www.pixies.zone/Pictures/FwaLogoBasisImage.png");//FwaLogoBasisImage.png//FwaLogoBasisImageReversed.png
		origionalBasisImage[3] = new Image("http://www.pixies.zone/Pictures/FwaUHDFlagLogoBasisImage.png");//FwaUHDFlagLogoBasisImage.png//FwaUHDFlagLogoBasisImageReversed.png//FwaUHDFlagLogoBasisCanvas.png//FwaUHDFlagLogoHalfGrayTest.png
		origionalBasisImage[4] = new Image("http://www.pixies.zone/Pictures/FwaUHDFlagLogoBasisImageReversed.png");
		//Image origionalBasisImage = new Image("http://www.pixies.zone/Pictures/SciMagOrderMagiEliteFullHD.png");
		Image backgroundBasisImage[] = new Image[5];
		backgroundBasisImage[0] = new Image("http://www.pixies.zone/Pictures/BuddhismTemplateHD.png");//BuddhismTemplateHD.png//FwaUHDFlagLogoBasisBackground.png//SciMagOrderMagiEliteBasisBackgroundFullHD.png//SciMagOrderMagiEliteBasisBackgroundFullHDWSpotches.png//FwaLogoBasisBackground.png
		backgroundBasisImage[1] = new Image("http://www.pixies.zone/Pictures/SciMagOrderBackGroundBasisUHD.png");//SciMagOrderMagiEliteBasisBackgroundFullHD.png
		backgroundBasisImage[2] = new Image("http://www.pixies.zone/Pictures/FwaLogoBasisBackground.png");//FwaLogoBasisBackground.png
		backgroundBasisImage[3] = new Image("http://www.pixies.zone/Pictures/FwaUHDFlagLogoBasisBackground.png");//FwaUHDFlagLogoBasisBackground.png//FwaUHDFlagLogoBasisCanvas.png
		backgroundBasisImage[4] = new Image("http://www.pixies.zone/Pictures/FwaUHDFlagLogoBasisBackground.png");//FwaUHDFlagLogoBasisBackground.png
		//Image backgroundBasisImage = new Image("http://www.pixies.zone/Pictures/SciMagOrderMagiEliteBasisBackgroundFullHD.png");
		Image measurementBasisImage[] = new Image[2];
		measurementBasisImage[0] = new Image("http://www.pixies.zone/Pictures/FwaUHDFlagLogoBasisForMeasurementImage.png");//FwaUHDFlagLogoBasisForMeasurementImage.png
		measurementBasisImage[1] = new Image("http://www.pixies.zone/Pictures/FwaUHDFlagLogoBasisForMeasurementImage2.png");//FwaUHDFlagLogoBasisForMeasurementImage2.png
		SnapshotParameters params = new SnapshotParameters();
		params.setFill(Color.TRANSPARENT);
		params.setViewport(new Rectangle2D(0, 0, primaryBounds.getWidth(), primaryBounds.getHeight()));
		//WritableImage snapshotImage = null;
		//browser.wait( 10000 );
		//Image firstBackUpWorkAroundImage = browser.snapshot( params, snapshotImage );
		///Image firstBackUpWorkAroundImage = new Image("http://www.pixies.zone/Pictures/2025-03-12.png");//FwaUHDFlagLogoText.png//http://www.pixies.zone/Pictures/PixieesTextWLinkWExtraMargin.png, BuyHempStartImage.png, PixiesWillAlwaysGetReincarnatedText.png, FwaLogoBasisImage.png
		FileInputStream inputForScreenShot = new FileInputStream("C:\\RainbowFirm\\FireFoxScreenShot.png"); 
        Image firstFireFoxScreenShot = new Image(inputForScreenShot);
		//Image firstChromeScreenShot = new Image("C:\\chromeScreenShot.png");
		//File javaScriptFile = new File ("C:/Users/AllAV/OneDrive/FWA Website/pixies.zone/scrollContinuously444.js");
		//File xSliderFile = new File ("C:/Users/AllAV/OneDrive/FWA Website/pixies.zone/xSlider.dat");

        
        
        /*SeekableByteChannel out = null;//From http://jcodec.org/
        try {
            out = NIOUtils.writableFileChannel("/tmp/output.mp4");
            // for Android use: AndroidSequenceEncoder
            AWTSequenceEncoder encoder = new AWTSequenceEncoder(out, Rational.R(25, 1));
            for (...) {
                // Generate the image, for Android use Bitmap
                BufferedImage image = ...;
                // Encode the image
                encoder.encodeImage(image);
            }
            // Finalize the encoding, i.e. clear the buffers, write the header, etc.
            encoder.finish();
        } finally {
            NIOUtils.closeQuietly(out);
        }// */
        
        /*FFmpegFrameRecorder primaryRecorder;
        //if ( fRateDivisor >= 6 )
        //{
	        primaryRecorder = new FFmpegFrameRecorder(vidoePath, (int)primaryBounds.getWidth(), (int)primaryBounds.getHeight(), 0);
	        primaryRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H265);//.AV_CODEC_ID_H265);//.AV_CODEC_ID_H264);//.AV_CODEC_ID_MPEG4);//.AV_CODEC_ID_H266);
	        //primaryRecorder.setPixelFormat(avutil.AV_PIX_FMT_RGB32_1);
	        primaryRecorder.setFormat("mp4");
	        primaryRecorder.setFrameRate(framesPerSecond);
	        primaryRecorder.setVideoQuality( 24 );
	        primaryRecorder.setVideoOption("lookahead", "4" );
	        System.out.println("primaryRecorder.getVideoQuality(): " + primaryRecorder.getVideoQuality());// */
	        //primaryRecorder.start();
        //}

        SeekableByteChannel primaryOutput = null;
        AWTSequenceEncoder primaryEncoder = null;//SequenceEncoder enc;// = new SequenceEncoder();
        if ( fRateDivisor >= 6 )
        {
        	try { primaryOutput = NIOUtils.writableFileChannel(vidoePath);
				  primaryEncoder = new AWTSequenceEncoder(primaryOutput, Rational.R(framesPerSecond, 1));}
			catch(IOException ie) { ie.printStackTrace(); }
        }// */
		//(selectedFile);
		//try { SequenceEncoder enc = new SequenceEncoder(selectedFile); }
		//catch (IOException e) {	throw new RuntimeException(e); }//*/

		//Boolean primaryFullScreened = false; //OLD OLD OLD Important For Full Screened
		//Dimension firstDim = new Dimension( (int)primaryBounds.getWidth(), (int)primaryBounds.getHeight() );
		//WritableImage origionalTextPicture = new WritableImage( firstDim.width, firstDim.height );//666, 888
		/*BufferedImage bf = null;
		try {
			bf = ImageIO.read(new File("C:\\Dev\\RainbowSoftware\\Pictures\\SciMagOrderMagiEliteFullHDGreenBacking.png") );///RainbowSoftware/Pictures/SciMagOrderMagiEliteFullHDGreenBacking.png"));
		}
		catch (IOException e) {
		}
		System.out.println( "bf = " + (bf == null) );// */
		/*try {
			bf = ImageIO.read(new File("C:/Dev/SciMagOrderMagiEliteFullHDGreenBacking.png"));
        } catch (IOException ex) {
            System.out.println("Image failed to load.");
        }
		//ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
		//ImageIO.write( SwingFXUtils.fromFXImage( origionalTextPicture, null ), "png", byteOutput );
		//origionalTextPicture = ImageIO.byteOutput.toByteArray();
		/*BufferedImage bf = null;
        try {
            bf = ImageIO.read(new File("C:/Dev/SciMagOrderMagiEliteFullHDGreenBacking.png"));
        } catch (IOException ex) {
            System.out.println("Image failed to load.");
        }

        //WritableImage wr = null;
        if (bf != null) {
        	origionalTextPicture = new WritableImage(bf.getWidth(), bf.getHeight());
            PixelWriter secondaryPW = origionalTextPicture.getPixelWriter();
            for (int x = 0; x < bf.getWidth(); x++) {
                for (int y = 0; y < bf.getHeight(); y++) {
                    secondaryPW.setArgb(x, y, bf.getRGB(x, y));
                }
            }
        }//*/
		//ImageView imView = new ImageView(origionalBasisImage);
		//origionalTextPicture = SwingFXUtils.toFXImage(bf, origionalTextPicture);
		//System.out.println( "origionalTextPicture = " + (origionalTextPicture == null) );
		//primaryScene[0].snapshot(SwingFXUtils.toFXImage(bf, null));//origionalTextPicture);
		//WritableImage origionalTextPicture = new WritableImage( (int)primaryBounds.getWidth(), (int)primaryBounds.getHeight() );
		/*
		//try { synchronized (webEngine) {
		//	webEngine.wait(2000);
		//} } catch (InterruptedException e) { e.printStackTrace(); }
		if ( primaryStage.isFullScreen() == false )
		{
			if ( primaryIsFullScreened != primaryStage.isFullScreen() )
			{
				primaryStage.setFullScreen(true);
				firstDim.width = 600;
				firstDim.height = 400;
			}
			else 
			{
				firstDim.width = (int)primaryStage.getWidth();
				firstDim.height = (int)primaryStage.getHeight();// + 40;
			}
			//primaryScene[0].snapshot(origionalTextPicture);
			//sP.setViewport( new Rectangle2D( (double)Dim.width, (double)Dim.height, 0, 0 ) );
			primaryStage.setScene(primaryScene[0]);
			primaryStage.setFullScreen(primaryIsFullScreened);
			primaryStage.show();// *_/

		}
		else if ( primaryIsFullScreened != primaryStage.isFullScreen() )
		{
			primaryScene[0].snapshot(origionalTextPicture);
			primaryStage.setFullScreen(primaryIsFullScreened);
			primaryStage.setWidth(primaryScreen.getBounds().getWidth());
			primaryStage.setHeight(primaryScreen.getBounds().getHeight());
			firstDim.width = (int)primaryStage.getWidth();
			firstDim.height = (int)primaryStage.getHeight();// + 40;

			//sP.setViewport( new Rectangle2D( (double)Dim.width, (double)Dim.height, 0, 0 ) );
			primaryStage.setScene(primaryScene[0]);
			primaryStage.setFullScreen(true);
			primaryStage.show();// *_/
		}// Important For Full Screened */

		/*EventHandler handler = new EventHandler(<InputEvent>() {
		    public void handle(InputEvent event) {
		        System.out.println("Handling event " + event.getEventType()); 
		        event.consume();
		    }

		public class MaximizeShortcut extends KeyCombination 
		{
			public MaximizeShortcut() {
				super( fullScreenedKeyCombination );
			}




			@Override
			public void handle(KeyEvent event) {
				primaryStage = (Stage) event.getSource();
				primaryStage.setMaximized(!primaryStage.isMaximized());
			}
		}	
		// Register the keyboard shortcut with the scene
		primaryScene.addEventHandler(KeyEvent.KEY_PRESSED, handle);// */
        Platform.runLater( () -> { try { Thread.sleep(1999);//tertiaryThread.sleep(2489);
		} catch (InterruptedException e) {
			System.out.println("Interrupted.");
		} } ) ;// */
        driver.quit();
		System.out.println("Got To Worker");
		 Platform.runLater( () -> { try { Thread.sleep(2599);//tertiaryThread.sleep(2489);
			} catch (InterruptedException e) {
				System.out.println("Interrupted.");
			} } ) ;// */
		//Worker<Void> worker = webEngine.getLoadWorker();
		//ASDF PROBLEM PROBLEM PROBLEM BEFORE System.out.println("Not At Problem");
		//worker.stateProperty().addListener(new ChangeListener<State>() {
		//	@Override
		//	public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {//System.out.println("Got To Worker Test");
		//		stateLabel.setText("Loading state: " + newValue.toString());
		//		if (newValue == Worker.State.SUCCEEDED) {System.out.println("Not At Problem");
		try { rainbowSystem.System(primaryStage, backgroundBasisImage, origionalBasisImage, measurementBasisImage,/*firstBackUpWorkAroundImage, webEngine, browser,*/ primaryStackPaneForBackground, primaryStackPaneForBasis, primaryStackPaneForMeasurement, primaryStackPaneForBrowser, primaryScene, primaryScreen, fRateDivisor, framesPerSecond, basisImageViewIndex, stateLabel, /*primaryRecorder,*/ primaryEncoder, primaryOutput, /*javaScriptFile, xSliderFile,*/ /*primaryThread,*/ primaryIsFullScreened, firstFireFoxScreenShot /*firstBackUpWorkAroundImage*/, primaryRoot, useRainbowPattern2Ddiagnostics ); }//, enc
		catch (IndexOutOfBoundsException e) { System.err.println("IndexOutOfBoundsException: " + e.getMessage()); }
		//}
		//}
		/*scene[(int)fRateDivisor].setOnKeyReleased(new EventHandler<KeyEvent>()
				{
					@Override
					public void handle(KeyEvent event)
					{
						if ( event.isAltDown() == true)
						{
							switch (event.getCode())
							{
							case ENTER: primaryStage.setFullScreen(!primaryStage.isFullScreen()); break;
							}
						}
					}
				});//*/
		/*try { RainbowSystem(primaryStage, browser, stackPane, scene, screen, fRateDivisor, stateLabel, selectedFile); }//enc,
				catch (IOException e) {	throw new RuntimeException(e); }//*/
		//}
		//});



		//primaryStage.setScene(primaryScene[0]);// ???
		//primaryStage.setFullScreen(primaryIsFullScreened);
		//primaryStage.show();

		//progressBar.progressProperty().bind(worker.progressProperty());



		/*goButton.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				String url = addressBar.getText();
				// Load the page.
				webEngine.load(url);
			}
		});//*/
	}
}