Free cookie consent management tool by TermsFeed Policy Generator

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

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

Renamed solution in formatters branch; implemented view for display of symbolic expression trees as strings depending on the chosen formatter. (#1270)

File size: 3.1 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    private ISymbolicExpressionTreeStringFormatter treeFormatter;
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      IEnumerator<ISymbolicExpressionTreeStringFormatter> formatters = ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeStringFormatter>().GetEnumerator();
43      treeFormattersList = new List<ISymbolicExpressionTreeStringFormatter>();
44      formatters.MoveNext();
45      int selectedIndex = -1;
46      while (formatters.Current != null) {
47        if (formatters.Current is SymbolicExpressionTreeStringFormatter)
48          selectedIndex = treeFormattersList.Count;
49        treeFormattersList.Add(formatters.Current.Clone() as ISymbolicExpressionTreeStringFormatter);
50        formattersComboBox.Items.Add(treeFormattersList[treeFormattersList.Count - 1].Name);
51        formatters.MoveNext();
52      }
53      formattersComboBox.SelectedIndex = selectedIndex;
54      //treeFormatter = new SymbolicExpressionTreeStringFormatter();
55    }
56
57    protected override void OnContentChanged() {
58      base.OnContentChanged();
59      if (Content == null)
60        textBox.Text = string.Empty;
61      else
62        textBox.Text = treeFormatter.Format(Content);
63    }
64
65    protected override void SetEnabledStateOfControls() {
66      base.SetEnabledStateOfControls();
67      textBox.Enabled = Content != null;
68      textBox.ReadOnly = ReadOnly;
69    }
70
71    private void formattersComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
72      treeFormatter = treeFormattersList[formattersComboBox.SelectedIndex];
73      OnContentChanged();
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.