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