[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.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Windows.Forms;
|
---|
[2669] | 29 | using HeuristicLab.Core;
|
---|
[2665] | 30 | using HeuristicLab.Core.Views;
|
---|
| 31 | using HeuristicLab.MainForm;
|
---|
[2713] | 32 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[2665] | 33 |
|
---|
| 34 | namespace HeuristicLab.Data.Views {
|
---|
[2917] | 35 | [View("StringConvertibleData View")]
|
---|
[2665] | 36 | [Content(typeof(IStringConvertibleData), true)]
|
---|
[2713] | 37 | public partial class StringConvertibleDataView : ContentView {
|
---|
| 38 | public new IStringConvertibleData Content {
|
---|
| 39 | get { return (IStringConvertibleData)base.Content; }
|
---|
| 40 | set { base.Content = value; }
|
---|
[2665] | 41 | }
|
---|
| 42 |
|
---|
| 43 | public StringConvertibleDataView() {
|
---|
| 44 | InitializeComponent();
|
---|
| 45 | Caption = "StringConvertibleData View";
|
---|
[2676] | 46 | errorProvider.SetIconAlignment(valueTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
| 47 | errorProvider.SetIconPadding(valueTextBox, 2);
|
---|
[2665] | 48 | }
|
---|
[2727] | 49 | public StringConvertibleDataView(IStringConvertibleData content)
|
---|
[2665] | 50 | : this() {
|
---|
[2727] | 51 | Content = content;
|
---|
[2665] | 52 | }
|
---|
| 53 |
|
---|
[2713] | 54 | protected override void DeregisterContentEvents() {
|
---|
[2932] | 55 | Content.ValueChanged -= new EventHandler(Content_ValueChanged);
|
---|
[2713] | 56 | base.DeregisterContentEvents();
|
---|
[2665] | 57 | }
|
---|
| 58 |
|
---|
[2713] | 59 | protected override void RegisterContentEvents() {
|
---|
| 60 | base.RegisterContentEvents();
|
---|
[2932] | 61 | Content.ValueChanged += new EventHandler(Content_ValueChanged);
|
---|
[2665] | 62 | }
|
---|
| 63 |
|
---|
[2713] | 64 | protected override void OnContentChanged() {
|
---|
| 65 | base.OnContentChanged();
|
---|
| 66 | if (Content == null) {
|
---|
[2665] | 67 | Caption = "StringConvertibleData View";
|
---|
[2669] | 68 | valueTextBox.Text = string.Empty;
|
---|
[2665] | 69 | valueTextBox.Enabled = false;
|
---|
| 70 | } else {
|
---|
[2713] | 71 | Caption = Content.GetValue() + " (" + Content.GetType().Name + ")";
|
---|
| 72 | valueTextBox.Text = Content.GetValue();
|
---|
[2665] | 73 | valueTextBox.Enabled = true;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[2932] | 77 | private void Content_ValueChanged(object sender, EventArgs e) {
|
---|
[2665] | 78 | if (InvokeRequired)
|
---|
[2932] | 79 | Invoke(new EventHandler(Content_ValueChanged), sender, e);
|
---|
[2665] | 80 | else
|
---|
[2713] | 81 | valueTextBox.Text = Content.GetValue();
|
---|
[2665] | 82 | }
|
---|
| 83 |
|
---|
[2676] | 84 | private void valueTextBox_KeyDown(object sender, KeyEventArgs e) {
|
---|
| 85 | if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
|
---|
| 86 | valueLabel.Focus(); // set focus on label to validate data
|
---|
| 87 | if (e.KeyCode == Keys.Escape) {
|
---|
[2713] | 88 | valueTextBox.Text = Content.GetValue();
|
---|
[2676] | 89 | valueLabel.Focus(); // set focus on label to validate data
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
[2665] | 92 | private void valueTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
[2694] | 93 | string errorMessage;
|
---|
[2713] | 94 | if (!Content.Validate(valueTextBox.Text, out errorMessage)) {
|
---|
[2676] | 95 | e.Cancel = true;
|
---|
[2694] | 96 | errorProvider.SetError(valueTextBox, errorMessage);
|
---|
[2665] | 97 | valueTextBox.SelectAll();
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | private void valueTextBox_Validated(object sender, EventArgs e) {
|
---|
[2713] | 101 | Content.SetValue(valueTextBox.Text);
|
---|
[2676] | 102 | errorProvider.SetError(valueTextBox, string.Empty);
|
---|
[2665] | 103 | }
|
---|
| 104 | }
|
---|
| 105 | }
|
---|