Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.PluginInfrastructure/Starter/AboutDialog.cs @ 3761

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

Replaced HeuristicLab logo and made some minor changes in AboutDialog (#989)

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.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using System.Reflection;
31using System.Diagnostics;
32using HeuristicLab.PluginInfrastructure.Advanced;
33
34namespace HeuristicLab.PluginInfrastructure.Starter {
35  /// <summary>
36  /// Shows product, version and copyright information for HeuristicLab and all plugins.
37  /// </summary>
38  public partial class AboutDialog : Form {
39    /// <summary>
40    /// Creates a new about dialog with all plugins loaded in the current application.
41    /// </summary>
42    public AboutDialog() {
43      InitializeComponent();
44      var curAssembly = this.GetType().Assembly;
45      productTextBox.Text = GetProduct(curAssembly);
46      versionTextBox.Text = GetVersion(curAssembly);
47      copyrightTextBox.Text = GetCopyright(curAssembly);
48      imageList.Images.Add(HeuristicLab.PluginInfrastructure.Resources.Plugin);
49      pictureBox.Image = HeuristicLab.PluginInfrastructure.Resources.HeuristicLabLogo;
50      licenseTextBox.Text = HeuristicLab.PluginInfrastructure.Resources.LicenseText;
51      UpdatePluginList(ApplicationManager.Manager.Plugins);
52      ActiveControl = okButton;
53    }
54
55    /// <summary>
56    /// Creates a new about dialog listing all plugins in the <paramref name="plugins"/> enumerable.
57    /// </summary>
58    /// <param name="plugins">Enumerable of plugins that should be listed.</param>
59    public AboutDialog(IEnumerable<IPluginDescription> plugins) : this() {
60      UpdatePluginList(plugins);
61    }
62
63    private void UpdatePluginList(IEnumerable<IPluginDescription> plugins) {
64      pluginListView.Items.Clear();
65      foreach (var plugin in plugins) {
66        ListViewItem pluginItem = CreateListViewItem(plugin);
67        pluginListView.Items.Add(pluginItem);
68      }
69      Util.ResizeColumns(pluginListView.Columns.OfType<ColumnHeader>());
70    }
71
72    private ListViewItem CreateListViewItem(IPluginDescription plugin) {
73      ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), plugin.Description });
74      item.Tag = plugin;
75      item.ImageIndex = 0;
76      return item;
77    }
78
79    private string GetCopyright(Assembly asm) {
80      AssemblyCopyrightAttribute attribute = GetAttribute<AssemblyCopyrightAttribute>(asm);
81      return attribute.Copyright;
82    }
83
84    private string GetVersion(Assembly asm) {
85      FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
86      return pluginInfrastructureVersion.FileVersion;
87    }
88
89    private string GetProduct(Assembly asm) {
90      AssemblyProductAttribute attribute = GetAttribute<AssemblyProductAttribute>(asm);
91      return attribute.Product;
92    }
93
94    private T GetAttribute<T>(Assembly asm) {
95      return (T)asm.GetCustomAttributes(typeof(T), false).Single();
96    }
97
98    private void okButton_Click(object sender, EventArgs e) {
99      Close();
100    }
101
102    private void pluginListView_ItemActivate(object sender, EventArgs e) {
103      if(pluginListView.SelectedItems.Count > 0) {
104        PluginView view = new PluginView((IPluginDescription)pluginListView.SelectedItems[0].Tag);
105        view.Show(this);
106      }
107    }
108
109    private void licenseTextBox_LinkClicked(object sender, LinkClickedEventArgs e) {
110      System.Diagnostics.Process.Start(e.LinkText);
111    }
112
113    private void webLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
114      System.Diagnostics.Process.Start(webLinkLabel.Text);
115    }
116
117    private void mailLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
118      System.Diagnostics.Process.Start("mailto:" + mailLinkLabel.Text);
119    }
120  }
121}
Note: See TracBrowser for help on using the repository browser.