GUI/MainForm.cs
author moel.mich
Wed, 04 Aug 2010 19:10:20 +0000
changeset 161 65f2d62d7838
parent 158 119693c3b7d1
child 165 813d8bc3192f
permissions -rw-r--r--
Adding missing class SensorVisitor.
moel@1
     1
/*
moel@1
     2
  
moel@1
     3
  Version: MPL 1.1/GPL 2.0/LGPL 2.1
moel@1
     4
moel@1
     5
  The contents of this file are subject to the Mozilla Public License Version
moel@1
     6
  1.1 (the "License"); you may not use this file except in compliance with
moel@1
     7
  the License. You may obtain a copy of the License at
moel@1
     8
 
moel@1
     9
  http://www.mozilla.org/MPL/
moel@1
    10
moel@1
    11
  Software distributed under the License is distributed on an "AS IS" basis,
moel@1
    12
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
moel@1
    13
  for the specific language governing rights and limitations under the License.
moel@1
    14
moel@1
    15
  The Original Code is the Open Hardware Monitor code.
moel@1
    16
moel@1
    17
  The Initial Developer of the Original Code is 
moel@1
    18
  Michael Möller <m.moeller@gmx.ch>.
moel@1
    19
  Portions created by the Initial Developer are Copyright (C) 2009-2010
moel@1
    20
  the Initial Developer. All Rights Reserved.
moel@1
    21
moel@1
    22
  Contributor(s):
moel@1
    23
moel@1
    24
  Alternatively, the contents of this file may be used under the terms of
moel@1
    25
  either the GNU General Public License Version 2 or later (the "GPL"), or
moel@1
    26
  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
moel@1
    27
  in which case the provisions of the GPL or the LGPL are applicable instead
moel@1
    28
  of those above. If you wish to allow use of your version of this file only
moel@1
    29
  under the terms of either the GPL or the LGPL, and not to allow others to
moel@1
    30
  use your version of this file under the terms of the MPL, indicate your
moel@1
    31
  decision by deleting the provisions above and replace them with the notice
moel@1
    32
  and other provisions required by the GPL or the LGPL. If you do not delete
moel@1
    33
  the provisions above, a recipient may use your version of this file under
moel@1
    34
  the terms of any one of the MPL, the GPL or the LGPL.
moel@1
    35
 
moel@1
    36
*/
moel@1
    37
moel@1
    38
using System;
moel@1
    39
using System.Collections.Generic;
moel@1
    40
using System.ComponentModel;
moel@1
    41
using System.Configuration;
moel@1
    42
using System.Drawing;
moel@83
    43
using System.IO;
moel@1
    44
using System.Text;
moel@1
    45
using System.Windows.Forms;
moel@1
    46
using Aga.Controls.Tree;
moel@1
    47
using Aga.Controls.Tree.NodeControls;
moel@1
    48
using OpenHardwareMonitor.Hardware;
moel@28
    49
using OpenHardwareMonitor.Utilities;
moel@1
    50
moel@1
    51
