GUI/MainForm.cs
author StephaneLenclud
Thu, 18 Apr 2013 19:51:05 +0200
branchMiniDisplay
changeset 443 8c139748f179
parent 441 2a02ad86a776
child 444 9b09e2ee0968
permissions -rw-r--r--
FrontView can now display time when not packed.
Now waiting 4 ticks before cycling.
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
StephaneLenclud@435
   327
StephaneLenclud@436
   328
      soundGraphDisplay.Init();
StephaneLenclud@436
   329
StephaneLenclud@435
   330
StephaneLenclud@435
   331
moel@142
   332
      startupMenuItem.Visible = startupManager.IsAvailable;
moel@125
   333
      
moel@55
   334
      if (startMinMenuItem.Checked) {
moel@82
   335
        if (!minTrayMenuItem.Checked) {
moel@55
   336
          WindowState = FormWindowState.Minimized;
moel@55
   337
          Show();
moel@55
   338
        }
moel@55
   339
      } else {
moel@55
   340
        Show();
moel@55
   341
      }
moel@70
   342
moel@71
   343
      // Create a handle, otherwise calling Close() does not fire FormClosed     
moel@71
   344
      IntPtr handle = Handle;
moel@128
   345
moel@128
   346
      // Make sure the settings are saved when the user logs off
paulwerelds@223
   347
      Microsoft.Win32.SystemEvents.SessionEnded += delegate {
moel@380
   348
        computer.Close();
paulwerelds@223
   349
        SaveConfiguration();
moel@348
   350
        if (runWebServer.Value) 
moel@387
   351
          server.Quit();
moel@304
   352
      };
moel@1
   353
    }
moel@295
   354
