1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 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;
|
---|
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;
|
---|
29 | using HeuristicLab.Common;
|
---|
30 | using HeuristicLab.Core;
|
---|
31 | using HeuristicLab.Core.Views;
|
---|
32 | using HeuristicLab.MainForm;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Data.Views {
|
---|
35 | [Content(typeof(IStringConvertibleArrayData), true)]
|
---|
36 | public partial class StringConvertibleArrayDataView : ObjectView {
|
---|
37 | public IStringConvertibleArrayData StringConvertibleArrayData {
|
---|
38 | get { return (IStringConvertibleArrayData)Object; }
|
---|
39 | set { base.Object = value; }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public StringConvertibleArrayDataView() {
|
---|
43 | InitializeComponent();
|
---|
44 | Caption = "StringConvertibleArrayDataView View";
|
---|
45 | }
|
---|
46 | public StringConvertibleArrayDataView(IStringConvertibleArrayData stringConvertibleArrayData)
|
---|
47 | : this() {
|
---|
48 | StringConvertibleArrayData = stringConvertibleArrayData;
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected override void DeregisterObjectEvents() {
|
---|
52 | StringConvertibleArrayData.ItemChanged -= new EventHandler<EventArgs<int>>(StringConvertibleArrayData_ItemChanged);
|
---|
53 | StringConvertibleArrayData.Changed -= new ChangedEventHandler(StringConvertibleArrayData_Changed);
|
---|
54 | base.DeregisterObjectEvents();
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | protected override void RegisterObjectEvents() {
|
---|
59 | base.RegisterObjectEvents();
|
---|
60 | StringConvertibleArrayData.ItemChanged += new EventHandler<EventArgs<int>>(StringConvertibleArrayData_ItemChanged);
|
---|
61 | StringConvertibleArrayData.Changed += new ChangedEventHandler(StringConvertibleArrayData_Changed);
|
---|
62 | }
|
---|
63 |
|
---|
64 | protected override void OnObjectChanged() {
|
---|
65 | base.OnObjectChanged();
|
---|
66 | if (StringConvertibleArrayData == null) {
|
---|
67 | Caption = "StringConvertibleData View";
|
---|
68 | sizeTextBox.Text = "";
|
---|
69 | sizeTextBox.Enabled = false;
|
---|
70 | dataGridView.Rows.Clear();
|
---|
71 | dataGridView.Enabled = false;
|
---|
72 | } else {
|
---|
73 | Caption = "StringConvertibleArrayData (" + StringConvertibleArrayData.GetType().Name + ")";
|
---|
74 | UpdateContent();
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | private void UpdateContent() {
|
---|
79 | sizeTextBox.Text = StringConvertibleArrayData.Length.ToString();
|
---|
80 | sizeTextBox.Enabled = true;
|
---|
81 | dataGridView.Rows.Clear();
|
---|
82 | if (StringConvertibleArrayData.Length > 0) {
|
---|
83 | dataGridView.ColumnCount = 1;
|
---|
84 | dataGridView.Rows.Add(StringConvertibleArrayData.Length);
|
---|
85 | }
|
---|
86 | for (int i = 0; i < StringConvertibleArrayData.Length; i++)
|
---|
87 | dataGridView.Rows[i].Cells[0].Value = StringConvertibleArrayData.GetValue(i);
|
---|
88 | dataGridView.Enabled = true;
|
---|
89 | }
|
---|
90 |
|
---|
91 | private void StringConvertibleArrayData_ItemChanged(object sender, EventArgs<int> e) {
|
---|
92 | if (InvokeRequired)
|
---|
93 | Invoke(new EventHandler<EventArgs<int>>(StringConvertibleArrayData_ItemChanged), sender, e);
|
---|
94 | else
|
---|
95 | dataGridView.Rows[e.Value].Cells[0].Value = StringConvertibleArrayData.GetValue(e.Value);
|
---|
96 | }
|
---|
97 | private void StringConvertibleArrayData_Changed(object sender, ChangedEventArgs e) {
|
---|
98 | if (InvokeRequired)
|
---|
99 | Invoke(new ChangedEventHandler(StringConvertibleArrayData_Changed), sender, e);
|
---|
100 | else
|
---|
101 | UpdateContent();
|
---|
102 | }
|
---|
103 |
|
---|
104 | private void sizeTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
105 | int i = 0;
|
---|
106 | e.Cancel = e.Cancel || !int.TryParse(sizeTextBox.Text, out i);
|
---|
107 | e.Cancel = e.Cancel || (i < 0);
|
---|
108 | if (e.Cancel) {
|
---|
109 | MessageBox.Show(this, "\"" + sizeTextBox.Text + "\" is not a valid array length.", "Invalid Array Length", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
110 | sizeTextBox.SelectAll();
|
---|
111 | sizeTextBox.Focus();
|
---|
112 | }
|
---|
113 | }
|
---|
114 | private void sizeTextBox_Validated(object sender, EventArgs e) {
|
---|
115 | StringConvertibleArrayData.Length = int.Parse(sizeTextBox.Text);
|
---|
116 | }
|
---|
117 | private void sizeTextBox_KeyDown(object sender, KeyEventArgs e) {
|
---|
118 | if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
|
---|
119 | sizeLabel.Focus();
|
---|
120 | }
|
---|
121 | private void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
|
---|
122 | e.Cancel = e.Cancel || !StringConvertibleArrayData.SetValue(e.FormattedValue.ToString(), e.RowIndex);
|
---|
123 | if (e.Cancel)
|
---|
124 | MessageBox.Show(this, "\"" + e.FormattedValue.ToString() + "\" is not a valid value.", "Invalid Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
125 | }
|
---|
126 | private void dataGridView_CellValidated(object sender, DataGridViewCellEventArgs e) {
|
---|
127 | dataGridView.Rows[e.RowIndex].Cells[0].Value = StringConvertibleArrayData.GetValue(e.RowIndex);
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|