Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6486 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
RevLine 
[3742]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3742]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
[5829]22using System;
[5513]23using System.Collections.Generic;
[3237]24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
[5416]27using HeuristicLab.PluginInfrastructure;
[3237]28
29namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
[3244]30  [View("SymbolicExpression View")]
[5513]31  [Content(typeof(ISymbolicExpressionTree), false)]
[3244]32  public partial class SymbolicExpressionView : AsynchronousContentView {
[3929]33
[5416]34    List<ISymbolicExpressionTreeStringFormatter> treeFormattersList = new List<ISymbolicExpressionTreeStringFormatter>();
35
[5829]36    public new ISymbolicExpressionTree Content {
37      get { return (ISymbolicExpressionTree)base.Content; }
[3237]38      set { base.Content = value; }
39    }
40
[3244]41    public SymbolicExpressionView() {
[3237]42      InitializeComponent();
[5416]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      }
[5835]49      if (formattersComboBox.Items.Count > 0)
50        formattersComboBox.SelectedIndex = 0;
51      else
52        formattersComboBox.SelectedIndex = -1;
[3237]53    }
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
[5416]57      UpdateTextbox();
58    }
59
60    private void UpdateTextbox() {
61      if (Content == null || formattersComboBox.SelectedIndex < 0)
[3237]62        textBox.Text = string.Empty;
[5750]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      }
[3237]70    }
71
[3904]72    protected override void SetEnabledStateOfControls() {
73      base.SetEnabledStateOfControls();
[3454]74      textBox.Enabled = Content != null;
75      textBox.ReadOnly = ReadOnly;
76    }
[5416]77
78    private void formattersComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
79      UpdateTextbox();
80    }
[3237]81  }
82}
Note: See TracBrowser for help on using the repository browser.