GUI/ParameterForm.cs
author moel.mich
Tue, 09 Mar 2010 22:27:10 +0000
changeset 79 9cdbe1d8d12a
child 86 b4f0f206173d
permissions -rw-r--r--
Changed the CPU clock calculation. If no invariant TSC is available, then the max CPU clock is estimated at startup under load, otherwise an average over one second is used.
     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Text;
     5 using System.Windows.Forms;
     6 using OpenHardwareMonitor.Hardware;
     7 using OpenHardwareMonitor.Utilities;
     8 
     9 namespace OpenHardwareMonitor.GUI {
    10   public partial class ParameterForm : Form {
    11 
    12     private IReadOnlyArray<IParameter> parameters;
    13     private BindingList<ParameterRow> parameterRows;
    14 
    15     public ParameterForm() {
    16       InitializeComponent();
    17     }
    18     
    19     public IReadOnlyArray<IParameter> Parameters {
    20       get {
    21         return parameters;
    22       }
    23       set {
    24         parameters = value;
    25         parameterRows = new BindingList<ParameterRow>();
    26         foreach (IParameter parameter in parameters)
    27           parameterRows.Add(new ParameterRow(parameter));
    28         bindingSource.DataSource = parameterRows;
    29       }
    30     }
    31 
    32     private class ParameterRow : INotifyPropertyChanged {
    33       public IParameter parameter;
    34       private float value;
    35       public bool isDefault;
    36 
    37       public event PropertyChangedEventHandler PropertyChanged;
    38 
    39       private void NotifyPropertyChanged(String propertyName) {
    40         if (PropertyChanged != null) {
    41           PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    42         }
    43       }
    44 
    45       public ParameterRow(IParameter parameter){
    46         this.parameter = parameter;
    47         this.value = parameter.Value;
    48         this.isDefault = parameter.IsDefault;
    49       }
    50 
    51       public string Name {
    52         get { return parameter.Name; }
    53       }
    54 
    55       public float Value {
    56         get { return value; }
    57         set {            
    58           this.isDefault = false;
    59           this.value = value;
    60           NotifyPropertyChanged("Default");
    61           NotifyPropertyChanged("Value");
    62         }
    63       }
    64 
    65       public bool Default {
    66         get { return isDefault; }
    67         set {
    68           isDefault = value;
    69           if (value)
    70             this.value = parameter.DefaultValue;
    71           NotifyPropertyChanged("Default");
    72           NotifyPropertyChanged("Value");
    73         }
    74       }
    75     }
    76 
    77     private void dataGridView_RowEnter(object sender, 
    78       DataGridViewCellEventArgs e) 
    79     {
    80       if (e.RowIndex >= 0 && e.RowIndex < parameters.Length)
    81         descriptionLabel.Text = parameters[e.RowIndex].Description;
    82       else
    83         descriptionLabel.Text = "";
    84     }
    85 
    86     private void dataGridView_CellValidating(object sender, 
    87       DataGridViewCellValidatingEventArgs e) 
    88     {
    89       float value;
    90       if (e.ColumnIndex == 2 &&
    91         !float.TryParse(e.FormattedValue.ToString(), out value)) {
    92         dataGridView.Rows[e.RowIndex].Cells[0].ErrorText = 
    93           "Invalid value";
    94         e.Cancel = true;
    95       }
    96     }
    97 
    98     private void dataGridView_CellEndEdit(object sender,
    99       DataGridViewCellEventArgs e) {
   100       dataGridView.Rows[e.RowIndex].Cells[0].ErrorText = "";
   101     }
   102 
   103     private void okButton_Click(object sender, EventArgs e) {
   104       foreach (ParameterRow row in parameterRows) {
   105         if (row.Default) {
   106           row.parameter.IsDefault = true;
   107         } else {
   108           row.parameter.Value = row.Value;
   109         }
   110       }
   111     }
   112 
   113     private void dataGridView_CurrentCellDirtyStateChanged(object sender, 
   114       EventArgs e) {
   115       if (dataGridView.CurrentCell is DataGridViewCheckBoxCell ||
   116         dataGridView.CurrentCell is DataGridViewComboBoxCell) 
   117       {
   118         dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
   119       }
   120     }
   121   }
   122 }