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
RevLine 
[2665]1#region License Information
2/* HeuristicLab
[15583]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2665]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;
[2713]26using HeuristicLab.MainForm.WindowsForms;
[16587]27using HeuristicLab.Problems.DataAnalysis;
[2665]28
29namespace HeuristicLab.Data.Views {
[16373]30  [View("TextValue View")]
31  [Content(typeof(ITextValue), true)]
32  public partial class TextValueView : AsynchronousContentView {
[3048]33    public new IStringConvertibleValue Content {
34      get { return (IStringConvertibleValue)base.Content; }
[2713]35      set { base.Content = value; }
[2665]36    }
37
[3430]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
[4485]46    public bool LabelVisible {
[5908]47      get { return !splitContainer.Panel1Collapsed; }
48      set { splitContainer.Panel1Collapsed = !value; }
[4485]49    }
50
[16373]51    public TextValueView() {
[2665]52      InitializeComponent();
[2676]53      errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
54      errorProvider.SetIconPadding(valueTextBox, 2);
[2665]55    }
56
[2713]57    protected override void DeregisterContentEvents() {
[2932]58      Content.ValueChanged -= new EventHandler(Content_ValueChanged);
[2713]59      base.DeregisterContentEvents();
[2665]60    }
61
[2713]62    protected override void RegisterContentEvents() {
63      base.RegisterContentEvents();
[2932]64      Content.ValueChanged += new EventHandler(Content_ValueChanged);
[2665]65    }
66
[2713]67    protected override void OnContentChanged() {
68      base.OnContentChanged();
69      if (Content == null) {
[2669]70        valueTextBox.Text = string.Empty;
[3764]71      } else
[2713]72        valueTextBox.Text = Content.GetValue();
[3904]73    }
[3764]74
[3904]75    protected override void SetEnabledStateOfControls() {
76      base.SetEnabledStateOfControls();
[3454]77      valueTextBox.Enabled = Content != null;
78      valueTextBox.ReadOnly = ReadOnly;
[2665]79    }
80
[9664]81    protected virtual void Content_ValueChanged(object sender, EventArgs e) {
[2665]82      if (InvokeRequired)
[2932]83        Invoke(new EventHandler(Content_ValueChanged), sender, e);
[2665]84      else
[2713]85        valueTextBox.Text = Content.GetValue();
[2665]86    }
87
[9664]88    protected virtual void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
[16373]89      if (e.Shift && (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return))
[5891]90        valueLabel.Select();  // select label to validate data
91
[2676]92      if (e.KeyCode == Keys.Escape) {
[2713]93        valueTextBox.Text = Content.GetValue();
[5998]94        valueLabel.Select();  // select label to validate data
[2676]95      }
96    }
[9664]97    protected virtual void valueTextBox_Validating(object sender, CancelEventArgs e) {
[8469]98      if (ReadOnly) return;
[2694]99      string errorMessage;
[2713]100      if (!Content.Validate(valueTextBox.Text, out errorMessage)) {
[2676]101        e.Cancel = true;
[2694]102        errorProvider.SetError(valueTextBox, errorMessage);
[2665]103        valueTextBox.SelectAll();
104      }
105    }
[9664]106    protected virtual void valueTextBox_Validated(object sender, EventArgs e) {
[8469]107      if (ReadOnly) return;
[3430]108      if (!Content.ReadOnly) Content.SetValue(valueTextBox.Text);
[2676]109      errorProvider.SetError(valueTextBox, string.Empty);
[3402]110      valueTextBox.Text = Content.GetValue();
[2665]111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.