diff options
| author | Jacob Palecki <[email protected]> | 2020-08-12 19:22:21 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-08-12 19:22:21 -0700 |
| commit | cc531c79f2bd664551071ef315a54814bd9ab914 (patch) | |
| tree | e6d1db3477e8ba41299d1d92eac4748a648c960b /grapher/Field.cs | |
| parent | Add ability to have x\y graphs (diff) | |
| download | rawaccel-cc531c79f2bd664551071ef315a54814bd9ab914.tar.xz rawaccel-cc531c79f2bd664551071ef315a54814bd9ab914.zip | |
Reorganized solution into directories
Diffstat (limited to 'grapher/Field.cs')
| -rw-r--r-- | grapher/Field.cs | 226 |
1 files changed, 0 insertions, 226 deletions
diff --git a/grapher/Field.cs b/grapher/Field.cs deleted file mode 100644 index 8d75172..0000000 --- a/grapher/Field.cs +++ /dev/null @@ -1,226 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace grapher -{ - public class Field - { - #region Constants - - public const string DefaultFormatString = "0.#########"; - - #endregion Constants - - #region Enums - - public enum FieldState - { - Undefined, - Default, - Typing, - Entered, - Unavailable, - } - - #endregion Enums - - - #region Constructors - - public Field(TextBox box, Form containingForm, double defaultData) - { - DefaultText = DecimalString(defaultData); - Box = box; - Data = defaultData; - DefaultData = defaultData; - State = FieldState.Undefined; - ContainingForm = containingForm; - FormatString = DefaultFormatString; - box.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyDown); - box.Leave += new System.EventHandler(FocusLeave); - - SetToDefault(); - } - - #endregion Constructors - - #region Properties - - public TextBox Box { get; } - - private Form ContainingForm { get; } - - public double Data { get; private set; } - - public string FormatString { get; set; } - - public string DefaultText { get; } - - public FieldState State { get; private set; } - - public FieldState PreviousState { get; private set; } - - private double DefaultData { get; } - - #endregion Properties - - #region Methods - - public void SetToDefault() - { - if (State != FieldState.Default) - { - Box.BackColor = Color.White; - Box.ForeColor = Color.Gray; - State = FieldState.Default; - PreviousState = FieldState.Default; - } - - Data = DefaultData; - Box.Text = DefaultText; - ContainingForm.ActiveControl = null; - } - - public void SetToTyping() - { - if (State != FieldState.Typing) - { - Box.BackColor = Color.White; - Box.ForeColor = Color.Black; - - PreviousState = State; - State = FieldState.Typing; - } - - Box.Text = string.Empty; - } - - public void SetToEntered() - { - if (State != FieldState.Entered) - { - Box.BackColor = Color.AntiqueWhite; - Box.ForeColor = Color.DarkGray; - - PreviousState = State; - State = FieldState.Entered; - } - - ContainingForm.ActiveControl = null; - } - - public void SetToEntered(double value) - { - SetToEntered(); - - Data = value; - Box.Text = DecimalString(Data); - } - - public void SetToUnavailable() - { - if (State != FieldState.Unavailable) - { - Box.BackColor = Color.LightGray; - Box.ForeColor = Color.LightGray; - Box.Text = string.Empty; - - PreviousState = State; - State = FieldState.Unavailable; - } - } - - public void KeyDown(object sender, KeyEventArgs e) - { - switch(State) - { - case FieldState.Default: - if (e.KeyCode == Keys.Enter) - { - SetToDefault(); - } - else - { - SetToTyping(); - } - break; - - case FieldState.Entered: - if (e.KeyCode != Keys.Enter) - { - SetToTyping(); - } - break; - case FieldState.Typing: - HandleTyping(sender, e); - break; - case FieldState.Unavailable: - Box.Text = string.Empty; - ContainingForm.ActiveControl = null; - break; - default: - break; - } - } - - private void FocusLeave(object sender, EventArgs e) - { - if (State == FieldState.Typing) - { - TextToData(); - } - } - - private void HandleTyping(object sender, KeyEventArgs e) - { - if (e.KeyCode == Keys.Enter) - { - TextToData(); - - e.Handled = true; - e.SuppressKeyPress = true; - } - else if (e.KeyCode == Keys.Escape) - { - ContainingForm.ActiveControl = null; - e.Handled = true; - e.SuppressKeyPress = true; - } - } - - private void TextToData() - { - try - { - Data = Convert.ToDouble(Box.Text); - } - catch - { - } - - Box.Text = DecimalString(Data); - - if (string.Equals(Box.Text, DefaultText)) - { - SetToDefault(); - } - else - { - SetToEntered(); - } - } - - private string DecimalString(double value) - { - return value.ToString(FormatString); - } - - - #endregion Methods - } -} |