GUI/MainForm.cs
author StephaneLenclud
Thu, 18 Apr 2013 23:25:10 +0200
branchMiniDisplay
changeset 444 9b09e2ee0968
parent 442 782b48689513
child 445 fe4c711fd7f8
permissions -rw-r--r--
Front View plug-in does not init if no sensor added.
Fixing some format to make strings shorter.
Now trying to start SoundGraphAccess.exe process from same directory.
Packed mode now can display three sensors along with the current time.
moel@1
     1
/*
moel@344
     2
 
moel@344
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@344
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@344
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@344
     6
 
moel@395
     7
  Copyright (C) 2009-2013 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344
     8
	Copyright (C) 2010 Paul Werelds <paul@werelds.net>
moel@348
     9
	Copyright (C) 2012 Prince Samuel <prince.samuel@gmail.com>
moel@1
    10
moel@1
    11
*/
moel@1
    12
moel@1
    13
using System;
moel@1
    14
using System.Collections.Generic;
moel@360
    15
using System.Collections.ObjectModel;
moel@1
    16
using System.ComponentModel;
moel@1
    17
using System.Drawing;
moel@83
    18
using System.IO;
moel@291
    19
using System.Reflection;
moel@1
    20
using System.Windows.Forms;
StephaneLenclud@434
    21
using System.Windows;
moel@1
    22
using Aga.Controls.Tree;
moel@1
    23
using Aga.Controls.Tree.NodeControls;
moel@1
    24
using OpenHardwareMonitor.Hardware;
paulwerelds@227
    25
using OpenHardwareMonitor.WMI;
moel@348
    26
using OpenHardwareMonitor.Utilities;
moel@1
    27
StephaneLenclud@435
    28
moel@1
    29
