Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/TextValueView.cs @ 16587

Last change on this file since 16587 was 16587, checked in by chaider, 5 years ago

#2971

  • Added TextValueView
  • Added IntervalConstraint Parser

This two classes will be moved to another plugin

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.ComponentModel;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27using HeuristicLab.Problems.DataAnalysis;
28
29namespace HeuristicLab.Data.Views {
30  [View("TextValue View")]
31  [Content(typeof(ITextValue), true)]
32  public partial class TextValueView : AsynchronousContentView {
33    public new IStringConvertibleValue Content {
34      get { return (IStringConvertibleValue)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public override bool ReadOnly {
39      get {
40        if ((Content != null) && Content.ReadOnly) return true;
41        return base.ReadOnly;
42      }
43      set { base.ReadOnly = value; }
44    }
45
46    public bool LabelVisible {
47      get { return !splitContainer.Panel1Collapsed; }
48      set { splitContainer.Panel1Collapsed = !value; }
49    }
50
51    public TextValueView() {
52      InitializeComponent();
53      errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
54      errorProvider.SetIconPadding(valueTextBox, 2);
55    }
56
57    protected override void DeregisterContentEvents() {
58      Content.ValueChanged -= new EventHandler(Content_ValueChanged);
59      base.DeregisterContentEvents();
60    }
61
62    protected override void RegisterContentEvents() {
63      base.RegisterContentEvents();
64      Content.ValueChanged += new EventHandler(Content_ValueChanged);
65    }
66
67    protected override void OnContentChanged() {
68      base.OnContentChanged();
69      if (Content == null) {
70        valueTextBox.Text = string.Empty;
71      } else
72        valueTextBox.Text = Content.GetValue();
73    }
74
75    protected override void SetEnabledStateOfControls() {
76      base.SetEnabledStateOfControls();
77      valueTextBox.Enabled = Content != null;
78      valueTextBox.ReadOnly = ReadOnly;
79    }
80
81    protected virtual void Content_ValueChanged(object sender, EventArgs e) {
82      if (InvokeRequired)
83        Invoke(new EventHandler(Content_ValueChanged), sender, e);
84      else
85        valueTextBox.Text = Content.GetValue();
86    }
87
88    protected virtual void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
89      if (e.Shift && (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return))
90        valueLabel.Select();  // select label to validate data
91
92      if (e.KeyCode == Keys.Escape) {
93        valueTextBox.Text = Content.GetValue();
94        valueLabel.Select();  // select label to validate data
95      }
96    }
97    protected virtual void valueTextBox_Validating(object sender, CancelEventArgs e) {
98      if (ReadOnly) return;
99      string errorMessage;
100      if (!Content.Validate(valueTextBox.Text, out errorMessage)) {
101        e.Cancel = true;
102        errorProvider.SetError(valueTextBox, errorMessage);
103        valueTextBox.SelectAll();
104      }
105    }
106    protected virtual void valueTextBox_Validated(object sender, EventArgs e) {
107      if (ReadOnly) return;
108      if (!Content.ReadOnly) Content.SetValue(valueTextBox.Text);
109      errorProvider.SetError(valueTextBox, string.Empty);
110      valueTextBox.Text = Content.GetValue();
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.