Java Code Examples for com.jogamp.newt.event.KeyEvent#VK_UP

The following examples show how to use com.jogamp.newt.event.KeyEvent#VK_UP . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OverlayEntity.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handleKeyPressed(int keyCode, char keyChar, boolean shift, boolean control, boolean alt) {
	if (!isMovable())
		return false;

	IntegerVector pos = screenPosition.getValue();
	int x = pos.get(0);
	int y = pos.get(1);

	switch (keyCode) {

		case KeyEvent.VK_LEFT:
			x += getAlignRight() ? 1 : -1;
			break;

		case KeyEvent.VK_RIGHT:
			x += getAlignRight() ? -1 : 1;
			break;

		case KeyEvent.VK_UP:
			y += getAlignBottom() ? 1 : -1;
			break;

		case KeyEvent.VK_DOWN:
			y += getAlignBottom() ? -1 : 1;
			break;

		default:
			return false;
	}

	x = Math.max(0, x);
	y = Math.max(0, y);
	KeywordIndex kw = InputAgent.formatIntegers(screenPosition.getKeyword(), x, y);
	InputAgent.storeAndExecute(new KeywordCommand(this, kw));
	return true;
}
 
Example 2
Source File: DisplayEntity.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
/**
 * Performs the specified keyboard event.
 * @param keyCode - newt key code
 * @param keyChar - alphanumeric character for the key (if applicable)
 * @param shift - true if the Shift key is held down
 * @param control - true if the Control key is held down
 * @param alt - true if the Alt key is held down
 * @return true if the key event was consumed by this entity
 */
public boolean handleKeyPressed(int keyCode, char keyChar, boolean shift, boolean control, boolean alt) {
	if (!isMovable())
		return false;
	double inc = getSimulation().getIncrementSize();
	if (getSimulation().isSnapToGrid())
		inc = Math.max(inc, getSimulation().getSnapGridSpacing());

	Vec3d offset = new Vec3d();
	switch (keyCode) {

		case KeyEvent.VK_LEFT:
			offset.x -= inc;
			break;

		case KeyEvent.VK_RIGHT:
			offset.x += inc;
			break;

		case KeyEvent.VK_UP:
			if (shift)
				offset.z += inc;
			else
				offset.y += inc;
			break;

		case KeyEvent.VK_DOWN:
			if (shift)
				offset.z -= inc;
			else
				offset.y -= inc;
			break;

		default:
			return false;
	}

	// Normal object
	Vec3d pos = getPosition();
	pos.add3(offset);
	if (getSimulation().isSnapToGrid())
		pos = getSimulation().getSnapGridPosition(pos, pos, shift);
	String posKey = positionInput.getKeyword();
	KeywordIndex posKw = InputAgent.formatVec3dInput(posKey, pos, DistanceUnit.class);

	if (!usePointsInput()) {
		InputAgent.storeAndExecute(new KeywordCommand(this, posKw));
		return true;
	}

	// Polyline object
	if (getSimulation().isSnapToGrid()) {
		Vec3d pts0 = new Vec3d(getPoints().get(0));
		pts0.add3(offset);
		pts0 = getSimulation().getSnapGridPosition(pts0, pts0, shift);
		offset = new Vec3d(pts0);
		offset.sub3(getPoints().get(0));
	}
	String ptsKey = pointsInput.getKeyword();
	KeywordIndex ptsKw = InputAgent.formatPointsInputs(ptsKey, getPoints(), offset);

	InputAgent.storeAndExecute(new KeywordCommand(this, posKw, ptsKw));
	return true;
}
 
Example 3
Source File: CameraControl.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {

	// If an entity has been selected, pass the key event to it
	boolean bool = RenderManager.inst().handleKeyPressed(e.getKeyCode(), e.getKeyChar(),
			e.isShiftDown(), e.isControlDown(), e.isAltDown());
	if (bool)
		return;

	// If no entity has been selected, the camera will handle the key event
	Vec3d pos = _updateView.getGlobalPosition();
	Vec3d cent = _updateView.getGlobalCenter();

	// Construct a unit vector in the x-y plane in the direction of the view center
	Vec3d forward = new Vec3d(cent);
	forward.sub3(pos);
	forward.z = 0.0d;
	forward.normalize3();

	// Trap the degenerate case where the camera look straight down on the x-y plane
	// For this case the normalize3 method returns a unit vector in the z-direction
	if (forward.z > 0.0)
		forward.set3(0.0d, 1.0d, 0.0d);

	// Construct a unit vector pointing to the left of the direction vector
	Vec3d left = new Vec3d( -forward.y, forward.x, 0.0d);

	// Scale the two vectors to the desired step size
	double inc = GUIFrame.getJaamSimModel().getSimulation().getIncrementSize();
	forward.scale3(inc);
	left.scale3(inc);

	int keyCode = e.getKeyCode();

	if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_A) {
		pos.add3(left);
		cent.add3(left);
	}

	else if (keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_D) {
		pos.sub3(left);
		cent.sub3(left);
	}

	else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_W) {
		if (e.isShiftDown()) {
			pos.set3(pos.x, pos.y, pos.z+inc);
			cent.set3(cent.x, cent.y, cent.z+inc);
		}
		else {
			pos.add3(forward);
			cent.add3(forward);
		}
	}

	else if (keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_S) {
		if (e.isShiftDown()) {
			pos.set3(pos.x, pos.y, pos.z-inc);
			cent.set3(cent.x, cent.y, cent.z-inc);
		}
		else {
			pos.sub3(forward);
			cent.sub3(forward);
		}
	}

	else
		return;

	_updateView.updateCenterAndPos(cent, pos);
}