namespace OpenHardwareMonitor.GUI {
moel@1
    30
  public partial class MainForm : Form {
moel@1
    31
moel@165
    32
    private PersistentSettings settings;
moel@165
    33
    private UnitManager unitManager;
moel@165
    34
    private Computer computer;
moel@1
    35
    private Node root;
moel@1
    36
    private TreeModel treeModel;
moel@1
    37
    private IDictionary<ISensor, Color> sensorPlotColors = 
moel@1
    38
      new Dictionary<ISensor, Color>();
moel@1
    39
    private Color[] plotColorPalette;
StephaneLenclud@433
    40
    private SystemTray systemTray;
StephaneLenclud@433
    41
    private SoundGraphDisplay soundGraphDisplay;
StephaneLenclud@436
    42
    private bool displayTick;
moel@82
    43
    private StartupManager startupManager = new StartupManager();
moel@110
    44
    private UpdateVisitor updateVisitor = new UpdateVisitor();
moel@176
    45
    private SensorGadget gadget;
moel@295
    46
    private Form plotForm;
moel@326
    47
    private PlotPanel plotPanel;
moel@1
    48
moel@156
    49
    private UserOption showHiddenSensors;
moel@156
    50
    private UserOption showPlot;
moel@156
    51
    private UserOption showValue;
moel@156
    52
    private UserOption showMin;
moel@156
    53
    private UserOption showMax;
moel@156
    54
    private UserOption startMinimized;
moel@156
    55
    private UserOption minimizeToTray;
paulwerelds@198
    56
    private UserOption minimizeOnClose;
moel@156
    57
    private UserOption autoStart;
StephaneLenclud@441
    58
    private UserOption frontViewPacked; //Tells whether FrontView should cycle or pack sensors
StephaneLenclud@441
    59
    private UserOption frontViewDisplayTime; //Tells whether or not FrontView should display current time
moel@360
    60
moel@360
    61
    private UserOption readMainboardSensors;
moel@360
    62
    private UserOption readCpuSensors;
moel@370
    63
    private UserOption readRamSensors;
moel@360
    64
    private UserOption readGpuSensors;
moel@360
    65
    private UserOption readFanControllersSensors;
moel@156
    66
    private UserOption readHddSensors;
moel@360
    67
moel@176
    68
    private UserOption showGadget;
moel@295
    69
    private UserRadioGroup plotLocation;
moel@348
    70
    private WmiProvider wmiProvider;
paulwerelds@223
    71
moel@348
    72
    private UserOption runWebServer;
moel@348
    73
    private HttpServer server;
moel@156
    74
moel@420
    75
    private UserOption logSensors;
moel@422
    76
    private UserRadioGroup loggingInterval;
moel@420
    77
    private Logger logger;
moel@420
    78
moel@288
    79
    private bool selectionDragging = false;
moel@288
    80
moel@28
    81
    public MainForm() {      
moel@1
    82
      InitializeComponent();
moel@156
    83
moel@291
    84
      // check if the OpenHardwareMonitorLib assembly has the correct version
moel@291
    85
      if (Assembly.GetAssembly(typeof(Computer)).GetName().Version !=
moel@291
    86
        Assembly.GetExecutingAssembly().GetName().Version) {
moel@291
    87
        MessageBox.Show(
moel@291
    88
          "The version of the file OpenHardwareMonitorLib.dll is incompatible.",
moel@291
    89
          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@291
    90
        Environment.Exit(0);
moel@291
    91
      }
moel@291
    92
moel@165
    93
      this.settings = new PersistentSettings();      
moel@165
    94
      this.settings.Load(Path.ChangeExtension(
paulwerelds@198
    95
        Application.ExecutablePath, ".config"));
moel@165
    96
moel@165
    97
      this.unitManager = new UnitManager(settings);
moel@165
    98
moel@304
    99
      // make sure the buffers used for double buffering are not disposed 
moel@304
   100
      // after each draw call
moel@304
   101
      BufferedGraphicsManager.Current.MaximumBuffer =
moel@304
   102
        Screen.PrimaryScreen.Bounds.Size;  
moel@304
   103
moel@156
   104
      // set the DockStyle here, to avoid conflicts with the MainMenu
moel@156
   105
      this.splitContainer.Dock = DockStyle.Fill;
moel@202
   106
            
moel@1
   107
      this.Font = SystemFonts.MessageBoxFont;
moel@1
   108
      treeView.Font = SystemFonts.MessageBoxFont;
moel@326
   109
moel@400
   110
      plotPanel = new PlotPanel(settings, unitManager);
moel@326
   111
      plotPanel.Font = SystemFonts.MessageBoxFont;
moel@326
   112
      plotPanel.Dock = DockStyle.Fill;
moel@1
   113
      
moel@133
   114
      nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
moel@133
   115
      nodeTextBoxText.DrawText += nodeTextBoxText_DrawText;
moel@133
   116
      nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText;
moel@133
   117
      nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText;
moel@133
   118
      nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
moel@141
   119
      nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;
moel@1
   120
moel@113
   121
      foreach (TreeColumn column in treeView.Columns) 
moel@165
   122
        column.Width = Math.Max(20, Math.Min(400,
moel@166
   123
          settings.GetValue("treeView.Columns." + column.Header + ".Width",
moel@113
   124
          column.Width)));
moel@113
   125
moel@1
   126
      treeModel = new TreeModel();
moel@1
   127
      root = new Node(System.Environment.MachineName);
moel@1
   128
      root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
moel@1
   129
      
moel@1
   130
      treeModel.Nodes.Add(root);
moel@165
   131
      treeView.Model = treeModel;
moel@40
   132
moel@165
   133
      this.computer = new Computer(settings);
moel@165
   134
moel@362
   135
      systemTray = new SystemTray(computer, settings, unitManager);
moel@133
   136
      systemTray.HideShowCommand += hideShowClick;
moel@133
   137
      systemTray.ExitCommand += exitClick;
StephaneLenclud@433
   138
  
StephaneLenclud@434
   139
      soundGraphDisplay = new SoundGraphDisplay(computer, settings, unitManager);
StephaneLenclud@434
   140
 
moel@1
   141
moel@202
   142
      int p = (int)Environment.OSVersion.Platform;
moel@202
   143
      if ((p == 4) || (p == 128)) { // Unix
moel@287
   144
        treeView.RowHeight = Math.Max(treeView.RowHeight, 18); 
moel@202
   145
        splitContainer.BorderStyle = BorderStyle.None;
moel@202
   146
        splitContainer.Border3DStyle = Border3DStyle.Adjust;
moel@202
   147
        splitContainer.SplitterWidth = 4;
moel@202
   148
        treeView.BorderStyle = BorderStyle.Fixed3D;
moel@202
   149
        plotPanel.BorderStyle = BorderStyle.Fixed3D;
moel@202
   150
        gadgetMenuItem.Visible = false;
moel@202
   151
        minCloseMenuItem.Visible = false;
moel@269
   152
        minTrayMenuItem.Visible = false;
moel@269
   153
        startMinMenuItem.Visible = false;
moel@202
   154
      } else { // Windows
moel@287
   155
        treeView.RowHeight = Math.Max(treeView.Font.Height + 1, 18); 
moel@267
   156
moel@202
   157
        gadget = new SensorGadget(computer, settings, unitManager);
moel@244
   158
        gadget.HideShowCommand += hideShowClick;
moel@244
   159
moel@232
   160
        wmiProvider = new WmiProvider(computer);
moel@327
   161
      }
moel@86
   162
moel@421
   163
      logger = new Logger(computer);
moel@421
   164
moel@111
   165
      plotColorPalette = new Color[13];
moel@1
   166
      plotColorPalette[0] = Color.Blue;
moel@1
   167
      plotColorPalette[1] = Color.OrangeRed;
moel@1
   168
      plotColorPalette[2] = Color.Green;
moel@1
   169
      plotColorPalette[3] = Color.LightSeaGreen;
moel@1
   170
      plotColorPalette[4] = Color.Goldenrod;
moel@1
   171
      plotColorPalette[5] = Color.DarkViolet;
moel@1
   172
      plotColorPalette[6] = Color.YellowGreen;
moel@1
   173
      plotColorPalette[7] = Color.SaddleBrown;
moel@111
   174
      plotColorPalette[8] = Color.RoyalBlue;
moel@111
   175
      plotColorPalette[9] = Color.DeepPink;
moel@111
   176
      plotColorPalette[10] = Color.MediumSeaGreen;
moel@111
   177
      plotColorPalette[11] = Color.Olive;
moel@111
   178
      plotColorPalette[12] = Color.Firebrick;
moel@327
   179
      
moel@327
   180
      computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
moel@327
   181
      computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);        
moel@327
   182
moel@327
   183
      computer.Open();
moel@327
   184
moel@327
   185
      timer.Enabled = true;
moel@1
   186
paulwerelds@223
   187
      showHiddenSensors = new UserOption("hiddenMenuItem", false,
paulwerelds@223
   188
        hiddenMenuItem, settings);
moel@156
   189
      showHiddenSensors.Changed += delegate(object sender, EventArgs e) {
moel@156
   190
        treeModel.ForceVisible = showHiddenSensors.Value;
moel@156
   191
      };
moel@111
   192
paulwerelds@223
   193
      showValue = new UserOption("valueMenuItem", true, valueMenuItem,
paulwerelds@223
   194
        settings);
moel@156
   195
      showValue.Changed += delegate(object sender, EventArgs e) {
moel@156
   196
        treeView.Columns[1].IsVisible = showValue.Value;
moel@156
   197
      };
moel@122
   198
moel@165
   199
      showMin = new UserOption("minMenuItem", false, minMenuItem, settings);
moel@156
   200
      showMin.Changed += delegate(object sender, EventArgs e) {
moel@156
   201
        treeView.Columns[2].IsVisible = showMin.Value;
moel@156
   202
      };
moel@156
   203
moel@165
   204
      showMax = new UserOption("maxMenuItem", true, maxMenuItem, settings);
moel@156
   205
      showMax.Changed += delegate(object sender, EventArgs e) {
moel@156
   206
        treeView.Columns[3].IsVisible = showMax.Value;
moel@156
   207
      };
moel@156
   208
paulwerelds@223
   209
      startMinimized = new UserOption("startMinMenuItem", false,
paulwerelds@223
   210
        startMinMenuItem, settings);
moel@156
   211
paulwerelds@223
   212
      minimizeToTray = new UserOption("minTrayMenuItem", true,
paulwerelds@223
   213
        minTrayMenuItem, settings);
moel@156
   214
      minimizeToTray.Changed += delegate(object sender, EventArgs e) {
moel@156
   215
        systemTray.IsMainIconEnabled = minimizeToTray.Value;
moel@156
   216
      };
moel@156
   217
paulwerelds@223
   218
      minimizeOnClose = new UserOption("minCloseMenuItem", false,
paulwerelds@223
   219
        minCloseMenuItem, settings);
paulwerelds@198
   220
paulwerelds@223
   221
      autoStart = new UserOption(null, startupManager.Startup,
paulwerelds@223
   222
        startupMenuItem, settings);
moel@156
   223
      autoStart.Changed += delegate(object sender, EventArgs e) {
moel@185
   224
        try {
moel@185
   225
          startupManager.Startup = autoStart.Value;
moel@185
   226
        } catch (InvalidOperationException) {
moel@185
   227
          MessageBox.Show("Updating the auto-startup option failed.", "Error", 
moel@185
   228
            MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@185
   229
          autoStart.Value = startupManager.Startup;
moel@185
   230
        }
moel@156
   231
      };
moel@156
   232
StephaneLenclud@441
   233
      frontViewPacked = new UserOption("frontViewPackedMenuItem", false, frontViewPackedMenuItem, settings);
StephaneLenclud@441
   234
      frontViewDisplayTime = new UserOption("frontViewDisplayTimeMenuItem", false, frontViewDisplayTimeMenuItem, settings);
StephaneLenclud@441
   235
moel@360
   236
      readMainboardSensors = new UserOption("mainboardMenuItem", true, 
moel@360
   237
        mainboardMenuItem, settings);
moel@360
   238
      readMainboardSensors.Changed += delegate(object sender, EventArgs e) {
moel@360
   239
        computer.MainboardEnabled = readMainboardSensors.Value;
moel@360
   240
      };
moel@360
   241
moel@360
   242
      readCpuSensors = new UserOption("cpuMenuItem", true,
moel@360
   243
        cpuMenuItem, settings);
moel@360
   244
      readCpuSensors.Changed += delegate(object sender, EventArgs e) {
moel@360
   245
        computer.CPUEnabled = readCpuSensors.Value;
moel@360
   246
      };
moel@360
   247
moel@370
   248
      readRamSensors = new UserOption("ramMenuItem", true,
moel@370
   249
        ramMenuItem, settings);
moel@370
   250
      readRamSensors.Changed += delegate(object sender, EventArgs e) {
moel@370
   251
        computer.RAMEnabled = readRamSensors.Value;
moel@370
   252
      };
moel@370
   253
moel@360
   254
      readGpuSensors = new UserOption("gpuMenuItem", true,
moel@360
   255
        gpuMenuItem, settings);
moel@360
   256
      readGpuSensors.Changed += delegate(object sender, EventArgs e) {
moel@360
   257
        computer.GPUEnabled = readGpuSensors.Value;
moel@360
   258
      };
moel@360
   259
moel@360
   260
      readFanControllersSensors = new UserOption("fanControllerMenuItem", true,
moel@360
   261
        fanControllerMenuItem, settings);
moel@360
   262
      readFanControllersSensors.Changed += delegate(object sender, EventArgs e) {
moel@360
   263
        computer.FanControllerEnabled = readFanControllersSensors.Value;
moel@360
   264
      };
moel@360
   265
paulwerelds@223
   266
      readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem,
paulwerelds@223
   267
        settings);
moel@156
   268
      readHddSensors.Changed += delegate(object sender, EventArgs e) {
moel@156
   269
        computer.HDDEnabled = readHddSensors.Value;
moel@156
   270
      };
moel@156
   271
paulwerelds@223
   272
      showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem,
paulwerelds@223
   273
        settings);
moel@176
   274
      showGadget.Changed += delegate(object sender, EventArgs e) {
moel@202
   275
        if (gadget != null) 
moel@202
   276
          gadget.Visible = showGadget.Value;
moel@176
   277
      };
moel@176
   278
moel@299
   279
      celsiusMenuItem.Checked = 
moel@299
   280
        unitManager.TemperatureUnit == TemperatureUnit.Celsius;
moel@299
   281
      fahrenheitMenuItem.Checked = !celsiusMenuItem.Checked;
moel@55
   282
moel@348
   283
      server = new HttpServer(root, this.settings.GetValue("listenerPort", 8085));
moel@387
   284
      if (server.PlatformNotSupported) {
moel@387
   285
        webMenuItemSeparator.Visible = false;
moel@387
   286
        webMenuItem.Visible = false;
moel@387
   287
      }
moel@387
   288
moel@348
   289
      runWebServer = new UserOption("runWebServerMenuItem", false,
moel@348
   290
        runWebServerMenuItem, settings);
moel@360
   291
      runWebServer.Changed += delegate(object sender, EventArgs e) {
moel@360
   292
        if (runWebServer.Value)
moel@387
   293
          server.StartHTTPListener();
moel@360
   294
        else
moel@386
   295
          server.StopHTTPListener();
moel@348
   296
      };
moel@348
   297
moel@420
   298
      logSensors = new UserOption("logSensorsMenuItem", false, logSensorsMenuItem,
moel@422
   299
        settings);
moel@422
   300
moel@422
   301
      loggingInterval = new UserRadioGroup("loggingInterval", 0,
moel@422
   302
        new[] { log1sMenuItem, log2sMenuItem, log5sMenuItem, log10sMenuItem,
moel@422
   303
        log30sMenuItem, log1minMenuItem, log2minMenuItem, log5minMenuItem, 
moel@422
   304
        log10minMenuItem, log30minMenuItem, log1hMenuItem, log2hMenuItem, 
moel@422
   305
        log6hMenuItem},
moel@422
   306
        settings);
moel@422
   307
      loggingInterval.Changed += (sender, e) => {
moel@422
   308
        switch (loggingInterval.Value) {
moel@422
   309
          case 0: logger.LoggingInterval = new TimeSpan(0, 0, 1); break;
moel@422
   310
          case 1: logger.LoggingInterval = new TimeSpan(0, 0, 2); break;
moel@422
   311
          case 2: logger.LoggingInterval = new TimeSpan(0, 0, 5); break;
moel@422
   312
          case 3: logger.LoggingInterval = new TimeSpan(0, 0, 10); break;
moel@422
   313
          case 4: logger.LoggingInterval = new TimeSpan(0, 0, 30); break;
moel@422
   314
          case 5: logger.LoggingInterval = new TimeSpan(0, 1, 0); break;
moel@422
   315
          case 6: logger.LoggingInterval = new TimeSpan(0, 2, 0); break;
moel@422
   316
          case 7: logger.LoggingInterval = new TimeSpan(0, 5, 0); break;
moel@422
   317
          case 8: logger.LoggingInterval = new TimeSpan(0, 10, 0); break;
moel@422
   318
          case 9: logger.LoggingInterval = new TimeSpan(0, 30, 0); break;
moel@422
   319
          case 10: logger.LoggingInterval = new TimeSpan(1, 0, 0); break;
moel@422
   320
          case 11: logger.LoggingInterval = new TimeSpan(2, 0, 0); break;
moel@422
   321
          case 12: logger.LoggingInterval = new TimeSpan(6, 0, 0); break;
moel@422
   322
        }
moel@422
   323
      };
moel@420
   324
moel@295
   325
      InitializePlotForm();
moel@295
   326
moel@142
   327
      startupMenuItem.Visible = startupManager.IsAvailable;
moel@125
   328
      
moel@55
   329
      if (startMinMenuItem.Checked) {
moel@82
   330
        if (!minTrayMenuItem.Checked) {
moel@55
   331
          WindowState = FormWindowState.Minimized;
moel@55
   332
          Show();
moel@55
   333
        }
moel@55
   334
      } else {
moel@55
   335
        Show();
moel@55
   336
      }
moel@70
   337
moel@71
   338
      // Create a handle, otherwise calling Close() does not fire FormClosed     
moel@71
   339
      IntPtr handle = Handle;
moel@128
   340
moel@128
   341
      // Make sure the settings are saved when the user logs off
paulwerelds@223
   342
      Microsoft.Win32.SystemEvents.SessionEnded += delegate {
moel@380
   343
        computer.Close();
paulwerelds@223
   344
        SaveConfiguration();
moel@348
   345
        if (runWebServer.Value) 
moel@387
   346
          server.Quit();
moel@304
   347
      };
moel@1
   348
    }
moel@295
   349
moel@295
   350
    private void InitializePlotForm() {
moel@295
   351
      plotForm = new Form();
moel@295
   352
      plotForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
moel@295
   353
      plotForm.ShowInTaskbar = false;
moel@295
   354
      plotForm.StartPosition = FormStartPosition.Manual;
moel@295
   355
      this.AddOwnedForm(plotForm);
moel@295
   356
      plotForm.Bounds = new Rectangle {
moel@295
   357
        X = settings.GetValue("plotForm.Location.X", -100000),
moel@295
   358
        Y = settings.GetValue("plotForm.Location.Y", 100),
moel@295
   359
        Width = settings.GetValue("plotForm.Width", 600),
moel@295
   360
        Height = settings.GetValue("plotForm.Height", 400)
moel@295
   361
      };
moel@295
   362
moel@295
   363
      showPlot = new UserOption("plotMenuItem", false, plotMenuItem, settings);
moel@295
   364
      plotLocation = new UserRadioGroup("plotLocation", 0,
moel@295
   365
        new[] { plotWindowMenuItem, plotBottomMenuItem, plotRightMenuItem },
moel@295
   366
        settings);
moel@295
   367
moel@295
   368
      showPlot.Changed += delegate(object sender, EventArgs e) {
moel@295
   369
        if (plotLocation.Value == 0) {
moel@295
   370
          if (showPlot.Value && this.Visible)
moel@295
   371
            plotForm.Show();
moel@295
   372
          else
moel@295
   373
            plotForm.Hide();
moel@295
   374
        } else {
moel@295
   375
          splitContainer.Panel2Collapsed = !showPlot.Value;
moel@295
   376
        }
moel@295
   377
        treeView.Invalidate();
moel@295
   378
      };
moel@295
   379
      plotLocation.Changed += delegate(object sender, EventArgs e) {
moel@295
   380
        switch (plotLocation.Value) {
moel@295
   381
          case 0:
moel@295
   382
            splitContainer.Panel2.Controls.Clear();
moel@295
   383
            splitContainer.Panel2Collapsed = true;
moel@295
   384
            plotForm.Controls.Add(plotPanel);
moel@295
   385
            if (showPlot.Value && this.Visible)
moel@295
   386
              plotForm.Show();
moel@295
   387
            break;
moel@295
   388
          case 1:
moel@295
   389
            plotForm.Controls.Clear();
moel@295
   390
            plotForm.Hide();
moel@295
   391
            splitContainer.Orientation = Orientation.Horizontal;
moel@295
   392
            splitContainer.Panel2.Controls.Add(plotPanel);
moel@295
   393
            splitContainer.Panel2Collapsed = !showPlot.Value;
moel@295
   394
            break;
moel@295
   395
          case 2:
moel@295
   396
            plotForm.Controls.Clear();
moel@295
   397
            plotForm.Hide();
moel@295
   398
            splitContainer.Orientation = Orientation.Vertical;
moel@295
   399
            splitContainer.Panel2.Controls.Add(plotPanel);
moel@295
   400
            splitContainer.Panel2Collapsed = !showPlot.Value;
moel@295
   401
            break;
moel@295
   402
        }
moel@295
   403
      };
moel@297
   404
moel@297
   405
      plotForm.FormClosing += delegate(object sender, FormClosingEventArgs e) {
moel@297
   406
        if (e.CloseReason == CloseReason.UserClosing) {
moel@297
   407
          // just switch off the plotting when the user closes the form
moel@297
   408
          if (plotLocation.Value == 0) {
moel@297
   409
            showPlot.Value = false;
moel@297
   410
          }
moel@297
   411
          e.Cancel = true;
moel@295
   412
        }
moel@295
   413
      };
moel@297
   414
moel@295
   415
      EventHandler moveOrResizePlotForm = delegate(object sender, EventArgs e) {
moel@295
   416
        if (plotForm.WindowState != FormWindowState.Minimized) {
moel@295
   417
          settings.SetValue("plotForm.Location.X", plotForm.Bounds.X);
moel@295
   418
          settings.SetValue("plotForm.Location.Y", plotForm.Bounds.Y);
moel@295
   419
          settings.SetValue("plotForm.Width", plotForm.Bounds.Width);
moel@295
   420
          settings.SetValue("plotForm.Height", plotForm.Bounds.Height);
moel@295
   421
        }
moel@295
   422
      };
moel@295
   423
      plotForm.Move += moveOrResizePlotForm;
moel@295
   424
      plotForm.Resize += moveOrResizePlotForm;
moel@295
   425
moel@295
   426
      plotForm.VisibleChanged += delegate(object sender, EventArgs e) {
moel@295
   427
        Rectangle bounds = new Rectangle(plotForm.Location, plotForm.Size);
moel@295
   428
        Screen screen = Screen.FromRectangle(bounds);
moel@295
   429
        Rectangle intersection =
moel@295
   430
          Rectangle.Intersect(screen.WorkingArea, bounds);
moel@295
   431
        if (intersection.Width < Math.Min(16, bounds.Width) ||
moel@295
   432
            intersection.Height < Math.Min(16, bounds.Height)) {
moel@295
   433
          plotForm.Location = new Point(
moel@295
   434
            screen.WorkingArea.Width / 2 - bounds.Width / 2,
moel@295
   435
            screen.WorkingArea.Height / 2 - bounds.Height / 2);
moel@295
   436
        }
moel@295
   437
      };
moel@295
   438
moel@295
   439
      this.VisibleChanged += delegate(object sender, EventArgs e) {
moel@295
   440
        if (this.Visible && showPlot.Value && plotLocation.Value == 0)
moel@295
   441
          plotForm.Show();
moel@295
   442
        else
moel@295
   443
          plotForm.Hide();
moel@295
   444
      };
moel@295
   445
    }
moel@360
   446
moel@360
   447
    private void InsertSorted(Collection<Node> nodes, HardwareNode node) {
moel@360
   448
      int i = 0;
moel@360
   449
      while (i < nodes.Count && nodes[i] is HardwareNode &&
moel@360
   450
        ((HardwareNode)nodes[i]).Hardware.HardwareType < 
moel@360
   451
          node.Hardware.HardwareType)
moel@360
   452
        i++;
moel@360
   453
      nodes.Insert(i, node);
moel@360
   454
    }
moel@128
   455
    
moel@64
   456
    private void SubHardwareAdded(IHardware hardware, Node node) {
moel@327
   457
      HardwareNode hardwareNode = 
moel@327
   458
        new HardwareNode(hardware, settings, unitManager);
moel@327
   459
      hardwareNode.PlotSelectionChanged += PlotSelectionChanged;
moel@327
   460
moel@360
   461
      InsertSorted(node.Nodes, hardwareNode);
moel@360
   462
moel@64
   463
      foreach (IHardware subHardware in hardware.SubHardware)
moel@64
   464
        SubHardwareAdded(subHardware, hardwareNode);  
moel@64
   465
    }
moel@64
   466
moel@327
   467
    private void HardwareAdded(IHardware hardware) {      
moel@327
   468
      SubHardwareAdded(hardware, root);
moel@327
   469
      PlotSelectionChanged(this, null);
moel@1
   470
    }
moel@1
   471
moel@327
   472
    private void HardwareRemoved(IHardware hardware) {
moel@327
   473
      List<HardwareNode> nodesToRemove = new List<HardwareNode>();
moel@28
   474
      foreach (Node node in root.Nodes) {
moel@28
   475
        HardwareNode hardwareNode = node as HardwareNode;
moel@28
   476
        if (hardwareNode != null && hardwareNode.Hardware == hardware)
moel@327
   477
          nodesToRemove.Add(hardwareNode);
moel@28
   478
      }
moel@327
   479
      foreach (HardwareNode hardwareNode in nodesToRemove) {
moel@327
   480
        root.Nodes.Remove(hardwareNode);
moel@327
   481
        hardwareNode.PlotSelectionChanged -= PlotSelectionChanged;
moel@327
   482
      }
moel@327
   483
      PlotSelectionChanged(this, null);
moel@1
   484
    }
moel@1
   485
moel@111
   486
    private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {       
moel@111
   487
      Node node = e.Node.Tag as Node;
moel@111
   488
      if (node != null) {
moel@1
   489
        Color color;
moel@111
   490
        if (node.IsVisible) {
moel@111
   491
          SensorNode sensorNode = node as SensorNode;
moel@111
   492
          if (plotMenuItem.Checked && sensorNode != null &&
moel@111
   493
            sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
moel@111
   494
            e.TextColor = color;
StephaneLenclud@440
   495
StephaneLenclud@440
   496
          //If displayed in FrontView draw background in green
StephaneLenclud@440
   497
          if (sensorNode != null && settings.GetValue(new Identifier(sensorNode.Sensor.Identifier, "FrontView").ToString(), false))
StephaneLenclud@440
   498
          {
StephaneLenclud@440
   499
              SolidBrush greenBrush = new SolidBrush(Color.FromName("mediumspringgreen"));
StephaneLenclud@440
   500
              e.BackgroundBrush = greenBrush;
StephaneLenclud@440
   501
          }
moel@111
   502
        } else {
StephaneLenclud@440
   503
moel@111
   504
          e.TextColor = Color.DarkGray;
moel@111
   505
        }
moel@1
   506
      }
moel@1
   507
    }
moel@1
   508
moel@327
   509
    private void PlotSelectionChanged(object sender, EventArgs e) {
moel@1
   510
      List<ISensor> selected = new List<ISensor>();
moel@1
   511
      IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
moel@1
   512
      int colorIndex = 0;
moel@1
   513
      foreach (TreeNodeAdv node in treeView.AllNodes) {
moel@1
   514
        SensorNode sensorNode = node.Tag as SensorNode;
moel@395
   515
        if (sensorNode != null) {
moel@1
   516
          if (sensorNode.Plot) {
moel@1
   517
            colors.Add(sensorNode.Sensor,
moel@1
   518
              plotColorPalette[colorIndex % plotColorPalette.Length]);
moel@1
   519
            selected.Add(sensorNode.Sensor);
moel@1
   520
          }
moel@1
   521
          colorIndex++;
moel@1
   522
        }
moel@1
   523
      }
moel@1
   524
      sensorPlotColors = colors;
moel@1
   525
      plotPanel.SetSensors(selected, colors);
moel@1
   526
    }
moel@1
   527
paulwerelds@223
   528
    private void nodeTextBoxText_EditorShowing(object sender,
paulwerelds@223
   529
      CancelEventArgs e) 
moel@141
   530
    {
moel@141
   531
      e.Cancel = !(treeView.CurrentNode != null &&
moel@275
   532
        (treeView.CurrentNode.Tag is SensorNode || 
moel@275
   533
         treeView.CurrentNode.Tag is HardwareNode));
moel@141
   534
    }
moel@141
   535
moel@1
   536
    private void nodeCheckBox_IsVisibleValueNeeded(object sender, 
moel@1
   537
      NodeControlValueEventArgs e) {
moel@1
   538
      SensorNode node = e.Node.Tag as SensorNode;
moel@395
   539
      e.Value = (node != null) && plotMenuItem.Checked;
moel@1
   540
    }
moel@1
   541
moel@133
   542
    private void exitClick(object sender, EventArgs e) {
paulwerelds@198
   543
      Close();
moel@1
   544
    }
moel@1
   545
moel@421
   546
    private int delayCount = 0;
moel@86
   547
    private void timer_Tick(object sender, EventArgs e) {
moel@110
   548
      computer.Accept(updateVisitor);
moel@1
   549
      treeView.Invalidate();
moel@395
   550
      plotPanel.InvalidatePlot();
paulwerelds@223
   551
      systemTray.Redraw();
moel@202
   552
      if (gadget != null)
moel@202
   553
        gadget.Redraw();
paulwerelds@223
   554
paulwerelds@223
   555
      if (wmiProvider != null)
paulwerelds@223
   556
        wmiProvider.Update();
moel@420
   557
StephaneLenclud@436
   558
      if (soundGraphDisplay != null)
StephaneLenclud@436
   559
      {
StephaneLenclud@442
   560
          soundGraphDisplay.Redraw(frontViewPacked.Value,frontViewDisplayTime.Value);
StephaneLenclud@438
   561
          /*
StephaneLenclud@436
   562
          displayTick=!displayTick;
StephaneLenclud@436
   563
          if (displayTick)
StephaneLenclud@436
   564
          {
StephaneLenclud@436
   565
              soundGraphDisplay.SetText("       ---", "");
StephaneLenclud@436
   566
          }
StephaneLenclud@436
   567
          else
StephaneLenclud@436
   568
          {
StephaneLenclud@436
   569
              soundGraphDisplay.SetText("       -+-", "");
StephaneLenclud@436
   570
          }
StephaneLenclud@438
   571
          */
StephaneLenclud@436
   572
      }  
StephaneLenclud@436
   573
moel@421
   574
moel@431
   575
      if (logSensors != null && logSensors.Value && delayCount >= 4)
moel@420
   576
        logger.Log();
moel@421
   577
moel@421
   578
      if (delayCount < 4)
moel@421
   579
        delayCount++;
moel@1
   580
    }
moel@1
   581
moel@128
   582
    private void SaveConfiguration() {
moel@395
   583
      plotPanel.SetCurrentSettings();
moel@128
   584
      foreach (TreeColumn column in treeView.Columns)
moel@166
   585
        settings.SetValue("treeView.Columns." + column.Header + ".Width",
moel@113
   586
          column.Width);
moel@113
   587
moel@348
   588
      this.settings.SetValue("listenerPort", server.ListenerPort);
moel@348
   589
moel@212
   590
      string fileName = Path.ChangeExtension(
moel@212
   591
          System.Windows.Forms.Application.ExecutablePath, ".config");
moel@212
   592
      try {
moel@212
   593
        settings.Save(fileName);
moel@212
   594
      } catch (UnauthorizedAccessException) {
paulwerelds@214
   595
        MessageBox.Show("Access to the path '" + fileName + "' is denied. " +
moel@284
   596
          "The current settings could not be saved.",
moel@284
   597
          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@284
   598
      } catch (IOException) {
moel@284
   599
        MessageBox.Show("The path '" + fileName + "' is not writeable. " +
moel@284
   600
          "The current settings could not be saved.",
moel@212
   601
          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@212
   602
      }
moel@128
   603
    }
moel@128
   604
paulwerelds@214
   605
    private void MainForm_Load(object sender, EventArgs e) {
paulwerelds@214
   606
      Rectangle newBounds = new Rectangle {
paulwerelds@214
   607
        X = settings.GetValue("mainForm.Location.X", Location.X),
paulwerelds@214
   608
        Y = settings.GetValue("mainForm.Location.Y", Location.Y),
paulwerelds@214
   609
        Width = settings.GetValue("mainForm.Width", 470),
paulwerelds@214
   610
        Height = settings.GetValue("mainForm.Height", 640)
paulwerelds@214
   611
      };
paulwerelds@214
   612
paulwerelds@223
   613
      Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
paulwerelds@214
   614
        int.MinValue, int.MinValue);
paulwerelds@214
   615
paulwerelds@214
   616
      foreach (Screen screen in Screen.AllScreens)
paulwerelds@223
   617
        fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
paulwerelds@214
   618
paulwerelds@223
   619
      Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);
paulwerelds@214
   620
      if (intersection.Width < 20 || intersection.Height < 20 ||
paulwerelds@214
   621
        !settings.Contains("mainForm.Location.X")
paulwerelds@214
   622
      ) {
paulwerelds@214
   623
        newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
paulwerelds@214
   624
                      (newBounds.Width/2);
paulwerelds@214
   625
paulwerelds@214
   626
        newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
paulwerelds@214
   627
                      (newBounds.Height / 2);
paulwerelds@214
   628
      }
paulwerelds@214
   629
paulwerelds@214
   630
      this.Bounds = newBounds;
paulwerelds@214
   631
    }
paulwerelds@214
   632
    
paulwerelds@214
   633
    private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
moel@298
   634
      Visible = false;      
moel@262
   635
      systemTray.IsMainIconEnabled = false;
moel@262
   636
      timer.Enabled = false;            
moel@28
   637
      computer.Close();
moel@298
   638
      SaveConfiguration();
moel@348
   639
      if (runWebServer.Value)
moel@348
   640
          server.Quit();
moel@262
   641
      systemTray.Dispose();
StephaneLenclud@433
   642
      soundGraphDisplay.Dispose();
moel@1
   643
    }
moel@1
   644
moel@156
   645
    private void aboutMenuItem_Click(object sender, EventArgs e) {
moel@1
   646
      new AboutBox().ShowDialog();
moel@1
   647
    }
moel@1
   648
moel@1
   649
    private void treeView_Click(object sender, EventArgs e) {
moel@275
   650
moel@1
   651
      MouseEventArgs m = e as MouseEventArgs;
moel@1
   652
      if (m == null || m.Button != MouseButtons.Right)
moel@1
   653
        return;
moel@1
   654
paulwerelds@223
   655
      NodeControlInfo info = treeView.GetNodeControlInfoAt(
paulwerelds@223
   656
        new Point(m.X, m.Y)
paulwerelds@223
   657
      );
moel@156
   658
      treeView.SelectedNode = info.Node;
moel@156
   659
      if (info.Node != null) {
moel@40
   660
        SensorNode node = info.Node.Tag as SensorNode;
moel@40
   661
        if (node != null && node.Sensor != null) {
moel@275
   662
          treeContextMenu.MenuItems.Clear();
moel@63
   663
          if (node.Sensor.Parameters.Length > 0) {
moel@156
   664
            MenuItem item = new MenuItem("Parameters...");
moel@63
   665
            item.Click += delegate(object obj, EventArgs args) {
moel@63
   666
              ShowParameterForm(node.Sensor);
moel@63
   667
            };
moel@275
   668
            treeContextMenu.MenuItems.Add(item);
moel@63
   669
          }
moel@156
   670
          if (nodeTextBoxText.EditEnabled) {
moel@156
   671
            MenuItem item = new MenuItem("Rename");
moel@141
   672
            item.Click += delegate(object obj, EventArgs args) {
moel@156
   673
              nodeTextBoxText.BeginEdit();
moel@141
   674
            };
moel@275
   675
            treeContextMenu.MenuItems.Add(item);
moel@176
   676
          }
moel@111
   677
          if (node.IsVisible) {
moel@156
   678
            MenuItem item = new MenuItem("Hide");
moel@111
   679
            item.Click += delegate(object obj, EventArgs args) {
moel@111
   680
              node.IsVisible = false;
moel@111
   681
            };
moel@275
   682
            treeContextMenu.MenuItems.Add(item);
moel@111
   683
          } else {
moel@156
   684
            MenuItem item = new MenuItem("Unhide");
moel@111
   685
            item.Click += delegate(object obj, EventArgs args) {
moel@111
   686
              node.IsVisible = true;
moel@111
   687
            };
moel@275
   688
            treeContextMenu.MenuItems.Add(item);
moel@176
   689
          }
moel@275
   690
          treeContextMenu.MenuItems.Add(new MenuItem("-"));
moel@178
   691
          {
moel@178
   692
            MenuItem item = new MenuItem("Show in Tray");
moel@178
   693
            item.Checked = systemTray.Contains(node.Sensor);
moel@178
   694
            item.Click += delegate(object obj, EventArgs args) {
moel@178
   695
              if (item.Checked)
moel@178
   696
                systemTray.Remove(node.Sensor);
moel@178
   697
              else
moel@178
   698
                systemTray.Add(node.Sensor, true);
moel@178
   699
            };
moel@275
   700
            treeContextMenu.MenuItems.Add(item);
moel@178
   701
          }
StephaneLenclud@433
   702
          {
StephaneLenclud@433
   703
              MenuItem item = new MenuItem("Show in iMON FrontView");
StephaneLenclud@438
   704
              item.Checked = soundGraphDisplay.Contains(node.Sensor);
StephaneLenclud@433
   705
              item.Click += delegate(object obj, EventArgs args)
StephaneLenclud@433
   706
              {
StephaneLenclud@433
   707
                  if (item.Checked)
StephaneLenclud@433
   708
                      soundGraphDisplay.Remove(node.Sensor);
StephaneLenclud@433
   709
                  else
StephaneLenclud@433
   710
                      soundGraphDisplay.Add(node.Sensor, true);
StephaneLenclud@433
   711
              };
StephaneLenclud@433
   712
              treeContextMenu.MenuItems.Add(item);
StephaneLenclud@433
   713
          }
moel@211
   714
          if (gadget != null) {
moel@178
   715
            MenuItem item = new MenuItem("Show in Gadget");
moel@178
   716
            item.Checked = gadget.Contains(node.Sensor);
moel@178
   717
            item.Click += delegate(object obj, EventArgs args) {
moel@178
   718
              if (item.Checked) {
moel@178
   719
                gadget.Remove(node.Sensor);
moel@178
   720
              } else {
moel@178
   721
                gadget.Add(node.Sensor);
moel@178
   722
              }
moel@178
   723
            };
moel@275
   724
            treeContextMenu.MenuItems.Add(item);
moel@178
   725
          }
moel@247
   726
          if (node.Sensor.Control != null) {
moel@275
   727
            treeContextMenu.MenuItems.Add(new MenuItem("-"));
moel@247
   728
            IControl control = node.Sensor.Control;
moel@247
   729
            MenuItem controlItem = new MenuItem("Control");
moel@247
   730
            MenuItem defaultItem = new MenuItem("Default");
moel@247
   731
            defaultItem.Checked = control.ControlMode == ControlMode.Default;
moel@247
   732
            controlItem.MenuItems.Add(defaultItem);
moel@247
   733
            defaultItem.Click += delegate(object obj, EventArgs args) {
moel@247
   734
              control.SetDefault();
moel@247
   735
            };
moel@275
   736
            MenuItem manualItem = new MenuItem("Manual");
moel@247
   737
            controlItem.MenuItems.Add(manualItem);
moel@247
   738
            manualItem.Checked = control.ControlMode == ControlMode.Software;
moel@247
   739
            for (int i = 0; i <= 100; i += 5) {
moel@247
   740
              if (i <= control.MaxSoftwareValue &&
moel@275
   741
                  i >= control.MinSoftwareValue) {
moel@247
   742
                MenuItem item = new MenuItem(i + " %");
moel@378
   743
                item.RadioCheck = true;
moel@247
   744
                manualItem.MenuItems.Add(item);
moel@247
   745
                item.Checked = control.ControlMode == ControlMode.Software &&
moel@247
   746
                  Math.Round(control.SoftwareValue) == i;
moel@247
   747
                int softwareValue = i;
moel@247
   748
                item.Click += delegate(object obj, EventArgs args) {
moel@247
   749
                  control.SetSoftware(softwareValue);
moel@247
   750
                };
moel@247
   751
              }
moel@247
   752
            }
moel@275
   753
            treeContextMenu.MenuItems.Add(controlItem);
moel@247
   754
          }
moel@176
   755
moel@275
   756
          treeContextMenu.Show(treeView, new Point(m.X, m.Y));
moel@275
   757
        }
moel@275
   758
moel@275
   759
        HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
moel@275
   760
        if (hardwareNode != null && hardwareNode.Hardware != null) {
moel@275
   761
          treeContextMenu.MenuItems.Clear();
moel@275
   762
moel@275
   763
          if (nodeTextBoxText.EditEnabled) {
moel@275
   764
            MenuItem item = new MenuItem("Rename");
moel@275
   765
            item.Click += delegate(object obj, EventArgs args) {
moel@275
   766
              nodeTextBoxText.BeginEdit();
moel@275
   767
            };
moel@275
   768
            treeContextMenu.MenuItems.Add(item);
moel@275
   769
          }
moel@275
   770
moel@275
   771
          treeContextMenu.Show(treeView, new Point(m.X, m.Y));
moel@40
   772
        }
moel@40
   773
      }
moel@1
   774
    }
moel@1
   775
moel@156
   776
    private void saveReportMenuItem_Click(object sender, EventArgs e) {
moel@83
   777
      string report = computer.GetReport();
moel@83
   778
      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
moel@83
   779
        using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
moel@83
   780
          w.Write(report);
moel@83
   781
        }
moel@83
   782
      }
