Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimizer/3.3/OptimizerMainForm.cs @ 4857

Last change on this file since 4857 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 6.8 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.ComponentModel;
24using System.IO;
25using System.Linq;
26using System.Reflection;
27using System.Windows.Forms;
28using HeuristicLab.Common;
29using HeuristicLab.Core;
30using HeuristicLab.Core.Views;
31using HeuristicLab.MainForm;
32using HeuristicLab.MainForm.WindowsForms;
33
34namespace HeuristicLab.Optimizer {
35  internal partial class OptimizerMainForm : DockingMainForm {
36    private string title;
37    private int appStartingCursors;
38    private int waitingCursors;
39
40    private Clipboard<IItem> clipboard;
41    public Clipboard<IItem> Clipboard {
42      get { return clipboard; }
43    }
44
45    public OptimizerMainForm()
46      : base() {
47      InitializeComponent();
48      appStartingCursors = 0;
49      waitingCursors = 0;
50    }
51    public OptimizerMainForm(Type userInterfaceItemType)
52      : base(userInterfaceItemType) {
53      InitializeComponent();
54      appStartingCursors = 0;
55      waitingCursors = 0;
56    }
57    public OptimizerMainForm(Type userInterfaceItemType, bool showContentInViewHost)
58      : this(userInterfaceItemType) {
59      this.ShowContentInViewHost = showContentInViewHost;
60    }
61
62    protected override void OnInitialized(EventArgs e) {
63      base.OnInitialized(e);
64      AssemblyFileVersionAttribute version = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).
65                                             Cast<AssemblyFileVersionAttribute>().FirstOrDefault();
66      title = "HeuristicLab Optimizer";
67      if (version != null) title += " " + version.Version;
68      Title = title;
69
70      ContentManager.Initialize(new PersistenceContentManager());
71
72      clipboard = new Clipboard<IItem>();
73      clipboard.Dock = DockStyle.Left;
74      clipboard.Collapsed = Properties.Settings.Default.CollapseClipboard;
75      if (Properties.Settings.Default.ShowClipboard) {
76        clipboard.Show();
77      }
78      if (Properties.Settings.Default.ShowOperatorsSidebar) {
79        OperatorsSidebar operatorsSidebar = new OperatorsSidebar();
80        operatorsSidebar.Dock = DockStyle.Left;
81        operatorsSidebar.Show();
82        operatorsSidebar.Collapsed = Properties.Settings.Default.CollapseOperatorsSidebar;
83      }
84      if (Properties.Settings.Default.ShowStartPage) {
85        StartPage startPage = new StartPage();
86        startPage.Show();
87      }
88
89      WindowState = Properties.Settings.Default.ShowMaximized ? FormWindowState.Maximized : FormWindowState.Normal;
90    }
91
92    private static string CHARTCONTROLASSEMBLY = "System.Windows.Forms.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
93    private bool CheckChartControls() {
94      try {
95        Assembly chartControlsAssembly = Assembly.Load(CHARTCONTROLASSEMBLY);
96        if (chartControlsAssembly != null)
97          return true;
98      }
99      catch (FileNotFoundException) {
100      }
101      catch (FileLoadException) {
102      }
103      catch (BadImageFormatException) {
104      }
105      return false;
106    }
107
108    protected override void OnShown(EventArgs e) {
109      base.OnShown(e);
110      if (!CheckChartControls()) {
111        ChartControlsWarning dlg = new ChartControlsWarning();
112        dlg.ShowDialog(this);
113      }
114    }
115
116    protected override void OnClosing(CancelEventArgs e) {
117      base.OnClosing(e);
118      if (MainFormManager.MainForm.Views.OfType<IContentView>().FirstOrDefault() != null) {
119        if (MessageBox.Show(this, "Some views are still opened. If their content has not been saved, it will be lost after closing. Do you really want to close HeuristicLab Optimizer?", "Close Optimizer", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No)
120          e.Cancel = true;
121      }
122    }
123    protected override void OnClosed(EventArgs e) {
124      base.OnClosed(e);
125      Properties.Settings.Default.ShowMaximized = WindowState == FormWindowState.Maximized;
126      Properties.Settings.Default.CollapseClipboard = clipboard.Collapsed;
127      OperatorsSidebar operatorsSidebar = MainFormManager.MainForm.Views.OfType<OperatorsSidebar>().FirstOrDefault();
128      if (operatorsSidebar != null) Properties.Settings.Default.CollapseOperatorsSidebar = operatorsSidebar.Collapsed;
129      Properties.Settings.Default.Save();
130    }
131
132    protected override void OnActiveViewChanged() {
133      base.OnActiveViewChanged();
134      UpdateTitle();
135    }
136
137    public void UpdateTitle() {
138      if (InvokeRequired)
139        Invoke(new Action(UpdateTitle));
140      else {
141        IContentView activeView = ActiveView as IContentView;
142        if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IStorableContent)) {
143          IStorableContent content = (IStorableContent)activeView.Content;
144          Title = title + " [" + (string.IsNullOrEmpty(content.Filename) ? "Unsaved" : content.Filename) + "]";
145        } else {
146          Title = title;
147        }
148      }
149    }
150
151    #region Cursor Handling
152    public void SetAppStartingCursor() {
153      if (InvokeRequired)
154        Invoke(new Action(SetAppStartingCursor));
155      else {
156        appStartingCursors++;
157        SetCursor();
158      }
159    }
160    public void ResetAppStartingCursor() {
161      if (InvokeRequired)
162        Invoke(new Action(ResetAppStartingCursor));
163      else {
164        appStartingCursors--;
165        SetCursor();
166      }
167    }
168    public void SetWaitCursor() {
169      if (InvokeRequired)
170        Invoke(new Action(SetWaitCursor));
171      else {
172        waitingCursors++;
173        SetCursor();
174      }
175    }
176    public void ResetWaitCursor() {
177      if (InvokeRequired)
178        Invoke(new Action(ResetWaitCursor));
179      else {
180        waitingCursors--;
181        SetCursor();
182      }
183    }
184    private void SetCursor() {
185      if (waitingCursors > 0) Cursor = Cursors.WaitCursor;
186      else if (appStartingCursors > 0) Cursor = Cursors.AppStarting;
187      else Cursor = Cursors.Default;
188    }
189    #endregion
190  }
191}
Note: See TracBrowser for help on using the repository browser.