namespace OpenHardwareMonitor.GUI {
moel@1
    52
  public partial class MainForm : Form {
moel@1
    53
moel@28
    54
    private Computer computer = new Computer();
moel@1
    55
    private Node root;
moel@1
    56
    private TreeModel treeModel;
moel@1
    57
    private IDictionary<ISensor, Color> sensorPlotColors = 
moel@1
    58
      new Dictionary<ISensor, Color>();
moel@1
    59
    private Color[] plotColorPalette;
moel@133
    60
    private SystemTray systemTray;    
moel@82
    61
    private StartupManager startupManager = new StartupManager();
moel@110
    62
    private UpdateVisitor updateVisitor = new UpdateVisitor();
moel@1
    63
moel@156
    64
    private UserOption showHiddenSensors;
moel@156
    65
    private UserOption showPlot;
moel@156
    66
    private UserOption showValue;
moel@156
    67
    private UserOption showMin;
moel@156
    68
    private UserOption showMax;
moel@156
    69
    private UserOption startMinimized;
moel@156
    70
    private UserOption minimizeToTray;
moel@156
    71
    private UserOption autoStart;
moel@156
    72
    private UserOption readHddSensors;
moel@156
    73
moel@28
    74
    public MainForm() {      
moel@1
    75
      InitializeComponent();
moel@156
    76
moel@156
    77
      // set the DockStyle here, to avoid conflicts with the MainMenu
moel@156
    78
      this.splitContainer.Dock = DockStyle.Fill;
moel@156
    79
      
moel@159
    80
      int p = (int)System.Environment.OSVersion.Platform;
moel@159
    81
      if ((p == 4) || (p == 128)) {
moel@159
    82
        splitContainer.BorderStyle = BorderStyle.None;
moel@159
    83
        splitContainer.Border3DStyle = Border3DStyle.Adjust;
moel@159
    84
        splitContainer.SplitterWidth = 4;
moel@159
    85
        treeView.BorderStyle = BorderStyle.Fixed3D;
moel@159
    86
        plotPanel.BorderStyle = BorderStyle.Fixed3D;
moel@159
    87
      }
moel@159
    88
      
moel@1
    89
      this.Font = SystemFonts.MessageBoxFont;
moel@1
    90
      treeView.Font = SystemFonts.MessageBoxFont;
moel@63
    91
      plotPanel.Font = SystemFonts.MessageBoxFont;
moel@1
    92
      
moel@133
    93
      nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
moel@133
    94
      nodeCheckBox.CheckStateChanged += UpdatePlotSelection;
moel@133
    95
      nodeTextBoxText.DrawText += nodeTextBoxText_DrawText;
moel@133
    96
      nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText;
moel@133
    97
      nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText;
moel@133
    98
      nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
moel@141
    99
      nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;
moel@1
   100
moel@1
   101
      if (Utilities.Config.Contains("mainForm.Location.X")) {
moel@1
   102
        int x = Utilities.Config.Get("mainForm.Location.X", Location.X);
moel@1
   103
        x = x < 0 ? 0 : x;
moel@1
   104
        int y = Utilities.Config.Get("mainForm.Location.Y", Location.Y);
moel@1
   105
        y = y < 0 ? 0 : y;
moel@1
   106
        this.Location = new Point(x, y);
moel@1
   107
      } else {
moel@1
   108
        StartPosition = FormStartPosition.CenterScreen;
moel@1
   109
      }
moel@1
   110
moel@156
   111
      ClientSize = new Size(
moel@158
   112
        Utilities.Config.Get("mainForm.Width", 470),
moel@158
   113
        Utilities.Config.Get("mainForm.Height", 640));
moel@113
   114
moel@113
   115
      foreach (TreeColumn column in treeView.Columns) 
moel@113
   116
        column.Width = Math.Max(20, Math.Min(400, 
moel@113
   117
          Config.Get("treeView.Columns." + column.Header + ".Width",
moel@113
   118
          column.Width)));
moel@113
   119
moel@1
   120
      treeModel = new TreeModel();
moel@1
   121
      root = new Node(System.Environment.MachineName);
moel@1
   122
      root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
moel@1
   123
      
moel@1
   124
      treeModel.Nodes.Add(root);
moel@133
   125
      treeView.Model = treeModel;     
moel@40
   126
moel@133
   127
      systemTray = new SystemTray(computer);
moel@133
   128
      systemTray.HideShowCommand += hideShowClick;
moel@133
   129
      systemTray.ExitCommand += exitClick;
moel@1
   130
moel@28
   131
      computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
moel@28
   132
      computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
moel@28
   133
      computer.Open();
moel@28
   134
moel@86
   135
      timer.Enabled = true;
moel@86
   136
moel@111
   137
      plotColorPalette = new Color[13];
moel@1
   138
      plotColorPalette[0] = Color.Blue;
moel@1
   139
      plotColorPalette[1] = Color.OrangeRed;
moel@1
   140
      plotColorPalette[2] = Color.Green;
moel@1
   141
      plotColorPalette[3] = Color.LightSeaGreen;
moel@1
   142
      plotColorPalette[4] = Color.Goldenrod;
moel@1
   143
      plotColorPalette[5] = Color.DarkViolet;
moel@1
   144
      plotColorPalette[6] = Color.YellowGreen;
moel@1
   145
      plotColorPalette[7] = Color.SaddleBrown;
moel@111
   146
      plotColorPalette[8] = Color.RoyalBlue;
moel@111
   147
      plotColorPalette[9] = Color.DeepPink;
moel@111
   148
      plotColorPalette[10] = Color.MediumSeaGreen;
moel@111
   149
      plotColorPalette[11] = Color.Olive;
moel@111
   150
      plotColorPalette[12] = Color.Firebrick;
moel@1
   151
moel@156
   152
      showHiddenSensors = new UserOption("hiddenMenuItem", false, hiddenMenuItem);
moel@156
   153
      showHiddenSensors.Changed += delegate(object sender, EventArgs e) {
moel@156
   154
        treeModel.ForceVisible = showHiddenSensors.Value;
moel@156
   155
      };
moel@111
   156
moel@156
   157
      showPlot = new UserOption("plotMenuItem", false, plotMenuItem);
moel@156
   158
      showPlot.Changed += delegate(object sender, EventArgs e) {
moel@156
   159
        splitContainer.Panel2Collapsed = !showPlot.Value;
moel@156
   160
        treeView.Invalidate();
moel@156
   161
      };
moel@1
   162
moel@156
   163
      showValue = new UserOption("valueMenuItem", true, valueMenuItem);
moel@156
   164
      showValue.Changed += delegate(object sender, EventArgs e) {
moel@156
   165
        treeView.Columns[1].IsVisible = showValue.Value;
moel@156
   166
      };
moel@122
   167
moel@156
   168
      showMin = new UserOption("minMenuItem", false, minMenuItem);
moel@156
   169
      showMin.Changed += delegate(object sender, EventArgs e) {
moel@156
   170
        treeView.Columns[2].IsVisible = showMin.Value;
moel@156
   171
      };
moel@156
   172
moel@156
   173
      showMax = new UserOption("maxMenuItem", true, maxMenuItem);
moel@156
   174
      showMax.Changed += delegate(object sender, EventArgs e) {
moel@156
   175
        treeView.Columns[3].IsVisible = showMax.Value;
moel@156
   176
      };
moel@156
   177
moel@156
   178
      startMinimized = new UserOption("startMinMenuItem", false, startMinMenuItem);
moel@156
   179
moel@156
   180
      minimizeToTray = new UserOption("minTrayMenuItem", true, minTrayMenuItem);
moel@156
   181
      minimizeToTray.Changed += delegate(object sender, EventArgs e) {
moel@156
   182
        systemTray.IsMainIconEnabled = minimizeToTray.Value;
moel@156
   183
      };
moel@156
   184
moel@156
   185
      autoStart = new UserOption(null, startupManager.Startup, startupMenuItem);
moel@156
   186
      autoStart.Changed += delegate(object sender, EventArgs e) {
moel@156
   187
        startupManager.Startup = autoStart.Value; ;
moel@156
   188
      };
moel@156
   189
moel@156
   190
      readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem);
moel@156
   191
      readHddSensors.Changed += delegate(object sender, EventArgs e) {
moel@156
   192
        computer.HDDEnabled = readHddSensors.Value;
moel@156
   193
        UpdatePlotSelection(null, null);
moel@156
   194
      };
moel@156
   195
moel@156
   196
      celciusMenuItem.Checked = 
moel@122
   197
        UnitManager.TemperatureUnit == TemperatureUnit.Celcius;
moel@156
   198
      fahrenheitMenuItem.Checked = !celciusMenuItem.Checked;
moel@55
   199
moel@142
   200
      startupMenuItem.Visible = startupManager.IsAvailable;
moel@125
   201
      
moel@55
   202
      if (startMinMenuItem.Checked) {
moel@82
   203
        if (!minTrayMenuItem.Checked) {
moel@55
   204
          WindowState = FormWindowState.Minimized;
moel@55
   205
          Show();
moel@55
   206
        }
moel@55
   207
      } else {
moel@55
   208
        Show();
moel@55
   209
      }
moel@70
   210
moel@71
   211
      // Create a handle, otherwise calling Close() does not fire FormClosed     
moel@71
   212
      IntPtr handle = Handle;
moel@128
   213
moel@128
   214
      // Make sure the settings are saved when the user logs off
moel@128
   215
      Microsoft.Win32.SystemEvents.SessionEnded +=
moel@128
   216
        delegate(object sender, Microsoft.Win32.SessionEndedEventArgs e) {
moel@128
   217
          SaveConfiguration();
moel@128
   218
        };
moel@1
   219
    }
moel@128
   220
    
moel@64
   221
    private void SubHardwareAdded(IHardware hardware, Node node) {
moel@64
   222
      Node hardwareNode = new HardwareNode(hardware);
moel@64
   223
      node.Nodes.Add(hardwareNode);
moel@64
   224
      foreach (IHardware subHardware in hardware.SubHardware)
moel@64
   225
        SubHardwareAdded(subHardware, hardwareNode);  
moel@64
   226
    }
moel@64
   227
moel@28
   228
    private void HardwareAdded(IHardware hardware) {
moel@64
   229
      Node hardwareNode = new HardwareNode(hardware);
moel@64
   230
      root.Nodes.Add(hardwareNode);
moel@64
   231
      foreach (IHardware subHardware in hardware.SubHardware)
moel@64
   232
        SubHardwareAdded(subHardware, hardwareNode);     
moel@1
   233
    }
moel@1
   234
moel@28
   235
    private void HardwareRemoved(IHardware hardware) {      
moel@1
   236
      List<Node> nodesToRemove = new List<Node>();
moel@28
   237
      foreach (Node node in root.Nodes) {
moel@28
   238
        HardwareNode hardwareNode = node as HardwareNode;
moel@28
   239
        if (hardwareNode != null && hardwareNode.Hardware == hardware)
moel@28
   240
          nodesToRemove.Add(node);
moel@28
   241
      }
moel@1
   242
      foreach (Node node in nodesToRemove)
moel@1
   243
        root.Nodes.Remove(node);
moel@1
   244
    }
moel@1
   245
moel@111
   246
    private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {       
moel@111
   247
      Node node = e.Node.Tag as Node;
moel@111
   248
      if (node != null) {
moel@1
   249
        Color color;
moel@111
   250
        if (node.IsVisible) {
moel@111
   251
          SensorNode sensorNode = node as SensorNode;
moel@111
   252
          if (plotMenuItem.Checked && sensorNode != null &&
moel@111
   253
            sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
moel@111
   254
            e.TextColor = color;
moel@111
   255
        } else {
moel@111
   256
          e.TextColor = Color.DarkGray;
moel@111
   257
        }
moel@1
   258
      }
moel@1
   259
    }
moel@1
   260
moel@1
   261
    private void UpdatePlotSelection(object sender, 
moel@1
   262
      TreePathEventArgs e) 
moel@1
   263
    {
moel@1
   264
      List<ISensor> selected = new List<ISensor>();
moel@1
   265
      IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
moel@1
   266
      int colorIndex = 0;
moel@1
   267
      foreach (TreeNodeAdv node in treeView.AllNodes) {
moel@1
   268
        SensorNode sensorNode = node.Tag as SensorNode;
moel@1
   269
        if (sensorNode != null && 
moel@1
   270
          sensorNode.Sensor.SensorType == SensorType.Temperature) {
moel@1
   271
          if (sensorNode.Plot) {
moel@1
   272
            colors.Add(sensorNode.Sensor,
moel@1
   273
              plotColorPalette[colorIndex % plotColorPalette.Length]);
moel@1
   274
            selected.Add(sensorNode.Sensor);
moel@1
   275
          }
moel@1
   276
          colorIndex++;
moel@1
   277
        }
moel@1
   278
      }
moel@1
   279
      sensorPlotColors = colors;
moel@1
   280
      plotPanel.SetSensors(selected, colors);
moel@1
   281
    }
moel@1
   282
moel@141
   283
    private void nodeTextBoxText_EditorShowing(object sender, CancelEventArgs e) 
moel@141
   284
    {
moel@141
   285
      e.Cancel = !(treeView.CurrentNode != null &&
moel@141
   286
        treeView.CurrentNode.Tag is SensorNode);
moel@141
   287
    }
moel@141
   288
moel@1
   289
    private void nodeCheckBox_IsVisibleValueNeeded(object sender, 
moel@1
   290
      NodeControlValueEventArgs e) {
moel@1
   291
      SensorNode node = e.Node.Tag as SensorNode;
moel@1
   292
      e.Value = (node != null) && 
moel@1
   293
        (node.Sensor.SensorType == SensorType.Temperature) && 
moel@1
   294
        plotMenuItem.Checked;
moel@1
   295
    }
moel@1
   296
moel@133
   297
    private void exitClick(object sender, EventArgs e) {
moel@70
   298
      Close();      
moel@1
   299
    }
moel@1
   300
moel@86
   301
    private void timer_Tick(object sender, EventArgs e) {
moel@110
   302
      computer.Accept(updateVisitor);
moel@1
   303
      treeView.Invalidate();
moel@1
   304
      plotPanel.Invalidate();
moel@133
   305
      systemTray.Redraw();
moel@1
   306
    }
moel@1
   307
moel@128
   308
    private void SaveConfiguration() {
moel@14
   309
      if (WindowState != FormWindowState.Minimized) {
moel@28
   310
        Config.Set("mainForm.Location.X", Location.X);
moel@28
   311
        Config.Set("mainForm.Location.Y", Location.Y);
moel@156
   312
        Config.Set("mainForm.Width", ClientSize.Width);
moel@156
   313
        Config.Set("mainForm.Height", ClientSize.Height);
moel@14
   314
      }
moel@86
   315
moel@128
   316
      foreach (TreeColumn column in treeView.Columns)
moel@128
   317
        Config.Set("treeView.Columns." + column.Header + ".Width",
moel@113
   318
          column.Width);
moel@113
   319
moel@128
   320
      Config.Save();
moel@128
   321
    }
moel@128
   322
moel@128
   323
    private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
moel@156
   324
      Visible = false;
moel@128
   325
      SaveConfiguration();
moel@128
   326
moel@86
   327
      timer.Enabled = false;
moel@133
   328
      systemTray.Dispose();      
moel@28
   329
      computer.Close();
moel@1
   330
    }
moel@1
   331
moel@156
   332
    private void aboutMenuItem_Click(object sender, EventArgs e) {
moel@1
   333
      new AboutBox().ShowDialog();
moel@1
   334
    }
moel@1
   335
moel@1
   336
    private void treeView_Click(object sender, EventArgs e) {
moel@1
   337
      
moel@1
   338
      MouseEventArgs m = e as MouseEventArgs;
moel@1
   339
      if (m == null || m.Button != MouseButtons.Right)
moel@1
   340
        return;
moel@1
   341
moel@1
   342
      NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
moel@156
   343
      treeView.SelectedNode = info.Node;
moel@156
   344
      if (info.Node != null) {
moel@40
   345
        SensorNode node = info.Node.Tag as SensorNode;
moel@40
   346
        if (node != null && node.Sensor != null) {
moel@156
   347
          sensorContextMenu.MenuItems.Clear();
moel@63
   348
          if (node.Sensor.Parameters.Length > 0) {
moel@156
   349
            MenuItem item = new MenuItem("Parameters...");
moel@63
   350
            item.Click += delegate(object obj, EventArgs args) {
moel@63
   351
              ShowParameterForm(node.Sensor);
moel@63
   352
            };
moel@156
   353
            sensorContextMenu.MenuItems.Add(item);
moel@63
   354
          }
moel@156
   355
          if (nodeTextBoxText.EditEnabled) {
moel@156
   356
            MenuItem item = new MenuItem("Rename");
moel@141
   357
            item.Click += delegate(object obj, EventArgs args) {
moel@156
   358
              nodeTextBoxText.BeginEdit();
moel@141
   359
            };
moel@156
   360
            sensorContextMenu.MenuItems.Add(item);
moel@141
   361
          }          
moel@111
   362
          if (node.IsVisible) {
moel@156
   363
            MenuItem item = new MenuItem("Hide");
moel@111
   364
            item.Click += delegate(object obj, EventArgs args) {
moel@111
   365
              node.IsVisible = false;
moel@111
   366
            };
moel@156
   367
            sensorContextMenu.MenuItems.Add(item);
moel@111
   368
          } else {
moel@156
   369
            MenuItem item = new MenuItem("Unhide");
moel@111
   370
            item.Click += delegate(object obj, EventArgs args) {
moel@111
   371
              node.IsVisible = true;
moel@111
   372
            };
moel@156
   373
            sensorContextMenu.MenuItems.Add(item);
moel@111
   374
          }         
moel@133
   375
          if (systemTray.Contains(node.Sensor)) {
moel@156
   376
            MenuItem item = new MenuItem("Remove From Tray");
moel@40
   377
            item.Click += delegate(object obj, EventArgs args) {
moel@133
   378
              systemTray.Remove(node.Sensor);
moel@40
   379
            };
moel@156
   380
            sensorContextMenu.MenuItems.Add(item);
moel@40
   381
          } else {
moel@156
   382
            MenuItem item = new MenuItem("Add To Tray");
moel@40
   383
            item.Click += delegate(object obj, EventArgs args) {
moel@133
   384
              systemTray.Add(node.Sensor, true);
moel@40
   385
            };
moel@156
   386
            sensorContextMenu.MenuItems.Add(item);
moel@40
   387
          }
moel@156
   388
          sensorContextMenu.Show(treeView, new Point(m.X, m.Y));
moel@40
   389
        }
moel@40
   390
      }
moel@1
   391
    }
moel@1
   392
moel@156
   393
    private void saveReportMenuItem_Click(object sender, EventArgs e) {
moel@83
   394
      string report = computer.GetReport();
moel@83
   395
      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
moel@83
   396
        using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
moel@83
   397
          w.Write(report);
moel@83
   398
        }
moel@83
   399
      }
