Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/tools/Templates/HeuristicLab.VS2010Wizards/ParametersControl.cs @ 4181

Last change on this file since 4181 was 4181, checked in by abeham, 14 years ago

#567

  • Improved algorithm wizard design
File size: 5.4 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.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30
31namespace HeuristicLab.VS2010Wizards {
32  public partial class ParametersControl : UserControl {
33    public ParametersControl() {
34      InitializeComponent();
35    }
36
37    public string GetParameterProperties(string accessModifier) {
38      return string.Empty;
39    }
40
41    public string GetProperties(string accessModifier) {
42      return string.Empty;
43    }
44
45    public string GetInitializers() {
46      return string.Empty;
47    }
48
49    private void parametersListView_MouseDoubleClick(object sender, MouseEventArgs e) {
50      var hit = parametersListView.HitTest(e.Location);
51      TextBox dynamicUserInput = new TextBox();
52      dynamicUserInput.Left = parametersListView.Left + hit.SubItem.Bounds.Left + 3;
53      dynamicUserInput.Top = parametersListView.Top + hit.SubItem.Bounds.Top;
54      dynamicUserInput.Width = hit.SubItem.Bounds.Width;
55      dynamicUserInput.Height = hit.SubItem.Bounds.Height;
56      dynamicUserInput.Text = hit.SubItem.Text;
57      dynamicUserInput.Tag = hit.SubItem;
58      Controls.Add(dynamicUserInput);
59      dynamicUserInput.BringToFront();
60      Refresh();
61      dynamicUserInput.Focus();
62      dynamicUserInput.SelectAll();
63      dynamicUserInput.KeyUp += new KeyEventHandler(dynamicUserInput_KeyUp);
64      dynamicUserInput.LostFocus += new EventHandler(dynamicUserInput_LostFocus);
65    }
66
67    private void dynamicUserInput_LostFocus(object sender, EventArgs e) {
68      TextBox t = (TextBox)sender;
69      System.Windows.Forms.ListViewItem.ListViewSubItem subItem = t.Tag as System.Windows.Forms.ListViewItem.ListViewSubItem;
70      subItem.Text = t.Text;
71      t.KeyUp -= new KeyEventHandler(dynamicUserInput_KeyUp);
72      t.LostFocus -= new EventHandler(dynamicUserInput_LostFocus);
73      Controls.Remove(t);
74    }
75
76    private void dynamicUserInput_KeyUp(object sender, KeyEventArgs e) {
77      if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter)
78        dynamicUserInput_LostFocus(sender, EventArgs.Empty);
79    }
80
81    private void parametersListView_SelectedIndexChanged(object sender, EventArgs e) {
82      if (parametersListView.SelectedIndices.Count > 0) {
83        removeButton.Enabled = true;
84        upButton.Enabled = true;
85        downButton.Enabled = true;
86      } else {
87        removeButton.Enabled = false;
88        upButton.Enabled = false;
89        downButton.Enabled = false;
90      }
91    }
92
93    private void removeButton_Click(object sender, EventArgs e) {
94      if (parametersListView.SelectedIndices.Count > 0) {
95        int row = parametersListView.SelectedIndices[0];
96        parametersListView.Items.RemoveAt(row);
97        if (parametersListView.Items.Count > 0) {
98          int index = Math.Max(Math.Min(row, parametersListView.Items.Count - 1), 0);
99          parametersListView.Items[index].Selected = true;
100        }
101      }
102    }
103
104    private void upButton_Click(object sender, EventArgs e) {
105      if (parametersListView.SelectedIndices.Count > 0) {
106        ListViewItem selected = parametersListView.SelectedItems[0];
107        int row = parametersListView.SelectedIndices[0];
108        parametersListView.Items.Remove(selected);
109        parametersListView.Items.Insert(Math.Max(row - 1, 0), selected);
110      }
111    }
112
113    private void downButton_Click(object sender, EventArgs e) {
114      if (parametersListView.SelectedIndices.Count > 0) {
115        ListViewItem selected = parametersListView.SelectedItems[0];
116        int row = parametersListView.SelectedIndices[0];
117        parametersListView.Items.Remove(selected);
118        if (row == parametersListView.Items.Count)
119          parametersListView.Items.Add(selected);
120        else
121          parametersListView.Items.Insert(row + 1, selected);
122      }
123    }
124
125    private void addButton_Click(object sender, EventArgs e) {
126      string name = "FormalName";
127      bool uniqueNameFound;
128      int i = 1;
129      do {
130        uniqueNameFound = true;
131        foreach (ListViewItem li in parametersListView.Items) {
132          if (li.Text.Equals(name)) {
133            name = "FormalName" + i.ToString();
134            i++;
135            uniqueNameFound = false;
136          }
137        }
138      } while (!uniqueNameFound);
139      ListViewItem item = new ListViewItem();
140      item.Text = name;
141      item.SubItems.Add("Value");
142      item.SubItems.Add("IItem");
143      item.SubItems.Add("Add a description.");
144      item.SubItems.Add("");
145      parametersListView.Items.Add(item);
146    }
147  }
148}
Note: See TracBrowser for help on using the repository browser.