moel@295
   355
    private void InitializePlotForm() {
moel@295
   356
      plotForm = new Form();
moel@295
   357
      plotForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
moel@295
   358
      plotForm.ShowInTaskbar = false;
moel@295
   359
      plotForm.StartPosition = FormStartPosition.Manual;
moel@295
   360
      this.AddOwnedForm(plotForm);
moel@295
   361
      plotForm.Bounds = new Rectangle {
moel@295
   362
        X = settings.GetValue("plotForm.Location.X", -100000),
moel@295
   363
        Y = settings.GetValue("plotForm.Location.Y", 100),
moel@295
   364
        Width = settings.GetValue("plotForm.Width", 600),
moel@295
   365
        Height = settings.GetValue("plotForm.Height", 400)
moel@295
   366
      };
moel@295
   367
moel@295
   368
      showPlot = new UserOption("plotMenuItem", false, plotMenuItem, settings);
moel@295
   369
      plotLocation = new UserRadioGroup("plotLocation", 0,
moel@295
   370
        new[] { plotWindowMenuItem, plotBottomMenuItem, plotRightMenuItem },
moel@295
   371
        settings);
moel@295
   372
moel@295
   373
      showPlot.Changed += delegate(object sender, EventArgs e) {
moel@295
   374
        if (plotLocation.Value == 0) {
moel@295
   375
          if (showPlot.Value && this.Visible)
moel@295
   376
            plotForm.Show();
moel@295
   377
          else
moel@295
   378
            plotForm.Hide();
moel@295
   379
        } else {
moel@295
   380
          splitContainer.Panel2Collapsed = !showPlot.Value;
moel@295
   381
        }
moel@295
   382
        treeView.Invalidate();
moel@295
   383
      };
moel@295
   384
      plotLocation.Changed += delegate(object sender, EventArgs e) {
moel@295
   385
        switch (plotLocation.Value) {
moel@295
   386
          case 0:
moel@295
   387
            splitContainer.Panel2.Controls.Clear();
moel@295
   388
            splitContainer.Panel2Collapsed = true;
moel@295
   389
            plotForm.Controls.Add(plotPanel);
moel@295
   390
            if (showPlot.Value && this.Visible)
moel@295
   391
              plotForm.Show();
moel@295
   392
            break;
moel@295
   393
          case 1:
moel@295
   394
            plotForm.Controls.Clear();
moel@295
   395
            plotForm.Hide();
moel@295
   396
            splitContainer.Orientation = Orientation.Horizontal;
moel@295
   397
            splitContainer.Panel2.Controls.Add(plotPanel);
moel@295
   398
            splitContainer.Panel2Collapsed = !showPlot.Value;
moel@295
   399
            break;
moel@295
   400
          case 2:
moel@295
   401
            plotForm.Controls.Clear();
moel@295
   402
            plotForm.Hide();
moel@295
   403
            splitContainer.Orientation = Orientation.Vertical;
moel@295
   404
            splitContainer.Panel2.Controls.Add(plotPanel);
moel@295
   405
            splitContainer.Panel2Collapsed = !showPlot.Value;
moel@295
   406
            break;
moel@295
   407
        }
moel@295
   408
      };
moel@297
   409
moel@297
   410
      plotForm.FormClosing += delegate(object sender, FormClosingEventArgs e) {
moel@297
   411
        if (e.CloseReason == CloseReason.UserClosing) {
moel@297
   412
          // just switch off the plotting when the user closes the form
moel@297
   413
          if (plotLocation.Value == 0) {
moel@297
   414
            showPlot.Value = false;
moel@297
   415
          }
moel@297
   416
          e.Cancel = true;
moel@295
   417
        }
moel@295
   418
      };
moel@297
   419
moel@295
   420
      EventHandler moveOrResizePlotForm = delegate(object sender, EventArgs e) {
moel@295
   421
        if (plotForm.WindowState != FormWindowState.Minimized) {
moel@295
   422
          settings.SetValue("plotForm.Location.X", plotForm.Bounds.X);
moel@295
   423
          settings.SetValue("plotForm.Location.Y", plotForm.Bounds.Y);
moel@295
   424
          settings.SetValue("plotForm.Width", plotForm.Bounds.Width);
moel@295
   425
          settings.SetValue("plotForm.Height", plotForm.Bounds.Height);
moel@295
   426
        }
moel@295
   427
      };
moel@295
   428
      plotForm.Move += moveOrResizePlotForm;
moel@295
   429
      plotForm.Resize += moveOrResizePlotForm;
moel@295
   430
moel@295
   431
      plotForm.VisibleChanged += delegate(object sender, EventArgs e) {
moel@295
   432
        Rectangle bounds = new Rectangle(plotForm.Location, plotForm.Size);
moel@295
   433
        Screen screen = Screen.FromRectangle(bounds);
moel@295
   434
        Rectangle intersection =
moel@295
   435
          Rectangle.Intersect(screen.WorkingArea, bounds);
moel@295
   436
        if (intersection.Width < Math.Min(16, bounds.Width) ||
moel@295
   437
            intersection.Height < Math.Min(16, bounds.Height)) {
moel@295
   438
          plotForm.Location = new Point(
moel@295
   439
            screen.WorkingArea.Width / 2 - bounds.Width / 2,
moel@295
   440
            screen.WorkingArea.Height / 2 - bounds.Height / 2);
moel@295
   441
        }
moel@295
   442
      };
moel@295
   443
moel@295
   444
      this.VisibleChanged += delegate(object sender, EventArgs e) {
moel@295
   445
        if (this.Visible && showPlot.Value && plotLocation.Value == 0)
moel@295
   446
          plotForm.Show();
moel@295
   447
        else
moel@295
   448
          plotForm.Hide();
moel@295
   449
      };
moel@295
   450
    }
moel@360
   451
moel@360
   452
    private void InsertSorted(Collection<Node> nodes, HardwareNode node) {
moel@360
   453
      int i = 0;
moel@360
   454
      while (i < nodes.Count && nodes[i] is HardwareNode &&
moel@360
   455
        ((HardwareNode)nodes[i]).Hardware.HardwareType < 
moel@360
   456
          node.Hardware.HardwareType)
moel@360
   457
        i++;
moel@360
   458
      nodes.Insert(i, node);
moel@360
   459
    }
moel@128
   460
    
moel@64
   461
    private void SubHardwareAdded(IHardware hardware, Node node) {
moel@327
   462
      HardwareNode hardwareNode = 
moel@327
   463
        new HardwareNode(hardware, settings, unitManager);
moel@327
   464
      hardwareNode.PlotSelectionChanged += PlotSelectionChanged;
moel@327
   465
moel@360
   466
      InsertSorted(node.Nodes, hardwareNode);
moel@360
   467
moel@64
   468
      foreach (IHardware subHardware in hardware.SubHardware)
moel@64
   469
        SubHardwareAdded(subHardware, hardwareNode);  
moel@64
   470
    }
