GUI/TypeNode.cs
author moel.mich
Wed, 25 Jul 2012 18:10:10 +0000
changeset 375 01d283b11596
parent 340 600962f8a298
permissions -rw-r--r--
Updated the version.
     1 /*
     2  
     3   This Source Code Form is subject to the terms of the Mozilla Public
     4   License, v. 2.0. If a copy of the MPL was not distributed with this
     5   file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  
     7   Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
     8 	
     9 */
    10 
    11 using System;
    12 using System.Collections.Generic;
    13 using OpenHardwareMonitor.Hardware;
    14 
    15 namespace OpenHardwareMonitor.GUI {
    16   public class TypeNode : Node {
    17 
    18     private SensorType sensorType;
    19 
    20     public TypeNode(SensorType sensorType) : base() {
    21       this.sensorType = sensorType;
    22 
    23       switch (sensorType) {
    24         case SensorType.Voltage: 
    25           this.Image = Utilities.EmbeddedResources.GetImage("voltage.png");
    26           this.Text = "Voltages";
    27           break;
    28         case SensorType.Clock:
    29           this.Image = Utilities.EmbeddedResources.GetImage("clock.png");
    30           this.Text = "Clocks";
    31           break;
    32         case SensorType.Load:
    33           this.Image = Utilities.EmbeddedResources.GetImage("load.png");
    34           this.Text = "Load";
    35           break;
    36         case SensorType.Temperature:
    37           this.Image = Utilities.EmbeddedResources.GetImage("temperature.png");
    38           this.Text = "Temperatures";
    39           break;
    40         case SensorType.Fan:
    41           this.Image = Utilities.EmbeddedResources.GetImage("fan.png");
    42           this.Text = "Fans";
    43           break;
    44         case SensorType.Flow:
    45           this.Image = Utilities.EmbeddedResources.GetImage("flow.png");
    46           this.Text = "Flows";
    47           break;
    48         case SensorType.Control:
    49           this.Image = Utilities.EmbeddedResources.GetImage("control.png");
    50           this.Text = "Controls";
    51           break;
    52         case SensorType.Level:
    53           this.Image = Utilities.EmbeddedResources.GetImage("level.png");
    54           this.Text = "Levels";
    55           break;
    56         case SensorType.Power:
    57           this.Image = Utilities.EmbeddedResources.GetImage("power.png");
    58           this.Text = "Powers";
    59           break;
    60         case SensorType.Data:
    61           this.Image = Utilities.EmbeddedResources.GetImage("data.png");
    62           this.Text = "Data";
    63           break;
    64         case SensorType.Factor:
    65           this.Image = Utilities.EmbeddedResources.GetImage("factor.png");
    66           this.Text = "Factors";
    67           break;
    68       }
    69 
    70       NodeAdded += new NodeEventHandler(TypeNode_NodeAdded);
    71       NodeRemoved += new NodeEventHandler(TypeNode_NodeRemoved);
    72     }
    73 
    74     private void TypeNode_NodeRemoved(Node node) {
    75       node.IsVisibleChanged -= new NodeEventHandler(node_IsVisibleChanged);
    76       node_IsVisibleChanged(null);
    77     }    
    78 
    79     private void TypeNode_NodeAdded(Node node) {
    80       node.IsVisibleChanged += new NodeEventHandler(node_IsVisibleChanged);
    81       node_IsVisibleChanged(null);
    82     }
    83 
    84     private void node_IsVisibleChanged(Node node) {      
    85       foreach (Node n in Nodes)
    86         if (n.IsVisible) {
    87           this.IsVisible = true;
    88           return;
    89         }
    90       this.IsVisible = false;
    91     }
    92 
    93     public SensorType SensorType {
    94       get { return sensorType; }
    95     }
    96   }
    97 }