/// <summary> /// Adds a new alarm display onto the list that is currently being managed /// </summary> /// <param name="alarm"> /// The alarm to add /// </param> public void AddAlarm(Alarm alarm) { AlarmDisplay display = CreateAlarmDisplay(alarm); alarmDisplayLookup.Add(alarm, display); alarmDisplayIndexed.Add(display); RenderCurrentDisplays(); }
/// <summary> /// Compares this alarm display using the target time of the contained alarm /// </summary> public int CompareTo(object obj) { if (obj.GetType() != typeof(AlarmDisplay)) { return(0); } AlarmDisplay toCompareWith = (AlarmDisplay)obj; return(alarm.GetAlarmTime().CompareTo(toCompareWith.alarm.GetAlarmTime())); }
/// <summary> /// /// </summary> /// <param name="alarm"></param> public void UpdateAlarm(Alarm alarm) { //find the display object AlarmDisplay display = alarmDisplayLookup[alarm]; //tell it to update display.UpdateAlarm(); //redraw RenderCurrentDisplays(); }
/// <summary> /// Removes the display for the provided alarm /// </summary> /// <param name="alarm"></param> public void RemoveAlarm(Alarm alarm) { //find the display object AlarmDisplay display = alarmDisplayLookup[alarm]; //delete the lookup entry alarmDisplayLookup.Remove(alarm); //remove display from the render list alarmDisplayIndexed.Remove(display); //attempt to move the list back one now that an element is missing AttemptDecrementDisplay(); //redraw the panel RenderCurrentDisplays(); }
/// <summary> /// Re draws the alarm list, putting the correct displays in the available slots /// </summary> private void RenderCurrentDisplays() { //sort the alarms to render alarmDisplayIndexed.Sort(); //iterate over all slots and empty them for (int i = 1; i <= slotCount; i++) { Grid targetSlot = GetDisplaySlot(i); targetSlot.Children.Clear(); } //iterate from the current top to the end of the list, and from slot 1 to 3, whichever ends first for (int alarmIndex = topOfTheListIndex, displaySlot = 1; alarmIndex < alarmDisplayIndexed.Count && displaySlot <= slotCount; alarmIndex++, displaySlot++) { Grid targetSlot = GetDisplaySlot(displaySlot); AlarmDisplay targetDisplay = alarmDisplayIndexed[alarmIndex]; targetSlot.Children.Add(targetDisplay); } //set the button visibility as appropriate if (topOfTheListIndex == 0) { mainControl.AlarmListTickUp.Visibility = Visibility.Collapsed; } else { mainControl.AlarmListTickUp.Visibility = Visibility.Visible; } if (topOfTheListIndex >= alarmDisplayIndexed.Count - slotCount) { mainControl.AlarmListTickDown.Visibility = Visibility.Collapsed; } else { mainControl.AlarmListTickDown.Visibility = Visibility.Visible; } }