package com.jaamsim.BasicObjects;

import com.jaamsim.DisplayModels.ShapeModel;
import com.jaamsim.Graphics.DisplayEntity;
import com.jaamsim.input.ColourInput;
import com.jaamsim.input.Keyword;
import com.jaamsim.input.Output;
import com.jaamsim.input.OutputInput;
import com.jaamsim.input.StringInput;
import com.jaamsim.units.DimensionlessUnit;

public class BooleanIndicator extends DisplayEntity {

	private final OutputInput<Boolean> boolProp;

	@Keyword(description = "The colour of the indicator when the property is true",
	         exampleList = {"green"})
	private final ColourInput trueColor;

	@Keyword(description = "The colour of the indicator when the property is false",
	         exampleList = {"red"})
	private final ColourInput falseColor;

	@Keyword(description = "The string displayed by the Text output when the property is true.",
	         exampleList = {"'True text'"})
	private final StringInput trueText;

	@Keyword(description = "The string displayed by the Text output when the property is false.",
	         exampleList = {"'False text'"})
	private final StringInput falseText;

	{
		boolProp = new OutputInput<>(Boolean.class, "OutputName", "Key Inputs", null);
		boolProp.setRequired(true);
		this.addInput(boolProp);

		trueColor = new ColourInput("TrueColour", "Graphics", ColourInput.GREEN);
		this.addInput(trueColor);
		this.addSynonym(trueColor, "TrueColor");

		falseColor = new ColourInput("FalseColour", "Graphics", ColourInput.RED);
		this.addInput(falseColor);
		this.addSynonym(falseColor, "FalseColor");

		trueText = new StringInput("TrueText", "Graphics", "TRUE");
		this.addInput(trueText);

		falseText = new StringInput("FalseText", "Graphics", "FALSE");
		this.addInput(falseText);
	}

	public BooleanIndicator() {
	}

	@Override
	public void updateGraphics( double time ) {
		if (boolProp.getValue() == null)
			return;
		Boolean b = boolProp.getOutputValue(time);
		if (b.booleanValue()) {
			setTagColour(ShapeModel.TAG_CONTENTS, trueColor.getValue());
		}
		else {
			setTagColour(ShapeModel.TAG_CONTENTS, falseColor.getValue());
		}
	}

	@Output(name = "Text",
	 description = "If the property is true, then return TrueText.  If the property is false, then return FalseText.",
	    unitType = DimensionlessUnit.class)
	public String getText(double time) {
		if (boolProp.getValue() == null)
			return "";
		Boolean b = boolProp.getOutputValue(time);
		if (b.booleanValue()) {
			return trueText.getValue();
		}
		else {
			return falseText.getValue();
		}
	}
}

@@ -116,16 +116,59 @@
 Entity;%0A
+import com.jaamsim.Samples.SampleExpInput;%0A
 import c
@@ -268,46 +268,8 @@
 ut;%0A
-import com.jaamsim.input.OutputInput;%0A
 impo
@@ -407,51 +407,221 @@
 %7B%0A%0A%09
-private final OutputInput%3CBoolean%3E boolProp
+@Keyword(description = %22An expression returning a boolean value: zero = FALSE, non-zero = TRUE.%22,%0A%09         exampleList = %7B%22'%5BQueue1%5D.QueueLength %3E 2'%22, %22%5BServer1%5D.Working%22%7D)%0A%09private final SampleExpInput expInput
 ;%0A%0A%09
@@ -1287,97 +1287,132 @@
 %7B%0A%09%09
-boolProp = new OutputInput%3C%3E(Boolean.class, %22OutputName%22, %22Key Inputs%22, null);%0A%09%09boolProp
+expInput = new SampleExpInput(%22OutputName%22, %22Key Inputs%22, null);%0A%09%09expInput.setUnitType(DimensionlessUnit.class);%0A%09%09expInput
 .set
@@ -1443,24 +1443,24 @@
 ddInput(
-boolProp
+expInput
 );%0A%0A%09%09tr
@@ -2017,21 +2017,22 @@
 ics(
- 
 double 
-t
+simT
 ime
- 
 ) %7B%0A
@@ -2033,32 +2033,32 @@
 me) %7B%0A%09%09if (
-boolProp
+expInput
 .getValue() 
@@ -2083,76 +2083,63 @@
 ;%0A%09%09
-Boolean b = boolProp.getOutputValue(time);%0A%09%09if (b.booleanValue()) %7B
+if (expInput.getValue().getNextSample(simTime) != 0.0d)
 %0A%09%09%09
@@ -2199,28 +2199,22 @@
 lue());%0A
-%09%09%7D%0A
 %09%09else
- %7B
 %0A%09%09%09setT
@@ -2271,20 +2271,16 @@
 lue());%0A
-%09%09%7D%0A
 %09%7D%0A%0A%09@Ou
@@ -2486,17 +2486,20 @@
 (double 
-t
+simT
 ime) %7B%0A%09
@@ -2503,24 +2503,24 @@
 %7B%0A%09%09if (
-boolProp
+expInput
 .getValu
@@ -2552,76 +2552,63 @@
 ;%0A%09%09
-Boolean b = boolProp.getOutputValue(time);%0A%09%09if (b.booleanValue()) %7B
+if (expInput.getValue().getNextSample(simTime) != 0.0d)
 %0A%09%09%09
@@ -2639,20 +2639,14 @@
 ();%0A
-%09%09%7D%0A
 %09%09else
- %7B
 %0A%09%09%09
@@ -2679,12 +2679,9 @@
 );%0A%09
-%09%7D%0A%09
 %7D
+%0A
 %0A%7D%0A

use SampleExpInput instead of OutputInput in BooleanIndicator