A countdown timer.
Наследование: Hourglass.Timing.TimerBase
Пример #1
0
        /// <summary>
        /// Shows an existing <see cref="Timer"/> in a new <see cref="TimerWindow"/>.
        /// </summary>
        /// <param name="savedTimer">An existing <see cref="Timer"/>.</param>
        private void ShowSavedTimerInNewWindow(Timer savedTimer)
        {
            TimerWindow newTimerWindow = new TimerWindow();

            if (savedTimer.Options.WindowSize != null)
            {
                newTimerWindow.Restore(savedTimer.Options.WindowSize);
            }
            else
            {
                newTimerWindow.RestoreFromWindow(this.timerWindow);
            }

            newTimerWindow.Show(savedTimer);
        }
Пример #2
0
 /// <summary>
 /// Shows an existing <see cref="Timer"/>.
 /// </summary>
 /// <param name="savedTimer">An existing <see cref="Timer"/>.</param>
 private void ShowSavedTimer(Timer savedTimer)
 {
     if (this.timerWindow.Timer.State == TimerState.Stopped || this.timerWindow.Timer.State == TimerState.Expired)
     {
         this.ShowSavedTimerInCurrentWindow(savedTimer);
     }
     else
     {
         this.ShowSavedTimerInNewWindow(savedTimer);
     }
 }
Пример #3
0
        /// <summary>
        /// Shows an existing <see cref="Timer"/> in the current <see cref="TimerWindow"/>.
        /// </summary>
        /// <param name="savedTimer">An existing <see cref="Timer"/>.</param>
        private void ShowSavedTimerInCurrentWindow(Timer savedTimer)
        {
            if (savedTimer.Options.WindowSize != null)
            {
                this.timerWindow.Restore(savedTimer.Options.WindowSize);
            }

            this.timerWindow.Show(savedTimer);
            this.UpdateMenuFromOptions();
        }
Пример #4
0
 /// <summary>
 /// Returns an object that can be set for the <see cref="MenuItem.Header"/> of a <see cref="MenuItem"/> that
 /// displays a <see cref="Timer"/>.
 /// </summary>
 /// <param name="timer">A <see cref="Timer"/>.</param>
 /// <returns>An object that can be set for the <see cref="MenuItem.Header"/>.</returns>
 private object GetHeaderForTimer(Timer timer)
 {
     return timer.ToString();
 }
Пример #5
0
        /// <summary>
        /// Returns an object that can be set for the <see cref="MenuItem.Icon"/> of a <see cref="MenuItem"/> that
        /// displays a <see cref="Timer"/>.
        /// </summary>
        /// <param name="timer">A <see cref="Timer"/>.</param>
        /// <returns>An object that can be set for the <see cref="MenuItem.Icon"/>.</returns>
        private object GetIconForTimer(Timer timer)
        {
            Border outerBorder = new Border();
            outerBorder.BorderBrush = new SolidColorBrush(Colors.LightGray);
            outerBorder.BorderThickness = new Thickness(1);
            outerBorder.CornerRadius = new CornerRadius(2);
            outerBorder.Width = 16;
            outerBorder.Height = 6;

            if (timer.State == TimerState.Expired)
            {
                Border progress = new Border();
                progress.Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(199, 80, 80));
                progress.Width = 16;
                progress.Height = 6;

                outerBorder.Child = progress;
            }
            else if (timer.TimeLeftAsPercentage.HasValue)
            {
                Border progress = new Border();
                progress.Background = timer.Options.Color.Brush;
                progress.HorizontalAlignment = HorizontalAlignment.Left;
                progress.Width = timer.TimeLeftAsPercentage.Value / 100.0 * 16.0;
                progress.Height = 6;

                outerBorder.Child = progress;
            }

            return outerBorder;
        }
Пример #6
0
        /// <summary>
        /// Add a new timer.
        /// </summary>
        /// <param name="timer">A <see cref="Timer"/>.</param>
        /// <exception cref="InvalidOperationException">If the <see cref="Timer"/> has already been added.
        /// </exception>
        public void Add(Timer timer)
        {
            if (this.timers.Contains(timer))
            {
                throw new InvalidOperationException();
            }

            this.timers.Insert(0, timer);
        }
