moel@1: /*
moel@1:  
moel@344:   This Source Code Form is subject to the terms of the Mozilla Public
moel@344:   License, v. 2.0. If a copy of the MPL was not distributed with this
moel@344:   file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@1:  
moel@344:   Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344: 	
moel@1: */
moel@1: 
moel@1: using System;
moel@1: using System.Collections.Generic;
moel@1: using OpenHardwareMonitor.Hardware;
moel@1: 
moel@1: namespace OpenHardwareMonitor.GUI {
moel@1:   public class TypeNode : Node {
moel@1: 
moel@1:     private SensorType sensorType;
moel@1: 
moel@1:     public TypeNode(SensorType sensorType) : base() {
moel@1:       this.sensorType = sensorType;
moel@1: 
moel@1:       switch (sensorType) {
moel@1:         case SensorType.Voltage: 
moel@1:           this.Image = Utilities.EmbeddedResources.GetImage("voltage.png");
moel@1:           this.Text = "Voltages";
moel@1:           break;
moel@1:         case SensorType.Clock:
moel@1:           this.Image = Utilities.EmbeddedResources.GetImage("clock.png");
moel@1:           this.Text = "Clocks";
moel@1:           break;
moel@24:         case SensorType.Load:
moel@24:           this.Image = Utilities.EmbeddedResources.GetImage("load.png");
moel@24:           this.Text = "Load";
moel@24:           break;
moel@1:         case SensorType.Temperature:
moel@1:           this.Image = Utilities.EmbeddedResources.GetImage("temperature.png");
moel@1:           this.Text = "Temperatures";
moel@1:           break;
moel@1:         case SensorType.Fan:
moel@1:           this.Image = Utilities.EmbeddedResources.GetImage("fan.png");
moel@1:           this.Text = "Fans";
moel@1:           break;
moel@57:         case SensorType.Flow:
moel@57:           this.Image = Utilities.EmbeddedResources.GetImage("flow.png");
moel@57:           this.Text = "Flows";
moel@57:           break;
moel@118:         case SensorType.Control:
moel@118:           this.Image = Utilities.EmbeddedResources.GetImage("control.png");
moel@118:           this.Text = "Controls";
moel@118:           break;
moel@217:         case SensorType.Level:
moel@217:           this.Image = Utilities.EmbeddedResources.GetImage("level.png");
moel@217:           this.Text = "Levels";
moel@217:           break;
moel@317:         case SensorType.Power:
moel@317:           this.Image = Utilities.EmbeddedResources.GetImage("power.png");
moel@317:           this.Text = "Powers";
moel@317:           break;
moel@324:         case SensorType.Data:
moel@324:           this.Image = Utilities.EmbeddedResources.GetImage("data.png");
moel@324:           this.Text = "Data";
moel@324:           break;
moel@340:         case SensorType.Factor:
moel@340:           this.Image = Utilities.EmbeddedResources.GetImage("factor.png");
moel@340:           this.Text = "Factors";
moel@340:           break;
moel@1:       }
moel@111: 
moel@111:       NodeAdded += new NodeEventHandler(TypeNode_NodeAdded);
moel@111:       NodeRemoved += new NodeEventHandler(TypeNode_NodeRemoved);
moel@111:     }
moel@111: 
moel@111:     private void TypeNode_NodeRemoved(Node node) {
moel@111:       node.IsVisibleChanged -= new NodeEventHandler(node_IsVisibleChanged);
moel@111:       node_IsVisibleChanged(null);
moel@111:     }    
moel@111: 
moel@111:     private void TypeNode_NodeAdded(Node node) {
moel@111:       node.IsVisibleChanged += new NodeEventHandler(node_IsVisibleChanged);
moel@111:       node_IsVisibleChanged(null);
moel@111:     }
moel@111: 
moel@111:     private void node_IsVisibleChanged(Node node) {      
moel@111:       foreach (Node n in Nodes)
moel@111:         if (n.IsVisible) {
moel@111:           this.IsVisible = true;
moel@111:           return;
moel@111:         }
moel@111:       this.IsVisible = false;
moel@1:     }
moel@1: 
moel@1:     public SensorType SensorType {
moel@1:       get { return sensorType; }
moel@1:     }
moel@1:   }
moel@1: }