moel@64
   471
moel@327
   472
    private void HardwareAdded(IHardware hardware) {      
moel@327
   473
      SubHardwareAdded(hardware, root);
moel@327
   474
      PlotSelectionChanged(this, null);
moel@1
   475
    }
moel@1
   476
moel@327
   477
    private void HardwareRemoved(IHardware hardware) {
moel@327
   478
      List<HardwareNode> nodesToRemove = new List<HardwareNode>();
moel@28
   479
      foreach (Node node in root.Nodes) {
moel@28
   480
        HardwareNode hardwareNode = node as HardwareNode;
moel@28
   481
        if (hardwareNode != null && hardwareNode.Hardware == hardware)
moel@327
   482
          nodesToRemove.Add(hardwareNode);
moel@28
   483
      }
moel@327
   484
      foreach (HardwareNode hardwareNode in nodesToRemove) {
moel@327
   485
        root.Nodes.Remove(hardwareNode);
moel@327
   486
        hardwareNode.PlotSelectionChanged -= PlotSelectionChanged;
moel@327
   487
      }
moel@327
   488
      PlotSelectionChanged(this, null);
moel@1
   489
    }
moel@1
   490
moel@111
   491
    private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {       
moel@111
   492
      Node node = e.Node.Tag as Node;
moel@111
   493
      if (node != null) {
moel@1
   494
        Color color;
moel@111
   495
        if (node.IsVisible) {
moel@111
   496
          SensorNode sensorNode = node as SensorNode;
moel@111
   497
          if (plotMenuItem.Checked && sensorNode != null &&
moel@111
   498
            sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
moel@111
   499
            e.TextColor = color;
StephaneLenclud@440
   500
StephaneLenclud@440
   501
          //If displayed in FrontView draw background in green
StephaneLenclud@440
   502
          if (sensorNode != null && settings.GetValue(new Identifier(sensorNode.Sensor.Identifier, "FrontView").ToString(), false))
StephaneLenclud@440
   503
          {
StephaneLenclud@440
   504
              SolidBrush greenBrush = new SolidBrush(Color.FromName("mediumspringgreen"));
StephaneLenclud@440
   505
              e.BackgroundBrush = greenBrush;
StephaneLenclud@440
   506
          }
moel@111
   507
        } else {
StephaneLenclud@440
   508
moel@111
   509
          e.TextColor = Color.DarkGray;
moel@111
   510
        }
moel@1
   511
      }
moel@1
   512
    }
moel@1
   513
moel@327
   514
    private void PlotSelectionChanged(object sender, EventArgs e) {
moel@1
   515
      List<ISensor> selected = new List<ISensor>();
moel@1
   516
      IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
moel@1
   517
      int colorIndex = 0;
moel@1
   518
      foreach (TreeNodeAdv node in treeView.AllNodes) {
moel@1
   519
        SensorNode sensorNode = node.Tag as SensorNode;
moel@395
   520
        if (sensorNode != null) {
moel@1
   521
          if (sensorNode.Plot) {
moel@1
   522
            colors.Add(sensorNode.Sensor,
moel@1
   523
              plotColorPalette[colorIndex % plotColorPalette.Length]);
moel@1
   524
            selected.Add(sensorNode.Sensor);
moel@1
   525
          }
moel@1
   526
          colorIndex++;
moel@1
   527
        }
moel@1
   528
      }
moel@1
   529
      sensorPlotColors = colors;
moel@1
   530
      plotPanel.SetSensors(selected, colors);
moel@1
   531
    }
moel@1
   532
paulwerelds@223
   533
    private void nodeTextBoxText_EditorShowing(object sender,
paulwerelds@223
   534
      CancelEventArgs e) 
moel@141
   535
    {
moel@141
   536
      e.Cancel = !(treeView.CurrentNode != null &&
moel@275
   537
        (treeView.CurrentNode.Tag is SensorNode || 
moel@275
   538
         treeView.CurrentNode.Tag is HardwareNode));
moel@141
   539
    }
moel@141
   540
moel@1
   541
    private void nodeCheckBox_IsVisibleValueNeeded(object sender, 
moel@1
   542
      NodeControlValueEventArgs e) {
moel@1
   543
      SensorNode node = e.Node.Tag as SensorNode;
moel@395
   544
      e.Value = (node != null) && plotMenuItem.Checked;
moel@1
   545
    }
moel@1
   546
moel@133
   547
    private void exitClick(object sender, EventArgs e) {
paulwerelds@198
   548
      Close();
moel@1
   549
    }
moel@1
   550
moel@421
   551
    private int delayCount = 0;
moel@86
   552
    private void timer_Tick(object sender, EventArgs e) {
moel@110
   553
      computer.Accept(updateVisitor);
moel@1
   554
      treeView.Invalidate();
moel@395
   555
      plotPanel.InvalidatePlot();
paulwerelds@223
   556
      systemTray.Redraw();
moel@202
   557
      if (gadget != null)
moel@202
   558
        gadget.Redraw();
paulwerelds@223
   559
paulwerelds@223
   560
      if (wmiProvider != null)
paulwerelds@223
   561
        wmiProvider.Update();
moel@420
   562
StephaneLenclud@436
   563
      if (soundGraphDisplay != null)
StephaneLenclud@436
   564
      {
StephaneLenclud@442
   565
          soundGraphDisplay.Redraw(frontViewPacked.Value,frontViewDisplayTime.Value);
StephaneLenclud@438
   566
          /*
StephaneLenclud@436
   567
          displayTick=!displayTick;
StephaneLenclud@436
   568
          if (displayTick)
StephaneLenclud@436
   569
          {
StephaneLenclud@436
   570
              soundGraphDisplay.SetText("       ---", "");
StephaneLenclud@436
   571
          }
StephaneLenclud@436
   572
          else
StephaneLenclud@436
   573
          {
StephaneLenclud@436
   574
              soundGraphDisplay.SetText("       -+-", "");
StephaneLenclud@436
   575
          }
StephaneLenclud@438
   576
          */
StephaneLenclud@436
   577
      }  
StephaneLenclud@436
   578
moel@421
   579
moel@431
   580
      if (logSensors != null && logSensors.Value && delayCount >= 4)
moel@420
   581
        logger.Log();
moel@421
   582
moel@421
   583
      if (delayCount < 4)
moel@421
   584
        delayCount++;
moel@1
   585
    }
moel@1
   586
moel@128
   587
    private void SaveConfiguration() {
moel@395
   588
      plotPanel.SetCurrentSettings();
moel@128
   589
      foreach (TreeColumn column in treeView.Columns)
moel@166
   590
        settings.SetValue("treeView.Columns." + column.Header + ".Width",
moel@113
   591
          column.Width);
moel@113
   592
moel@348
   593
      this.settings.SetValue("listenerPort", server.ListenerPort);
moel@348
   594
moel@212
   595
      string fileName = Path.ChangeExtension(
moel@212
   596
          System.Windows.Forms.Application.ExecutablePath, ".config");
moel@212
   597
      try {
moel@212
   598
        settings.Save(fileName);
moel@212
   599
      } catch (UnauthorizedAccessException) {
paulwerelds@214
   600
        MessageBox.Show("Access to the path '" + fileName + "' is denied. " +
moel@284
   601
          "The current settings could not be saved.",
moel@284
   602
          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@284
   603
      } catch (IOException) {
moel@284
   604
        MessageBox.Show("The path '" + fileName + "' is not writeable. " +
moel@284
   605
          "The current settings could not be saved.",
moel@212
   606
          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@212
   607
      }
moel@128
   608
    }
moel@128
   609
paulwerelds@214
   610
    private void MainForm_Load(object sender, EventArgs e) {
paulwerelds@214
   611
      Rectangle newBounds = new Rectangle {
paulwerelds@214
   612
        X = settings.GetValue("mainForm.Location.X", Location.X),
paulwerelds@214
   613
        Y = settings.GetValue("mainForm.Location.Y", Location.Y),
paulwerelds@214
   614
        Width = settings.GetValue("mainForm.Width", 470),
paulwerelds@214
   615
        Height = settings.GetValue("mainForm.Height", 640)
paulwerelds@214
   616
      };
paulwerelds@214
   617
paulwerelds@223
   618
      Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
paulwerelds@214
   619
        int.MinValue, int.MinValue);
paulwerelds@214
   620
paulwerelds@214
   621
      foreach (Screen screen in Screen.AllScreens)
paulwerelds@223
   622
        fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
paulwerelds@214
   623
paulwerelds@223
   624
      Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);
paulwerelds@214
   625
      if (intersection.Width < 20 || intersection.Height < 20 ||
paulwerelds@214
   626
        !settings.Contains("mainForm.Location.X")
paulwerelds@214
   627
      ) {
paulwerelds@214
   628
        newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
paulwerelds@214
   629
                      (newBounds.Width/2);
paulwerelds@214
   630
paulwerelds@214
   631
        newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
paulwerelds@214
   632
                      (newBounds.Height / 2);
paulwerelds@214
   633
      }
paulwerelds@214
   634
paulwerelds@214
   635
      this.Bounds = newBounds;
paulwerelds@214
   636
    }
paulwerelds@214
   637
    
paulwerelds@214
   638
    private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
moel@298
   639
      Visible = false;      
moel@262
   640
      systemTray.IsMainIconEnabled = false;
moel@262
   641
      timer.Enabled = false;            
moel@28
   642
      computer.Close();
moel@298
   643
      SaveConfiguration();
moel@348
   644
      if (runWebServer.Value)
moel@348
   645
          server.Quit();
moel@262
   646
      systemTray.Dispose();
StephaneLenclud@433
   647
      soundGraphDisplay.Dispose();
moel@1
   648
    }
