Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3496 was 3483, checked in by swagner, 15 years ago

Worked on the refactoring of saving and loading items (#990)

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