TBF.UI : Item.EditXyz added.
This commit is contained in:
@@ -2156,6 +2156,12 @@
|
|||||||
<DependentUpon>PicturesTabPageCtrl.cs</DependentUpon>
|
<DependentUpon>PicturesTabPageCtrl.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="UI\Constants.cs" />
|
<Compile Include="UI\Constants.cs" />
|
||||||
|
<Compile Include="UI\Item\EditDouble.cs" />
|
||||||
|
<Compile Include="UI\Item\EditEnum.cs" />
|
||||||
|
<Compile Include="UI\Item\EditFloat.cs" />
|
||||||
|
<Compile Include="UI\Item\EditInt.cs" />
|
||||||
|
<Compile Include="UI\Item\EditString.cs" />
|
||||||
|
<Compile Include="UI\Item\IEditItem.cs" />
|
||||||
<Compile Include="UI\Graphs\GraphsTabPageCtrl.cs">
|
<Compile Include="UI\Graphs\GraphsTabPageCtrl.cs">
|
||||||
<SubType>UserControl</SubType>
|
<SubType>UserControl</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace TBF.UI.Item
|
||||||
|
{
|
||||||
|
public class EditDouble : IEditItem
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
double variable;
|
||||||
|
double lowerLimit;
|
||||||
|
double upperLimit;
|
||||||
|
string format;
|
||||||
|
TextBox textBox;
|
||||||
|
|
||||||
|
public EditDouble(string name, ref double variable, double lowerLimit, double upperLimit)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.variable = variable;
|
||||||
|
this.lowerLimit = lowerLimit;
|
||||||
|
this.upperLimit = upperLimit;
|
||||||
|
this.format = null;
|
||||||
|
|
||||||
|
this.textBox = new TextBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditDouble(string name, ref double variable, double lowerLimit)
|
||||||
|
: this (name, ref variable, lowerLimit, Double.MaxValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditDouble(string name, ref double variable)
|
||||||
|
: this(name, ref variable, Double.MinValue, Double.MaxValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name() { return name; }
|
||||||
|
public Control EmbeddedControl() { return textBox; }
|
||||||
|
public string Print() { return string.IsNullOrEmpty(format) ? variable.ToString() : variable.ToString(format); }
|
||||||
|
public void Update(string strValue) { variable = Utils.ParseSDouble(strValue); }
|
||||||
|
|
||||||
|
public bool Validate(string strValue, out string message)
|
||||||
|
{
|
||||||
|
double dummy;
|
||||||
|
if (!Utils.TryParseSDouble(strValue, out dummy))
|
||||||
|
{
|
||||||
|
message = string.Format("{0} is invalid", name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (dummy < lowerLimit)
|
||||||
|
{
|
||||||
|
message = string.Format("{0} is smaller then {1}", name, lowerLimit);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (dummy > upperLimit)
|
||||||
|
{
|
||||||
|
message = string.Format("{0} is larger then {1}", name, upperLimit);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message = string.Empty;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace TBF.UI.Item
|
||||||
|
{
|
||||||
|
public class EditEnum<T> : IEditItem where T : IComparable
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
T variable;
|
||||||
|
IEnumerable<T> values;
|
||||||
|
string[] strValues;
|
||||||
|
ComboBox comboBox;
|
||||||
|
|
||||||
|
public EditEnum(string name, ref T variable, IList<T>values, string[] strValues)
|
||||||
|
{
|
||||||
|
if (values.Count != strValues.Length) throw new Exception("values and strValues lengths are different");
|
||||||
|
|
||||||
|
this.name = name;
|
||||||
|
this.variable = variable;
|
||||||
|
this.values = values;
|
||||||
|
this.strValues = strValues;
|
||||||
|
|
||||||
|
this.comboBox = new ComboBox();
|
||||||
|
foreach (var v in strValues) comboBox.Items.Add(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name() { return name; }
|
||||||
|
public Control EmbeddedControl() { return comboBox; }
|
||||||
|
|
||||||
|
public string Print()
|
||||||
|
{
|
||||||
|
int ix = 0;
|
||||||
|
foreach (var v in values)
|
||||||
|
{
|
||||||
|
if (v.CompareTo(variable) == 0) return strValues[ix];
|
||||||
|
ix++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(string strValue)
|
||||||
|
{
|
||||||
|
int ix = 0;
|
||||||
|
foreach (var v in values)
|
||||||
|
{
|
||||||
|
if (strValues[ix++].Equals(strValue))
|
||||||
|
{
|
||||||
|
variable = v;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Validate(string strValue, out string message)
|
||||||
|
{
|
||||||
|
foreach (var sv in strValues)
|
||||||
|
{
|
||||||
|
if (sv == strValue)
|
||||||
|
{
|
||||||
|
message = string.Empty;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message = string.Format("{0} is invalid", name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace TBF.UI.Item
|
||||||
|
{
|
||||||
|
public class EditFloat
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
float variable;
|
||||||
|
float lowerLimit;
|
||||||
|
float upperLimit;
|
||||||
|
string format;
|
||||||
|
TextBox textBox;
|
||||||
|
|
||||||
|
public EditFloat(string name, ref float variable, float lowerLimit, float upperLimit)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.variable = variable;
|
||||||
|
this.lowerLimit = lowerLimit;
|
||||||
|
this.upperLimit = upperLimit;
|
||||||
|
this.format = null;
|
||||||
|
|
||||||
|
this.textBox = new TextBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditFloat(string name, ref float variable, float lowerLimit)
|
||||||
|
: this(name, ref variable, lowerLimit, Single.MaxValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditFloat(string name, ref float variable)
|
||||||
|
: this(name, ref variable, Single.MinValue, Single.MaxValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name() { return name; }
|
||||||
|
public Control EmbeddedControl() { return textBox; }
|
||||||
|
public string Print() { return string.IsNullOrEmpty(format) ? variable.ToString() : variable.ToString(format); }
|
||||||
|
public void Update(string strValue) { variable = Utils.ParseSFloat(strValue); }
|
||||||
|
|
||||||
|
public bool Validate(string strValue, out string message)
|
||||||
|
{
|
||||||
|
float dummy;
|
||||||
|
if (!Utils.TryParseSFloat(strValue, out dummy))
|
||||||
|
{
|
||||||
|
message = string.Format("{0} is invalid", name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (dummy < lowerLimit)
|
||||||
|
{
|
||||||
|
message = string.Format("{0} is smaller then {1}", name, lowerLimit);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (dummy > upperLimit)
|
||||||
|
{
|
||||||
|
message = string.Format("{0} is larger then {1}", name, upperLimit);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message = string.Empty;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace TBF.UI.Item
|
||||||
|
{
|
||||||
|
public class EditInt : IEditItem
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
int variable;
|
||||||
|
int lowerLimit;
|
||||||
|
int upperLimit;
|
||||||
|
TextBox textBox;
|
||||||
|
|
||||||
|
public EditInt(string name, ref int variable, int lowerLimit, int upperLimit)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.variable = variable;
|
||||||
|
this.lowerLimit = lowerLimit;
|
||||||
|
this.upperLimit = upperLimit;
|
||||||
|
|
||||||
|
this.textBox = new TextBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditInt(string name, ref int variable, int lowerLimit)
|
||||||
|
: this (name, ref variable, lowerLimit, Int32.MaxValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditInt(string name, ref int variable)
|
||||||
|
: this(name, ref variable, Int32.MinValue, Int32.MaxValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name() { return name; }
|
||||||
|
public Control EmbeddedControl() { return textBox; }
|
||||||
|
public string Print() { return variable.ToString(); }
|
||||||
|
public void Update(string strValue) { variable = int.Parse(strValue); }
|
||||||
|
|
||||||
|
public bool Validate(string strValue, out string message)
|
||||||
|
{
|
||||||
|
int dummy;
|
||||||
|
if (!int.TryParse(strValue, out dummy))
|
||||||
|
{
|
||||||
|
message = string.Format("{0} is invalid", name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (dummy < lowerLimit)
|
||||||
|
{
|
||||||
|
message = string.Format("{0} is smaller then {1}", name, lowerLimit);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (dummy > upperLimit)
|
||||||
|
{
|
||||||
|
message = string.Format("{0} is larger then {1}", name, upperLimit);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message = string.Empty;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace TBF.UI.Item
|
||||||
|
{
|
||||||
|
public class EditString
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
string variable;
|
||||||
|
IList<string> alreadyUsed;
|
||||||
|
TextBox textBox;
|
||||||
|
|
||||||
|
public EditString(string name, ref string variable, IList<string> alreadyUsed)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.variable = variable;
|
||||||
|
this.alreadyUsed = alreadyUsed;
|
||||||
|
|
||||||
|
this.textBox = new TextBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditString(string name, ref string variable)
|
||||||
|
: this (name, ref variable, new List<string>())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name() { return name; }
|
||||||
|
public Control EmbeddedControl() { return textBox; }
|
||||||
|
public string Print() { return variable; }
|
||||||
|
public void Update(string strValue) { variable = strValue; }
|
||||||
|
|
||||||
|
public bool Validate(string strValue, out string message)
|
||||||
|
{
|
||||||
|
if (alreadyUsed.Contains(strValue))
|
||||||
|
{
|
||||||
|
message = string.Format("Value '{0}' was already used", strValue);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message = string.Empty;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace TBF.UI.Item
|
||||||
|
{
|
||||||
|
public interface IEditItem
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns name of the parameter to be displayed as a column header, etc.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Name of the parameter</returns>
|
||||||
|
string Name();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns embedded control (Textbox, ComboBox, etc.).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Embedded control</returns>
|
||||||
|
Control EmbeddedControl();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the embedded variable value to its string representation.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String representation of the embedded variable</returns>
|
||||||
|
string Print();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the associated embedded variable from the given string representation.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="strValue">String representation of the new value</param>
|
||||||
|
void Update(string strValue);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the edited value (string representation) is valid.
|
||||||
|
/// If Validate(..) returns true, then Update(..) has to correctly update the embedded variable.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="strValue">Edited value</param>
|
||||||
|
/// <param name="message">Explanation message in case Validate() returns false</param>
|
||||||
|
/// <returns>true = string is OK, false = string is wrong (see 'message')</returns>
|
||||||
|
bool Validate(string strValue, out string message);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user