Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
FObermaier committed Apr 18, 2014
0 parents commit 1f1b62b
Show file tree
Hide file tree
Showing 9 changed files with 674 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin
obj
/packages/*
*.suo
154 changes: 154 additions & 0 deletions CategoryTheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Copyright 2014 - Felix Obermaier (www.ivv-aachen.de)
//
// This file is part of SharpMap.Rendering.Thematics.CategoryTheme.
// SharpMap.Rendering.Decoration.Legend is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SharpMap.Rendering.Thematics.CategoryTheme is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

using System;
using System.Collections.Generic;

namespace SharpMap.Rendering.Thematics
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;

using SharpMap.Data;
using SharpMap.Styles;
using SharpMap.Utilities;
///<summary>
///</summary>
[Serializable]
public class CategoryTheme<T> : /*NotificationObject,*/ ITheme
where T: IComparable<T>
{
private readonly List<ICategoryThemeItem<T>> _items = new List<ICategoryThemeItem<T>> ();

private string _columnName;

private bool _sorted;

public bool UseDefaultStyleForDbNull;

/// <summary>
/// The column name to get the value from
/// </summary>
public string ColumnName
{
get
{
return _columnName;
}
set
{
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentNullException("value");
if (value.Equals(_columnName))
return;

_columnName = value;
//this.OnPropertyChanged("ColumnName");
}
}

private ICategoryThemeItem<T> _default;

/// <summary>
/// Gets or sets the default <see cref="IStyle"/>, used when the attribute value does not match the criteria
/// </summary>
public ICategoryThemeItem<T> Default
{
get
{
return this._default;
}
set
{
this._default = value;
//this.OnPropertyChanged("Default");
}
}

///<summary>
///</summary>
///<param name="cti"></param>
public void Add(ICategoryThemeItem<T> cti)
{
_items.Add(cti);
_sorted = false;
//this.OnPropertyChanged("Items");
}

///<summary>
///</summary>
public void Clear()
{
_items.Clear();
//this.OnPropertyChanged("Items");
}

/// <summary>
/// Method to evaluate the style
/// </summary>
public IStyle GetStyle(FeatureDataRow attribute)
{
Debug.Assert(!String.IsNullOrEmpty(_columnName));
Debug.Assert(_default != null);

if (attribute == null)
throw new ArgumentNullException("attribute", "The attribute row must not be null!");

// If the row has no value return the default style
if (attribute.IsNull(_columnName) && UseDefaultStyleForDbNull) return _default.Style;

// Sort the list
if (!_sorted)
{
_items.Sort();
_sorted = true;
}

object val = attribute[_columnName];
if (val is T)
{
var tval = (T)val;
try
{
var cti = _items.Find(c => c.Matches(tval));
return cti.Style;
}
catch(ArgumentNullException)
{
}
//foreach (ICategoryThemeItem<T> categoryThemeItem in _items)
//{
// if (categoryThemeItem.Matches(tval)) return categoryThemeItem.Style;
//}
}

return Default.Style;
}

/// <summary>
/// Method to expose all <see cref="ICategoryThemeItem{T}"/>s.
/// </summary>
/// <returns></returns>
public System.Collections.ObjectModel.ReadOnlyCollection<ICategoryThemeItem<T>> ItemsAsReadOnly()
{
return _items.AsReadOnly();
}

}
}
104 changes: 104 additions & 0 deletions CategoryThemeItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2014 - Felix Obermaier (www.ivv-aachen.de)
//
// This file is part of SharpMap.Rendering.Thematics.CategoryTheme.
// SharpMap.Rendering.Decoration.Legend is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SharpMap.Rendering.Thematics.CategoryTheme is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;

