[2665] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[2790] | 3 | * Copyright (C) 2002-2010 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.ComponentModel;
|
---|
| 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.MainForm;
|
---|
[2713] | 26 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[2665] | 27 |
|
---|
| 28 | namespace HeuristicLab.Data.Views {
|
---|
[3048] | 29 | [View("StringConvertibleValue View")]
|
---|
| 30 | [Content(typeof(IStringConvertibleValue), true)]
|
---|
[3228] | 31 | public partial class StringConvertibleValueView : AsynchronousContentView {
|
---|
[3048] | 32 | public new IStringConvertibleValue Content {
|
---|
| 33 | get { return (IStringConvertibleValue)base.Content; }
|
---|
[2713] | 34 | set { base.Content = value; }
|
---|
[2665] | 35 | }
|
---|
| 36 |
|
---|
[3430] | 37 | public override bool ReadOnly {
|
---|
| 38 | get {
|
---|
| 39 | if ((Content != null) && Content.ReadOnly) return true;
|
---|
| 40 | return base.ReadOnly;
|
---|
| 41 | }
|
---|
| 42 | set { base.ReadOnly = value; }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[4485] | 45 | public bool LabelVisible {
|
---|
| 46 | get { return valueLabel.Visible; }
|
---|
| 47 | set { valueLabel.Visible = value; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[3048] | 50 | public StringConvertibleValueView() {
|
---|
[2665] | 51 | InitializeComponent();
|
---|
[2676] | 52 | errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
| 53 | errorProvider.SetIconPadding(valueTextBox, 2);
|
---|
[2665] | 54 | }
|
---|
| 55 |
|
---|
[2713] | 56 | protected override void DeregisterContentEvents() {
|
---|
[2932] | 57 | Content.ValueChanged -= new EventHandler(Content_ValueChanged);
|
---|
[2713] | 58 | base.DeregisterContentEvents();
|
---|
[2665] | 59 | }
|
---|
| 60 |
|
---|
[2713] | 61 | protected override void RegisterContentEvents() {
|
---|
| 62 | base.RegisterContentEvents();
|
---|
[2932] | 63 | Content.ValueChanged += new EventHandler(Content_ValueChanged);
|
---|
[2665] | 64 | }
|
---|
| 65 |
|
---|
[2713] | 66 | protected override void OnContentChanged() {
|
---|
| 67 | base.OnContentChanged();
|
---|
| 68 | if (Content == null) {
|
---|
[2669] | 69 | valueTextBox.Text = string.Empty;
|
---|
[3764] | 70 | } else
|
---|
[2713] | 71 | valueTextBox.Text = Content.GetValue();
|
---|
[3904] | 72 | }
|
---|
[3764] | 73 |
|
---|
[3904] | 74 | protected override void SetEnabledStateOfControls() {
|
---|
| 75 | base.SetEnabledStateOfControls();
|
---|
[3454] | 76 | valueTextBox.Enabled = Content != null;
|
---|
| 77 | valueTextBox.ReadOnly = ReadOnly;
|
---|
[2665] | 78 | }
|
---|
| 79 |
|
---|
[2932] | 80 | private void Content_ValueChanged(object sender, EventArgs e) {
|
---|
[2665] | 81 | if (InvokeRequired)
|
---|
[2932] | 82 | Invoke(new EventHandler(Content_ValueChanged), sender, e);
|
---|
[2665] | 83 | else
|
---|
[2713] | 84 | valueTextBox.Text = Content.GetValue();
|
---|
[2665] | 85 | }
|
---|
| 86 |
|
---|
[2676] | 87 | private void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
|
---|
| 88 | if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
|
---|
| 89 | valueLabel.Focus(); // set focus on label to validate data
|
---|
| 90 | if (e.KeyCode == Keys.Escape) {
|
---|
[2713] | 91 | valueTextBox.Text = Content.GetValue();
|
---|
[2676] | 92 | valueLabel.Focus(); // set focus on label to validate data
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
[2665] | 95 | private void valueTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
[2694] | 96 | string errorMessage;
|
---|
[2713] | 97 | if (!Content.Validate(valueTextBox.Text, out errorMessage)) {
|
---|
[2676] | 98 | e.Cancel = true;
|
---|
[2694] | 99 | errorProvider.SetError(valueTextBox, errorMessage);
|
---|
[2665] | 100 | valueTextBox.SelectAll();
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | private void valueTextBox_Validated(object sender, EventArgs e) {
|
---|
[3430] | 104 | if (!Content.ReadOnly) Content.SetValue(valueTextBox.Text);
|
---|
[2676] | 105 | errorProvider.SetError(valueTextBox, string.Empty);
|
---|
[3402] | 106 | valueTextBox.Text = Content.GetValue();
|
---|
[2665] | 107 | }
|
---|
[4485] | 108 |
|
---|
| 109 | private void valueLabel_VisibleChanged(object sender, EventArgs e) {
|
---|
| 110 | if (valueLabel.Visible)
|
---|
| 111 | valueTextBox.Dock = DockStyle.None;
|
---|
| 112 | else
|
---|
| 113 | valueTextBox.Dock = DockStyle.Fill;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[2665] | 116 | }
|
---|
| 117 | }
|
---|