Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.3/SymbolicExpressionView.cs @ 6004

Last change on this file since 6004 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 3.0 KB
RevLine 
[3742]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3742]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
[3237]22using System.Windows.Forms;
23using HeuristicLab.MainForm;
24using HeuristicLab.MainForm.WindowsForms;
[5416]25using HeuristicLab.PluginInfrastructure;
26using System.Collections.Generic;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Formatters;
[3237]28
29namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
[3244]30  [View("SymbolicExpression View")]
31  [Content(typeof(SymbolicExpressionTree), false)]
32  public partial class SymbolicExpressionView : AsynchronousContentView {
[3929]33
[5416]34    List<ISymbolicExpressionTreeStringFormatter> treeFormattersList = new List<ISymbolicExpressionTreeStringFormatter>();
35
[3237]36    public new SymbolicExpressionTree Content {
37      get { return (SymbolicExpressionTree)base.Content; }
38      set { base.Content = value; }
39    }
40
[3244]41    public SymbolicExpressionView() {
[3237]42      InitializeComponent();
[5416]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;
[3237]53    }
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
[5416]57      UpdateTextbox();
58    }
59
60    private void UpdateTextbox() {
61      if (Content == null || formattersComboBox.SelectedIndex < 0)
[3237]62        textBox.Text = string.Empty;
[3764]63      else
[5416]64        textBox.Text = treeFormattersList[formattersComboBox.SelectedIndex].Format(Content);
[3237]65    }
66
[3904]67    protected override void SetEnabledStateOfControls() {
68      base.SetEnabledStateOfControls();
[3454]69      textBox.Enabled = Content != null;
70      textBox.ReadOnly = ReadOnly;
71    }
[5416]72
73    private void formattersComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
74      UpdateTextbox();
75    }
[3237]76  }
77}
Note: See TracBrowser for help on using the repository browser.