Refactoring and fine tuning for Linux GUI.
1.1 --- a/GUI/MainForm.Designer.cs Sat Jul 24 20:15:49 2010 +0000
1.2 +++ b/GUI/MainForm.Designer.cs Tue Jul 27 18:38:11 2010 +0000
1.3 @@ -440,7 +440,7 @@
1.4 //
1.5 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
1.6 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
1.7 - this.ClientSize = new System.Drawing.Size(418, 596);
1.8 + this.ClientSize = new System.Drawing.Size(418, 554);
1.9 this.Controls.Add(this.splitContainer);
1.10 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
1.11 this.Menu = this.mainMenu;
2.1 --- a/GUI/MainForm.cs Sat Jul 24 20:15:49 2010 +0000
2.2 +++ b/GUI/MainForm.cs Tue Jul 27 18:38:11 2010 +0000
2.3 @@ -77,6 +77,15 @@
2.4 // set the DockStyle here, to avoid conflicts with the MainMenu
2.5 this.splitContainer.Dock = DockStyle.Fill;
2.6
2.7 + int p = (int)System.Environment.OSVersion.Platform;
2.8 + if ((p == 4) || (p == 128)) {
2.9 + splitContainer.BorderStyle = BorderStyle.None;
2.10 + splitContainer.Border3DStyle = Border3DStyle.Adjust;
2.11 + splitContainer.SplitterWidth = 4;
2.12 + treeView.BorderStyle = BorderStyle.Fixed3D;
2.13 + plotPanel.BorderStyle = BorderStyle.Fixed3D;
2.14 + }
2.15 +
2.16 this.Font = SystemFonts.MessageBoxFont;
2.17 treeView.Font = SystemFonts.MessageBoxFont;
2.18 plotPanel.Font = SystemFonts.MessageBoxFont;
2.19 @@ -459,8 +468,10 @@
2.20 }
2.21
2.22 private void resetMinMaxMenuItem_Click(object sender, EventArgs e) {
2.23 - IVisitor visitor = new ResetMinMaxVisitor();
2.24 - computer.Accept(visitor);
2.25 + computer.Accept(new SensorVisitor(delegate(ISensor sensor) {
2.26 + sensor.ResetMin();
2.27 + sensor.ResetMax();
2.28 + }));
2.29 }
2.30 }
2.31 }
3.1 --- a/GUI/PlotPanel.cs Sat Jul 24 20:15:49 2010 +0000
3.2 +++ b/GUI/PlotPanel.cs Tue Jul 27 18:38:11 2010 +0000
3.3 @@ -86,12 +86,12 @@
3.4 float? minTempNullable = null;
3.5 float? maxTempNullable = null;
3.6 foreach (ISensor sensor in temperatures) {
3.7 - IEnumerable<ISensorEntry> graph = sensor.Plot;
3.8 - foreach (ISensorEntry entry in graph) {
3.9 - if (!minTempNullable.HasValue || minTempNullable > entry.Value)
3.10 - minTempNullable = entry.Value;
3.11 - if (!maxTempNullable.HasValue || maxTempNullable < entry.Value)
3.12 - maxTempNullable = entry.Value;
3.13 + IEnumerable<SensorValue> values = sensor.Values;
3.14 + foreach (SensorValue value in values) {
3.15 + if (!minTempNullable.HasValue || minTempNullable > value.Value)
3.16 + minTempNullable = value.Value;
3.17 + if (!maxTempNullable.HasValue || maxTempNullable < value.Value)
3.18 + maxTempNullable = value.Value;
3.19 }
3.20 }
3.21 if (!minTempNullable.HasValue) {
3.22 @@ -125,8 +125,8 @@
3.23
3.24 float maxTime = 5;
3.25 if (temperatures.Count > 0) {
3.26 - IEnumerator<ISensorEntry> enumerator =
3.27 - temperatures[0].Plot.GetEnumerator();
3.28 + IEnumerator<SensorValue> enumerator =
3.29 + temperatures[0].Values.GetEnumerator();
3.30 if (enumerator.MoveNext()) {
3.31 maxTime = (float)(now - enumerator.Current.Time).TotalMinutes;
3.32 }
3.33 @@ -193,13 +193,13 @@
3.34 float deltaTime = timeGrid[timeGrid.Count - 1];
3.35 foreach (ISensor sensor in temperatures) {
3.36 using (Pen pen = new Pen(colors[sensor])) {
3.37 - IEnumerable<ISensorEntry> graph = sensor.Plot;
3.38 + IEnumerable<SensorValue> values = sensor.Values;
3.39 PointF last = new PointF();
3.40 bool first = true;
3.41 - foreach (ISensorEntry entry in graph) {
3.42 + foreach (SensorValue value in values) {
3.43 PointF point = new PointF(
3.44 - x0 + w - w * (float)(now - entry.Time).TotalMinutes / deltaTime,
3.45 - y0 + h - h * (entry.Value - tempGrid[0]) / deltaTemp);
3.46 + x0 + w - w * (float)(now - value.Time).TotalMinutes / deltaTime,
3.47 + y0 + h - h * (value.Value - tempGrid[0]) / deltaTemp);
3.48 if (!first)
3.49 g.DrawLine(pen, last, point);
3.50 last = point;
4.1 --- a/GUI/ResetMinMaxVisitor.cs Sat Jul 24 20:15:49 2010 +0000
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,59 +0,0 @@
4.4 -/*
4.5 -
4.6 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
4.7 -
4.8 - The contents of this file are subject to the Mozilla Public License Version
4.9 - 1.1 (the "License"); you may not use this file except in compliance with
4.10 - the License. You may obtain a copy of the License at
4.11 -
4.12 - http://www.mozilla.org/MPL/
4.13 -
4.14 - Software distributed under the License is distributed on an "AS IS" basis,
4.15 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
4.16 - for the specific language governing rights and limitations under the License.
4.17 -
4.18 - The Original Code is the Open Hardware Monitor code.
4.19 -
4.20 - The Initial Developer of the Original Code is
4.21 - Michael Möller <m.moeller@gmx.ch>.
4.22 - Portions created by the Initial Developer are Copyright (C) 2009-2010
4.23 - the Initial Developer. All Rights Reserved.
4.24 -
4.25 - Contributor(s):
4.26 -
4.27 - Alternatively, the contents of this file may be used under the terms of
4.28 - either the GNU General Public License Version 2 or later (the "GPL"), or
4.29 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
4.30 - in which case the provisions of the GPL or the LGPL are applicable instead
4.31 - of those above. If you wish to allow use of your version of this file only
4.32 - under the terms of either the GPL or the LGPL, and not to allow others to
4.33 - use your version of this file under the terms of the MPL, indicate your
4.34 - decision by deleting the provisions above and replace them with the notice
4.35 - and other provisions required by the GPL or the LGPL. If you do not delete
4.36 - the provisions above, a recipient may use your version of this file under
4.37 - the terms of any one of the MPL, the GPL or the LGPL.
4.38 -
4.39 -*/
4.40 -
4.41 -using System;
4.42 -using System.Collections.Generic;
4.43 -using OpenHardwareMonitor.Hardware;
4.44 -
4.45 -namespace OpenHardwareMonitor.GUI {
4.46 - public class ResetMinMaxVisitor : IVisitor {
4.47 - public void VisitComputer(IComputer computer) {
4.48 - computer.Traverse(this);
4.49 - }
4.50 -
4.51 - public void VisitHardware(IHardware hardware) {
4.52 - hardware.Traverse(this);
4.53 - }
4.54 -
4.55 - public void VisitSensor(ISensor sensor) {
4.56 - sensor.ResetMin();
4.57 - sensor.ResetMax();
4.58 - }
4.59 -
4.60 - public void VisitParameter(IParameter parameter) { }
4.61 - }
4.62 -}
5.1 --- a/Hardware/ISensor.cs Sat Jul 24 20:15:49 2010 +0000
5.2 +++ b/Hardware/ISensor.cs Tue Jul 27 18:38:11 2010 +0000
5.3 @@ -51,9 +51,17 @@
5.4 Control
5.5 }
5.6
5.7 - public interface ISensorEntry {
5.8 - float Value { get; }
5.9 - DateTime Time { get; }
5.10 + public struct SensorValue {
5.11 + private float value;
5.12 + private DateTime time;
5.13 +
5.14 + public SensorValue(float value, DateTime time) {
5.15 + this.value = value;
5.16 + this.time = time;
5.17 + }
5.18 +
5.19 + public float Value { get { return value; } }
5.20 + public DateTime Time { get { return time; } }
5.21 }
5.22
5.23 public interface ISensor : IElement {
5.24 @@ -77,7 +85,7 @@
5.25 void ResetMin();
5.26 void ResetMax();
5.27
5.28 - IEnumerable<ISensorEntry> Plot { get; }
5.29 + IEnumerable<SensorValue> Values { get; }
5.30 }
5.31
5.32 }
6.1 --- a/Hardware/Sensor.cs Sat Jul 24 20:15:49 2010 +0000
6.2 +++ b/Hardware/Sensor.cs Tue Jul 27 18:38:11 2010 +0000
6.3 @@ -53,8 +53,8 @@
6.4 private float? value;
6.5 private float? min;
6.6 private float? max;
6.7 - private Queue<ISensorEntry> entries =
6.8 - new Queue<ISensorEntry>(MAX_MINUTES * 15);
6.9 + private Queue<SensorValue> values =
6.10 + new Queue<SensorValue>(MAX_MINUTES * 15);
6.11
6.12 private float sum = 0;
6.13 private int count = 0;
6.14 @@ -138,15 +138,15 @@
6.15 return value;
6.16 }
6.17 set {
6.18 - while (entries.Count > 0 &&
6.19 - (DateTime.Now - entries.Peek().Time).TotalMinutes > MAX_MINUTES)
6.20 - entries.Dequeue();
6.21 + while (values.Count > 0 &&
6.22 + (DateTime.Now - values.Peek().Time).TotalMinutes > MAX_MINUTES)
6.23 + values.Dequeue();
6.24
6.25 if (value.HasValue) {
6.26 sum += value.Value;
6.27 count++;
6.28 if (count == 4) {
6.29 - entries.Enqueue(new Entry(sum / count, DateTime.Now));
6.30 + values.Enqueue(new SensorValue(sum / count, DateTime.Now));
6.31 sum = 0;
6.32 count = 0;
6.33 }
6.34 @@ -171,22 +171,9 @@
6.35 max = null;
6.36 }
6.37
6.38 - public IEnumerable<ISensorEntry> Plot {
6.39 - get { return entries; }
6.40 - }
6.41 -
6.42 - public struct Entry : ISensorEntry {
6.43 - private float value;
6.44 - private DateTime time;
6.45 -
6.46 - public Entry(float value, DateTime time) {
6.47 - this.value = value;
6.48 - this.time = time;
6.49 - }
6.50 -
6.51 - public float Value { get { return value; } }
6.52 - public DateTime Time { get { return time; } }
6.53 - }
6.54 + public IEnumerable<SensorValue> Values {
6.55 + get { return values; }
6.56 + }
6.57
6.58 public void Accept(IVisitor visitor) {
6.59 visitor.VisitSensor(this);
7.1 --- a/OpenHardwareMonitor.csproj Sat Jul 24 20:15:49 2010 +0000
7.2 +++ b/OpenHardwareMonitor.csproj Tue Jul 27 18:38:11 2010 +0000
7.3 @@ -83,7 +83,7 @@
7.4 <Compile Include="GUI\ParameterForm.Designer.cs">
7.5 <DependentUpon>ParameterForm.cs</DependentUpon>
7.6 </Compile>
7.7 - <Compile Include="GUI\ResetMinMaxVisitor.cs" />
7.8 + <Compile Include="Hardware\SensorVisitor.cs" />
7.9 <Compile Include="GUI\SensorNotifyIcon.cs" />
7.10 <Compile Include="GUI\SplitContainerAdv.cs">
7.11 <SubType>Component</SubType>