moel@1
   649
moel@156
   650
    private void aboutMenuItem_Click(object sender, EventArgs e) {
moel@1
   651
      new AboutBox().ShowDialog();
moel@1
   652
    }
moel@1
   653
moel@1
   654
    private void treeView_Click(object sender, EventArgs e) {
moel@275
   655
moel@1
   656
      MouseEventArgs m = e as MouseEventArgs;
moel@1
   657
      if (m == null || m.Button != MouseButtons.Right)
moel@1
   658
        return;
moel@1
   659
paulwerelds@223
   660
      NodeControlInfo info = treeView.GetNodeControlInfoAt(
paulwerelds@223
   661
        new Point(m.X, m.Y)
paulwerelds@223
   662
      );
moel@156
   663
      treeView.SelectedNode = info.Node;
moel@156
   664
      if (info.Node != null) {
moel@40
   665
        SensorNode node = info.Node.Tag as SensorNode;
moel@40
   666
        if (node != null && node.Sensor != null) {
moel@275
   667
          treeContextMenu.MenuItems.Clear();
moel@63
   668
          if (node.Sensor.Parameters.Length > 0) {
moel@156
   669
            MenuItem item = new MenuItem("Parameters...");
moel@63
   670
            item.Click += delegate(object obj, EventArgs args) {
moel@63
   671
              ShowParameterForm(node.Sensor);
moel@63
   672
            };
moel@275
   673
            treeContextMenu.MenuItems.Add(item);
moel@63
   674
          }
moel@156
   675
          if (nodeTextBoxText.EditEnabled) {
moel@156
   676
            MenuItem item = new MenuItem("Rename");
moel@141
   677
            item.Click += delegate(object obj, EventArgs args) {
moel@156
   678
              nodeTextBoxText.BeginEdit();
moel@141
   679
            };
moel@275
   680
            treeContextMenu.MenuItems.Add(item);
moel@176
   681
          }
moel@111
   682
          if (node.IsVisible) {
moel@156
   683
            MenuItem item = new MenuItem("Hide");
moel@111
   684
            item.Click += delegate(object obj, EventArgs args) {
moel@111
   685
              node.IsVisible = false;
moel@111
   686
            };
moel@275
   687
            treeContextMenu.MenuItems.Add(item);
moel@111
   688
          } else {
moel@156
   689
            MenuItem item = new MenuItem("Unhide");
moel@111
   690
            item.Click += delegate(object obj, EventArgs args) {
moel@111
   691
              node.IsVisible = true;
moel@111
   692
            };
moel@275
   693
            treeContextMenu.MenuItems.Add(item);
moel@176
   694
          }
moel@275
   695
          treeContextMenu.MenuItems.Add(new MenuItem("-"));
moel@178
   696
          {
moel@178
   697
            MenuItem item = new MenuItem("Show in Tray");
moel@178
   698
            item.Checked = systemTray.Contains(node.Sensor);
moel@178
   699
            item.Click += delegate(object obj, EventArgs args) {
moel@178
   700
              if (item.Checked)
moel@178
   701
                systemTray.Remove(node.Sensor);
moel@178
   702
              else
moel@178
   703
                systemTray.Add(node.Sensor, true);
moel@178
   704
            };
moel@275
   705
            treeContextMenu.MenuItems.Add(item);
moel@178
   706
          }
StephaneLenclud@433
   707
          {
StephaneLenclud@433
   708
              MenuItem item = new MenuItem("Show in iMON FrontView");
StephaneLenclud@438
   709
              item.Checked = soundGraphDisplay.Contains(node.Sensor);
StephaneLenclud@433
   710
              item.Click += delegate(object obj, EventArgs args)
StephaneLenclud@433
   711
              {
StephaneLenclud@433
   712
                  if (item.Checked)
StephaneLenclud@433
   713
                      soundGraphDisplay.Remove(node.Sensor);
StephaneLenclud@433
   714
                  else
StephaneLenclud@433
   715
                      soundGraphDisplay.Add(node.Sensor, true);
StephaneLenclud@433
   716
              };
StephaneLenclud@433
   717
              treeContextMenu.MenuItems.Add(item);
StephaneLenclud@433
   718
          }
moel@211
   719
          if (gadget != null) {
moel@178
   720
            MenuItem item = new MenuItem("Show in Gadget");
moel@178
   721
            item.Checked = gadget.Contains(node.Sensor);
moel@178
   722
            item.Click += delegate(object obj, EventArgs args) {
moel@178
   723
              if (item.Checked) {
moel@178
   724
                gadget.Remove(node.Sensor);
moel@178
   725
              } else {
moel@178
   726
                gadget.Add(node.Sensor);
moel@178
   727
              }
moel@178
   728
            };
moel@275
   729
            treeContextMenu.MenuItems.Add(item);
moel@178
   730
          }
moel@247
   731
          if (node.Sensor.Control != null) {
moel@275
   732
            treeContextMenu.MenuItems.Add(new MenuItem("-"));
moel@247
   733
            IControl control = node.Sensor.Control;
moel@247
   734
            MenuItem controlItem = new MenuItem("Control");
moel@247
   735
            MenuItem defaultItem = new MenuItem("Default");
moel@247
   736
            defaultItem.Checked = control.ControlMode == ControlMode.Default;
moel@247
   737
            controlItem.MenuItems.Add(defaultItem);
moel@247
   738
            defaultItem.Click += delegate(object obj, EventArgs args) {
moel@247
   739
              control.SetDefault();
moel@247
   740
            };
moel@275
   741
            MenuItem manualItem = new MenuItem("Manual");
moel@247
   742
            controlItem.MenuItems.Add(manualItem);
moel@247
   743
            manualItem.Checked = control.ControlMode == ControlMode.Software;
moel@247
   744
            for (int i = 0; i <= 100; i += 5) {
moel@247
   745
              if (i <= control.MaxSoftwareValue &&
moel@275
   746
                  i >= control.MinSoftwareValue) {
moel@247
   747
                MenuItem item = new MenuItem(i + " %");
moel@378
   748
                item.RadioCheck = true;
moel@247
   749
                manualItem.MenuItems.Add(item);
moel@247
   750
                item.Checked = control.ControlMode == ControlMode.Software &&
moel@247
   751
                  Math.Round(control.SoftwareValue) == i;
moel@247
   752
                int softwareValue = i;
moel@247
   753
                item.Click += delegate(object obj, EventArgs args) {
moel@247
   754
                  control.SetSoftware(softwareValue);
moel@247
   755
                };
moel@247
   756
              }
moel@247
   757
            }
moel@275
   758
            treeContextMenu.MenuItems.Add(controlItem);
moel@247
   759
          }
moel@176
   760
moel@275
   761
          treeContextMenu.Show(treeView, new Point(m.X, m.Y));
moel@275
   762
        }
moel@275
   763
moel@275
   764
        HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
moel@275
   765
        if (hardwareNode != null && hardwareNode.Hardware != null) {
moel@275
   766
          treeContextMenu.MenuItems.Clear();
moel@275
   767
moel@275
   768
          if (nodeTextBoxText.EditEnabled) {
moel@275
   769
            MenuItem item = new MenuItem("Rename");
moel@275
   770
            item.Click += delegate(object obj, EventArgs args) {
moel@275
   771
              nodeTextBoxText.BeginEdit();
moel@275
   772
            };
moel@275
   773
            treeContextMenu.MenuItems.Add(item);
moel@275
   774
          }
moel@275
   775
moel@275
   776
          treeContextMenu.Show(treeView, new Point(m.X, m.Y));
moel@40
   777
        }
moel@40
   778
      }
moel@1
   779
    }