moel@1
   783
    }
moel@1
   784
moel@82
   785
    private void SysTrayHideShow() {
moel@82
   786
      Visible = !Visible;
moel@82
   787
      if (Visible)
moel@82
   788
        Activate();    
moel@27
   789
    }
moel@27
   790
moel@27
   791
    protected override void WndProc(ref Message m) {
moel@27
   792
      const int WM_SYSCOMMAND = 0x112;
moel@27
   793
      const int SC_MINIMIZE = 0xF020;
paulwerelds@198
   794
      const int SC_CLOSE = 0xF060;
paulwerelds@198
   795
StephaneLenclud@436
   796
 
StephaneLenclud@436
   797
      if (minimizeToTray.Value &&
StephaneLenclud@435
   798
        m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_MINIMIZE)
StephaneLenclud@435
   799
      {
paulwerelds@198
   800
          SysTrayHideShow();
StephaneLenclud@435
   801
      }
StephaneLenclud@435
   802
      else if (minimizeOnClose.Value &&
StephaneLenclud@435
   803
      m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_CLOSE)
StephaneLenclud@435
   804
      {
StephaneLenclud@435
   805
          /*
StephaneLenclud@435
   806
           * Apparently the user wants to minimize rather than close
StephaneLenclud@435
   807
           * Now we still need to check if we're going to the tray or not
StephaneLenclud@435
   808
           * 
StephaneLenclud@435
   809
           * Note: the correct way to do this would be to send out SC_MINIMIZE,
StephaneLenclud@435
   810
           * but since the code here is so simple,
StephaneLenclud@435
   811
           * that would just be a waste of time.
StephaneLenclud@435
   812
           */
StephaneLenclud@435
   813
          if (minimizeToTray.Value)
StephaneLenclud@435
   814
              SysTrayHideShow();
StephaneLenclud@435
   815
          else
StephaneLenclud@435
   816
              WindowState = FormWindowState.Minimized;
StephaneLenclud@435
   817
      }
StephaneLenclud@435
   818
      else
StephaneLenclud@435
   819
      {
StephaneLenclud@435
   820
          base.WndProc(ref m);
moel@27
   821
      }
moel@27
   822
    }
