#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections; using System.Collections.Generic; using System.Windows.Forms; using HeuristicLab.Common; using HeuristicLab.PluginInfrastructure; namespace HeuristicLab.Problems.DataAnalysis.Views { internal partial class BenchmarkGeneratorDialog : Form { private bool initialized; private IDataAnalysisProblem Content; private IDataAnalysisProblemData problemData; public IDataAnalysisProblemData ProblemData { get { return problemData; } } public BenchmarkGeneratorDialog(IDataAnalysisProblem Content) { initialized = false; InitializeComponent(); this.Content = Content; } private void NewItemDialog_Load(object sender, EventArgs e) { if (!initialized) { IEnumerable generators = new List(); if (Content is IRegressionProblem) generators = ApplicationManager.Manager.GetInstances(); else if (Content is IClassificationProblem) generators = ApplicationManager.Manager.GetInstances(); else if (Content is IClusteringProblem) generators = ApplicationManager.Manager.GetInstances(); foreach (var generator in generators) { ListViewItem item = new ListViewItem(new string[] { generator.Name, generator.Description }); item.Tag = generator; BenchmarkGeneratorListView.Items.Add(item); } BenchmarkGeneratorListView.ListViewItemSorter = new ListViewItemComparer(); for (int i = 0; i < BenchmarkGeneratorListView.Columns.Count; i++) BenchmarkGeneratorListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); initialized = true; } } private void NewItemDialog_Shown(object sender, EventArgs e) { problemData = null; } private void BenchmarkGeneratorListView_SelectedIndexChanged(object sender, EventArgs e) { okButton.Enabled = BenchmarkGeneratorListView.SelectedItems.Count == 1; } private void okButton_Click(object sender, EventArgs e) { if (BenchmarkGeneratorListView.SelectedItems.Count == 1) { problemData = ((IDataAnalysisBenchmarkProblemDataGenerator)BenchmarkGeneratorListView.SelectedItems[0].Tag).GenerateProblemData(); DialogResult = DialogResult.OK; Close(); } } private void BenchmarkGeneratorListView_DoubleClick(object sender, EventArgs e) { if (BenchmarkGeneratorListView.SelectedItems.Count == 1) { problemData = ((IDataAnalysisBenchmarkProblemDataGenerator)BenchmarkGeneratorListView.SelectedItems[0].Tag).GenerateProblemData(); DialogResult = DialogResult.OK; Close(); } } private class ListViewItemComparer : IComparer { private NaturalStringComparer comp = new NaturalStringComparer(); public int Compare(object x, object y) { return comp.Compare(((ListViewItem)x).SubItems[0].Text, ((ListViewItem)y).SubItems[0].Text); } } } }