Free cookie consent management tool by TermsFeed Policy Generator

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

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

Implemented reviewers' comments (#893)

  • enhanced optimizer settings to customize appearance
File size: 6.0 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.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      WindowState = Properties.Settings.Default.ShowMaximized ? FormWindowState.Maximized : FormWindowState.Normal;
72
73      clipboard = new Clipboard<IItem>();
74      clipboard.Dock = DockStyle.Left;
75      clipboard.Collapsed = Properties.Settings.Default.CollapseClipboard;
76      if (Properties.Settings.Default.ShowClipboard) {
77        clipboard.Show();
78      }
79      if (Properties.Settings.Default.ShowOperatorsSidebar) {
80        OperatorsSidebar operatorsSidebar = new OperatorsSidebar();
81        operatorsSidebar.Dock = DockStyle.Left;
82        operatorsSidebar.Show();
83        operatorsSidebar.Collapsed = Properties.Settings.Default.CollapseOperatorsSidebar;
84      }
85      if (Properties.Settings.Default.ShowStartPage) {
86        StartPage startPage = new StartPage();
87        startPage.Show();
88      }
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.