package Projects.Cible1;

import gpclasses.baseclasses.*;
import gpclasses.animations.*;
import gpclasses.graphics.*;
import gpclasses.macroobjects.*;
import gpclasses.system.*;
import gpclasses.tags.*;
import gpclasses.baseclasses.CgpReferenceTag;
import gpclasses.system.CgpRefTagFactory;
import gpclasses.util.misc.*;
import gpclasses.util.io.*;
import gpclasses.plugins.diag.*;
import gpclasses.plugins.script.*;
import gpclasses.userScripts.*;
import gpclasses.alarms.*;

import java.text.Format;

import java.util.Vector;

public class Panel1 extends CgpPanel
{
	public Panel1XprSrv exprServer;

	public CgpNumericDisplay AffichageNumerique01;
	public CgpNumericDisplay AffichageNumerique02;
	public Lamp_0002 Voyant01;
	public Lamp_0002 Voyant02;
	public Switch_0003 Switch01;
	CgpFont FoTrendGraph1;
	CgpFont F5;
	CgpFont F12;
	CgpGraphicFile Image01;
	CgpClassicTrend TrendGraph1;
	public CgpSmartKeypadDec  decKeypad;
	private CgpMasterPanel masterPanel = null;
	public int publishedTo()
		{
			return CgpSystem.HMI;
		}

	public void createStaticObjects()
	{
		exprServer = new Panel1XprSrv();
	}
	public String getPanelName()
	{
		return "Ecran1";
	}
	public int getPanelID()
	{
		return 1;
	}

	public int getBackColor()
	{
		return 0x00a10000;
	}

