/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

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