Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionView.cs @ 6619

Last change on this file since 6619 was 5835, checked in by mkommend, 14 years ago

#1418: Changed default formatter of SymbolicExpressionView and hid the maximization parameter for single objective symbolic data analysis problems.

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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
22using System;
23using System.Collections.Generic;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27using HeuristicLab.PluginInfrastructure;
28
29namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
30  [View("SymbolicExpression View")]
31  [Content(typeof(ISymbolicExpressionTree), false)]
32  public partial class SymbolicExpressionView : AsynchronousContentView {
33
34    List<ISymbolicExpressionTreeStringFormatter> treeFormattersList = new List<ISymbolicExpressionTreeStringFormatter>();
35
36    public new ISymbolicExpressionTree Content {
37      get { return (ISymbolicExpressionTree)base.Content; }
38      set { base.Content = value; }
39    }
40
41    public SymbolicExpressionView() {
42      InitializeComponent();
43      IEnumerable<ISymbolicExpressionTreeStringFormatter> formatters = ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeStringFormatter>();
44      treeFormattersList = new List<ISymbolicExpressionTreeStringFormatter>();
45      foreach (ISymbolicExpressionTreeStringFormatter formatter in formatters) {
46        treeFormattersList.Add(formatter);
47        formattersComboBox.Items.Add(formatter.Name);
48      }
49      if (formattersComboBox.Items.Count > 0)
50        formattersComboBox.SelectedIndex = 0;
51      else
52        formattersComboBox.SelectedIndex = -1;
53    }
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
57      UpdateTextbox();
58    }
59
60    private void UpdateTextbox() {
61      if (Content == null || formattersComboBox.SelectedIndex < 0)
62        textBox.Text = string.Empty;
63      else {
64        try {
65          textBox.Text = treeFormattersList[formattersComboBox.SelectedIndex].Format(Content);
66        }
67        catch (ArgumentException) { textBox.Text = "Cannot format the symbolic expression tree with the selected formatter."; }
68        catch (NotSupportedException) { textBox.Text = "Formatting of the symbolic expression tree is not supported by the selected formatter."; }
69      }
70    }
71
72    protected override void SetEnabledStateOfControls() {
73      base.SetEnabledStateOfControls();
74      textBox.Enabled = Content != null;
75      textBox.ReadOnly = ReadOnly;
76    }
77
78    private void formattersComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
79      UpdateTextbox();
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.