using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using FastReport.Utils;
namespace FastReport
{
///
/// Represents a collection of the objects.
///
public class StyleSheet : CollectionBase, IFRSerializable
{
///
/// Gets or sets the element at the specified index.
///
/// Index of an element.
/// The element at the specified index.
public StyleCollection this[int index]
{
get { return List[index] as StyleCollection; }
set { List[index] = value; }
}
///
/// Adds the specified elements to the end of this collection.
///
///
public void AddRange(StyleCollection[] range)
{
foreach (StyleCollection s in range)
{
Add(s);
}
}
///
/// Adds an object to the end of this collection.
///
/// Object to add.
/// Index of the added object.
public int Add(StyleCollection value)
{
return List.Add(value);
}
///
/// Inserts an object into this collection at the specified index.
///
/// The zero-based index at which value should be inserted.
/// The object to insert.
public void Insert(int index, StyleCollection value)
{
List.Insert(index, value);
}
///
/// Removes the specified object from the collection.
///
/// Object to remove.
public void Remove(StyleCollection value)
{
int i = IndexOf(value);
if (i != -1)
List.RemoveAt(i);
}
///
/// Returns the zero-based index of the first occurrence of an object.
///
/// The object to locate in the collection.
/// The zero-based index of the first occurrence of value within the entire collection, if found;
/// otherwise, -1.
public int IndexOf(StyleCollection value)
{
return List.IndexOf(value);
}
///
/// Returns the zero-based index of the first occurrence of a style collection with specified name.
///
/// The style collection name to locate in the collection.
/// The zero-based index of the first occurrence of value within the entire collection, if found;
/// otherwise, -1.
public int IndexOf(string value)
{
for (int i = 0; i < Count; i++)
{
StyleCollection s = this[i];
if (String.Compare(s.Name, value, true) == 0)
return i;
}
return -1;
}
///
/// Determines whether an element is in the collection.
///
/// The object to locate in the collection.
/// true if object is found in the collection; otherwise, false.
public bool Contains(StyleCollection value)
{
return IndexOf(value) != -1;
}
///
/// Determines whether a style collection with specified name is in the collection.
///
/// The style collection name to locate in the collection.
/// true if object is found in the collection; otherwise, false.
public bool Contains(string value)
{
return IndexOf(value) != -1;
}
///
/// Gets an array containing all collection items.
///
/// An array containing all collection items.
public object[] ToArray()
{
List list = new List();
foreach (StyleCollection s in this)
{
list.Add(s.Name);
}
return list.ToArray();
}
///
/// Serializes the collection.
///
/// Writer object.
///
/// This method is for internal use only.
///
public void Serialize(FRWriter writer)
{
writer.ItemName = "StyleSheet";
foreach (StyleCollection s in this)
{
writer.Write(s);
}
}
///
/// Deserializes the collection.
///
/// Reader object.
///
/// This method is for internal use only.
///
public void Deserialize(FRReader reader)
{
while (reader.NextItem())
{
StyleCollection s = new StyleCollection();
reader.Read(s);
Add(s);
}
}
///
/// Saves the collection to a stream.
///
/// Stream to save to.
public void Save(Stream stream)
{
using (FRWriter writer = new FRWriter())
{
writer.Write(this);
writer.Save(stream);
}
}
///
/// Saves the collection to a file with specified name.
///
/// File name to save to.
public void Save(string fileName)
{
using (FileStream f = new FileStream(fileName, FileMode.Create))
{
Save(f);
}
}
///
/// Loads the collection from a stream.
///
/// Stream to load from.
public void Load(Stream stream)
{
Clear();
using (FRReader reader = new FRReader(null))
{
reader.Load(stream);
reader.Read(this);
}
}
///
/// Loads the collection from a file with specified name.
///
/// Name of a file.
public void Load(string fileName)
{
using (FileStream f = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
Load(f);
}
}
}
}