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