Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 9013 was 4968, checked in by gkronber, 14 years ago

Moved graphviz formatter into symbolic expression tree encoding plugin. #1270

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