/*
Copyright 2012 Justin LeCheminant
This file is part of WindowsFormsCalendar.
indowsFormsCalendar is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
indowsFormsCalendar 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with indowsFormsCalendar. If not, see .
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace WindowsFormsCalendar
{
///
/// Represents a selectable timescale unit on a
///
public class CalendarTimeScaleUnit
: CalendarSelectableElement
{
#region Events
#endregion
#region Fields
private DateTime _date;
private CalendarDay _day;
private bool _highlighted;
private int _hours;
private int _index;
private int _minutes;
private List _passingItems;
private bool _visible;
#endregion
#region Properties
///
/// Gets the exact date when the unit starts
///
public override DateTime Date
{
get
{
if( _date.Equals( DateTime.MinValue ) )
{
_date = new DateTime( Day.Date.Year, Day.Date.Month, Day.Date.Day, Hours, Minutes, 0 );
}
return _date;
}
}
///
/// Gets the this unit belongs to
///
public CalendarDay Day
{
get { return _day; }
}
///
/// Gets the duration of the unit.
///
public TimeSpan Duration
{
get
{
return new TimeSpan( 0, (int)Calendar.TimeScale, 0 );
}
}
///
/// Gets if the unit is highlighted because it fits in some of the calendar's highlight ranges
///
public bool Highlighted
{
get { return _highlighted; }
}
///
/// Gets the hour when this unit starts
///
public int Hours
{
get { return _hours; }
}
///
/// Gets the index of the unit relative to the day
///
public int Index
{
get { return _index; }
}
///
/// Gets the minute when this unit starts
///
public int Minutes
{
get { return _minutes; }
set { _minutes = value; }
}
///
/// Gets or sets the amount of items that pass over the unit
///
internal List PassingItems
{
get { return _passingItems; }
set { _passingItems = value; }
}
///
/// Gets a value indicating if the unit is currently visible on viewport
///
public bool Visible
{
get { return _visible; }
}
#endregion
///
/// Creates a new
///
/// this unit belongs to
/// Index of the unit relative to the container day
/// Hour of the unit
/// Minutes of the unit
internal CalendarTimeScaleUnit( CalendarDay day, int index, int hours, int minutes )
: base( day.Calendar )
{
_day = day;
_index = index;
_hours = hours;
_minutes = minutes;
_passingItems = new List();
}
#region Public Methods
///
/// Returns a that represents this instance.
///
///
/// A that represents this instance.
///
public override string ToString()
{
return string.Format( "[{0}] - {1}", Index, Date.ToShortTimeString() );
}
#endregion
#region Private Methods
///
/// Gets a value indicating if the unit should be higlighted
///
///
internal bool CheckHighlighted()
{
for( int i = 0; i < Day.Calendar.HighlightRanges.Length; i++ )
{
CalendarHighlightRange range = Day.Calendar.HighlightRanges[i];
if( range.DayOfWeek != Date.DayOfWeek )
continue;
if( Date.TimeOfDay.CompareTo( range.StartTime ) >= 0
&& Date.TimeOfDay.CompareTo( range.EndTime ) < 0 )
{
return true;
}
}
return false;
}
///
/// Sets the value of the property
///
/// Value of the property
internal void SetHighlighted( bool highlighted )
{
_highlighted = highlighted;
}
///
/// Sets the value of the property
///
/// Value indicating if the unit is currently visible on viewport
internal void SetVisible( bool visible )
{
_visible = visible;
}
#endregion
#region Internal Methods
///
/// Adds the passing item.
///
/// The item.
internal void AddPassingItem( CalendarItem item )
{
if( !PassingItems.Contains( item ) )
{
PassingItems.Add( item );
Day.AddContainedItem( item );
}
}
///
/// Clears existance of item from this unit and it's corresponding day.
///
///
internal void ClearItemExistance( CalendarItem item )
{
if( PassingItems.Contains( item ) )
{
PassingItems.Remove( item );
}
if( Day.ContainedItems.Contains( item ) )
{
Day.ContainedItems.Remove( item );
}
}
#endregion
}
}