?? calendardisplay.as
字號:
dayCount = Math.abs(dayCount);
if(_userDisplayMode == "auto")
{
if(dayCount <= 7)
_pendingDisplayMode = "days";
else
_pendingDisplayMode = "weeks";
dispatchEvent(new CalendarDisplayEvent(CalendarDisplayEvent.DISPLAY_MODE_CHANGE));
}
_pendingRange = value;
// by resetting this to NaN, we'll force the layout to recompute an appropriate hour to
// make sure values are visible.
_scrollHour = NaN;
dispatchEvent(new Event("change"));
var dm:String = (_pendingDisplayMode == null)? _pendingDisplayMode:_displayMode;
_removeAllEventData = (layoutMode == LayoutMode.WEEKS);
invalidateProperties();
}
// the current range displayed by the calendar. getting this property returns the full range visible in the calendar,
// which may be larger than the range set by the client.
[Bindable("change")]
public function get range():DateRange
{
var result:DateRange = _computedRange;
var bRecompute:Boolean = false;
var pr:DateRange = _currentRange;
var mode:String = _displayMode;
if(_pendingRange != null)
{
bRecompute = true;
pr = _pendingRange;
}
if(_pendingDisplayMode != null)
{
bRecompute = true;
mode = _pendingDisplayMode;
}
if(bRecompute)
{
var ranges:Object = computeRanges(pr,mode);
result = ranges._computedRange;
}
return result;
}
// the data displayed in the calendar. This should be an array of CalendarEvent objects.
// the calendar makes no assumption about sorting or range of these events...it will subset
// to the appropriate visible set.
public function set dataProvider(value:*):void
{
if(_dataProvider != null)
_dataProvider.removeEventListener(CollectionEvent.COLLECTION_CHANGE,eventsChanged);
if (value is Array)
{
value = new ArrayCollection(value as Array);
}
else if (value is IList)
{
}
else if (value is XMLList)
{
value = new XMLListCollection(XMLList(value));
}
else
{
value = new ArrayCollection();
}
if(_dataProvider == value)
return;
_dataProvider = value;
if(_dataProvider != null)
{
_dataProvider.addEventListener(CollectionEvent.COLLECTION_CHANGE,eventsChanged);
}
_removeAllEventData = true;
_allEventsDirty = true;
invalidateProperties();
}
public function get dataProvider():*
{
return _dataProvider;
}
// given a date, find its 0 based index in the current visible range of the calendar (in days).
private function indexForDate(value:Date):int
{
return Math.floor((value.getTime() - _visibleRange.start.getTime())/DateUtils.MILLI_IN_DAY);
}
// returns the date of the nth date currently visible in the calendar.
private function dateForIndex(index:int):Date
{
var result:Date = new Date(_visibleRange.start.getTime());
result.date = result.date + index;
return result;
}
// event handler that fires when the dataprovider changes.
private function eventsChanged(event:Event):void
{
_removeAllEventData = false;
_allEventsDirty = true;
invalidateProperties();
}
//----------------------------------------------------------------------------------------------------
// Navigation
//----------------------------------------------------------------------------------------------------
// advances the current display of the calendar to the next logical range.
// for arbitrary 'auto' ranges, this takes into account the assigned range, not
// the currently visible range. i.e., a range of the 7th-11th would advance to
// 12th-15th.
public function next():void
{
var r:DateRange = _currentRange.clone();
switch(_userDisplayMode)
{
case "day":
r.start.date += 1;
r.end.date += 1;
break;
case "week":
r.start.date += 7;
r.end.date += 7;
break;
case "auto":
r = _currentRange.clone();
r.start = r.end;
r.start.date += 1;
r.end = new Date(r.start);
r.end.date += _tz.daySpan(_currentRange.start,_currentRange.end)-1;
break;
case "month":
default:
r.start.month++;
r.end.month++;
break;
}
range = r;
}
// sets the current display of the calendar to the next logical range.
// for arbitrary 'auto' ranges, this takes into account the assigned range, not
// the currently visible range. i.e., a range of 7th-11th would change to
// 2nd-6th.
public function previous():void
{
var r:DateRange = _currentRange.clone();
switch(_userDisplayMode)
{
case "day":
r.start.date -= 1;
r.end.date -= 1;
break;
case "week":
r.start.date -= 7;
r.end.date -= 7;
break;
case "auto":
r = _currentRange.clone();
r.end = r.start;
r.end.date -= 1;
r.start = new Date(r.end);
var t:Number = _tz.daySpan(_currentRange.start,_currentRange.end);
r.start.date = r.start.date - t + 1;
/*if(r.start.getTime() <= r.end.getTime()){
}else{
var temp:Date = r.start;
r.start = r.end;
r.end = temp;
}*/
break;
case "month":
default:
r.start.month--;
r.end.month--;
break;
}
range = r;
}
//----------------------------------------------------------------------------------------------------
// Property Management
//----------------------------------------------------------------------------------------------------
// comparison functions used when sorting the set of visible events.
// compares either two events or an event and a date based on start time.
private function eventStartDateCompare(lhs:*,rhs:*):Number
{
if(lhs is CalendarEvent)
lhs = lhs.start.getTime();
if(rhs is CalendarEvent)
rhs = rhs.start.getTime();
return (lhs < rhs)? -1:
(lhs > rhs)? 1:0;
}
// comparison functions used when sorting the set of visible events.
// compares either two events or an event and a date based on end time.
private function eventEndDateCompare(lhs:*,rhs:*):Number
{
if(lhs is CalendarEvent)
lhs = lhs.end.getTime();
if(rhs is CalendarEvent)
rhs = rhs.end.getTime();
return (lhs < rhs)? -1:
(lhs > rhs)? 1:0;
}
// comparison functions used when sorting the set of visible events.
// compares two events based on start time.
private function startEventCompare(levent:CalendarEvent,revent:CalendarEvent):Number
{
var lhs:Number = levent.start.getTime();
var rhs:Number = revent.start.getTime();
return (lhs < rhs)? -1:
(lhs > rhs)? 1:0;
}
// comparison functions used when sorting the set of visible events.
// compares two events based on end time.
private function endEventCompare(levent:CalendarEvent,revent:CalendarEvent):Number
{
var lhs:Number = levent.end.getTime();
var rhs:Number = revent.end.getTime();
return (lhs < rhs)? -1:
(lhs > rhs)? 1:0;
}
override protected function commitProperties():void
{
var prevDM:String = _displayMode;
var prevFirstDate:Date = new Date(_visibleRange.start);
var startIndex:int;
var endIndex:int;
// if our event set has changed, build a new list of events sorted by
// end time
if(_allEventsDirty)
{
_allEventsDirty = false;
_allEventsSortedByStart = new SortedArray(null,null,endEventCompare);
for(var i:int = 0;i<_dataProvider.length;i++)
{
var e:CalendarEvent = CalendarEvent(_dataProvider.getItemAt(i));
e.addEventListener("change",eventChangeHandler);
_allEventsSortedByStart.addItem(e);
}
}
// update our current range if changed by the client.
if(_pendingRange != null)
{
_currentRange = _pendingRange;
_pendingRange = null;
}
// store off our visible range. We'll compare this to any new
// visible range to decide what kind of animation we'll need.
var oldVisible:DateRange = _visibleRange.clone();
// check to see if the display mode has been changed.
if(_pendingDisplayMode != null)
{
_displayMode = _pendingDisplayMode;
_pendingDisplayMode = null;
}
// now, given our current assigned range and display mode,
// figure out our visible range (days on screen) and computed range
// ('active' days given our display mode)
var ranges:Object = computeRanges(_currentRange,_displayMode);
if(oldVisible.containsRange(ranges._visibleRange))
{
// our new visible range is a subset of our old one.
// we'll want to throw out all the days we're losing,
// but keep the common ones in place.
_animateRemovingDays = true;
// figure out which days are staying on screen,
startIndex = indexForDate(ranges._visibleRange.start);
endIndex = indexForDate(ranges._visibleRange.end) + 1;
// and narrow our day and header renderers down to only those.
_dayCache.slice(startIndex,endIndex);
_headerCache.slice(startIndex,endIndex);
_visibleRange = ranges._visibleRange;
_computedRange = ranges._computedRange;
updateDetails();
}
else if (ranges._visibleRange.containsRange(oldVisible))
{
// our new visible range is a superset of our old one.
// we'll want to allocate new day and header renderers
// for the new days, but make sure we end up keeping
// the renderers in place for the ones we were using
// before.
_animateRemovingDays = false;
_visibleRange = ranges._visibleRange;
_computedRange = ranges._computedRange;
updateDetails();
// figure out how many days were in our old visible range
var dayCount:int = _tz.rangeDaySpan(_visibleRange);
// and where it begins in our new visible range
startIndex = indexForDate(oldVisible.start);
// and expand our day and header renderer caches,
// making sure the existing ranges end up in the right place.
_dayCache.unslice(dayCount,startIndex);
_headerCache.unslice(dayCount,startIndex);
}
else
{
// we either don't overlap, or have a non continguous
// overlap.
_animateRemovingDays = false;
_visibleRange = ranges._visibleRange;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -