[312] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.ComponentModel;
|
---|
| 4 | using System.Drawing;
|
---|
| 5 | using System.Data;
|
---|
| 6 | using System.Linq;
|
---|
| 7 | using System.Text;
|
---|
| 8 | using System.Windows.Forms;
|
---|
| 9 | using HeuristicLab.PluginInfrastructure;
|
---|
| 10 | using HeuristicLab.Core;
|
---|
| 11 |
|
---|
| 12 | namespace HeuristicLab.DataAnalysis {
|
---|
| 13 | public partial class ManualScalingControl : Form {
|
---|
| 14 | public ManualScalingControl(bool editingAllowed) {
|
---|
| 15 | InitializeComponent();
|
---|
| 16 | dataGridView.ReadOnly = !editingAllowed;
|
---|
| 17 | okButton.Text = editingAllowed ? "Scale" : "Close";
|
---|
| 18 | cancelButton.Visible = editingAllowed;
|
---|
| 19 | cancelButton.Text = "Cancel";
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | private double[,] data;
|
---|
| 23 | public double[,] Data {
|
---|
| 24 | get {
|
---|
| 25 | return data;
|
---|
| 26 | }
|
---|
| 27 | set {
|
---|
| 28 | data = value;
|
---|
| 29 | UpdateControls();
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | protected void UpdateControls() {
|
---|
| 34 | Refresh();
|
---|
| 35 | dataGridView.ColumnCount = data.GetLength(0);
|
---|
| 36 | dataGridView.RowCount = data.GetLength(1);
|
---|
| 37 | for(int i = 0; i < dataGridView.RowCount; i++) {
|
---|
| 38 | for(int j = 0; j < dataGridView.ColumnCount; j++) {
|
---|
| 39 | dataGridView[j,i].Value = data[j, i];
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 | dataGridView.Columns[0].HeaderText = "Factor";
|
---|
| 43 | dataGridView.Columns[1].HeaderText = "Offset";
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | private void button_Click(object sender, EventArgs e) {
|
---|
| 47 | DialogResult = DialogResult.OK;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | private void cancelButton_Click(object sender, EventArgs e) {
|
---|
| 51 | DialogResult = DialogResult.Cancel;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | // stolen from the internets
|
---|
| 55 | private void dataGridView_KeyDown(object sender, KeyEventArgs e) {
|
---|
| 56 | if(e.Control && e.KeyCode == Keys.C) {
|
---|
| 57 | DataObject d = dataGridView.GetClipboardContent();
|
---|
| 58 | Clipboard.SetDataObject(d);
|
---|
| 59 | e.Handled = true;
|
---|
| 60 | } else if(e.Control && e.KeyCode == Keys.V) {
|
---|
| 61 | string s = Clipboard.GetText();
|
---|
| 62 | string[] lines = s.Split(new char[] {'\n', '\r'},StringSplitOptions.RemoveEmptyEntries);
|
---|
| 63 | int row = dataGridView.CurrentCell.RowIndex;
|
---|
| 64 | int col = dataGridView.CurrentCell.ColumnIndex;
|
---|
| 65 | foreach(string line in lines) {
|
---|
| 66 | if(row < dataGridView.RowCount && line.Length > 0) {
|
---|
| 67 | string[] cells = line.Split(new char[] {'\t',' ',';'},StringSplitOptions.RemoveEmptyEntries);
|
---|
| 68 | for(int i = 0; i < cells.Length; i++) {
|
---|
| 69 | if(col + i < this.dataGridView.ColumnCount) {
|
---|
| 70 | dataGridView[col + i, row].Value = double.Parse(cells[i]);
|
---|
| 71 | } else {
|
---|
| 72 | break;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | row++;
|
---|
| 76 | } else {
|
---|
| 77 | break;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | e.Handled = true;
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) {
|
---|
| 85 | if(e.RowIndex >= 0 && e.ColumnIndex >= 0) {
|
---|
| 86 | data[e.ColumnIndex, e.RowIndex] = (double)dataGridView[e.ColumnIndex, e.RowIndex].Value;
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | }
|
---|