moel@1
   780
moel@156
   781
    private void saveReportMenuItem_Click(object sender, EventArgs e) {
moel@83
   782
      string report = computer.GetReport();
moel@83
   783
      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
moel@83
   784
        using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
moel@83
   785
          w.Write(report);
moel@83
   786
        }
moel@83
   787
      }
moel@1
   788
    }
moel@1
   789
moel@82
   790
    private void SysTrayHideShow() {
moel@82
   791
      Visible = !Visible;
moel@82
   792
      if (Visible)
moel@82
   793
        Activate();    
moel@27
   794
    }
moel@27
   795
moel@27
   796
    protected override void WndProc(ref Message m) {
moel@27
   797
      const int WM_SYSCOMMAND = 0x112;
moel@27
   798
      const int SC_MINIMIZE = 0xF020;
paulwerelds@198
   799
      const int SC_CLOSE = 0xF060;
paulwerelds@198
   800
StephaneLenclud@436
   801
 
StephaneLenclud@436
   802
      if (minimizeToTray.Value &&
StephaneLenclud@435
   803
        m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_MINIMIZE)
StephaneLenclud@435
   804
      {
paulwerelds@198
   805
          SysTrayHideShow();
StephaneLenclud@435
   806
      }
StephaneLenclud@435
   807
      else if (minimizeOnClose.Value &&
StephaneLenclud@435
   808
      m.Msg == WM_SYSCOMMAND && m.WParam.ToInt64() == SC_CLOSE)
StephaneLenclud@435
   809
      {
StephaneLenclud@435
   810
          /*
StephaneLenclud@435
   811
           * Apparently the user wants to minimize rather than close
StephaneLenclud@435
   812
           * Now we still need to check if we're going to the tray or not
StephaneLenclud@435
   813
           * 
StephaneLenclud@435
   814
           * Note: the correct way to do this would be to send out SC_MINIMIZE,
StephaneLenclud@435
   815
           * but since the code here is so simple,
StephaneLenclud@435
   816
           * that would just be a waste of time.
StephaneLenclud@435
   817
           */
StephaneLenclud@435
   818
          if (minimizeToTray.Value)
StephaneLenclud@435
   819
              SysTrayHideShow();
StephaneLenclud@435
   820
          else
StephaneLenclud@435
   821
              WindowState = FormWindowState.Minimized;
StephaneLenclud@435
   822
      }
StephaneLenclud@435
   823
      else
StephaneLenclud@435
   824
      {
StephaneLenclud@435
   825
          base.WndProc(ref m);
moel@27
   826
      }
moel@27
   827
    }