moel@1
   400
    }
moel@1
   401
moel@82
   402
    private void SysTrayHideShow() {
moel@82
   403
      Visible = !Visible;
moel@82
   404
      if (Visible)
moel@82
   405
        Activate();    
moel@27
   406
    }
moel@27
   407
moel@27
   408
    protected override void WndProc(ref Message m) {
moel@27
   409
      const int WM_SYSCOMMAND = 0x112;
moel@27
   410
      const int SC_MINIMIZE = 0xF020;
moel@156
   411
      if (minimizeToTray.Value && 
moel@28
   412
        m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
moel@82
   413
        SysTrayHideShow();
moel@27
   414
      } else {      
moel@27
   415
        base.WndProc(ref m);
moel@27
   416
      }
moel@27
   417
    }
moel@27
   418
moel@82
   419
    private void hideShowClick(object sender, EventArgs e) {
moel@82
   420
      SysTrayHideShow();
moel@27
   421
    }
moel@27
   422
moel@156
   423
    private void removeMenuItem_Click(object sender, EventArgs e) {
moel@156
   424
      MenuItem item = sender as MenuItem;
moel@40
   425
      if (item == null)
moel@40
   426
        return;
moel@40
   427
moel@156
   428
      ISensor sensor = item.Parent.Tag as ISensor;
moel@40
   429
      if (sensor == null)
moel@40
   430
        return;
moel@40
   431
moel@133
   432
      systemTray.Remove(sensor);
moel@40
   433
    }
