Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis.Extensions/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.3/SymbolicExpressionView.cs @ 4842

Last change on this file since 4842 was 4842, checked in by swinkler, 13 years ago

Improved management of formatters in view for display of symbolic expression trees as strings as discussed with mkommend. (#1270)

File size: 2.8 KB
Line 
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
22using System.Windows.Forms;
23using HeuristicLab.MainForm;
24using HeuristicLab.MainForm.WindowsForms;
25using HeuristicLab.PluginInfrastructure;
26using System.Collections.Generic;
27
28namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
29  [View("SymbolicExpression View")]
30  [Content(typeof(SymbolicExpressionTree), false)]
31  public partial class SymbolicExpressionView : AsynchronousContentView {
32
33    List<ISymbolicExpressionTreeStringFormatter> treeFormattersList = new List<ISymbolicExpressionTreeStringFormatter>();
34
35    public new SymbolicExpressionTree Content {
36      get { return (SymbolicExpressionTree)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      int selectedIndex = -1;
45      foreach (ISymbolicExpressionTreeStringFormatter formatter in formatters) {
46        if (formatter is SymbolicExpressionTreeStringFormatter)
47          selectedIndex = treeFormattersList.Count;
48        treeFormattersList.Add(formatter);
49        formattersComboBox.Items.Add(formatter.Name);
50      }
51      formattersComboBox.SelectedIndex = selectedIndex;
52    }
53
54    protected override void OnContentChanged() {
55      base.OnContentChanged();
56      UpdateTextbox();
57    }
58
59    private void UpdateTextbox() {
60      if (Content == null)
61        textBox.Text = string.Empty;
62      else
63        textBox.Text = treeFormattersList[formattersComboBox.SelectedIndex].Format(Content);
64    }
65
66    protected override void SetEnabledStateOfControls() {
67      base.SetEnabledStateOfControls();
68      textBox.Enabled = Content != null;
69      textBox.ReadOnly = ReadOnly;
70    }
71
72    private void formattersComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
73      UpdateTextbox();
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.