[3824] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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.Linq;
|
---|
| 28 | using System.Text;
|
---|
| 29 | using System.Windows.Forms;
|
---|
| 30 | using HeuristicLab.MainForm;
|
---|
| 31 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 32 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
|
---|
| 33 | using HeuristicLab.Core.Views;
|
---|
| 34 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
|
---|
| 35 |
|
---|
| 36 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
|
---|
| 37 | [View("Constant View")]
|
---|
| 38 | [Content(typeof(Constant), true)]
|
---|
| 39 | public partial class ConstantView : SymbolView {
|
---|
| 40 | public new Constant Content {
|
---|
| 41 | get { return (Constant)base.Content; }
|
---|
| 42 | set { base.Content = value; }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public ConstantView() {
|
---|
| 46 | InitializeComponent();
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | protected override void RegisterContentEvents() {
|
---|
| 50 | base.RegisterContentEvents();
|
---|
| 51 | Content.Changed += new EventHandler(Content_Changed);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | protected override void DeregisterContentEvents() {
|
---|
| 55 | base.DeregisterContentEvents();
|
---|
| 56 | Content.Changed -= new EventHandler(Content_Changed);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | protected override void OnContentChanged() {
|
---|
| 60 | base.OnContentChanged();
|
---|
| 61 | UpdateControl();
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | protected override void OnReadOnlyChanged() {
|
---|
| 65 | base.OnReadOnlyChanged();
|
---|
| 66 | SetEnabledStateOfControls();
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | private void SetEnabledStateOfControls() {
|
---|
| 70 | minValueTextBox.Enabled = Content != null;
|
---|
| 71 | maxValueTextBox.Enabled = Content != null;
|
---|
| 72 | valueChangeNuTextBox.Enabled = Content != null;
|
---|
| 73 | valueChangeSigmaTextBox.Enabled = Content != null;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | #region content event handlers
|
---|
| 77 | private void Content_Changed(object sender, EventArgs e) {
|
---|
| 78 | UpdateControl();
|
---|
| 79 | }
|
---|
| 80 | #endregion
|
---|
| 81 |
|
---|
| 82 | #region control event handlers
|
---|
| 83 | private void minValueTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 84 | double min;
|
---|
| 85 | if (double.TryParse(minValueTextBox.Text, out min)) {
|
---|
| 86 | Content.MinValue = min;
|
---|
| 87 | errorProvider.SetError(minValueTextBox, string.Empty);
|
---|
| 88 | } else {
|
---|
| 89 | errorProvider.SetError(minValueTextBox, "Invalid value");
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | private void maxValueTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 93 | double max;
|
---|
| 94 | if (double.TryParse(maxValueTextBox.Text, out max)) {
|
---|
| 95 | Content.MaxValue = max;
|
---|
| 96 | errorProvider.SetError(maxValueTextBox, string.Empty);
|
---|
| 97 | } else {
|
---|
| 98 | errorProvider.SetError(maxValueTextBox, "Invalid value");
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | private void valueChangeNuTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 103 | double nu;
|
---|
| 104 | if (double.TryParse(valueChangeNuTextBox.Text, out nu)) {
|
---|
| 105 | Content.ManipulatorNu = nu;
|
---|
| 106 | errorProvider.SetError(valueChangeNuTextBox, string.Empty);
|
---|
| 107 | } else {
|
---|
| 108 | errorProvider.SetError(valueChangeNuTextBox, "Invalid value");
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | private void valueChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 113 | double sigma;
|
---|
| 114 | if (double.TryParse(valueChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
|
---|
| 115 | Content.ManipulatorSigma = sigma;
|
---|
| 116 | errorProvider.SetError(valueChangeSigmaTextBox, string.Empty);
|
---|
| 117 | } else {
|
---|
| 118 | errorProvider.SetError(valueChangeSigmaTextBox, "Invalid value");
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | #endregion
|
---|
| 122 |
|
---|
| 123 | #region helpers
|
---|
| 124 | private void UpdateControl() {
|
---|
| 125 | if (Content == null) {
|
---|
| 126 | minValueTextBox.Text = string.Empty;
|
---|
| 127 | maxValueTextBox.Text = string.Empty;
|
---|
| 128 | minValueTextBox.Text = string.Empty;
|
---|
| 129 | valueChangeSigmaTextBox.Text = string.Empty;
|
---|
| 130 | } else {
|
---|
| 131 | minValueTextBox.Text = Content.MinValue.ToString();
|
---|
| 132 | maxValueTextBox.Text = Content.MaxValue.ToString();
|
---|
| 133 | valueChangeNuTextBox.Text = Content.ManipulatorNu.ToString();
|
---|
| 134 | valueChangeSigmaTextBox.Text = Content.ManipulatorSigma.ToString();
|
---|
| 135 | }
|
---|
| 136 | SetEnabledStateOfControls();
|
---|
| 137 | }
|
---|
| 138 | #endregion
|
---|
| 139 | }
|
---|
| 140 | }
|
---|