Esempio n. 1
0
        private void UpdatePlotSelection(object sender,
                                         TreePathEventArgs e)
        {
            List <ISensor> selected             = new List <ISensor>();
            IDictionary <ISensor, Color> colors = new Dictionary <ISensor, Color>();
            int colorIndex = 0;

            foreach (TreeNodeAdv node in treeView.AllNodes)
            {
                SensorNode sensorNode = node.Tag as SensorNode;
                if (sensorNode != null &&
                    sensorNode.Sensor.SensorType == SensorType.Temperature)
                {
                    if (sensorNode.Plot)
                    {
                        colors.Add(sensorNode.Sensor,
                                   plotColorPalette[colorIndex % plotColorPalette.Length]);
                        selected.Add(sensorNode.Sensor);
                    }
                    colorIndex++;
                }
            }
            sensorPlotColors = colors;
            plotPanel.SetSensors(selected, colors);
        }
Esempio n. 2
0
 private void SensorRemoved(ISensor sensor)
 {
     foreach (TypeNode typeNode in typeNodes)
     {
         if (typeNode.SensorType == sensor.SensorType)
         {
             SensorNode sensorNode = null;
             foreach (Node node in typeNode.Nodes)
             {
                 SensorNode n = node as SensorNode;
                 if (n != null && n.Sensor == sensor)
                 {
                     sensorNode = n;
                 }
             }
             if (sensorNode != null)
             {
                 sensorNode.PlotSelectionChanged -= SensorPlotSelectionChanged;
                 typeNode.Nodes.Remove(sensorNode);
                 UpdateNode(typeNode);
             }
         }
     }
     if (PlotSelectionChanged != null)
     {
         PlotSelectionChanged(this, null);
     }
 }
Esempio n. 3
0
        private void nodeCheckBox_IsVisibleValueNeeded(object sender,
                                                       NodeControlValueEventArgs e)
        {
            SensorNode node = e.Node.Tag as SensorNode;

            e.Value = false;
        }
Esempio n. 4
0
        private void nodeCheckBox_IsVisibleValueNeeded(object sender,
                                                       NodeControlValueEventArgs e)
        {
            SensorNode node = e.Node.Tag as SensorNode;

            e.Value = (node != null) && plotMenuItem.Checked;
        }
Esempio n. 5
0
        private void nodeTextBoxLimit_DrawText(object sender, DrawEventArgs e)
        {
            SensorNode sensorNode = e.Node.Tag as SensorNode;

            if (sensorNode != null)
            {
                e.Text = sensorNode.ValueToString(sensorNode.Sensor.Limit);
            }
        }
