package de.lessvoid.nifty.controls;
import java.util.Properties;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.input.NiftyInputEvent;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.xml.xpp3.Attributes;
public class MenuItemControl extends AbstractController {
private Screen screen;
private Element element;
private FocusHandler focusHandler;
public void bind(
final Nifty nifty,
final Screen screenParam,
final Element newElement,
final Properties properties,
final Attributes controlDefinitionAttributes) {
element = newElement;
screen = screenParam;
}
public void onStartScreen() {
focusHandler = screen.getFocusHandler();
}
public boolean inputEvent(final NiftyInputEvent inputEvent) {
if (inputEvent == NiftyInputEvent.NextInputElement) {
if (focusHandler != null) {
Element nextElement = focusHandler.getNext(element);
nextElement.setFocus();
return true;
}
} else if (inputEvent == NiftyInputEvent.PrevInputElement) {
if (focusHandler != null) {
Element prevElement = focusHandler.getPrev(element);
prevElement.setFocus();
return true;
}
} else if (inputEvent == NiftyInputEvent.MoveCursorDown) {
if (focusHandler != null) {
Element nextElement = focusHandler.getNext(element);
if (nextElement.getParent().equals(element.getParent())) {
nextElement.setFocus();
return true;
}
}
} else if (inputEvent == NiftyInputEvent.MoveCursorUp) {
if (focusHandler != null) {
Element prevElement = focusHandler.getPrev(element);
if (prevElement.getParent().equals(element.getParent())) {
prevElement.setFocus();
return true;
}
}
} else if (inputEvent == NiftyInputEvent.Activate) {
element.onClick();
return true;
}
return false;
}
@Override
public void onFocus(final boolean getFocus) {
super.onFocus(getFocus);
}
}