using SharpMap.Data;
using SharpMap.Styles;
using SharpMap.Utilities;
namespace SharpMap.Rendering.Thematics
{

/// <summary>
/// Abstract base class for <see cref="ICategoryThemeItem{T}"/>
/// </summary>
/// <typeparam name="T"></typeparam>
[Serializable]
public abstract class CategoryThemeItem<T> : ICategoryThemeItem<T>
where T : IComparable<T>
{
private string _title;
private IStyle _style;


/// <summary>
/// Compares the current object with another of type <see cref="ICategoryThemeItem{T}"/>.
/// </summary>
/// <returns>
/// A value, that indicates the relative order of the compared objects. The value has the following meaning:
/// <list type="Table">
/// <item>&lt; 0</item><description>This object is less than the <paramref name="other"/>.</description>
/// <item>0</item><description>The object is equal</description>
/// <item>&gt;</item><description>This object is greater than the <paramref name="other"/>.</description>
/// </list>
/// Wert Bedeutung Kleiner als 0 (null) Dieses Objekt ist kleiner als der <paramref name="other"/>-Parameter.Zero Dieses Objekt ist gleich <paramref name="other"/>. Größer als 0 (null) Dieses Objekt ist größer als <paramref name="other"/>.
/// </returns>
/// <param name="other">An Object of type <see cref="ICategoryThemeItem{T}"/> that should be compared with this item.</param>
public abstract int CompareTo(ICategoryThemeItem<T> other);

/// <summary>
/// Evaluate that <paramref name="value"/> matches this <see cref="ICategoryThemeItem{T}"/>
/// </summary>
/// <param name="value">The value to test.</param>
/// <returns>true, if <paramref name="value"/></returns>
public abstract bool Matches(T value);

/// <summary>
/// Gets or sets the title for this <see cref="CategoryThemeItem{T}"/>
/// </summary>
public string Title
{
get
{
return this._title ?? this.ToString();
}
set
{
if (value.Equals(_title))
return;
this._title = value;
//this.OnPropertyChanged("Title");
}
}

/// <summary>
/// Gets or sets the <see cref="IStyle"/> for this <see cref="CategoryThemeItem{T}"/>
/// </summary>
public IStyle Style
{
get
{
return this._style;
}
set
{
if (value == null)
throw new ArgumentNullException("value");

if (value.Equals(_style))
return;

this._style = value;
//this.OnPropertyChanged("Style");
}
}

}
}
121 changes: 121 additions & 0 deletions CategoryThemeRangeItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright 2014 - Felix Obermaier (www.ivv-aachen.de)
//
// This file is part of SharpMap.Rendering.Thematics.CategoryTheme.
// SharpMap.Rendering.Decoration.Legend is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SharpMap.Rendering.Thematics.CategoryTheme is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;

using SharpMap.Data;
using SharpMap.Styles;
using SharpMap.Utilities;

namespace SharpMap.Rendering.Thematics
{
/// <summary>
/// Implementation that
/// </summary>
/// <typeparam name="T"></typeparam>
[Serializable]
public class CategoryThemeRangeItem<T> : CategoryThemeItem<T>
where T : IComparable<T>
{
private T _lowerBound;
private T _upperBound;

///<summary>
/// Gets or sets the lower bound for this <see cref="CategoryThemeRangeItem{T}"/>
///</summary>
public T LowerBound
{
get
{
return this._lowerBound;
}
set
{
if (_lowerBound.CompareTo(value) == 0)
return;
this._lowerBound = value;
//this.OnPropertyChanged("LowerBound");
}
}


///<summary>
/// Gets or sets the upper bound for this <see cref="CategoryThemeRangeItem{T}"/>
///</summary>
public T UpperBound
{
get
{
return this._upperBound;
}
set
{
if (_upperBound.CompareTo(value) == 0)
return;
this._upperBound = value;
//this.OnPropertyChanged("UpperBound");
}
}

/// <summary>
/// Compares the current object with another of type <see cref="ICategoryThemeItem{T}"/>.
/// </summary>
/// <returns>
/// A value, that indicates the relative order of the compared objects. The value has the following meaning:
/// <list type="Table">
/// <item>&lt; 0</item><description>This object is less than the <paramref name="other"/>.</description>
/// <item>0</item><description>The object is equal</description>
/// <item>&gt;</item><description>This object is greater than the <paramref name="other"/>.</description>
/// </list>
/// </returns>
/// <param name="other">An Object of type <see cref="ICategoryThemeItem{T}"/> that should be compared with this item.</param>
public override int CompareTo(ICategoryThemeItem<T> other)
{
var o = other as CategoryThemeRangeItem<T>;
if (o == null) return -1;

if (this.Matches(o.LowerBound)) return 0;
if (this.Matches(o.UpperBound)) return 0;

return _lowerBound.CompareTo(o.LowerBound);
}


/// <summary>
/// Evaluate that <paramref name="value"/> matches this <see cref="ICategoryThemeItem{T}"/>
/// </summary>
/// <remarks>
/// <paramref name="value"/> matches if it is in the range [LowerBound, UpperBound[
/// </remarks>
/// <param name="value">The value to test.</param>
/// <returns>true, if <paramref name="value"/> matches.</returns>
public override bool Matches(T value)
{
if (_lowerBound.CompareTo(value) < 0) return false;
if (_upperBound.CompareTo(value) >= 0) return false;
return true;
}

public override string ToString()
{
return string.Format("{0} - {1}", _lowerBound, _upperBound);
}
}
}
Loading

0 comments on commit 1f1b62b

Please sign in to comment.