	public void onOpen()
	{
		super.onOpen();

		Integer contextObject = new Integer(panelContext);

		F5 = new CgpFont("TCP13x23F", CgpFont.EMPHASIZED, (byte)23, (byte)13);

		F12 = new CgpFont("PF Utah (WF) S", CgpFont.EMPHASIZED, (byte)24, (byte)0);

		CgpFont textFont0 = new CgpFont("TCP13x23F", CgpFont.PLAIN, (byte)23, (byte)13);

		decKeypad = new CgpSmartKeypadDec(panelContext, this);
		decKeypad.init();
		TrendGraph1 = new CgpClassicTrend(
			"TrendGraph1",	// the object name
			61,	// whole trend graph x1
			100,	// whole trend graph y1
			580,	// whole trend graph x2
			319,	// whole trend graph y2
			88,	// grid area x1
			109,	// grid area y1
			574,	// grid area x2
			309,	// grid area y2
			panelContext
		);

		TrendGraph1.setChannels(
			2,	// num channels
			10	// num samples
		);

		TrendGraph1.setGraphSettings(
			CgpClassicTrend.RIGHT,	// direction
			CgpClassicTrend.LEFT,	// data location
			CgpClassicTrend.BOTTOM,	// time location
			10,	// num samples
			1	// units to scroll
		);

		TrendGraph1.setBorderColor(
			0x00ffffff	// color
		);

		TrendGraph1.setPlateColor(
			0x00000000	// color
		);

		TrendGraph1.setDataSampling(
			CgpClassicTrend.SAMPLING_TYPE_PERIODIC,	// sampling type
			60,	// sampling rate
			null,	// periodic trigger
			null,	// manual trigger
			null	// clear trigger
		);

		TrendGraph1.setRangeSettings(
			0d,	// value range from
			100d,	// value range to
			10d,	// display range from
			40d	// display range to
		);

		FoTrendGraph1 = new CgpFont("TCP8x13", CgpFont.PLAIN, (byte)13, (byte)8);

		TrendGraph1.setDataAxisLabel(
			FoTrendGraph1,	// font
			0x00000000,	// color
			0,	// decimals
			1	// spacing
		);

		TrendGraph1.setTimeAxisGridLine(
			1,	// spacing
			0x00999999	// line color
		);

		TrendGraph1.setDataAxisGridLine(
			1,	// spacing
			0x00999999	// line color
		);

		TrendGraph1.setTimeAxisScale(
			CgpClassicTrend.MANUAL_DIVISIONS,	// division type
			9,	// number of divisions
			0x00ff00ff	// line color
		);

		TrendGraph1.setDataAxisScale(
			10,	// number of divisions
			0x00ff00ff	// line color
		);

		TrendGraph1.setChannelSettings(
			0,	// channel number
			TagDB.REG48_PV,	// variable
			CgpClassicTrend.CHART_LINE,	// display format
			0x00ff6666,	// fore color
			CgpLinePattern.LINE_SOLID,	// line style/fill pattern
			1,	// line width
			0x00000000,	// back color
			false,	// track
			false	// mark
		);

		TrendGraph1.setChannelOORSettings(
			0,	// channel number
			0,	// min
			100,	// max
			0x000000ff,	// fore color
			CgpLinePattern.LINE_SOLID,	// line style
			1,	// line width
			0x00000000	// back color
		);

		TrendGraph1.setChannelSettings(
			1,	// channel number
			TagDB.REG48_SV,	// variable
			CgpClassicTrend.CHART_LINE,	// display format
			0x0000ff66,	// fore color
			CgpLinePattern.LINE_SOLID,	// line style/fill pattern
			1,	// line width
			0x00000000,	// back color
			false,	// track
			false	// mark
		);

		TrendGraph1.setChannelOORSettings(
			1,	// channel number
			0,	// min
			100,	// max
			0x000000ff,	// fore color
			CgpLinePattern.LINE_SOLID,	// line style
			1,	// line width
			0x00000000	// back color
		);

		TrendGraph1.init();
		TrendGraph1.alwaysDrawBackground = false;


		AffichageNumerique01 = new CgpNumericDisplay(120, 362, 259, 401, panelContext, this);
		AffichageNumerique01.dataType = CgpNumericDisplay.DATA_TYPE_FLOAT;
		AffichageNumerique01.displayFormat = CgpNumericDisplay.DISPLAY_FMT_FLOAT;
		AffichageNumerique01.variable = TagDB.REG48_PV;
		AffichageNumerique01.zeroSuppress = true;
		AffichageNumerique01.zeroDisplay = true;
		AffichageNumerique01.displayDigits = 6;
		AffichageNumerique01.decimalPlaces = 0;
		CgpFont	fonts2[][] = {
			{ textFont0 },
			};
		AffichageNumerique01.fonts = fonts2;
		AffichageNumerique01.horizontalAlign = CgpText.DISPLAY_ALIGNMENT_CENTER;
		AffichageNumerique01.verticalAlign = CgpText.DISPLAY_POSITION_MIDDLE;
		AffichageNumerique01.enableInput = false;
		AffichageNumerique01.barcode = false;
		AffichageNumerique01.frameColor = 0x006e726e;
		AffichageNumerique01.foreColor = 0x00cccccc;
		AffichageNumerique01.textColor = 0x007f0044;
		AffichageNumerique01.text3DColor = 0x00000000;
		AffichageNumerique01.textBlinkSpeed = CgpNumericDisplay.BLINK_TYPE_NONE;
		AffichageNumerique01.changeColor = false;
		AffichageNumerique01.blinkSpeed = CgpNumericDisplay.BLINK_TYPE_NONE;
		CgpNumericDisplayDraw displayDraw0 = new D_Display02(9,9,9,9);
		AffichageNumerique01.drawObject = displayDraw0;
		AffichageNumerique01.alwaysDrawBackground = false;
		AffichageNumerique01.init();

		AffichageNumerique02 = new CgpNumericDisplay(120, 422, 259, 461, panelContext, this);
		AffichageNumerique02.dataType = CgpNumericDisplay.DATA_TYPE_INT;
		AffichageNumerique02.variable = TagDB.REG48_SV;
		AffichageNumerique02.zeroSuppress = true;
		AffichageNumerique02.zeroDisplay = true;
		AffichageNumerique02.displayDigits = 6;
		AffichageNumerique02.decimalPlaces = 0;
		AffichageNumerique02.displayFormat = CgpNumericDisplay.DISPLAY_FMT_DECIMAL;
		AffichageNumerique02.fonts = fonts2;
		AffichageNumerique02.horizontalAlign = CgpText.DISPLAY_ALIGNMENT_CENTER;
		AffichageNumerique02.verticalAlign = CgpText.DISPLAY_POSITION_MIDDLE;
		AffichageNumerique02.enableInput = true;
		AffichageNumerique02.displayPopupKeypad = true;
		AffichageNumerique02.keypad = decKeypad;
		AffichageNumerique02.beepOnTouch = false;
		AffichageNumerique02.barcode = false;
		AffichageNumerique02.frameColor = 0x006e726e;
		AffichageNumerique02.foreColor = 0x00d4d4d4;
		AffichageNumerique02.textColor = 0x007f0044;
		AffichageNumerique02.text3DColor = 0x00000000;
		AffichageNumerique02.textBlinkSpeed = CgpNumericDisplay.BLINK_TYPE_NONE;
		AffichageNumerique02.changeColor = false;
		AffichageNumerique02.blinkSpeed = CgpNumericDisplay.BLINK_TYPE_NONE;
		AffichageNumerique02.drawObject = displayDraw0;
		AffichageNumerique02.alwaysDrawBackground = false;
		AffichageNumerique02.exprServer = exprServer;
		AffichageNumerique02.useLocalMinMax  = true;
		AffichageNumerique02.minExpr   = 1000;
		AffichageNumerique02.maxExpr   = 1001;
		AffichageNumerique02.init();
		Voyant01 = new Lamp_0002(500, 360, 539, 399, panelContext, this);
		int intArray0[] = {0x0000ff00, 0x000000ff, };
		Voyant01.foreClr = intArray0;
		int intArray1[] = {0x00000000, 0x00000000, };
		Voyant01.backClr = intArray1;
		int intArray2[] = {1, 1, };
		Voyant01.pattern = intArray2;
		Voyant01.controlTag01 = TagDB.REG48_AL1;
		Voyant01.exprServer = exprServer;
		Voyant01.alwaysDrawBackground = false;

		Voyant01.init();
		Voyant02 = new Lamp_0002(500, 420, 539, 459, panelContext, this);
		Voyant02.foreClr = intArray0;
		Voyant02.backClr = intArray1;
		Voyant02.pattern = intArray2;
		Voyant02.controlTag01 = TagDB.REG48_AL2;
		Voyant02.exprServer = exprServer;
		Voyant02.alwaysDrawBackground = false;

		Voyant02.init();
		Image01 = new CgpGraphicFile
		(
			"Bitmap1.bmp",
			0,	// x1
			0,	// y1
			79,	// x2
			79,	// y2
			0,
			0,	// Transparent color
			this
		);

		Switch01 = new Switch_0003(520, 20, 619, 60, panelContext, this);
		Switch01.frameClr = 0x006e726e;
		Switch01.foreClr = 0x0000ff00;
		Switch01.backClr = 0x00000000;
		Switch01.pattern = 1;

		CgpFont	fonts13[];
		String	labels13[];
		fonts13 = new CgpFont[1];
		labels13 = new String[1];

		labels13[0] = "Store data";
		fonts13[0] = FoTrendGraph1;

		Switch01.buzzer = true;

		Switch01.switchFonts = fonts13;
		Switch01.labels = labels13;

		int intArray3[] = {0x00ffffff, };
		Switch01.labelClr = intArray3;
		int intArray4[] = {0x00000000, };
		Switch01.label3DClr = intArray4;
		Switch01.horzAlign = CgpText.DISPLAY_ALIGNMENT_LEFT;
		Switch01.vertAlign = CgpText.DISPLAY_POSITION_MIDDLE;
		Switch01.scriptID0 = 1002;
		Switch01.exprServer = exprServer;
		Switch01.alwaysDrawBackground = false;

		Switch01.init();
		((CgpWindow)owner).drawBack();
		TagDB.REG48_PV.addEventListener(AffichageNumerique01, 0, panelContext);
		TagDB._Seconds.addEventListener(AffichageNumerique02, 0, panelContext);
		TagDB.REG48_SV.addEventListener(AffichageNumerique02, 0, panelContext);
		TagDB.REG48_AL1.addEventListener(Voyant01, 0, panelContext);
		TagDB.REG48_AL2.addEventListener(Voyant02, 0, panelContext);

		CgpGraphics zOrderList[] = new CgpGraphics[7];
		zOrderList[0] = TrendGraph1;
		zOrderList[1] = AffichageNumerique01;
		zOrderList[2] = AffichageNumerique02;
		zOrderList[3] = Voyant01;
		zOrderList[4] = Voyant02;
		zOrderList[5] = Switch01;
		zOrderList[6] = decKeypad;
		theZstack = zOrderList;

		IgpTouch touchList[] =
		{
			decKeypad,
			Switch01,
			AffichageNumerique02,
		};

		registerTouchList(touchList);

		registerTagList();
		postOnOpen();
	}

