#region gnu_license
/*
Crystal Controls - C# control library containing the following tools:
CrystalControl - base class
CrystalGradientControl - a control that can either have a gradient background or be totally transparent.
CrystalLabel - a homegrown label that can have a gradient or transparent background.
CrystalPanel - a panel that can have a gradient or transparent background.
CrystalTrackBar - a homegrown trackbar that can have a gradient or transparent background.
CrystalToolStripTrackBar - a host for CrystalTrackBar that allows it to work in a ToolStrip.
CrystalImageGridView - a control that hosts thumbnail images in a virtual grid.
CrystalImageGridModel - a data model that holds a collection of CrystalImageItems
to feed to CrystalImageGridView.
CrystalImageItem - a class that describes an Image file.
CrystalThumbnailer - provides thumbnailing methods for images.
CrystalCollector - a base class for a controller that links
CrystalImageGridView to the CrystalImageGridModel.
CrystalFileCollector - a controller that works on disk-based Image files.
CrystalDesignCollector - a controller that works in Visual Studio toolbox designer.
CrystalMemoryCollector - a controller that can be used to add images from memory.
CrystalMemoryZipCollector - a controller that accesses images in zip files by streaming them into memory.
CrystalZipCollector - a controller that accesses images in zip files by unpacking them.
CrystalRarCollector - a controller that accesses images in rar files by unpacking them.
CrystalPictureBox - a picture box control, derived from CrystalGradientControl.
CrystalPictureShow - a control for viewing images and processing slideshows.
CrystalComicShow - a control for viewing comic-book images in the CDisplay format.
Copyright (C) 2006, 2008 Richard Guion
Attilan Software Factory: http://www.attilan.com
Contact: richard@attilan.com
Version 1.0.0
This is a work in progress: USE AT YOUR OWN RISK! Interfaces/Methods may change!
This library 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.1 of the License, or (at your option) any later version.
This library 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 this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#endregion
using System.IO;
using Attilan.Crystal.Tools;
namespace Attilan.Crystal.Controls
{
/// <summary>
/// Factory class that creates crystal collector objects.
/// </summary>
public class CrystalCollectorFactory
{
/// <summary>
/// Default static instance of this factory.
/// </summary>
private static CrystalCollectorFactory _defaultFactory = new CrystalCollectorFactory();
/// <summary>
/// Default static instance of this factory.
/// </summary>
public static CrystalCollectorFactory DefaultFactory
{
get { return _defaultFactory; }
set { _defaultFactory = value; }
}
/// <summary>
/// Creates the appropriate collector based on the source location.
/// If the source location is a folder, CrystalFileCollector will be returned.
/// If the source location is a .zip file, CrystalZipCollector will be returned.
/// If the source location is a .rar file, CrystalRarCollector will be returned.
/// </summary>
/// <param name="sourcePath">Full path to the source, either a folder, zip file, or rar file.</param>
/// <returns>CrystalCollector-based object.</returns>
public virtual CrystalCollector CreateCollector(string sourcePath)
{
CrystalCollector returnCollector = null;
if (!string.IsNullOrEmpty(sourcePath))
{
string ext = Path.GetExtension(sourcePath);
ext = ext.ToLower();
if ((ext == ".cbz") || (ext == ".zip"))
{
returnCollector = CreateCollector(CrystalCollectorType.CrystalMemoryZipCollector);
}
else
if ((ext == ".cbr") || (ext == ".rar"))
{
returnCollector = CreateCollector(CrystalCollectorType.CrystalRarCollector);
}
}
// Default: File-based collector.
if (returnCollector == null)
{
returnCollector = CreateCollector(CrystalCollectorType.CrystalFileCollector);
}
InitCollectorSource(sourcePath, returnCollector);
return returnCollector;
}
/// <summary>
/// Creates a crystal collector based on the enumerated type.
/// </summary>
/// <param name="collectorType">Type of crystal collector to be created.</param>
/// <returns>Crystal Collector based object.</returns>
public virtual CrystalCollector CreateCollector(CrystalCollectorType collectorType)
{
CrystalLogger.LogEvent(
string.Format("Factory creating a collector for type: {0}", collectorType));
switch (collectorType)
{
case CrystalCollectorType.CrystalZipCollector:
{
return new CrystalZipCollector();
}
case CrystalCollectorType.CrystalMemoryZipCollector:
{
return new CrystalMemoryZipCollector();
}
case CrystalCollectorType.CrystalRarCollector:
{
return new CrystalRarCollector();
}
case CrystalCollectorType.CrystalDesignCollector:
{
return new CrystalDesignCollector();
}
case CrystalCollectorType.CrystalMemoryCollector:
{
return new CrystalMemoryCollector();
}
default:
{
return new CrystalFileCollector();
}
}
}
/// <summary>
/// Initializes the collector with the source target.
/// </summary>
/// <param name="sourcePath">Path to source files (folder, zip, rar, cbz, cbr)</param>
/// <param name="collector">CrystalCollector object.</param>
public virtual void InitCollectorSource(string sourcePath, CrystalCollector collector)
{
if (!string.IsNullOrEmpty(sourcePath))
{
CrystalLogger.LogEvent(
string.Format("Factory initializing {0} for source: {1}", collector.GetType(), sourcePath));
}
else
{
CrystalLogger.LogEvent(
string.Format("Factory initializing {0} for null source: {1}", collector.GetType(), "default is My Pictures folder."));
}
if (collector is ICrystalCompressedCollector)
{
ICrystalCompressedCollector compCollector = (ICrystalCompressedCollector)collector;
compCollector.InitCompressedFile(sourcePath);
}
else
{
// If the source path is empty, and the CrystalFileCollector has
// just been initialized, the default ImageLocation is set to MyPictures.
if (!string.IsNullOrEmpty(sourcePath))
{
collector.ImageLocation = sourcePath;
}
}
}
}
/// <summary>
/// Enumerator for types of Crystal Collector objects.
/// </summary>
public enum CrystalCollectorType
{
/// <summary>
/// File based collector, operates on a folder of images.
/// </summary>
CrystalFileCollector = 0,
/// <summary>
/// Zip-based collector, unpacks images in the first level of the zip file and thumbnails them.
/// </summary>
CrystalZipCollector = 1,
/// <summary>
/// Zip-based collector, streams images out of the zip instead of unpacking them.
/// </summary>
CrystalMemoryZipCollector = 2,
/// <summary>
/// Rar-based collector, unpacks images in the first level of a rar file and thumbnails them.
/// </summary>
CrystalRarCollector = 3,
/// <summary>
/// Collector used in the Windows Forms designer.
/// </summary>
CrystalDesignCollector = 4,
/// <summary>
/// Memory based collector, images must be manually loaded.
/// </summary>
CrystalMemoryCollector = 5
}
}