/src/main/java/uk/ac/cam/ch/ami/amievents/events/SensorAmiEvent.java
https://bitbucket.org/jat45/ami · Java · 122 lines · 72 code · 17 blank · 33 comment · 13 complexity · c49c85bc72d0d0820989d8a7a1b3ee86 MD5 · raw file
- package uk.ac.cam.ch.ami.amievents.events;
-
- import uk.ac.cam.ch.ami.sensors.SensorInput;
- import uk.ac.cam.ch.ami.amievents.verbs.SensorVerb;
- import uk.ac.cam.ch.ami.amievents.AmiEventType;
-
- /**
- * Created by IntelliJ IDEA.
- * User: Matthew
- * Date: 02-Sep-2010
- * Time: 15:39:41
- */
- public class SensorAmiEvent extends AmiEvent {
-
- /**
- * The sensor associated with this event
- */
- private SensorInput sensor = null;
- /**
- * Verb to describe what this event is, eg STARTED
- */
- private SensorVerb verb;
- /**
- * (Optional) value associated with the event, eg record the fact that a sensor has exceeded the maximum limit value
- * set in the SensorControlTab
- */
- private Double value;
-
- public SensorAmiEvent(SensorVerb verb, SensorInput sensor, Double value) {
- this(verb,sensor);
- this.value = value;
- }
-
- public SensorAmiEvent(SensorVerb verb, SensorInput sensor) {
- this(verb);
- this.sensor = sensor;
- }
-
- public SensorAmiEvent(SensorVerb verb) {
- super(AmiEventType.SENSOR_EVENT);
- this.verb = verb;
- }
-
- public SensorInput getSensor() {
- return sensor;
- }
-
- @Override
- public String toString() {
- return "Sensor Event: "+ this.getVerb() + " at " + this.getTimeAddedFormatted();
- }
-
- @Override
- public String getTimelineText() {
- String s = this.getShortName();
- if(this.getValue()!=null) {
- s = s + this.getValue().toString() + " " + this.getUnits();
- }
- s = s + " " + this.getVerb().toString().toLowerCase();
- return s;
- }
-
- /**
- * Should never be called because this event type can't be edited, but we need to implement the method
- * as it's abstract in the base class
- */
- @Override
- public void edit() {
- }
-
- public SensorVerb getVerb() {
- return verb;
- }
-
- /**
- * @return The full name onf the sensor
- */
- public String getSensorName() {
- if(sensor != null) {
- return sensor.getSensorName();
- } else {
- return "None";
- }
- }
-
- /**
- * @return An abbreviated name for the sensor, eg "Distance sensor" rather than "PING Ultransonic distance sensor"
- */
- public String getShortName(){
- if (sensor != null){
- return sensor.getDisplayName();
- } else {
- // if name hasn't been set, the event is non-sensor-specific so return
- // an appropriate name
- return "Sensor control";
- }
- }
-
- @Override
- public boolean canBeEdited() {
- return false;
- }
-
- /**
- *
- * @return true if the event is simply recording that the sensors or the webcam were started or stopped, false
- * otherwise
- */
- @Override
- public boolean canBeDeleted() {
- return verb == SensorVerb.STARTED || verb == SensorVerb.STOPPED ||
- verb == SensorVerb.RECORD_STARTED || verb == SensorVerb.RECORD_STOPPED;
- }
-
- public Double getValue() {
- return value;
- }
-
- public String getUnits() {
- return sensor.getUnits();
- }
- }