moel@27
   823
moel@82
   824
    private void hideShowClick(object sender, EventArgs e) {
moel@82
   825
      SysTrayHideShow();
moel@27
   826
    }
moel@27
   827
moel@63
   828
    private void ShowParameterForm(ISensor sensor) {
moel@63
   829
      ParameterForm form = new ParameterForm();
moel@63
   830
      form.Parameters = sensor.Parameters;
moel@63
   831
      form.captionLabel.Text = sensor.Name;
moel@63
   832
      form.ShowDialog();
moel@63
   833
    }
moel@63
   834
moel@63
   835
    private void treeView_NodeMouseDoubleClick(object sender, 
moel@63
   836
      TreeNodeAdvMouseEventArgs e) {
moel@63
   837
      SensorNode node = e.Node.Tag as SensorNode;
moel@63
   838
      if (node != null && node.Sensor != null && 
moel@63
   839
        node.Sensor.Parameters.Length > 0) {
moel@63
   840
        ShowParameterForm(node.Sensor);
moel@63
   841
      }
moel@63
   842
    }
moel@82
   843
moel@299
   844
    private void celsiusMenuItem_Click(object sender, EventArgs e) {
moel@299
   845
      celsiusMenuItem.Checked = true;
moel@156
   846
      fahrenheitMenuItem.Checked = false;
moel@299
   847
      unitManager.TemperatureUnit = TemperatureUnit.Celsius;
moel@122
   848
    }
