Package framework.component.util

Source Code of framework.component.util.MouseFollowerComponent

package framework.component.util;

import java.io.IOException;

import framework.component.Component;
import framework.event.Event;
import framework.event.EventListener;
import framework.event.EventSystem;
import framework.io.CustomInputStream;
import framework.spacial.PositionComponent;
import framework.userinput.MouseListenerSystem.MouseMovedEvent;

public class MouseFollowerComponent extends Component implements EventListener{
  public MouseFollowerComponent() {
    super();
    EventSystem.getInstance().registerEventListener(this, "MouseMoved", null);
  }

  public MouseFollowerComponent(CustomInputStream in, int baseID, byte versionNum) throws IOException {
    super(in, baseID, versionNum);
    EventSystem.getInstance().registerEventListener(this, "MouseMoved", null);
  }

  @Override
  public boolean allowSameTypedSiblings() {
    return false;
  }

  @Override
  protected byte getDataFormatVersion() {
    return 0;
  }

  @Override
  public void onEvent(Event e) {
    if(e != null && e.getType().equals("MouseMoved")){
      PositionComponent pos = (PositionComponent) getSiblingByType(PositionComponent.class.getName());
      if(pos != null){
        MouseMovedEvent m = (MouseMovedEvent) e;
        pos.setVector(m.getTo());
      }
    }
  }

}
TOP

Related Classes of framework.component.util.MouseFollowerComponent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.