Пример #7
0
        /// <summary>
        /// Returns a <see cref="TimerInfo"/> for the specified <see cref="Timer"/>.
        /// </summary>
        /// <param name="timer">A <see cref="Timer"/>.</param>
        /// <returns>A <see cref="TimerInfo"/> for the specified <see cref="Timer"/>.</returns>
        public static TimerInfo FromTimer(Timer timer)
        {
            if (timer == null)
            {
                return null;
            }

            return timer.ToTimerInfo();
        }
Пример #8
0
        /// <summary>
        /// Remove an existing timer.
        /// </summary>
        /// <param name="timer">A <see cref="Timer"/>.</param>
        /// <exception cref="InvalidOperationException">If the timer had not been added previously or has already been
        /// removed.</exception>
        public void Remove(Timer timer)
        {
            if (!this.timers.Contains(timer))
            {
                throw new InvalidOperationException();
            }

            this.timers.Remove(timer);
            timer.Dispose();
        }
Пример #9
0
 /// <summary>
 /// Returns a value indicating whether a timer is bound to any <see cref="TimerWindow"/>.</summary>
 /// <param name="timer">A <see cref="Timer"/>.</param>
 /// <returns>A value indicating whether the timer is bound to any <see cref="TimerWindow"/>. </returns>
 private static bool IsBoundToWindow(Timer timer)
 {
     return Application.Current != null
         && Application.Current.Windows.OfType<TimerWindow>().Any(w => w.Timer == timer);
 }
Пример #10
0
        /// <summary>
        /// Opens the <see cref="TimerWindow"/> if it is not already open and displays the specified timer.
        /// </summary>
        /// <param name="existingTimer">A timer.</param>
        public void Show(Timer existingTimer)
        {
            // Show the status of the existing timer
            this.Timer = existingTimer;
            this.SwitchToStatusMode();

            // Show the window if it is not already open
            if (!this.IsVisible)
            {
                this.Show();
            }

            // Notify expiration if the existing timer is expired
            if (this.Timer.State == TimerState.Expired)
            {
                if (this.Options.LoopSound)
                {
                    this.BeginExpirationAnimationAndSound();
                }
                else
                {
                    this.BeginExpirationAnimation(true /* glowOnly */);
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Opens the <see cref="TimerWindow"/> if it is not already open and displays a new timer started with the
        /// specified <see cref="TimerStart"/>.
        /// </summary>
        /// <param name="timerStart">A <see cref="TimerStart"/>.</param>
        public void Show(TimerStart timerStart)
        {
            // Keep track of the input
            this.LastTimerStart = timerStart;

            // Start a new timer
            Timer newTimer = new Timer(this.Options);
            if (!newTimer.Start(timerStart))
            {
                this.Show();
                this.SwitchToInputMode();
                this.BeginValidationErrorAnimation();
                return;
            }

            TimerManager.Instance.Add(newTimer);
            TimerStartManager.Instance.Add(timerStart);

            // Show the window
            this.Show(newTimer);
        }
Пример #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TimerWindow"/> class.
 /// </summary>
 /// <param name="timer">The timer to resume when the window loads, or <c>null</c> if no timer is to be resumed.
 /// </param>
 public TimerWindow(Timer timer)
     : this()
 {
     this.timerToResumeOnLoad = timer;
 }
Пример #13
0
        /// <summary>
        /// Invoked when the <see cref="TimerWindow"/> is laid out, rendered, and ready for interaction.
        /// </summary>
        /// <param name="sender">The <see cref="TimerWindow"/>.</param>
        /// <param name="e">The event data.</param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Deal with any input or timer set in the constructor
            if (this.timerStartToStartOnLoad != null)
            {
                this.Show(this.timerStartToStartOnLoad);
                this.timerStartToStartOnLoad = null;
                this.timerToResumeOnLoad = null;
            }
            else if (this.timerToResumeOnLoad != null)
            {
                this.Show(this.timerToResumeOnLoad);
                this.timerStartToStartOnLoad = null;
                this.timerToResumeOnLoad = null;
            }

            // Minimize to notification area if required
            if (this.WindowState == WindowState.Minimized && Settings.Default.ShowInNotificationArea)
            {
                this.MinimizeToNotificationArea();
            }
        }
Пример #14
0
        /// <summary>
        /// Invoked when the <see cref="StopCommand"/> is executed.
        /// </summary>
        /// <param name="sender">The <see cref="TimerWindow"/>.</param>
        /// <param name="e">The event data.</param>
        private void StopCommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            this.Timer = new Timer(this.Options);
            TimerManager.Instance.Add(this.Timer);

            this.SwitchToInputMode();
            this.StopButton.Unfocus();
        }