/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2016 JaamSim Software Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jaamsim.Graphics;

import com.jaamsim.DisplayModels.ShapeModel;
import com.jaamsim.Samples.SampleConstant;
import com.jaamsim.Samples.SampleInput;
import com.jaamsim.input.ColourInput;
import com.jaamsim.input.Keyword;
import com.jaamsim.input.Output;
import com.jaamsim.units.DimensionlessUnit;

public class BarGauge extends DisplayEntity {

	@Keyword(description = "Height of the bar expressed as a value between 0 and 1. Values "
	                     + "outside this range will be truncated.",
	         exampleList = {"0.5", "'0.5 + 0.5*sin(this.SimTime/10[s])'"})
	private final SampleInput dataSource;

	@Keyword(description = "Colour of the bar.",
	         exampleList = {"red"})
	private final ColourInput colour;

	{
		dataSource = new SampleInput("DataSource", "Key Inputs", new SampleConstant(0.5));
		dataSource.setUnitType(DimensionlessUnit.class);
		dataSource.setEntity(this);
		dataSource.setValidRange(0.0d, 1.0d);
		this.addInput(dataSource);

		colour = new ColourInput("Colour", "Key Inputs", ColourInput.BLUE);
		this.addInput(colour);
		this.addSynonym(colour, "Color");
	}

	@Output(name = "Value",
	 description = "Value displayed by the gauge.",
	    unitType = DimensionlessUnit.class)
	public double getValue(double simTime) {
		double ret = dataSource.getValue().getNextSample(simTime);
		ret = Math.min(ret, 1.0d);
		ret = Math.max(ret, 0.0d);
		return ret;
	}

	@Override
	public void updateGraphics(double simTime) {
		super.updateGraphics(simTime);

		double val = this.getValue(simTime);
		if (Double.isNaN(val)) {
			val = 0.0d;
		}

		setTagSize(ShapeModel.TAG_CONTENTS, val);
		setTagColour(ShapeModel.TAG_CONTENTS, colour.getValue());
	}

}

@@ -1381,11 +1381,147 @@
 r;%0A%0A
+%09@Keyword(description = %22Colour of the gauge's body.%22,%0A%09         exampleList = %7B%22white%22%7D)%0A%09private final ColourInput backgroundColour;%0A%0A
 %09%7B%0A
-
 %09%09da
@@ -1882,16 +1882,204 @@
 Color%22);
+%0A%0A%09%09backgroundColour = new ColourInput(%22BackgroundColour%22, %22Key Inputs%22, ColourInput.LIGHT_GREY);%0A%09%09this.addInput(backgroundColour);%0A%09%09this.addSynonym(backgroundColour, %22BackgroundColor%22);
 %0A%09%7D%0A%0A%09@O
@@ -2590,16 +2590,16 @@
 , val);%0A
-
 %09%09setTag
@@ -2650,14 +2650,80 @@
 lue());%0A
+%09%09setTagColour(ShapeModel.TAG_BODY, backgroundColour.getValue());%0A
 %09%7D%0A%0A%7D%0A

add the keyword BackgroundColour to BarGauge