/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2013 Ausenco Engineering Canada 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.datatypes.IntegerVector;
import com.jaamsim.input.BooleanInput;
import com.jaamsim.input.IntegerListInput;
import com.jaamsim.input.Keyword;

/**
 * OverlayEntity is the superclass for DisplayEntities that have 2D overlay graphics instead of 3D graphics.  Overlay graphics
 * are those that appear relative to the View window and whose position and size are specified in pixels.
 * @author Harry King
 *
 */
public abstract class OverlayEntity extends DisplayEntity {

	@Keyword(description = "The position of the overlay, from the upper left corner of the window to the upper left corner " +
	                "of the overlay. Value is in pixels",
	         exampleList = {"20 20"})
	private final IntegerListInput screenPosition;

	@Keyword(description = "If this overlay should be aligned from the right edge of the window (instead of the left)",
	         exampleList = {"TRUE"})
	private final BooleanInput alignRight;

	@Keyword(description = "If this overlay should be aligned from the bottom edge of the window (instead of the top)",
	         exampleList = {"TRUE"})
	private final BooleanInput alignBottom;

	{
		IntegerVector defPos = new IntegerVector(2);
		defPos.add(10);
		defPos.add(10);
		screenPosition = new IntegerListInput("ScreenPosition", GRAPHICS, defPos);
		screenPosition.setValidCount(2);
		screenPosition.setValidRange(0, 2500);
		this.addInput(screenPosition);

		alignRight = new BooleanInput("AlignRight", GRAPHICS, false);
		this.addInput(alignRight);

		alignBottom = new BooleanInput("AlignBottom", GRAPHICS, false);
		this.addInput(alignBottom);
	}

	public boolean getAlignRight() {
		return alignRight.getValue();
	}

	public boolean getAlignBottom() {
		return alignBottom.getValue();
	}

	public IntegerVector getScreenPosition() {
		return screenPosition.getValue();
	}

}

@@ -680,16 +680,60 @@
 phics;%0A%0A
+import com.jaamsim.Commands.KeywordCommand;%0A
 import c
@@ -768,16 +768,16 @@
 Vector;%0A
-
 import c
@@ -803,24 +803,61 @@
 oleanInput;%0A
+import com.jaamsim.input.InputAgent;%0A
 import com.j
@@ -883,24 +883,24 @@
 rListInput;%0A
-
 import com.j
@@ -920,16 +920,125 @@
 Keyword;
+%0Aimport com.jaamsim.input.KeywordIndex;%0Aimport com.jaamsim.math.Vec3d;%0Aimport com.jogamp.newt.event.KeyEvent;
 %0A%0A/**%0A *
@@ -2699,10 +2699,791 @@
 ();%0A%09%7D%0A%0A
+%09@Override%0A%09public void dragged(Vec3d newPos) %7B%7D%0A%0A%09@Override%0A%09public void handleKeyPressed(int keyCode, char keyChar, boolean shift, boolean control, boolean alt) %7B%0A%09%09if (!isMovable())%0A%09%09%09return;%0A%0A%09%09IntegerVector pos = screenPosition.getValue();%0A%09%09int x = pos.get(0);%0A%09%09int y = pos.get(1);%0A%0A%09%09switch (keyCode) %7B%0A%0A%09%09%09case KeyEvent.VK_LEFT:%0A%09%09%09%09x += getAlignRight() ? 1 : -1;%0A%09%09%09%09break;%0A%0A%09%09%09case KeyEvent.VK_RIGHT:%0A%09%09%09%09x += getAlignRight() ? -1 : 1;%0A%09%09%09%09break;%0A%0A%09%09%09case KeyEvent.VK_UP:%0A%09%09%09%09y += getAlignBottom() ? 1 : -1;%0A%09%09%09%09break;%0A%0A%09%09%09case KeyEvent.VK_DOWN:%0A%09%09%09%09y += getAlignBottom() ? -1 : 1;%0A%09%09%09%09break;%0A%0A%09%09%09default:%0A%09%09%09%09return;%0A%09%09%7D%0A%0A%09%09KeywordIndex kw = InputAgent.formatIntegers(screenPosition.getKeyword(), x, y);%0A%09%09InputAgent.storeAndExecute(new KeywordCommand(this, kw));%0A%09%7D%0A%0A
 %7D%0A

allow an OverlayEntity to be moved with the arrow keys