1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 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 |
|
---|
22 | using System.Windows.Forms;
|
---|
23 | using HeuristicLab.MainForm;
|
---|
24 | using HeuristicLab.MainForm.WindowsForms;
|
---|
25 |
|
---|
26 | namespace 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 | e.SuppressKeyPress = true;
|
---|
63 | } else if (e.KeyCode == Keys.Escape) {
|
---|
64 | valueTextBox.Text = Content.Value.ToString();
|
---|
65 | label.Focus(); // set focus on label to validate data
|
---|
66 | e.SuppressKeyPress = true;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | private void valueTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
70 | HeuristicLab.Data.IStringConvertibleValue p = new HeuristicLab.Data.PercentValue();
|
---|
71 |
|
---|
72 | string errorMessage;
|
---|
73 | if (!p.Validate(valueTextBox.Text, out errorMessage)) {
|
---|
74 | e.Cancel = true;
|
---|
75 | errorProvider.SetError(valueTextBox, "Invalid Percent Value");
|
---|
76 | valueTextBox.SelectAll();
|
---|
77 | }
|
---|
78 | }
|
---|
79 | private void valueTextBox_Validated(object sender, System.EventArgs e) {
|
---|
80 | if (Content != null) {
|
---|
81 | HeuristicLab.Data.IStringConvertibleValue p = new HeuristicLab.Data.PercentValue();
|
---|
82 |
|
---|
83 | p.SetValue(valueTextBox.Text);
|
---|
84 | Content.Value = ((HeuristicLab.Data.PercentValue)p).Value;
|
---|
85 | errorProvider.SetError(valueTextBox, string.Empty);
|
---|
86 | valueTextBox.Text = p.GetValue();
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|