|
/////////////////////////////////////////////////////////////////////////////
//
// (c) 2007 BinaryComponents Ltd. All Rights Reserved.
//
// http://www.binarycomponents.com/
//
/////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;
namespace BinaryComponents.VectorGraphics.Styles
{
public sealed class Lookup
{
public Lookup( Primitives.Container container )
{
if( container == null )
{
throw new ArgumentNullException( "container" );
}
Visitor visitor = new Visitor( _mapStyleToItems );
container.Visit( visitor );
}
public Primitives.VisualItem[] GetVisualItems( string styleClass )
{
List<Primitives.VisualItem> list;
if( _mapStyleToItems.TryGetValue( styleClass, out list ) )
{
return list.ToArray();
}
else
{
return new Primitives.VisualItem[] { };
}
}
#region Visitor
private sealed class Visitor : Primitives.Visitor
{
internal Visitor( Dictionary<string, List<Primitives.VisualItem>> mapStyleToItems )
{
_mapStyleToItems = mapStyleToItems;
}
public override void PreVisitVisualItem( Primitives.VisualItem visualItem )
{
foreach( string c in visualItem.Style.Classes )
{
List<Primitives.VisualItem> items;
if( !_mapStyleToItems.TryGetValue( c, out items ) )
{
items = new List<Primitives.VisualItem>();
_mapStyleToItems.Add( c, items );
}
items.Add( visualItem );
}
}
private Dictionary<string, List<Primitives.VisualItem>> _mapStyleToItems;
}
#endregion
private Dictionary<string, List<Primitives.VisualItem>> _mapStyleToItems = new Dictionary<string, List<Primitives.VisualItem>>();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm currently working for a small start-up company, BinaryComponents Ltd, producing the FeedGhost RSS reader.
FeedGhost RSS Reader:
http://www.feedghost.com
Bespoke Software Development
http://www.binarycomponents.com