PageRenderTime 25ms CodeModel.GetById 19ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  1package uk.ac.cam.ch.ami.amievents.events;
  2
  3import uk.ac.cam.ch.ami.sensors.SensorInput;
  4import uk.ac.cam.ch.ami.amievents.verbs.SensorVerb;
  5import uk.ac.cam.ch.ami.amievents.AmiEventType;
  6
  7/**
  8 * Created by IntelliJ IDEA.
  9 * User: Matthew
 10 * Date: 02-Sep-2010
 11 * Time: 15:39:41
 12 */
 13public class SensorAmiEvent extends AmiEvent {
 14
 15    /**
 16     * The sensor associated with this event
 17     */
 18    private SensorInput sensor = null;
 19    /**
 20     * Verb to describe what this event is, eg STARTED
 21     */
 22    private SensorVerb verb;
 23    /**
 24     * (Optional) value associated with the event, eg record the fact that a sensor has exceeded the maximum limit value
 25     * set in the SensorControlTab
 26     */
 27    private Double value;
 28
 29    public SensorAmiEvent(SensorVerb verb, SensorInput sensor, Double value) {
 30        this(verb,sensor);
 31        this.value = value;
 32    }
 33
 34    public SensorAmiEvent(SensorVerb verb, SensorInput sensor) {
 35        this(verb);
 36        this.sensor = sensor;
 37    }
 38
 39    public SensorAmiEvent(SensorVerb verb) {
 40        super(AmiEventType.SENSOR_EVENT);
 41        this.verb = verb;
 42    }
 43
 44    public SensorInput getSensor() {
 45        return sensor;
 46    }
 47
 48    @Override
 49    public String toString() {
 50        return "Sensor Event: "+ this.getVerb() + " at " + this.getTimeAddedFormatted();
 51    }
 52
 53    @Override
 54    public String getTimelineText() {
 55        String s = this.getShortName();
 56        if(this.getValue()!=null) {
 57            s = s + this.getValue().toString() + " " + this.getUnits();
 58        }
 59        s = s + " " + this.getVerb().toString().toLowerCase();
 60        return s;
 61    }
 62
 63    /**
 64     * Should never be called because this event type can't be edited, but we need to implement the method
 65     * as it's abstract in the base class
 66     */
 67    @Override
 68    public void edit() {
 69    }
 70
 71    public SensorVerb getVerb() {
 72        return verb;
 73    }
 74
 75    /**
 76     * @return The full name onf the sensor
 77     */
 78    public String getSensorName() {
 79        if(sensor != null) {
 80            return sensor.getSensorName();
 81        } else {
 82            return "None";
 83        }
 84    }
 85
 86    /**
 87     * @return An abbreviated name for the sensor, eg "Distance sensor" rather than "PING Ultransonic distance sensor"
 88     */
 89    public String getShortName(){
 90        if (sensor != null){
 91            return sensor.getDisplayName();
 92        } else {
 93            // if name hasn't been set, the event is non-sensor-specific so return
 94            // an appropriate name
 95            return "Sensor control";
 96        }
 97    }
 98
 99    @Override
100    public boolean canBeEdited() {
101        return false;
102    }
103
104    /**
105     *
106     * @return true if the event is simply recording that the sensors or the webcam were started or stopped, false
107     * otherwise
108     */
109    @Override
110    public boolean canBeDeleted() {
111        return verb == SensorVerb.STARTED || verb == SensorVerb.STOPPED ||
112                verb == SensorVerb.RECORD_STARTED || verb == SensorVerb.RECORD_STOPPED;
113    }
114
115    public Double getValue() {
116        return value;
117    }
118
119    public String getUnits() {
120        return sensor.getUnits();
121    }
122}