moel@27
   828
moel@82
   829
    private void hideShowClick(object sender, EventArgs e) {
moel@82
   830
      SysTrayHideShow();
moel@27
   831
    }
moel@27
   832
moel@63
   833
    private void ShowParameterForm(ISensor sensor) {
moel@63
   834
      ParameterForm form = new ParameterForm();
moel@63
   835
      form.Parameters = sensor.Parameters;
moel@63
   836
      form.captionLabel.Text = sensor.Name;
moel@63
   837
      form.ShowDialog();
moel@63
   838
    }
moel@63
   839
moel@63
   840
    private void treeView_NodeMouseDoubleClick(object sender, 
moel@63
   841
      TreeNodeAdvMouseEventArgs e) {
moel@63
   842
      SensorNode node = e.Node.Tag as SensorNode;
moel@63
   843
      if (node != null && node.Sensor != null && 
moel@63
   844
        node.Sensor.Parameters.Length > 0) {
moel@63
   845
        ShowParameterForm(node.Sensor);
moel@63
   846
      }
moel@63
   847
    }
moel@82
   848
moel@299
   849
    private void celsiusMenuItem_Click(object sender, EventArgs e) {
moel@299
   850
      celsiusMenuItem.Checked = true;
moel@156
   851
      fahrenheitMenuItem.Checked = false;
moel@299
   852
      unitManager.TemperatureUnit = TemperatureUnit.Celsius;
moel@122
   853
    }
