Free cookie consent management tool by TermsFeed Policy Generator

source: branches/gteufl/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionView.cs @ 11614

Last change on this file since 11614 was 9821, checked in by gkronber, 11 years ago

#1270 made changes as suggested in the review comments

  • initially select default string formatter in the symbolic expression view
  • renamed smalltalk formatter and fixed the namespace
  • fixed namespace of GraphViz formatter
  • removed unused usings
File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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    private readonly List<ISymbolicExpressionTreeStringFormatter> treeFormattersList = new List<ISymbolicExpressionTreeStringFormatter>();
34
35    public new ISymbolicExpressionTree Content {
36      get { return (ISymbolicExpressionTree)base.Content; }
37      set { base.Content = value; }
38    }
39
40    public SymbolicExpressionView() {
41      InitializeComponent();
42      IEnumerable<ISymbolicExpressionTreeStringFormatter> formatters = ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeStringFormatter>();
43      treeFormattersList = new List<ISymbolicExpressionTreeStringFormatter>();
44      foreach (ISymbolicExpressionTreeStringFormatter formatter in formatters) {
45        treeFormattersList.Add(formatter);
46        formattersComboBox.Items.Add(formatter.Name);
47      }
48      if (formattersComboBox.Items.Count > 0)
49        formattersComboBox.SelectedIndex = treeFormattersList.FindIndex(0, treeFormattersList.Count, (f) => f.Name.Contains("Default"));
50      else
51        formattersComboBox.SelectedIndex = -1;
52    }
53
54    protected override void OnContentChanged() {
55      base.OnContentChanged();
56      UpdateTextbox();
57    }
58
59    private void UpdateTextbox() {
60      if (Content == null || formattersComboBox.SelectedIndex < 0)
61        textBox.Text = string.Empty;
62      else {
63        try {
64          textBox.Text = treeFormattersList[formattersComboBox.SelectedIndex].Format(Content);
65        }
66        catch (ArgumentException) { textBox.Text = "Cannot format the symbolic expression tree with the selected formatter."; }
67        catch (NotSupportedException) { textBox.Text = "Formatting of the symbolic expression tree is not supported by the selected formatter."; }
68      }
69    }
70
71    protected override void SetEnabledStateOfControls() {
72      base.SetEnabledStateOfControls();
73      textBox.Enabled = Content != null;
74      textBox.ReadOnly = ReadOnly;
75    }
76
77    private void formattersComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
78      UpdateTextbox();
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.