Esempio n. 6
0
 private void InsertSorted(Node node, ISensor sensor)
 {
     int i = 0;
     while (i < node.Nodes.Count && ((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index)
         i++;
     SensorNode sensorNode = new SensorNode(sensor, settings, unitManager);
     sensorNode.PlotSelectionChanged += SensorPlotSelectionChanged;
     node.Nodes.Insert(i, sensorNode);
 }
Esempio n. 7
0
        private void treeView_NodeMouseDoubleClick(object sender,
                                                   TreeNodeAdvMouseEventArgs e)
        {
            SensorNode node = e.Node.Tag as SensorNode;

            if (node != null && node.Sensor != null && node.Sensor.Parameters.Length > 0)
            {
                ShowParameterForm(node.Sensor);
            }
        }
    public override bool Equals(System.Object obj) {
      if (obj == null) 
        return false;

      SensorNode s = obj as SensorNode;
      if (s == null) 
        return false;

      return (sensor == s.sensor);
    }
Esempio n. 9
0
        private void PlotSelectionChanged(object sender, EventArgs e)
        {
            List <ISensor> selected             = new List <ISensor>();
            IDictionary <ISensor, Color> colors = new Dictionary <ISensor, Color>();
            int colorIndex = 0;

            foreach (TreeNodeAdv node in treeView.AllNodes)
            {
                SensorNode sensorNode = node.Tag as SensorNode;
                if (sensorNode != null)
                {
                    if (sensorNode.Plot)
                    {
                        colors.Add(sensorNode.Sensor,
                                   plotColorPalette[colorIndex % plotColorPalette.Length]);
                        selected.Add(sensorNode.Sensor);
                    }
                    colorIndex++;
                }
            }

            // if a sensor is assigned a color that's already being used by another
            // sensor, try to assign it a new color. This is done only after the
            // previous loop sets an unchanging default color for all sensors, so that
            // colors jump around as little as possible as sensors get added/removed
            // from the plot
            var usedColors = new List <Color>();

            foreach (var curSelectedSensor in selected)
            {
                var curColor = colors[curSelectedSensor];
                if (usedColors.Contains(curColor))
                {
                    foreach (var potentialNewColor in plotColorPalette)
                    {
                        if (!colors.Values.Contains(potentialNewColor))
                        {
                            colors[curSelectedSensor] = potentialNewColor;
                            usedColors.Add(potentialNewColor);
                            break;
                        }
                    }
                }
                else
                {
                    usedColors.Add(curColor);
                }
            }

            sensorPlotColors = colors;
            plotPanel.SetSensors(selected, colors);
        }
Esempio n. 10
0
        private void InsertSorted(Node node, ISensor sensor)
        {
            int i = 0;

            while (i < node.Nodes.Count &&
                   ((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index)
            {
                i++;
            }
            SensorNode sensorNode = new SensorNode(sensor, settings, unitManager);

            node.Nodes.Insert(i, sensorNode);
        }
Esempio n. 11
0
        private void treeView_Click(object sender, EventArgs e)
        {
            MouseEventArgs m = e as MouseEventArgs;

            if (m == null || m.Button != MouseButtons.Right)
            {
                return;
            }

            NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));

            if (info.Control == null)
            {
                columnsContextMenuStrip.Show(treeView, m.X, m.Y);
            }
            else
            {
                SensorNode node = info.Node.Tag as SensorNode;
                if (node != null && node.Sensor != null)
                {
                    sensorContextMenuStrip.Items.Clear();
                    if (node.Sensor.Parameters.Length > 0)
                    {
                        ToolStripMenuItem item = new ToolStripMenuItem("Parameters...");
                        item.Click += delegate(object obj, EventArgs args) {
                            ShowParameterForm(node.Sensor);
                        };
                        sensorContextMenuStrip.Items.Add(item);
                    }
                    if (sensorSystemTray.Contains(node.Sensor))
                    {
                        ToolStripMenuItem item = new ToolStripMenuItem("Remove From Tray");
                        item.Click += delegate(object obj, EventArgs args) {
                            sensorSystemTray.Remove(node.Sensor);
                        };
                        sensorContextMenuStrip.Items.Add(item);
                    }
                    else
                    {
                        ToolStripMenuItem item = new ToolStripMenuItem("Add To Tray");
                        item.Click += delegate(object obj, EventArgs args) {
                            sensorSystemTray.Add(node.Sensor, true);
                        };
                        sensorContextMenuStrip.Items.Add(item);
                    }
                    sensorContextMenuStrip.Show(treeView, m.X, m.Y);
                }
            }
        }
Esempio n. 12
0
        private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e)
        {
            if (!plotMenuItem.Checked)
            {
                return;
            }

            SensorNode sensorNode = e.Node.Tag as SensorNode;

            if (sensorNode != null)
            {
                Color color;
                if (sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
                {
                    e.TextColor = color;
                }
            }
        }
 private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e)
 {
     if (e.Node.Tag is Node node)
     {
         if (node.IsVisible)
         {
             SensorNode sensorNode = node as SensorNode;
             if (plotMenuItem.Checked && sensorNode != null &&
                 sensorPlotColors.TryGetValue(sensorNode.Sensor, out Color color))
             {
                 e.TextColor = color;
             }
         }
         else
         {
             e.TextColor = Color.DarkGray;
         }
     }
 }
Esempio n. 14
0
 private void SensorRemoved(ISensor sensor)
 {
     foreach (TypeNode typeNode in typeNodes)
     {
         if (typeNode.SensorType == sensor.SensorType)
         {
             SensorNode sensorNode = null;
             foreach (Node node in typeNode.Nodes)
             {
                 SensorNode n = node as SensorNode;
                 if (n != null && n.Sensor == sensor)
                 {
                     sensorNode = n;
                 }
             }
             typeNode.Nodes.Remove(sensorNode);
             UpdateNode(typeNode);
         }
     }
 }
Esempio n. 15
0
        private void treeView_Click(object sender, EventArgs e)
        {
            MouseEventArgs m = e as MouseEventArgs;

            if (m == null || m.Button != MouseButtons.Right)
            {
                return;
            }

            NodeControlInfo info = treeView.GetNodeControlInfoAt(
                new Point(m.X, m.Y)
                );

            treeView.SelectedNode = info.Node;
            if (info.Node != null)
            {
                SensorNode node = info.Node.Tag as SensorNode;
                if (node != null && node.Sensor != null)
                {
                    treeContextMenu.MenuItems.Clear();
                    if (node.Sensor.Parameters.Count > 0)
                    {
                        MenuItem item = new MenuItem("Parameters...");
                        item.Click += delegate(object obj, EventArgs args) {
                            ShowParameterForm(node.Sensor);
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("Rename");
                        item.Click += delegate(object obj, EventArgs args) {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.IsVisible)
                    {
                        MenuItem item = new MenuItem("Hide");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = false;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    else
                    {
                        MenuItem item = new MenuItem("Unhide");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = true;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    treeContextMenu.MenuItems.Add(new MenuItem("-"));
                    {
                        MenuItem item = new MenuItem("Pen Color...");
                        item.Click += delegate(object obj, EventArgs args) {
                            ColorDialog dialog = new ColorDialog();
                            dialog.Color = node.PenColor.GetValueOrDefault();
                            if (dialog.ShowDialog() == DialogResult.OK)
                            {
                                node.PenColor = dialog.Color;
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    {
                        MenuItem item = new MenuItem("Reset Pen Color");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.PenColor = null;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    treeContextMenu.MenuItems.Add(new MenuItem("-"));
                    {
                        MenuItem item = new MenuItem("Show in Tray");
                        item.Checked = systemTray.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args) {
                            if (item.Checked)
                            {
                                systemTray.Remove(node.Sensor);
                            }
                            else
                            {
                                systemTray.Add(node.Sensor, true);
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (gadget != null)
                    {
                        MenuItem item = new MenuItem("Show in Gadget");
                        item.Checked = gadget.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args) {
                            if (item.Checked)
                            {
                                gadget.Remove(node.Sensor);
                            }
                            else
                            {
                                gadget.Add(node.Sensor);
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.Sensor.Control != null)
                    {
                        treeContextMenu.MenuItems.Add(new MenuItem("-"));
                        IControl control     = node.Sensor.Control;
                        MenuItem controlItem = new MenuItem("Control");
                        MenuItem defaultItem = new MenuItem("Default");
                        defaultItem.Checked = control.ControlMode == ControlMode.Default;
                        controlItem.MenuItems.Add(defaultItem);
                        defaultItem.Click += delegate(object obj, EventArgs args) {
                            control.SetDefault();
                        };
                        MenuItem manualItem = new MenuItem("Manual");
                        controlItem.MenuItems.Add(manualItem);
                        manualItem.Checked = control.ControlMode == ControlMode.Software;
                        for (int i = 0; i <= 100; i += 5)
                        {
                            if (i <= control.MaxSoftwareValue &&
                                i >= control.MinSoftwareValue)
                            {
                                MenuItem item = new MenuItem(i + " %");
                                item.RadioCheck = true;
                                manualItem.MenuItems.Add(item);
                                item.Checked = control.ControlMode == ControlMode.Software &&
                                               Math.Round(control.SoftwareValue) == i;
                                int softwareValue = i;
                                item.Click += delegate(object obj, EventArgs args) {
                                    control.SetSoftware(softwareValue);
                                };
                            }
                        }
                        treeContextMenu.MenuItems.Add(controlItem);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }

                HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
                if (hardwareNode != null && hardwareNode.Hardware != null)
                {
                    treeContextMenu.MenuItems.Clear();

                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("Rename");
                        item.Click += delegate(object obj, EventArgs args) {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }
            }
        }
Esempio n. 16
0
        private void treeView_Click(object sender, EventArgs e)
        {
            MouseEventArgs m = e as MouseEventArgs;

            if (m == null || m.Button != MouseButtons.Right)
            {
                return;
            }

            NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));

            treeView.SelectedNode = info.Node;
            if (info.Node != null)
            {
                SensorNode node = info.Node.Tag as SensorNode;
                if (node != null && node.Sensor != null)
                {
                    treeContextMenu.MenuItems.Clear();
                    if (node.Sensor.Parameters.Length > 0)
                    {
                        MenuItem item = new MenuItem("参数...");
                        item.Click += delegate(object obj, EventArgs args)
                        {
                            ShowParameterForm(node.Sensor);
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("重命名");
                        item.Click += delegate(object obj, EventArgs args)
                        {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.IsVisible)
                    {
                        MenuItem item = new MenuItem("隐藏");
                        item.Click += delegate(object obj, EventArgs args)
                        {
                            node.IsVisible = false;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    else
                    {
                        MenuItem item = new MenuItem("取消隐藏");
                        item.Click += delegate(object obj, EventArgs args)
                        {
                            node.IsVisible = true;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    treeContextMenu.MenuItems.Add(new MenuItem("-"));
                    {
                        MenuItem item = new MenuItem("在托盘中显示");
                        item.Checked = systemTray.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args)
                        {
                            if (item.Checked)
                            {
                                systemTray.Remove(node.Sensor);
                            }
                            else
                            {
                                systemTray.Add(node.Sensor, true);
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (gadget != null)
                    {
                        MenuItem item = new MenuItem("显示小工具");
                        item.Checked = gadget.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args)
                        {
                            if (item.Checked)
                            {
                                gadget.Remove(node.Sensor);
                            }
                            else
                            {
                                gadget.Add(node.Sensor);
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.Sensor.Control != null)
                    {
                        treeContextMenu.MenuItems.Add(new MenuItem("-"));
                        IControl control     = node.Sensor.Control;
                        MenuItem controlItem = new MenuItem("控制");
                        MenuItem defaultItem = new MenuItem("默认");
                        defaultItem.Checked = control.ControlMode == ControlMode.Default;
                        controlItem.MenuItems.Add(defaultItem);
                        defaultItem.Click += delegate(object obj, EventArgs args)
                        {
                            control.SetDefault();
                        };
                        MenuItem manualItem = new MenuItem("手动");
                        controlItem.MenuItems.Add(manualItem);
                        manualItem.Checked = control.ControlMode == ControlMode.Software;
                        for (int i = 0; i <= 100; i += 5)
                        {
                            if (i <= control.MaxSoftwareValue &&
                                i >= control.MinSoftwareValue)
                            {
                                MenuItem item = new MenuItem(i + " %");
                                item.RadioCheck = true;
                                manualItem.MenuItems.Add(item);
                                item.Checked = control.ControlMode == ControlMode.Software && Math.Round(control.SoftwareValue) == i;
                                int softwareValue = i;
                                item.Click += delegate(object obj, EventArgs args)
                                {
                                    control.SetSoftware(softwareValue);
                                };
                            }
                        }
                        treeContextMenu.MenuItems.Add(controlItem);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }

                HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
                if (hardwareNode != null && hardwareNode.Hardware != null)
                {
                    treeContextMenu.MenuItems.Clear();

                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("重命名");
                        item.Click += delegate(object obj, EventArgs args)
                        {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }
            }
        }
Esempio n. 17
0
        private void treeView_Click(object sender, EventArgs e)
        {
            MouseEventArgs m = e as MouseEventArgs;

            if (m == null || m.Button != MouseButtons.Right)
            {
                return;
            }

            NodeControlInfo info = treeView.GetNodeControlInfoAt(
                new Point(m.X, m.Y)
                );

            treeView.SelectedNode = info.Node;
            if (info.Node != null)
            {
                SensorNode node = info.Node.Tag as SensorNode;
                if (node != null && node.Sensor != null)
                {
                    treeContextMenu.MenuItems.Clear();
                    if (node.Sensor.Parameters.Length > 0)
                    {
                        MenuItem item = new MenuItem("Parameters...");
                        item.Click += delegate(object obj, EventArgs args) {
                            ShowParameterForm(node.Sensor);
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("Rename");
                        item.Click += delegate(object obj, EventArgs args) {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.IsVisible)
                    {
                        MenuItem item = new MenuItem("Hide");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = false;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    else
                    {
                        MenuItem item = new MenuItem("Unhide");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = true;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    treeContextMenu.MenuItems.Add(new MenuItem("-"));
                    {
                        MenuItem item = new MenuItem("Show in Tray");
                        item.Checked = systemTray.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args) {
                            if (item.Checked)
                            {
                                systemTray.Remove(node.Sensor);
                            }
                            else
                            {
                                systemTray.Add(node.Sensor, true);
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (gadget != null)
                    {
                        MenuItem item = new MenuItem("Show in Gadget");
                        item.Checked = gadget.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args) {
                            if (item.Checked)
                            {
                                gadget.Remove(node.Sensor);
                            }
                            else
                            {
                                gadget.Add(node.Sensor);
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.Sensor.Control != null)
                    {
                        treeContextMenu.MenuItems.Add(new MenuItem("-"));
                        IControl control     = node.Sensor.Control;
                        MenuItem controlItem = new MenuItem("控制");
                        MenuItem defaultItem = new MenuItem("默认");
                        defaultItem.Checked = control.ControlMode == ControlMode.Default;
                        controlItem.MenuItems.Add(defaultItem);
                        defaultItem.Click += delegate(object obj, EventArgs args) {
                            control.SetDefault();
                        };
                        MenuItem manualItem = new MenuItem("手动");
                        controlItem.MenuItems.Add(manualItem);
                        manualItem.Checked = control.ControlMode == ControlMode.Software;
                        for (int i = 0; i <= 100; i += 5)
                        {
                            if (i <= control.MaxSoftwareValue &&
                                i >= control.MinSoftwareValue)
                            {
                                MenuItem item = new MenuItem(i + " %");
                                manualItem.MenuItems.Add(item);
                                item.Checked = control.ControlMode == ControlMode.Software &&
                                               Math.Round(control.SoftwareValue) == i;
                                int softwareValue = i;
                                item.Click += delegate(object obj, EventArgs args) {
                                    control.SetSoftware(softwareValue);
                                };
                            }
                        }
                        treeContextMenu.MenuItems.Add(controlItem);
                        //fan add
                        if (node.Sensor.SensorType.Equals(SensorType.TinyFanControl))
                        {
                            MenuItem controlModeItem = new MenuItem("风扇类型");
                            treeContextMenu.MenuItems.Add(controlModeItem);
                            MenuItem Pin3 = new MenuItem("3针");
                            Pin3.Checked = control.FanMode == FanMode.Pin3;
                            Pin3.Click  += delegate(object obj, EventArgs args){
                                control.SetTheFanMode(FanMode.Pin3);
                            };
                            MenuItem Pin4 = new MenuItem("4针 (PWM)");
                            Pin4.Checked = control.FanMode == FanMode.Pin4;
                            Pin4.Click  += delegate(object obj, EventArgs args){
                                control.SetTheFanMode(FanMode.Pin4);
                            };
                            controlModeItem.MenuItems.Add(Pin3);
                            controlModeItem.MenuItems.Add(Pin4);
                            //add fan-follow. should all fan support this feature. TODO
                            MenuItem controlFanFollow = new MenuItem("自动跟随");
                            treeContextMenu.MenuItems.Add(controlFanFollow);
                            MenuItem followGPU = new MenuItem("显卡");
                            followGPU.Checked = control.FanFollow == FanFollow.GPU;
                            followGPU.Click  += delegate(object obj, EventArgs args)
                            {
                                control.SetTheFanFollow(FanFollow.GPU);
                            };
                            MenuItem followCPU = new MenuItem("CPU");
                            followCPU.Checked = control.FanFollow == FanFollow.CPU;
                            followCPU.Click  += delegate(object obj, EventArgs args)
                            {
                                control.SetTheFanFollow(FanFollow.CPU);
                            };
                            MenuItem followNONE = new MenuItem("关闭");
                            followNONE.Checked = control.FanFollow == FanFollow.NONE;
                            followNONE.Click  += delegate(object obj, EventArgs args)
                            {
                                control.SetTheFanFollow(FanFollow.NONE);
                            };
                            controlFanFollow.MenuItems.Add(followNONE);
                            controlFanFollow.MenuItems.Add(followGPU);
                            controlFanFollow.MenuItems.Add(followCPU);
                        }
                        //fan extend
                    }
                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }

                HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
                if (hardwareNode != null && hardwareNode.Hardware != null)
                {
                    treeContextMenu.MenuItems.Clear();

                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("Rename");
                        item.Click += delegate(object obj, EventArgs args) {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }
            }
        }
Esempio n. 18
0
        private void treeView_Click(object sender, EventArgs e)
        {
            // timer = System.Timers.Timer(DoubleClickTime);
            int clicks = 0;

            int            totalHarddriveCount = 0;
            MouseEventArgs m = e as MouseEventArgs;

            if (m == null || m.Button != MouseButtons.Right) // this means left-mouseclick
            {
                clicks++;



                System.Windows.Forms.MessageBox.Show("Left mouse clicked");
            }

            else
            {
                NodeControlInfo info = treeView.GetNodeControlInfoAt(
                    new Point(m.X, m.Y)
                    );
                treeView.SelectedNode = info.Node;
                if (info.Node != null)
                {
                    SensorNode node = info.Node.Tag as SensorNode;
                    if (node != null && node.Sensor != null)
                    {
                        treeContextMenu.MenuItems.Clear();
                        if (node.Sensor.Parameters.Length > 0)
                        {
                            MenuItem item = new MenuItem("Parameters...");
                            item.Click += delegate(object obj, EventArgs args)
                            {
                                ShowParameterForm(node.Sensor);
                            };
                            treeContextMenu.MenuItems.Add(item);
                        }
                        if (nodeTextBoxText.EditEnabled)
                        {
                            MenuItem item = new MenuItem("Rename");
                            item.Click += delegate(object obj, EventArgs args)
                            {
                                nodeTextBoxText.BeginEdit();
                            };
                            treeContextMenu.MenuItems.Add(item);
                        }
                        if (node.IsVisible)
                        {
                            MenuItem item = new MenuItem("Hide");
                            item.Click += delegate(object obj, EventArgs args)
                            {
                                node.IsVisible = false;
                            };
                            treeContextMenu.MenuItems.Add(item);
                        }
                        else
                        {
                            MenuItem item = new MenuItem("Unhide");
                            item.Click += delegate(object obj, EventArgs args)
                            {
                                node.IsVisible = true;
                            };
                            treeContextMenu.MenuItems.Add(item);
                        }
                        treeContextMenu.MenuItems.Add(new MenuItem("-"));
                        {
                            MenuItem item = new MenuItem("Show in Tray");
                            item.Checked = systemTray.Contains(node.Sensor);
                            item.Click  += delegate(object obj, EventArgs args)
                            {
                                if (item.Checked)
                                {
                                    systemTray.Remove(node.Sensor);
                                }
                                else
                                {
                                    systemTray.Add(node.Sensor, true);
                                }
                            };
                            treeContextMenu.MenuItems.Add(item);
                        }
                        if (gadget != null)
                        {
                            MenuItem item = new MenuItem("Show in Gadget");
                            item.Checked = gadget.Contains(node.Sensor);
                            item.Click  += delegate(object obj, EventArgs args)
                            {
                                if (item.Checked)
                                {
                                    gadget.Remove(node.Sensor);
                                }
                                else
                                {
                                    gadget.Add(node.Sensor);
                                }
                            };
                            treeContextMenu.MenuItems.Add(item);
                        }
                        if (node.Sensor.Control != null)
                        {
                            treeContextMenu.MenuItems.Add(new MenuItem("-"));
                            IControl control     = node.Sensor.Control;
                            MenuItem controlItem = new MenuItem("Control");
                            MenuItem defaultItem = new MenuItem("Default");
                            defaultItem.Checked = control.ControlMode == ControlMode.Default;
                            controlItem.MenuItems.Add(defaultItem);
                            defaultItem.Click += delegate(object obj, EventArgs args)
                            {
                                control.SetDefault();
                            };
                            MenuItem manualItem = new MenuItem("Manual");
                            controlItem.MenuItems.Add(manualItem);
                            manualItem.Checked = control.ControlMode == ControlMode.Software;
                            for (int i = 0; i <= 100; i += 5)
                            {
                                if (i <= control.MaxSoftwareValue &&
                                    i >= control.MinSoftwareValue)
                                {
                                    MenuItem item = new MenuItem(i + " %");
                                    item.RadioCheck = true;
                                    manualItem.MenuItems.Add(item);
                                    item.Checked = control.ControlMode == ControlMode.Software &&
                                                   Math.Round(control.SoftwareValue) == i;
                                    int softwareValue = i;
                                    item.Click += delegate(object obj, EventArgs args)
                                    {
                                        control.SetSoftware(softwareValue);
                                    };
                                }
                            }
                            treeContextMenu.MenuItems.Add(controlItem);
                        }

                        treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                    }

                    HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
                    if (hardwareNode != null && hardwareNode.Hardware != null)
                    {
                        treeContextMenu.MenuItems.Clear();

                        if (nodeTextBoxText.EditEnabled)
                        {
                            MenuItem item = new MenuItem("Rename");
                            item.Click += delegate(object obj, EventArgs args)
                            {
                                nodeTextBoxText.BeginEdit();
                            };
                            treeContextMenu.MenuItems.Add(item);
                        }

                        if (hardwareNode.Hardware.HardwareType.ToString() == hardwareNode.HDDType()) // For the HDD's in the system
                        {
                            MenuItem item = new MenuItem("Properties");
                            item.Click += delegate(object obj, EventArgs args)
                            {
                                // Harddrive with Identifier /hdd/7 is at the top of the list and harddrive with identifier /hdd/0 is at the bottom of the list!!!


                                string[]            hddInfo       = { };
                                List <HardwareNode> hardWareNodes = new List <HardwareNode>();
                                foreach (Node n in root.Nodes)
                                {
                                    HardwareNode HN = n as HardwareNode;

                                    if (HN.Hardware.HardwareType.ToString() == hardwareNode.HDDType())
                                    {
                                        totalHarddriveCount++;
                                    }
                                }

                                HDDDialog = new HDDForm();
                                int    driveIndex       = Convert.ToInt32(hardwareNode.Hardware.Identifier.ToString().Replace("/hdd/", ""));
                                string harddriveAddress = @"\\.\PhysicalDrive" + driveIndex;
                                //  IntPtr deviceHandle = smart.OpenDrive(driveIndex);


                                HDDDialog.SelectRequestedHardDisk(hardwareNode.Hardware.Name);
                                HDDDialog.Show();
                            };
                            treeContextMenu.MenuItems.Add(item);
                        }
                        ;

                        if (hardwareNode.Hardware.HardwareType.ToString() == hardwareNode.RAMType()) // For the RAM memory
                        {
                            MenuItem item = new MenuItem("Properties");
                            item.Click += delegate(object obj, EventArgs args)
                            {
                                RAMDialog = new RAMForm();
                                RAMDialog.Show();
                            };
                            treeContextMenu.MenuItems.Add(item);
                        }

                        treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                    }
                }


                return;
            }
        }
Esempio n. 19
0
        private void treeView_Click(object sender, EventArgs e)
        {
            MouseEventArgs m = e as MouseEventArgs;

            if (m == null || m.Button != MouseButtons.Right)
            {
                return;
            }

            NodeControlInfo info = treeView.GetNodeControlInfoAt(
                new Point(m.X, m.Y)
                );

            treeView.SelectedNode = info.Node;
            if (info.Node != null)
            {
                SensorNode node = info.Node.Tag as SensorNode;
                if (node != null && node.Sensor != null)
                {
                    treeContextMenu.MenuItems.Clear();
                    if (node.Sensor.Parameters.Length > 0)
                    {
                        MenuItem item = new MenuItem("Parameters...");
                        item.Click += delegate(object obj, EventArgs args) {
                            ShowParameterForm(node.Sensor);
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("Rename");
                        item.Click += delegate(object obj, EventArgs args) {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.IsVisible)
                    {
                        MenuItem item = new MenuItem("Hide");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = false;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    else
                    {
                        MenuItem item = new MenuItem("Unhide");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = true;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    treeContextMenu.MenuItems.Add(new MenuItem("-"));
                    {
                        MenuItem item = new MenuItem("Pen Color...");
                        item.Click += delegate(object obj, EventArgs args) {
                            ColorDialog dialog = new ColorDialog();
                            dialog.Color = node.PenColor.GetValueOrDefault();
                            if (dialog.ShowDialog() == DialogResult.OK)
                            {
                                node.PenColor = dialog.Color;
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    {
                        MenuItem item = new MenuItem("Reset Pen Color");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.PenColor = null;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    treeContextMenu.MenuItems.Add(new MenuItem("-"));
                    {
                        MenuItem item = new MenuItem("Show in Tray");
                        item.Checked = systemTray.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args) {
                            if (item.Checked)
                            {
                                systemTray.Remove(node.Sensor);
                            }
                            else
                            {
                                systemTray.Add(node.Sensor, true);
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (gadget != null)
                    {
                        MenuItem item = new MenuItem("Show in Gadget");
                        item.Checked = gadget.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args) {
                            if (item.Checked)
                            {
                                gadget.Remove(node.Sensor);
                            }
                            else
                            {
                                gadget.Add(node.Sensor);
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.Sensor.Control != null)
                    {
                        treeContextMenu.MenuItems.Add(new MenuItem("-"));
                        IControl control     = node.Sensor.Control;
                        MenuItem controlItem = new MenuItem("Control");
                        MenuItem defaultItem = new MenuItem("Default");
                        defaultItem.Checked = control.ActualControlMode == ControlMode.Default;
                        controlItem.MenuItems.Add(defaultItem);
                        defaultItem.Click += delegate(object obj, EventArgs args) {
                            control.SetDefault();
                        };
                        MenuItem manualItem = new MenuItem("Manual");
                        controlItem.MenuItems.Add(manualItem);
                        manualItem.Checked = control.ActualControlMode == ControlMode.Software;
                        for (int i = 0; i <= 100; i += 5)
                        {
                            if (i <= control.MaxSoftwareValue &&
                                i >= control.MinSoftwareValue)
                            {
                                MenuItem item = new MenuItem(i + " %");
                                item.RadioCheck = true;
                                manualItem.MenuItems.Add(item);
                                item.Checked = control.ActualControlMode == ControlMode.Software &&
                                               Math.Round(control.SoftwareValue) == i;
                                int softwareValue = i;
                                item.Click += delegate(object obj, EventArgs args) {
                                    control.SetSoftware(softwareValue);
                                };
                            }
                        }
                        MenuItem curveItem = new MenuItem("Manual Curve");
                        controlItem.MenuItems.Add(curveItem);
                        curveItem.Checked = control.ActualControlMode == ControlMode.SoftwareCurve;
                        MenuItem newCurveItem = new MenuItem("New");
                        newCurveItem.Click += delegate(object obj, EventArgs args) {
                            var confirmSensorselect = MessageBox.Show("Select the other sensor after clicking OK.", "New Manual Curve", MessageBoxButtons.OKCancel);
                            if (confirmSensorselect == DialogResult.OK)
                            {
                                // Listen for user click on sensor
                                EventHandler selectorListener = null;
                                selectorListener = (curveselect_sender, curveselect_e) => {
                                    MouseEventArgs curveselect_m = curveselect_e as MouseEventArgs;
                                    if (curveselect_m == null || curveselect_m.Button != MouseButtons.Left)
                                    {
                                        this.treeView.Click -= selectorListener;
                                        return;
                                    }
                                    // Try find sensor user clicked
                                    NodeControlInfo curveselect_info = treeView.GetNodeControlInfoAt(new Point(curveselect_m.X, curveselect_m.Y));
                                    if (curveselect_info.Node != null)
                                    {
                                        SensorNode curveselect_node = curveselect_info.Node.Tag as SensorNode;
                                        if (curveselect_node != null && curveselect_node.Sensor != null)
                                        {
                                            new SensorControlForm(node.Sensor, curveselect_node.Sensor, null).ShowDialog();
                                            return;
                                        }
                                    }

                                    var tryagainSensorselect = MessageBox.Show("Could not find sensor. Try again?", "Manual Curve", MessageBoxButtons.RetryCancel);
                                    if (tryagainSensorselect != DialogResult.Retry)
                                    {
                                        this.treeView.Click -= selectorListener;
                                    }
                                };
                                this.treeView.Click += selectorListener;
                            }
                        };
                        curveItem.MenuItems.Add(newCurveItem);
                        var softwareCurve = node.Sensor.Control.GetSoftwareCurve();
                        if (softwareCurve != null)
                        {
                            // edit curve
                            MenuItem editCurveItem = new MenuItem("Edit");
                            curveItem.MenuItems.Add(editCurveItem);
                            editCurveItem.Click += delegate(object obj, EventArgs args) {
                                new SensorControlForm(node.Sensor, softwareCurve.Sensor, softwareCurve.Points).ShowDialog();
                            };

                            if (control.ActualControlMode != ControlMode.SoftwareCurve)
                            {
                                // enable curve
                                MenuItem enableCurveItem = new MenuItem("Enable");
                                curveItem.MenuItems.Add(enableCurveItem);
                                enableCurveItem.Click += delegate(object obj, EventArgs args) {
                                    node.Sensor.Control.SetSoftwareCurve(softwareCurve.Points, softwareCurve.Sensor);
                                };
                            }
                        }
                        treeContextMenu.MenuItems.Add(controlItem);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }

                HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
                if (hardwareNode != null && hardwareNode.Hardware != null)
                {
                    treeContextMenu.MenuItems.Clear();

                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("Rename");
                        item.Click += delegate(object obj, EventArgs args) {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }
            }
        }
 private void InsertSorted(Node node, ISensor sensor) {
   int i = 0;
   while (i < node.Nodes.Count &&
     ((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index)
     i++;
   SensorNode sensorNode = new SensorNode(sensor, settings, unitManager);
   sensorNode.PlotSelectionChanged += SensorPlotSelectionChanged;
   node.Nodes.Insert(i, sensorNode);
 }
Esempio n. 21
0
        private void treeView_Click(object sender, EventArgs e)
        {
            MouseEventArgs m = e as MouseEventArgs;

            if (m == null || m.Button != MouseButtons.Right)
            {
                return;
            }

            NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));

            treeView.SelectedNode = info.Node;
            if (info.Node != null)
            {
                SensorNode node = info.Node.Tag as SensorNode;
                if (node != null && node.Sensor != null)
                {
                    sensorContextMenu.MenuItems.Clear();
                    if (node.Sensor.Parameters.Length > 0)
                    {
                        MenuItem item = new MenuItem("Parameters...");
                        item.Click += delegate(object obj, EventArgs args) {
                            ShowParameterForm(node.Sensor);
                        };
                        sensorContextMenu.MenuItems.Add(item);
                    }
                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("Rename");
                        item.Click += delegate(object obj, EventArgs args) {
                            nodeTextBoxText.BeginEdit();
                        };
                        sensorContextMenu.MenuItems.Add(item);
                    }
                    if (node.IsVisible)
                    {
                        MenuItem item = new MenuItem("Hide");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = false;
                        };
                        sensorContextMenu.MenuItems.Add(item);
                    }
                    else
                    {
                        MenuItem item = new MenuItem("Unhide");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = true;
                        };
                        sensorContextMenu.MenuItems.Add(item);
                    }
                    sensorContextMenu.MenuItems.Add(new MenuItem("-"));
                    {
                        MenuItem item = new MenuItem("Show in Tray");
                        item.Checked = systemTray.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args) {
                            if (item.Checked)
                            {
                                systemTray.Remove(node.Sensor);
                            }
                            else
                            {
                                systemTray.Add(node.Sensor, true);
                            }
                        };
                        sensorContextMenu.MenuItems.Add(item);
                    }
                    {
                        MenuItem item = new MenuItem("Show in Gadget");
                        item.Checked = gadget.Contains(node.Sensor);
                        item.Click  += delegate(object obj, EventArgs args) {
                            if (item.Checked)
                            {
                                gadget.Remove(node.Sensor);
                            }
                            else
                            {
                                gadget.Add(node.Sensor);
                            }
                        };
                        sensorContextMenu.MenuItems.Add(item);
                    }

                    sensorContextMenu.Show(treeView, new Point(m.X, m.Y));
                }
            }
        }