package sim.credit;

import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.util.*;

public class SplashWindow {

	private Font font;
	//background
	private SplashScreen splash;
	private Graphics2D splashGraphics;
	private int ssHeight;
	private int ssWidth;
	//text
	//private int tHeight;
	private int tWidth;
	private int tX;
	private int tY;
	//progress bar
	private int pHeight;
	private int pWidth;
	private int pX;
	private int pY;

	public SplashWindow() {

		splash = SplashScreen.getSplashScreen();

		if (splash != null) {
			Dimension ssDim = splash.getSize();
			ssHeight = ssDim.height;
			ssWidth = ssDim.width;

			//location of text area
			tWidth = ssWidth * 2 / 3;
			//tHeight = ssHeight / 3;
			tX = (int) ((ssWidth - tWidth) * 0.7);
			tY = ssHeight * 13 / 20;

			//location of progress bar
			pX = tX;
			pY = (int) (ssHeight * 0.92);
			pWidth = ssWidth * 1 / 3;
			pHeight = 12;

			text();
		
		}
	}

	private void text() {

		splashGraphics = splash.createGraphics();

		InputStream input = SplashWindow.class.getResourceAsStream("splash.txt");
		Scanner sc = new Scanner(input);
		String str = sc.nextLine();

		//version
		splashGraphics.setPaint(Color.GREEN);
		font = new Font("Arial", Font.BOLD, 18);
		splashGraphics.setFont(font);
		FontMetrics fm = splashGraphics.getFontMetrics(font);
		int x = (pX + pWidth) + (ssWidth - (pX + pWidth) - fm.stringWidth(str)) / 2;
		splashGraphics.drawString(str, x, pY + 9);

		//credit
		splashGraphics.setPaint(Color.GREEN);
		font = new Font("Arial", Font.BOLD, 13);
		splashGraphics.setFont(font);

		while (sc.hasNextLine()) {
			str = sc.nextLine();
			splashGraphics.drawString(str, tX, tY);
			tY += 15;
		}

		splash.update();

	}

	public void progress(int pct) {
		/*splashGraphics.setPaint(Color.LIGHT_GRAY);
		splashGraphics.fill(new Rectangle(pX, pY, pWidth, pHeight));

		splashGraphics.setPaint(Color.BLUE);
		splashGraphics.draw(new Rectangle(pX, pY, pWidth, pHeight));

		int doneWidth = pct * pWidth / 100;

		splashGraphics.setPaint(Color.BLUE);
		splashGraphics.fillRect(pX, pY + 1, doneWidth, pHeight - 1);

		splash.update();*/

	}

	public void dispose() {
		if (splash != null) {
			splash.close();
		}
	}
}
