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