[Roam-commit] SF.net SVN: roam: [119] Trunk/Source
Status: Alpha
Brought to you by:
jonfroehlich
|
From: <jon...@us...> - 2008-02-25 17:54:22
|
Revision: 119
http://roam.svn.sourceforge.net/roam/?rev=119&view=rev
Author: jonfroehlich
Date: 2008-02-25 09:54:19 -0800 (Mon, 25 Feb 2008)
Log Message:
-----------
added IsFull property to Buffer
changed MaxItems property in Buffer to Capacity
Modified Paths:
--------------
Trunk/Source/Roam.Common/Collections/Buffer.cs
Trunk/Source/Roam.UI/Controls/ScrollableLabel.cs
Modified: Trunk/Source/Roam.Common/Collections/Buffer.cs
===================================================================
--- Trunk/Source/Roam.Common/Collections/Buffer.cs 2008-02-25 09:42:47 UTC (rev 118)
+++ Trunk/Source/Roam.Common/Collections/Buffer.cs 2008-02-25 17:54:19 UTC (rev 119)
@@ -29,13 +29,17 @@
/// <author>Jon Froehlich</author>
public class Buffer<T> : ICollection<T>
{
+ #region Fields
private LinkedList<T> _listItems = new LinkedList<T>();
- private int _maxItems = 30;
+ private int _capacity = 30;
+ #endregion fields
- public Buffer(int maxItems)
+ #region Constructors
+ public Buffer(int capacity)
{
- _maxItems = maxItems;
+ _capacity = capacity;
}
+ #endregion Constructors
#region Properties
public virtual bool IsSynchronized
@@ -80,7 +84,7 @@
{
throw new ArgumentOutOfRangeException(String.Format(
"There is no item {0}; the number of items contained in this buffer is {1} (maximum {2})",
- index, _listItems.Count, this.MaxItems));
+ index, _listItems.Count, this.Capacity));
}
node = node.Next;
}
@@ -88,18 +92,18 @@
}
}
- public virtual int MaxItems
+ public virtual int Capacity
{
get
{
- return _maxItems;
+ return _capacity;
}
set
{
- if (_maxItems != value)
+ if (_capacity != value)
{
- _maxItems = value;
- while (_listItems.Count > _maxItems)
+ _capacity = value;
+ while (_listItems.Count > _capacity)
{
_listItems.RemoveFirst();
}
@@ -117,16 +121,21 @@
get { return false; }
}
+ public virtual bool IsFull
+ {
+ get { return Count == Capacity; }
+ }
+
//protected virtual LinkedList<T> Items
//{
// get { return _listItems; }
//}
#endregion Properties
-
+ #region Methods
public virtual void Add(T item)
{
- while (_listItems.Count >= _maxItems)
+ while (_listItems.Count >= _capacity)
{
_listItems.RemoveFirst();
}
@@ -136,18 +145,18 @@
public virtual void AddRange(T[] items)
{
//jeffixme test this method
- if (items.Length >= _maxItems)
+ if (items.Length >= _capacity)
{
_listItems.Clear();
- int startIndex = items.Length - _maxItems;
- for (int i = 0; i < _maxItems; i++)
+ int startIndex = items.Length - _capacity;
+ for (int i = 0; i < _capacity; i++)
{
_listItems.AddLast(items[startIndex + i]);
}
}
else
{
- while (_listItems.Count + items.Length >= _maxItems)
+ while (_listItems.Count + items.Length >= _capacity)
{
_listItems.RemoveFirst();
}
@@ -195,11 +204,14 @@
{
return _listItems.GetEnumerator();
}
+ #endregion Methods
+ #region Static Methods
public static SyncBuffer Synchronized(Buffer<T> b)
{
return new SyncBuffer(b);
}
+ #endregion Static Methods
/// <summary>
///
@@ -210,15 +222,19 @@
/// <author>Jon Froehlich</author>
public class SyncBuffer : Buffer<T>
{
+ #region Fields
private Buffer<T> _buffer;
private object _root;
+ #endregion Fields
+ #region Constructors
public SyncBuffer(Buffer<T> buffer)
: base(0)
{
_buffer = buffer;
_root = buffer.SyncRoot;
}
+ #endregion Constructors
#region Properties
public override bool IsSynchronized
@@ -242,17 +258,17 @@
}
}
- public override int MaxItems
+ public override int Capacity
{
get
{
- return _buffer.MaxItems;
+ return _buffer.Capacity;
}
set
{
lock (this._root)
{
- _buffer.MaxItems = value;
+ _buffer.Capacity = value;
}
}
}
@@ -272,8 +288,20 @@
{
get { return _buffer.IsReadOnly; }
}
+
+ public override bool IsFull
+ {
+ get
+ {
+ lock (this._root)
+ {
+ return base.IsFull;
+ }
+ }
+ }
#endregion Properties
+ #region Methods
public override void Add(T item)
{
lock (this._root)
@@ -329,6 +357,7 @@
return _buffer.GetEnumerator();
}
}
+ #endregion Methods
}
}
}
Modified: Trunk/Source/Roam.UI/Controls/ScrollableLabel.cs
===================================================================
--- Trunk/Source/Roam.UI/Controls/ScrollableLabel.cs 2008-02-25 09:42:47 UTC (rev 118)
+++ Trunk/Source/Roam.UI/Controls/ScrollableLabel.cs 2008-02-25 17:54:19 UTC (rev 119)
@@ -73,7 +73,7 @@
public ScrollableLabel(int maxLines)
: this(string.Empty)
{
- _buffer.MaxItems = maxLines;
+ _buffer.Capacity = maxLines;
}
public ScrollableLabel(string text)
@@ -204,12 +204,12 @@
public int MaxLines
{
- get { return _buffer.MaxItems; }
+ get { return _buffer.Capacity; }
set
{
- if (_buffer.MaxItems != value)
+ if (_buffer.Capacity != value)
{
- _buffer.MaxItems = value;
+ _buffer.Capacity = value;
UpdateLayout();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|