2015-06-25 18:05:24 -04:00
|
|
|
|
using System;
|
2015-07-05 17:43:17 -04:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
2015-06-25 18:05:24 -04:00
|
|
|
|
using System.Windows.Media;
|
2015-07-05 17:43:17 -04:00
|
|
|
|
using Filtration.ObjectModel.Annotations;
|
2015-06-26 12:42:20 -04:00
|
|
|
|
using Filtration.ObjectModel.Enums;
|
2015-06-25 18:05:24 -04:00
|
|
|
|
|
2015-06-26 12:42:20 -04:00
|
|
|
|
namespace Filtration.ObjectModel.ThemeEditor
|
2015-06-25 18:05:24 -04:00
|
|
|
|
{
|
2015-06-26 12:42:20 -04:00
|
|
|
|
[Serializable]
|
2015-07-05 17:43:17 -04:00
|
|
|
|
public class ThemeComponent : INotifyPropertyChanged
|
2015-06-25 18:05:24 -04:00
|
|
|
|
{
|
2015-07-05 17:43:17 -04:00
|
|
|
|
private Color _color;
|
2015-07-06 07:01:48 -04:00
|
|
|
|
private EventHandler _themeComponentUpdatedEventHandler;
|
|
|
|
|
private readonly object _eventLock = new object();
|
2015-07-06 10:33:25 -04:00
|
|
|
|
|
|
|
|
|
public ThemeComponent()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-26 12:42:20 -04:00
|
|
|
|
public ThemeComponent(ThemeComponentType componentType, string componentName, Color componentColor)
|
|
|
|
|
{
|
|
|
|
|
if (componentName == null || componentColor == null)
|
2015-06-25 18:05:24 -04:00
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Null parameters not allowed in ThemeComponent constructor");
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-26 12:42:20 -04:00
|
|
|
|
ComponentType = componentType;
|
2015-06-25 18:05:24 -04:00
|
|
|
|
Color = componentColor;
|
|
|
|
|
ComponentName = componentName;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-06 07:01:48 -04:00
|
|
|
|
// By implementing a custom event accessor here we can keep the UsageCount up to date.
|
|
|
|
|
public event EventHandler ThemeComponentUpdated
|
|
|
|
|
{
|
|
|
|
|
add
|
|
|
|
|
{
|
|
|
|
|
lock (_eventLock)
|
|
|
|
|
{
|
|
|
|
|
_themeComponentUpdatedEventHandler += value;
|
|
|
|
|
OnPropertyChanged("UsageCount");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
remove
|
|
|
|
|
{
|
|
|
|
|
lock (_eventLock)
|
|
|
|
|
{
|
|
|
|
|
// ReSharper disable once DelegateSubtraction
|
|
|
|
|
_themeComponentUpdatedEventHandler -= value;
|
|
|
|
|
OnPropertyChanged("UsageCount");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 17:43:17 -04:00
|
|
|
|
public event EventHandler ThemeComponentDeleted;
|
|
|
|
|
|
2015-06-25 18:05:24 -04:00
|
|
|
|
public string ComponentName { get; set; }
|
2015-07-06 10:33:25 -04:00
|
|
|
|
public ThemeComponentType ComponentType{ get; set; }
|
2015-07-05 17:43:17 -04:00
|
|
|
|
|
|
|
|
|
public Color Color
|
|
|
|
|
{
|
|
|
|
|
get { return _color; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_color = value;
|
|
|
|
|
OnPropertyChanged();
|
2015-12-13 15:17:15 -05:00
|
|
|
|
_themeComponentUpdatedEventHandler?.Invoke(this, EventArgs.Empty);
|
2015-07-05 17:43:17 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-06 07:01:48 -04:00
|
|
|
|
public int UsageCount
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_themeComponentUpdatedEventHandler == null)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _themeComponentUpdatedEventHandler.GetInvocationList().Length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 17:43:17 -04:00
|
|
|
|
public void TerminateComponent()
|
|
|
|
|
{
|
2015-12-13 15:17:15 -05:00
|
|
|
|
ThemeComponentDeleted?.Invoke(this, EventArgs.Empty);
|
2015-07-05 17:43:17 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
|
|
|
|
[NotifyPropertyChangedInvocator]
|
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
|
|
{
|
|
|
|
|
var handler = PropertyChanged;
|
2015-12-13 15:17:15 -05:00
|
|
|
|
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
2015-07-05 17:43:17 -04:00
|
|
|
|
}
|
2015-06-25 18:05:24 -04:00
|
|
|
|
}
|
|
|
|
|
}
|