moel@122
   854
moel@156
   855
    private void fahrenheitMenuItem_Click(object sender, EventArgs e) {
moel@299
   856
      celsiusMenuItem.Checked = false;
moel@156
   857
      fahrenheitMenuItem.Checked = true;
moel@165
   858
      unitManager.TemperatureUnit = TemperatureUnit.Fahrenheit;
moel@122
   859
    }
moel@150
   860
moel@156
   861
    private void sumbitReportMenuItem_Click(object sender, EventArgs e) 
moel@150
   862
    {
moel@150
   863
      ReportForm form = new ReportForm();
moel@150
   864
      form.Report = computer.GetReport();
moel@150
   865
      form.ShowDialog();      
moel@150
   866
    }
moel@151
   867
moel@151
   868
    private void resetMinMaxMenuItem_Click(object sender, EventArgs e) {
moel@159
   869
      computer.Accept(new SensorVisitor(delegate(ISensor sensor) {
moel@159
   870
        sensor.ResetMin();
moel@159
   871
        sensor.ResetMax();
moel@159
   872
      }));
moel@151
   873
    }
moel@241
   874
moel@241
   875
    private void MainForm_MoveOrResize(object sender, EventArgs e) {
moel@241
   876
      if (WindowState != FormWindowState.Minimized) {
moel@241
   877
        settings.SetValue("mainForm.Location.X", Bounds.X);
moel@241
   878
        settings.SetValue("mainForm.Location.Y", Bounds.Y);
moel@241
   879
        settings.SetValue("mainForm.Width", Bounds.Width);
moel@241
   880
        settings.SetValue("mainForm.Height", Bounds.Height);
moel@241
   881
      }
moel@241
   882
    }