	public void registerTagList()
	{
		Vector tagListVector = new Vector();
		tagListVector.add(TagDB._UserApplicationLanguage);
		tagListVector.add(TagDB.REG48_PV);
		tagListVector.add(TagDB.REG48_SV);
		tagListVector.add(TagDB.REG48_AL1);
		tagListVector.add(TagDB.REG48_AL2);
		tagListVector.add(TagDB.Savedata);

		super.registerTagList(tagListVector);
	}

	public void onClose()
	{
		super.onClose();
		decKeypad.shutdown();
		TrendGraph1.shutdown();
		Image01.clean();

		Switch01.shutdown();

		Voyant02.shutdown();

		Voyant01.shutdown();

		AffichageNumerique02.shutdown();

		AffichageNumerique01.shutdown();
	}

	public boolean drawBackground(int gp)
	{
		CgpCanvas _g = new CgpCanvas(gp);

		TrendGraph1.drawBackground(_g);

		AffichageNumerique01.drawBackground(_g);

		AffichageNumerique02.drawBackground(_g);

		// Texte01
		_g.drawStringWithBorder
		(
			CgpColor.makeTransparentColor(0x08ffffff),	// border color
			0x00ffffff,	// text color
			CgpColor.makeTransparentColor(0x08000000),	// bg color
			0x00ff0000,	// 3D color
			1,	// line width
			CgpLinePattern.LINE_SOLID,	// line pattern
			"PV:",	// text
			20 + _dx,	// x
			360 + _dy,	// y
			80,	// width
			40,	// height
			CgpText.DISPLAY_ANGLE_0,	// display angle
			CgpText.DISPLAY_DIRECTION_HORIZONTAL,	// display direction
			CgpText.DISPLAY_ALIGNMENT_CENTER,	// display alignment
			CgpText.DISPLAY_POSITION_MIDDLE,	// display position
			0,	// line spacing
			F5	// font type
		);
		// Texte02
		_g.drawStringWithBorder
		(
			CgpColor.makeTransparentColor(0x08ffffff),	// border color
			0x00ffffff,	// text color
			CgpColor.makeTransparentColor(0x08000000),	// bg color
			0x00ff0000,	// 3D color
			1,	// line width
			CgpLinePattern.LINE_SOLID,	// line pattern
			"SV:",	// text
			20 + _dx,	// x
			420 + _dy,	// y
			80,	// width
			40,	// height
			CgpText.DISPLAY_ANGLE_0,	// display angle
			CgpText.DISPLAY_DIRECTION_HORIZONTAL,	// display direction
			CgpText.DISPLAY_ALIGNMENT_CENTER,	// display alignment
			CgpText.DISPLAY_POSITION_MIDDLE,	// display position
			0,	// line spacing
			F5	// font type
		);
		// Texte03
		_g.drawStringWithBorder
		(
			CgpColor.makeTransparentColor(0x08ffffff),	// border color
			0x00ffffff,	// text color
			CgpColor.makeTransparentColor(0x08000000),	// bg color
			0x00ff0000,	// 3D color
			1,	// line width
			CgpLinePattern.LINE_SOLID,	// line pattern
			"Alarm 1",	// text
			360 + _dx,	// x
			361 + _dy,	// y
			120,	// width
			40,	// height
			CgpText.DISPLAY_ANGLE_0,	// display angle
			CgpText.DISPLAY_DIRECTION_HORIZONTAL,	// display direction
			CgpText.DISPLAY_ALIGNMENT_CENTER,	// display alignment
			CgpText.DISPLAY_POSITION_MIDDLE,	// display position
			0,	// line spacing
			F5	// font type
		);
		// Texte04
		_g.drawStringWithBorder
		(
			CgpColor.makeTransparentColor(0x08ffffff),	// border color
			0x00ffffff,	// text color
			CgpColor.makeTransparentColor(0x08000000),	// bg color
			0x00ff0000,	// 3D color
			1,	// line width
			CgpLinePattern.LINE_SOLID,	// line pattern
			"Alarm 2",	// text
			360 + _dx,	// x
			421 + _dy,	// y
			120,	// width
			40,	// height
			CgpText.DISPLAY_ANGLE_0,	// display angle
			CgpText.DISPLAY_DIRECTION_HORIZONTAL,	// display direction
			CgpText.DISPLAY_ALIGNMENT_CENTER,	// display alignment
			CgpText.DISPLAY_POSITION_MIDDLE,	// display position
			0,	// line spacing
			F5	// font type
		);
		// Image01
		_g.drawImage(Image01, 220 + _dx, 0 + _dy);
		// Texte05
		_g.drawStringWithBorder
		(
			CgpColor.makeTransparentColor(0x08ffffff),	// border color
			0x00ffffff,	// text color
			CgpColor.makeTransparentColor(0x08000000),	// bg color
			0x00ff0000,	// 3D color
			1,	// line width
			CgpLinePattern.LINE_SOLID,	// line pattern
			"ZELIO REG",	// text
			20 + _dx,	// x
			20 + _dy,	// y
			220,	// width
			60,	// height
			CgpText.DISPLAY_ANGLE_0,	// display angle
			CgpText.DISPLAY_DIRECTION_HORIZONTAL,	// display direction
			CgpText.DISPLAY_ALIGNMENT_CENTER,	// display alignment
			CgpText.DISPLAY_POSITION_MIDDLE,	// display position
			0,	// line spacing
			F12	// font type
		);
		return true;
	}
	public CgpMasterPanel getMasterPanel()
	{
		return masterPanel;
	}

}
