[3742] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9456] | 3 | * Copyright (C) 2002-2013 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 |
|
---|
[5829] | 22 | using System;
|
---|
[5513] | 23 | using System.Collections.Generic;
|
---|
[3237] | 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.MainForm;
|
---|
| 26 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[5416] | 27 | using HeuristicLab.PluginInfrastructure;
|
---|
[3237] | 28 |
|
---|
| 29 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
|
---|
[3244] | 30 | [View("SymbolicExpression View")]
|
---|
[5513] | 31 | [Content(typeof(ISymbolicExpressionTree), false)]
|
---|
[3244] | 32 | public partial class SymbolicExpressionView : AsynchronousContentView {
|
---|
[9862] | 33 | private readonly List<ISymbolicExpressionTreeStringFormatter> treeFormattersList = new List<ISymbolicExpressionTreeStringFormatter>();
|
---|
[3929] | 34 |
|
---|
[5829] | 35 | public new ISymbolicExpressionTree Content {
|
---|
| 36 | get { return (ISymbolicExpressionTree)base.Content; }
|
---|
[3237] | 37 | set { base.Content = value; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[3244] | 40 | public SymbolicExpressionView() {
|
---|
[3237] | 41 | InitializeComponent();
|
---|
[5416] | 42 | IEnumerable<ISymbolicExpressionTreeStringFormatter> formatters = ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeStringFormatter>();
|
---|
| 43 | treeFormattersList = new List<ISymbolicExpressionTreeStringFormatter>();
|
---|
| 44 | foreach (ISymbolicExpressionTreeStringFormatter formatter in formatters) {
|
---|
| 45 | treeFormattersList.Add(formatter);
|
---|
| 46 | formattersComboBox.Items.Add(formatter.Name);
|
---|
| 47 | }
|
---|
[5835] | 48 | if (formattersComboBox.Items.Count > 0)
|
---|
[9862] | 49 | formattersComboBox.SelectedIndex = treeFormattersList.FindIndex(0, treeFormattersList.Count, (f) => f.Name.Contains("Default"));
|
---|
[5835] | 50 | else
|
---|
| 51 | formattersComboBox.SelectedIndex = -1;
|
---|
[3237] | 52 | }
|
---|
| 53 |
|
---|
| 54 | protected override void OnContentChanged() {
|
---|
| 55 | base.OnContentChanged();
|
---|
[5416] | 56 | UpdateTextbox();
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | private void UpdateTextbox() {
|
---|
| 60 | if (Content == null || formattersComboBox.SelectedIndex < 0)
|
---|
[3237] | 61 | textBox.Text = string.Empty;
|
---|
[5750] | 62 | else {
|
---|
| 63 | try {
|
---|
| 64 | textBox.Text = treeFormattersList[formattersComboBox.SelectedIndex].Format(Content);
|
---|
| 65 | }
|
---|
| 66 | catch (ArgumentException) { textBox.Text = "Cannot format the symbolic expression tree with the selected formatter."; }
|
---|
| 67 | catch (NotSupportedException) { textBox.Text = "Formatting of the symbolic expression tree is not supported by the selected formatter."; }
|
---|
| 68 | }
|
---|
[3237] | 69 | }
|
---|
| 70 |
|
---|
[3904] | 71 | protected override void SetEnabledStateOfControls() {
|
---|
| 72 | base.SetEnabledStateOfControls();
|
---|
[3454] | 73 | textBox.Enabled = Content != null;
|
---|
| 74 | textBox.ReadOnly = ReadOnly;
|
---|
| 75 | }
|
---|
[5416] | 76 |
|
---|
| 77 | private void formattersComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
| 78 | UpdateTextbox();
|
---|
| 79 | }
|
---|
[3237] | 80 | }
|
---|
| 81 | }
|
---|