moel@262
   883
moel@262
   884
    private void resetClick(object sender, EventArgs e) {
moel@262
   885
      // disable the fallback MainIcon during reset, otherwise icon visibility
moel@262
   886
      // might be lost 
moel@262
   887
      systemTray.IsMainIconEnabled = false;
moel@262
   888
      computer.Close();
moel@262
   889
      computer.Open();
moel@262
   890
      // restore the MainIcon setting
moel@262
   891
      systemTray.IsMainIconEnabled = minimizeToTray.Value;
moel@262
   892
    }
moel@287
   893
moel@287
   894
    private void treeView_MouseMove(object sender, MouseEventArgs e) {
moel@288
   895
      selectionDragging = selectionDragging &
moel@288
   896
        (e.Button & (MouseButtons.Left | MouseButtons.Right)) > 0; 
moel@288
   897
moel@288
   898
      if (selectionDragging)
moel@288
   899
        treeView.SelectedNode = treeView.GetNodeAt(e.Location);     
moel@288
   900
    }
moel@288
   901
moel@288
   902
    private void treeView_MouseDown(object sender, MouseEventArgs e) {
moel@288
   903
      selectionDragging = true;
moel@288
   904
    }
moel@288
   905
moel@288
   906
    private void treeView_MouseUp(object sender, MouseEventArgs e) {
moel@288
   907
      selectionDragging = false;
moel@287
   908
    }
moel@348
   909
moel@348
   910
    private void serverPortMenuItem_Click(object sender, EventArgs e) {
moel@348
   911
      new PortForm(this).ShowDialog();
moel@348
   912
    }
moel@348
   913
moel@348
   914
    public HttpServer Server {
moel@348
   915
      get { return server; }
moel@348
   916
    }
moel@348
   917
moel@1
   918
  }
moel@1
   919
}