moel@122
   849
moel@156
   850
    private void fahrenheitMenuItem_Click(object sender, EventArgs e) {
moel@299
   851
      celsiusMenuItem.Checked = false;
moel@156
   852
      fahrenheitMenuItem.Checked = true;
moel@165
   853
      unitManager.TemperatureUnit = TemperatureUnit.Fahrenheit;
moel@122
   854
    }
moel@150
   855
moel@156
   856
    private void sumbitReportMenuItem_Click(object sender, EventArgs e) 
moel@150
   857
    {
moel@150
   858
      ReportForm form = new ReportForm();
moel@150
   859
      form.Report = computer.GetReport();
moel@150
   860
      form.ShowDialog();      
moel@150
   861
    }
moel@151
   862
moel@151
   863
    private void resetMinMaxMenuItem_Click(object sender, EventArgs e) {
moel@159
   864
      computer.Accept(new SensorVisitor(delegate(ISensor sensor) {
moel@159
   865
        sensor.ResetMin();
moel@159
   866
        sensor.ResetMax();
moel@159
   867
      }));
moel@151
   868
    }
moel@241
   869
moel@241
   870
    private void MainForm_MoveOrResize(object sender, EventArgs e) {
moel@241
   871
      if (WindowState != FormWindowState.Minimized) {
moel@241
   872
        settings.SetValue("mainForm.Location.X", Bounds.X);
moel@241
   873
        settings.SetValue("mainForm.Location.Y", Bounds.Y);
moel@241
   874
        settings.SetValue("mainForm.Width", Bounds.Width);
moel@241
   875
        settings.SetValue("mainForm.Height", Bounds.Height);
moel@241
   876
      }
moel@241
   877
    }
