Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/UserDefinedAlgorithmView.cs @ 2900

Last change on this file since 2900 was 2852, checked in by swagner, 14 years ago

Operator architecture refactoring (#95)

  • worked on algorithms
File size: 4.3 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;
23using System.Windows.Forms;
24using HeuristicLab.Core;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27using HeuristicLab.Persistence.Default.Xml;
28
29namespace HeuristicLab.Optimization.Views {
30  /// <summary>
31  /// The base class for visual representations of items.
32  /// </summary>
33  [Content(typeof(UserDefinedAlgorithm), true)]
34  public sealed partial class UserDefinedAlgorithmView : EngineAlgorithmView {
35    public new UserDefinedAlgorithm Content {
36      get { return (UserDefinedAlgorithm)base.Content; }
37      set { base.Content = value; }
38    }
39
40    /// <summary>
41    /// Initializes a new instance of <see cref="ItemBaseView"/>.
42    /// </summary>
43    public UserDefinedAlgorithmView() {
44      InitializeComponent();
45    }
46    /// <summary>
47    /// Intializes a new instance of <see cref="ItemBaseView"/> with the given <paramref name="item"/>.
48    /// </summary>
49    /// <param name="item">The item that should be displayed.</param>
50    public UserDefinedAlgorithmView(UserDefinedAlgorithm content)
51      : this() {
52      Content = content;
53    }
54
55    protected override void DeregisterContentEvents() {
56      Content.OperatorGraphChanged -= new EventHandler(Content_OperatorGraphChanged);
57      base.DeregisterContentEvents();
58    }
59    protected override void RegisterContentEvents() {
60      base.RegisterContentEvents();
61      Content.OperatorGraphChanged += new EventHandler(Content_OperatorGraphChanged);
62    }
63
64    protected override void OnContentChanged() {
65      base.OnContentChanged();
66      if (Content == null) {
67        operatorGraphViewHost.Content = null;
68        globalScopeView.Content = null;
69      } else {
70        operatorGraphViewHost.Content = Content.OperatorGraph;
71        globalScopeView.Content = Content.GlobalScope;
72      }
73    }
74
75    private void Content_OperatorGraphChanged(object sender, EventArgs e) {
76      if (InvokeRequired)
77        Invoke(new EventHandler(Content_OperatorGraphChanged), sender, e);
78      else
79        operatorGraphViewHost.Content = Content.OperatorGraph;
80    }
81
82    private void newOperatorGraphButton_Click(object sender, EventArgs e) {
83      Content.OperatorGraph = new OperatorGraph();
84    }
85    private void openOperatorGraphButton_Click(object sender, EventArgs e) {
86      openFileDialog.Title = "Open Operator Graph";
87      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
88        OperatorGraph operatorGraph = null;
89        try {
90          operatorGraph = XmlParser.Deserialize(openFileDialog.FileName) as OperatorGraph;
91        }
92        catch (Exception ex) {
93          Auxiliary.ShowErrorMessageBox(ex);
94        }
95        if (operatorGraph == null)
96          MessageBox.Show(this, "The selected file does not contain an operator graph.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
97        else
98          Content.OperatorGraph = operatorGraph;
99      }
100    }
101    private void saveOperatorGraphButton_Click(object sender, EventArgs e) {
102      saveFileDialog.Title = "Save Operator Graph";
103      if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
104        try {
105          if (saveFileDialog.FilterIndex == 1)
106            XmlGenerator.Serialize(Content.OperatorGraph, saveFileDialog.FileName, 0);
107          else
108            XmlGenerator.Serialize(Content.OperatorGraph, saveFileDialog.FileName, 9);
109        }
110        catch (Exception ex) {
111          Auxiliary.ShowErrorMessageBox(ex);
112        }
113      }
114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.