#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols; using HeuristicLab.Core.Views; namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views { [View("Symbol View")] [Content(typeof(Symbol), false)] public partial class SymbolView : NamedItemView { public new Symbol Content { get { return (Symbol)base.Content; } set { base.Content = value; } } public SymbolView() { InitializeComponent(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.Changed += new EventHandler(Content_Changed); } protected override void DeregisterContentEvents() { base.DeregisterContentEvents(); Content.Changed -= new EventHandler(Content_Changed); } protected override void OnContentChanged() { base.OnContentChanged(); UpdateControl(); } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); initialFrequencyTextBox.Enabled = Content != null; initialFrequencyTextBox.ReadOnly = ReadOnly; } #region content event handlers private void Content_Changed(object sender, EventArgs e) { UpdateControl(); } #endregion #region control event handlers private void initialFrequencyTextBox_TextChanged(object sender, EventArgs e) { double freq; if (double.TryParse(initialFrequencyTextBox.Text, out freq) && freq >= 0.0) { Content.InitialFrequency = freq; errorProvider.SetError(initialFrequencyTextBox, string.Empty); } else { errorProvider.SetError(initialFrequencyTextBox, "Invalid value"); } } #endregion #region helpers private void UpdateControl() { if (Content == null) { initialFrequencyTextBox.Text = string.Empty; } else { initialFrequencyTextBox.Text = Content.InitialFrequency.ToString(); } SetEnabledStateOfControls(); } #endregion } }