[Roam-commit] SF.net SVN: roam: [61] Trunk/Source
Status: Alpha
Brought to you by:
jonfroehlich
|
From: <jon...@us...> - 2007-03-04 09:24:35
|
Revision: 61
http://roam.svn.sourceforge.net/roam/?rev=61&view=rev
Author: jonfroehlich
Date: 2007-03-04 01:24:32 -0800 (Sun, 04 Mar 2007)
Log Message:
-----------
1. added AddRange methods to HashSet
2. Added a non-generic version of ReverseComparer
3. Added EnumUtils--has one method which returns the value names in the enum
Modified Paths:
--------------
Trunk/Source/Roam/PocketOutlook/Sms.cs
Trunk/Source/Roam/Utils/DeviceUtils.cs
Trunk/Source/Roam.Common/Collections/HashSet.cs
Trunk/Source/Roam.Common/Collections/ReverseComparer.cs
Trunk/Source/Roam.Common/Roam.Common.csproj
Trunk/Source/Roam.Common/Utils/CollectionUtils.cs
Trunk/Source/Roam.Common/Utils/FontUtils.cs
Trunk/Source/Roam.Common/Utils/StringUtils.cs
Trunk/Source/Roam.Test/Roam.Test.csproj
Trunk/Source/Roam.Test/UI/Controls/FontTest.Designer.cs
Trunk/Source/Roam.Test/UI/Controls/FontTest.cs
Trunk/Source/Roam.UI/Controls/NumericTextBox.cs
Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
Trunk/Source/Roam.suo
Added Paths:
-----------
Trunk/Source/Roam.Common/Utils/EnumUtils.cs
Modified: Trunk/Source/Roam/PocketOutlook/Sms.cs
===================================================================
--- Trunk/Source/Roam/PocketOutlook/Sms.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam/PocketOutlook/Sms.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -425,7 +425,6 @@
return "The radio hardware is unavailable.";
default:
return "error code unknown.";
- break;
}
}
#endregion SMS Error
Modified: Trunk/Source/Roam/Utils/DeviceUtils.cs
===================================================================
--- Trunk/Source/Roam/Utils/DeviceUtils.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam/Utils/DeviceUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -84,6 +84,7 @@
/// to be easily tested for correct overflow handling.
/// </summary>
/// <returns>The number of milliseconds indicates success.</returns>
+ [DllImport("coredll.dll")]
public extern static int GetTickCount();
Modified: Trunk/Source/Roam.Common/Collections/HashSet.cs
===================================================================
--- Trunk/Source/Roam.Common/Collections/HashSet.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Collections/HashSet.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -109,6 +109,36 @@
return true;
}
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="items"></param>
+ /// <returns>Returns the number of items added to the list</returns>
+ public int AddRange(T[] items)
+ {
+ int cnt = 0;
+ foreach (T t in items)
+ {
+ if (!Add(t)) { cnt++; }
+ }
+ return cnt;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="items"></param>
+ /// <returns>Returns the number of items added to the list</returns>
+ public int AddRange(ICollection<T> items)
+ {
+ int cnt = 0;
+ foreach (T t in items)
+ {
+ if (!Add(t)) { cnt++; }
+ }
+ return cnt;
+ }
+
public void Clear()
{
_dictionary.Clear();
Modified: Trunk/Source/Roam.Common/Collections/ReverseComparer.cs
===================================================================
--- Trunk/Source/Roam.Common/Collections/ReverseComparer.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Collections/ReverseComparer.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -49,4 +49,23 @@
return Compare((T)x, (T)y);
}
}
+
+ public class ReverseComparer : IComparer
+ {
+ private IComparer _comparer;
+
+ public ReverseComparer(IComparer comparer)
+ {
+ if (comparer == null)
+ {
+ throw new ArgumentNullException("comparer");
+ }
+ _comparer = comparer;
+ }
+
+ public int Compare(object x, object y)
+ {
+ return _comparer.Compare(y, x);
+ }
+ }
}
Modified: Trunk/Source/Roam.Common/Roam.Common.csproj
===================================================================
--- Trunk/Source/Roam.Common/Roam.Common.csproj 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Roam.Common.csproj 2007-03-04 09:24:32 UTC (rev 61)
@@ -75,6 +75,7 @@
<Compile Include="Collections\WalkUpTreeBranchEnumerator.cs" />
<Compile Include="Collections\WalkUpTreeBranch.cs" />
<Compile Include="Utils\DebugWriteAppender.cs" />
+ <Compile Include="Utils\EnumUtils.cs" />
<Compile Include="Utils\ErrorUtils.cs" />
<Compile Include="Utils\ImagingUtils.cs" />
<Compile Include="Utils\Vector2.cs" />
Modified: Trunk/Source/Roam.Common/Utils/CollectionUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/CollectionUtils.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Utils/CollectionUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -113,7 +113,6 @@
public static string ToString<T, S>(Dictionary<T, S> dict)
{
- int i = 0;
StringBuilder sb = new StringBuilder();
foreach (T key in dict.Keys)
{
Added: Trunk/Source/Roam.Common/Utils/EnumUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/EnumUtils.cs (rev 0)
+++ Trunk/Source/Roam.Common/Utils/EnumUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Reflection;
+
+namespace Roam.Common.Utils
+{
+ public static class EnumUtils
+ {
+ public static string[] GetNames(Type t)
+ {
+ List<string> l = new List<string>();
+ foreach (FieldInfo fi in t.GetFields())
+ {
+ if (fi.Name != "value__")
+ {
+ l.Add(fi.Name);
+ }
+ }
+ return l.ToArray();
+ }
+ }
+}
Modified: Trunk/Source/Roam.Common/Utils/FontUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/FontUtils.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Utils/FontUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -45,5 +45,20 @@
return defaultFont;
}
}
- }
+
+ public static FontFamily GetFontFamily(string fontFamily)
+ {
+ switch (fontFamily)
+ {
+ case "GenericSansSerif":
+ return FontFamily.GenericSansSerif;
+ case "GenericMonospace":
+ return FontFamily.GenericMonospace;
+ case "GenericSerif":
+ return FontFamily.GenericSerif;
+ default:
+ throw new ArgumentException("The FontFamliy " + fontFamily + " was not found. ", "fontFamily");
+ }
+ }
+ }
}
Modified: Trunk/Source/Roam.Common/Utils/StringUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/StringUtils.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Utils/StringUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -15,6 +15,7 @@
using System;
using System.Text;
using System.Collections;
+using System.Collections.Generic;
namespace Roam.Common.Utils
{
@@ -43,5 +44,21 @@
string str = new string(chars);
return str.Trim(new char[] { '\0' });
}
+
+ public static string [] ParseWords(string s)
+ {
+ char[] whitespace = new char[] { ' ', '\t', '\r', '\n' };
+ string [] words = s.Split(whitespace);
+ List<string> list = new List<string>();
+ foreach (string w in words)
+ {
+ string wTrim = w.Trim();
+ if (wTrim.Length > 0)
+ {
+ list.Add(wTrim);
+ }
+ }
+ return list.ToArray();
+ }
}
}
Modified: Trunk/Source/Roam.Test/Roam.Test.csproj
===================================================================
--- Trunk/Source/Roam.Test/Roam.Test.csproj 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Test/Roam.Test.csproj 2007-03-04 09:24:32 UTC (rev 61)
@@ -576,7 +576,7 @@
<DependentUpon>SystemColorTest.cs</DependentUpon>
</Compile>
<Compile Include="UI\Controls\TabControlTest.cs">
- <SubType>Form</SubType>
+ <SubType>Component</SubType>
</Compile>
<Compile Include="UI\Controls\TabControlTest.Designer.cs">
<DependentUpon>TabControlTest.cs</DependentUpon>
Modified: Trunk/Source/Roam.Test/UI/Controls/FontTest.Designer.cs
===================================================================
(Binary files differ)
Modified: Trunk/Source/Roam.Test/UI/Controls/FontTest.cs
===================================================================
--- Trunk/Source/Roam.Test/UI/Controls/FontTest.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Test/UI/Controls/FontTest.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -19,6 +19,8 @@
using System.Drawing;
using System.Text;
using System.Windows.Forms;
+using System.Reflection;
+using Roam.Common.Utils;
namespace Roam.Test.UI.Controls
{
@@ -34,6 +36,93 @@
public FontTest()
{
InitializeComponent();
+ _textBoxFontSize.TextChanged += new EventHandler(OnTextBoxFontSizeChanged);
+ _comboBoxFontFamily.SelectedValueChanged += new EventHandler(OnComboBoxFontFamilySelectedValueChanged);
+ _comboBoxFontStyle.SelectedValueChanged += new EventHandler(OnComboBoxFontStyleSelectedValueChanged);
+ _comboBoxFontName.SelectedValueChanged += new EventHandler(OnComboBoxFontNameSelectedValueChanged);
+ _textBox.TextChanged += new EventHandler(OnTextBoxTextChanged);
+
+ foreach(string s in EnumUtils.GetNames(typeof(FontStyle)))
+ {
+ _comboBoxFontStyle.Items.Add(s);
+ }
+
+ _comboBoxFontName.Items.Add(this.Font.Name);
+ _comboBoxFontName.SelectedItem = this.Font.Name;
+ _comboBoxFontFamily.Items.Add("GenericSansSerif");
+ _comboBoxFontFamily.Items.Add("GenericMonospace");
+ _comboBoxFontFamily.Items.Add("GenericSerif");
+
+ _fontTestControl.Text = "This is example text.";
+ _fontTestControl.TabStop = false;
+
+ _textBoxFontSize.Text = _fontTestControl.Font.Size.ToString();
+ //_comboBoxFontFamily.SelectedItem = new FontFamily();
}
+
+ void MeasureTextbox()
+ {
+ Graphics g = _fontTestControl.CreateGraphics();
+ SizeF textSize = g.MeasureString(_fontTestControl.Text, _fontTestControl.Font);
+ _labelStringMetrics.Text = string.Format("[{0:#.#}, {1:#.#}]", textSize.Width, textSize.Height);
+ g.Dispose();
+ }
+
+ void OnComboBoxFontNameSelectedValueChanged(object sender, EventArgs e)
+ {
+
+ }
+
+ void OnComboBoxFontStyleSelectedValueChanged(object sender, EventArgs e)
+ {
+ FontStyle fs = (FontStyle)Enum.Parse(typeof(FontStyle), _comboBoxFontStyle.Text, true);
+ _fontTestControl.Font = FontUtils.GetFont(_fontTestControl.Font.Name, _fontTestControl.Font.Size, fs, _fontTestControl.Font);
+ MeasureTextbox();
+ }
+
+ void OnComboBoxFontFamilySelectedValueChanged(object sender, EventArgs e)
+ {
+ FontFamily fontFamily = FontUtils.GetFontFamily(_comboBoxFontFamily.SelectedItem.ToString());
+ _fontTestControl.Font = new Font(FontUtils.GetFontFamily(_comboBoxFontFamily.Text),
+ _fontTestControl.Font.Size, _fontTestControl.Font.Style);
+ MeasureTextbox();
+ }
+
+ void OnTextBoxTextChanged(object sender, EventArgs e)
+ {
+ _fontTestControl.Text = _textBox.Text;
+ MeasureTextbox();
+ }
+
+ void OnTextBoxFontSizeChanged(object sender, EventArgs e)
+ {
+ if (_textBoxFontSize.TextAsInt > 0)
+ {
+ _fontTestControl.Font = FontUtils.GetFont(_fontTestControl.Font.Name,
+ _textBoxFontSize.TextAsInt, _fontTestControl.Font.Style, _fontTestControl.Font);
+ MeasureTextbox();
+ }
+ }
+
+ private void menuItem1_Click(object sender, EventArgs e)
+ {
+ this.Close();
+ }
+
+ private void menuItem3_Click(object sender, EventArgs e)
+ {
+ this.Invalidate();
+ }
}
+
+ public class FontTestControl : Control
+ {
+ protected override void OnPaint(PaintEventArgs e)
+ {
+ SolidBrush solidBrush = new SolidBrush(this.ForeColor);
+ e.Graphics.DrawString(this.Text, this.Font, solidBrush, 0, 0);
+ solidBrush.Dispose();
+ base.OnPaint(e);
+ }
+ }
}
Modified: Trunk/Source/Roam.UI/Controls/NumericTextBox.cs
===================================================================
--- Trunk/Source/Roam.UI/Controls/NumericTextBox.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.UI/Controls/NumericTextBox.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -39,12 +39,12 @@
public virtual int TextAsInt
{
- get { return int.Parse(Text); }
+ get { return (Text.Length <= 0) ? 0 : int.Parse(Text); }
}
public virtual double TextAsFloat
{
- get { return float.Parse(Text); }
+ get { return (Text.Length <= 0) ? 0 : float.Parse(Text); }
}
public bool AcceptDecimal
Modified: Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
===================================================================
--- Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -252,9 +252,10 @@
public static bool AlphaBlend(Image imageDest, Image imageSrc, float blend)
{
Graphics g = Graphics.FromImage(imageDest);
- return AlphaBlend(g, new Rectangle(0, 0, imageDest.Width, imageDest.Height),
+ bool b = AlphaBlend(g, new Rectangle(0, 0, imageDest.Width, imageDest.Height),
imageSrc, blend);
g.Dispose();
+ return b;
}
public static bool AlphaBlend(Graphics gxDest, Rectangle destRect, Image imageSrc, float blend)
Modified: Trunk/Source/Roam.suo
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|