Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SimulationCore/HeuristicLab.Optimizer/3.3/OptimizerMainForm.cs @ 6818

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

Updated year of copyrights (#1406)

File size: 6.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Linq;
25using System.Reflection;
26using System.Windows.Forms;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Core.Views;
30using HeuristicLab.MainForm;
31using HeuristicLab.MainForm.WindowsForms;
32
33namespace HeuristicLab.Optimizer {
34  internal partial class OptimizerMainForm : DockingMainForm {
35    private string title;
36    private int appStartingCursors;
37    private int waitingCursors;
38
39    private Clipboard<IItem> clipboard;
40    public Clipboard<IItem> Clipboard {
41      get { return clipboard; }
42    }
43
44    public OptimizerMainForm()
45      : base() {
46      InitializeComponent();
47      appStartingCursors = 0;
48      waitingCursors = 0;
49    }
50    public OptimizerMainForm(Type userInterfaceItemType)
51      : base(userInterfaceItemType) {
52      InitializeComponent();
53      appStartingCursors = 0;
54      waitingCursors = 0;
55    }
56    public OptimizerMainForm(Type userInterfaceItemType, bool showContentInViewHost)
57      : this(userInterfaceItemType) {
58      this.ShowContentInViewHost = showContentInViewHost;
59    }
60
61    protected override void OnInitialized(EventArgs e) {
62      base.OnInitialized(e);
63      AssemblyFileVersionAttribute version = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).
64                                             Cast<AssemblyFileVersionAttribute>().FirstOrDefault();
65      title = "HeuristicLab Optimizer";
66      if (version != null) title += " " + version.Version;
67      Title = title;
68
69      ContentManager.Initialize(new PersistenceContentManager());
70
71      clipboard = new Clipboard<IItem>();
72      clipboard.Dock = DockStyle.Left;
73      clipboard.Collapsed = Properties.Settings.Default.CollapseClipboard;
74      if (Properties.Settings.Default.ShowClipboard) {
75        clipboard.Show();
76      }
77      if (Properties.Settings.Default.ShowOperatorsSidebar) {
78        OperatorsSidebar operatorsSidebar = new OperatorsSidebar();
79        operatorsSidebar.Dock = DockStyle.Left;
80        operatorsSidebar.Show();
81        operatorsSidebar.Collapsed = Properties.Settings.Default.CollapseOperatorsSidebar;
82      }
83      if (Properties.Settings.Default.ShowStartPage) {
84        StartPage startPage = new StartPage();
85        startPage.Show();
86      }
87
88      WindowState = Properties.Settings.Default.ShowMaximized ? FormWindowState.Maximized : FormWindowState.Normal;
89    }
90
91    protected override void OnClosing(CancelEventArgs e) {
92      base.OnClosing(e);
93      if (MainFormManager.MainForm.Views.OfType<IContentView>().FirstOrDefault() != null) {
94        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)
95          e.Cancel = true;
96      }
97    }
98    protected override void OnClosed(EventArgs e) {
99      base.OnClosed(e);
100      Properties.Settings.Default.ShowMaximized = WindowState == FormWindowState.Maximized;
101      Properties.Settings.Default.CollapseClipboard = clipboard.Collapsed;
102      OperatorsSidebar operatorsSidebar = MainFormManager.MainForm.Views.OfType<OperatorsSidebar>().FirstOrDefault();
103      if (operatorsSidebar != null) Properties.Settings.Default.CollapseOperatorsSidebar = operatorsSidebar.Collapsed;
104      Properties.Settings.Default.Save();
105    }
106
107    protected override void OnActiveViewChanged() {
108      base.OnActiveViewChanged();
109      UpdateTitle();
110    }
111
112    public void UpdateTitle() {
113      if (InvokeRequired)
114        Invoke(new Action(UpdateTitle));
115      else {
116        IContentView activeView = ActiveView as IContentView;
117        if ((activeView != null) && (activeView.Content != null) && (activeView.Content is IStorableContent)) {
118          IStorableContent content = (IStorableContent)activeView.Content;
119          Title = title + " [" + (string.IsNullOrEmpty(content.Filename) ? "Unsaved" : content.Filename) + "]";
120        } else {
121          Title = title;
122        }
123      }
124    }
125
126    #region Cursor Handling
127    public void SetAppStartingCursor() {
128      if (InvokeRequired)
129        Invoke(new Action(SetAppStartingCursor));
130      else {
131        appStartingCursors++;
132        SetCursor();
133      }
134    }
135    public void ResetAppStartingCursor() {
136      if (InvokeRequired)
137        Invoke(new Action(ResetAppStartingCursor));
138      else {
139        appStartingCursors--;
140        SetCursor();
141      }
142    }
143    public void SetWaitCursor() {
144      if (InvokeRequired)
145        Invoke(new Action(SetWaitCursor));
146      else {
147        waitingCursors++;
148        SetCursor();
149      }
150    }
151    public void ResetWaitCursor() {
152      if (InvokeRequired)
153        Invoke(new Action(ResetWaitCursor));
154      else {
155        waitingCursors--;
156        SetCursor();
157      }
158    }
159    private void SetCursor() {
160      if (waitingCursors > 0) Cursor = Cursors.WaitCursor;
161      else if (appStartingCursors > 0) Cursor = Cursors.AppStarting;
162      else Cursor = Cursors.Default;
163    }
164    #endregion
165  }
166}
Note: See TracBrowser for help on using the repository browser.