source: branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/Query/Views/OrdinalComparisonPercentFilterView.cs @ 7573

Last change on this file since 7573 was 7573, checked in by ascheibe, 8 years ago

#1174 added support for PercentValue

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Windows.Forms;
23using HeuristicLab.MainForm;
24using HeuristicLab.MainForm.WindowsForms;
25
26namespace HeuristicLab.Clients.OKB.Query {
27  [View("OrdinalComparisonPercentFilterView View")]
28  [Content(typeof(OrdinalComparisonPercentFilter), true)]
29  public partial class OrdinalComparisonPercentFilterView : OrdinalComparisonFilterView {
30    public new OrdinalComparisonPercentFilter Content {
31      get { return (OrdinalComparisonPercentFilter)base.Content; }
32      set { base.Content = value; }
33    }
34
35    public OrdinalComparisonPercentFilterView() {
36      InitializeComponent();
37      errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
38      errorProvider.SetIconPadding(valueTextBox, 2);
39    }
40
41    protected override void OnContentChanged() {
42      base.OnContentChanged();
43
44      if (Content == null) {
45        valueTextBox.Text = "%";
46      } else if (Content.Value == 0.0) {
47        valueTextBox.Text = "0 %";
48      } else {
49        valueTextBox.Text = Content.Value.ToString();
50      }
51    }
52
53    protected override void SetEnabledStateOfControls() {
54      base.SetEnabledStateOfControls();
55      valueTextBox.Enabled = Content != null;
56      valueTextBox.ReadOnly = ReadOnly;
57    }
58
59    private void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
60      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
61        label.Focus();  // set focus on label to validate data
62      if (e.KeyCode == Keys.Escape) {
63        valueTextBox.Text = Content.Value.ToString();
64        label.Focus();  // set focus on label to validate data
65      }
66    }
67    private void valueTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
68      HeuristicLab.Data.IStringConvertibleValue p = new HeuristicLab.Data.PercentValue();
69
70      string errorMessage;
71      if (!p.Validate(valueTextBox.Text, out errorMessage)) {
72        e.Cancel = true;
73        errorProvider.SetError(valueTextBox, "Invalid Percent Value");
74        valueTextBox.SelectAll();
75      }
76    }
77    private void valueTextBox_Validated(object sender, System.EventArgs e) {
78      if (Content != null) {
79        HeuristicLab.Data.IStringConvertibleValue p = new HeuristicLab.Data.PercentValue();
80
81        p.SetValue(valueTextBox.Text);
82        Content.Value = ((HeuristicLab.Data.PercentValue)p).Value;
83        errorProvider.SetError(valueTextBox, string.Empty);
84        valueTextBox.Text = p.GetValue();
85      }
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.