moel@262
   878
moel@262
   879
    private void resetClick(object sender, EventArgs e) {
moel@262
   880
      // disable the fallback MainIcon during reset, otherwise icon visibility
moel@262
   881
      // might be lost 
moel@262
   882
      systemTray.IsMainIconEnabled = false;
moel@262
   883
      computer.Close();
moel@262
   884
      computer.Open();
moel@262
   885
      // restore the MainIcon setting
moel@262
   886
      systemTray.IsMainIconEnabled = minimizeToTray.Value;
moel@262
   887
    }
moel@287
   888
moel@287
   889
    private void treeView_MouseMove(object sender, MouseEventArgs e) {
moel@288
   890
      selectionDragging = selectionDragging &
moel@288
   891
        (e.Button & (MouseButtons.Left | MouseButtons.Right)) > 0; 
moel@288
   892
moel@288
   893
      if (selectionDragging)
moel@288
   894
        treeView.SelectedNode = treeView.GetNodeAt(e.Location);     
moel@288
   895
    }
moel@288
   896
moel@288
   897
    private void treeView_MouseDown(object sender, MouseEventArgs e) {
moel@288
   898
      selectionDragging = true;
moel@288
   899
    }
moel@288
   900
moel@288
   901
    private void treeView_MouseUp(object sender, MouseEventArgs e) {
moel@288
   902
      selectionDragging = false;
moel@287
   903
    }
moel@348
   904
moel@348
   905
    private void serverPortMenuItem_Click(object sender, EventArgs e) {
moel@348
   906
      new PortForm(this).ShowDialog();
moel@348
   907
    }
moel@348
   908
moel@348
   909
    public HttpServer Server {
moel@348
   910
      get { return server; }
moel@348
   911
    }
moel@348
   912
moel@1
   913
  }
moel@1
   914
}