moel@63
   434
moel@63
   435
    private void ShowParameterForm(ISensor sensor) {
moel@63
   436
      ParameterForm form = new ParameterForm();
moel@63
   437
      form.Parameters = sensor.Parameters;
moel@63
   438
      form.captionLabel.Text = sensor.Name;
moel@63
   439
      form.ShowDialog();
moel@63
   440
    }
moel@63
   441
moel@63
   442
    private void treeView_NodeMouseDoubleClick(object sender, 
moel@63
   443
      TreeNodeAdvMouseEventArgs e) {
moel@63
   444
      SensorNode node = e.Node.Tag as SensorNode;
moel@63
   445
      if (node != null && node.Sensor != null && 
moel@63
   446
        node.Sensor.Parameters.Length > 0) {
moel@63
   447
        ShowParameterForm(node.Sensor);
moel@63
   448
      }
moel@63
   449
    }
moel@82
   450
moel@156
   451
    private void celciusMenuItem_Click(object sender, EventArgs e) {
moel@156
   452
      celciusMenuItem.Checked = true;
moel@156
   453
      fahrenheitMenuItem.Checked = false;
moel@122
   454
      UnitManager.TemperatureUnit = TemperatureUnit.Celcius;
moel@122
   455
    }
moel@122
   456
moel@156
   457
    private void fahrenheitMenuItem_Click(object sender, EventArgs e) {
moel@156
   458
      celciusMenuItem.Checked = false;
moel@156
   459
      fahrenheitMenuItem.Checked = true;
moel@122
   460
      UnitManager.TemperatureUnit = TemperatureUnit.Fahrenheit;
moel@122
   461
    }
moel@150
   462
moel@156
   463
    private void sumbitReportMenuItem_Click(object sender, EventArgs e) 
moel@150
   464
    {
moel@150
   465
      ReportForm form = new ReportForm();
moel@150
   466
      form.Report = computer.GetReport();
moel@150
   467
      form.ShowDialog();      
moel@150
   468
    }
moel@151
   469
moel@151
   470
    private void resetMinMaxMenuItem_Click(object sender, EventArgs e) {
moel@159
   471
      computer.Accept(new SensorVisitor(delegate(ISensor sensor) {
moel@159
   472
        sensor.ResetMin();
moel@159
   473
        sensor.ResetMax();
moel@159
   474
      }));
moel@151
   475
    }
moel@1
   476
  }
moel@1
   477
}