using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Tango.Core
{
/// <summary>
/// Represents a component parameter name and value which can be bound to UI elements.
/// </summary>
/// <seealso cref="System.Windows.DependencyObject" />
public class ParameterItem : DependencyObject
{
/// <summary>
/// Occurs when the parameter value has changed.
/// </summary>
public event EventHandler<ParameterItem> ParameterValueChanged;
/// <summary>
/// Gets or sets the parameterized object.
/// </summary>
public IParameterized ParameterizedObject
{
get { return (IParameterized)GetValue(ParameterizedObjectProperty); }
set { SetValue(ParameterizedObjectProperty, value); }
}
public static readonly DependencyProperty ParameterizedObjectProperty =
DependencyProperty.Register("ParameterizedObject", typeof(IParameterized), typeof(ParameterItem), new PropertyMetadata(null));
/// <summary>
/// Gets or sets the parameter index.
/// </summary>
public int Index
{
get { return (int)GetValue(IndexProperty); }
set { SetValue(IndexProperty, value); }
}
public static readonly DependencyProperty IndexProperty =
DependencyProperty.Register("Index", typeof(int), typeof(ParameterItem), new PropertyMetadata(0));
/// <summary>
/// Gets or sets the parameter value type.
/// </summary>
public Type Type
{
get { return (Type)GetValue(TypeProperty); }
set { SetValue(TypeProperty, value); }
}
public static readonly DependencyProperty TypeProperty =
DependencyProperty.Register("Type", typeof(Type), typeof(ParameterItem), new PropertyMetadata(typeof(double)));
/// <summary>
/// Gets or sets the parameter name.
/// </summary>
public String Name
{
get { return (String)GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
public static readonly DependencyProperty NameProperty =
DependencyProperty.Register("Name", typeof(String), typeof(ParameterItem), new PropertyMetadata(null));
/// <summary>
/// Gets or sets the current parameter value.
/// </summary>
public object Value
{
get { return (object)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(object), typeof(ParameterItem), new PropertyMetadata(null, new PropertyChangedCallback(OnValueChanged)));
/// <summary>
/// Gets or sets the minimum parameter value.
/// </summary>
public object Minimum
{
get { return (object)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}
public static readonly DependencyProperty MinimumProperty =
DependencyProperty.Register("Minimum", typeof(object), typeof(ParameterItem), new PropertyMetadata(0.0d));
/// <summary>
/// Gets or sets the maximum parameter value.
/// </summary>
public object Maximum
{
get { return (object)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
public static readonly DependencyProperty MaximumProperty =
DependencyProperty.Register("Maximum", typeof(object), typeof(ParameterItem), new PropertyMetadata(1.0d));
/// <summary>
/// Gets or sets an optional extra object.
/// </summary>
public object ExtraObject
{
get { return (object)GetValue(ExtraObjectProperty); }
set { SetValue(ExtraObjectProperty, value); }
}
public static readonly DependencyProperty ExtraObjectProperty =
DependencyProperty.Register("ExtraObject", typeof(object), typeof(ParameterItem), new PropertyMetadata(null));
/// <summary>
/// Gets or sets an optional custom editor.
/// </summary>
public String CustomEditorTypeName
{
get { return (String)GetValue(CustomEditorTypeNameProperty); }
set { SetValue(CustomEditorTypeNameProperty, value); }
}
public static readonly DependencyProperty CustomEditorTypeNameProperty =
DependencyProperty.Register("CustomEditorType", typeof(String), typeof(ParameterItem), new PropertyMetadata(null));
/// <summary>
/// Gets or sets the parameter description.
/// </summary>
public String Description
{
get { return (String)GetValue(DescriptionProperty); }
set { SetValue(DescriptionProperty, value); }
}
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(String), typeof(ParameterItem), new PropertyMetadata(null));
/// <summary>
/// Gets or sets the parameter string format.
/// </summary>
public String StringFormat
{
get { return (String)GetValue(StringFormatProperty); }
set { SetValue(StringFormatProperty, value); }
}
public static readonly DependencyProperty StringFormatProperty =
DependencyProperty.Register("StringFormat", typeof(String), typeof(ParameterItem), new PropertyMetadata("0.0"));
/// <summary>
/// Gets a value indicating whether this instance requires custom editor.
/// </summary>
public bool HasCustomEditor
{
get { return false; }
}
/// <summary>
/// Called when value has changed.
/// </summary>
/// <param name="d">The d.</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as ParameterItem).OnParameterChanged();
}
/// <summary>
/// Called when the parameter value has changed.
/// </summary>
protected virtual void OnParameterChanged()
{
if (ParameterValueChanged != null) ParameterValueChanged(this, this);
}
/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents this instance.
/// </returns>
public override string ToString()
{
return Name;
}
}
}