Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionView.cs @ 5513

Last change on this file since 5513 was 5513, checked in by mkommend, 13 years ago

#1418: Adapted views to new symbolic expression tree encoding.

File size: 2.9 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.Collections.Generic;
23using System.Windows.Forms;
24using HeuristicLab.MainForm;
25using HeuristicLab.MainForm.WindowsForms;
26using HeuristicLab.PluginInfrastructure;
27
28namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
29  [View("SymbolicExpression View")]
30  [Content(typeof(ISymbolicExpressionTree), 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 ISymbolicExpressionTreeStringFormatter)
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 || formattersComboBox.SelectedIndex < 0)
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.