Flex Scheduling Framework:ScheduleViewer Adding Background Areas Sample
From Adobe Labs
You can add customized background areas to ScheduleViewer using the backgroundItems property. backgroundItems expects an Array of BackgroundItem objects. You can specify a time range, a color and a description. The latter will be used as a tool tip when the user mouses over area.
For further customizations of the background area in ScheduleViewer, you can create a customized version of the background layout manager via the backgroundLayout property. Take a look into the default layout manager com.adobe.ac.controls.scheduleClasses.layout.BackgroundLayout for more information. eg. you could add a colored current time area, which moves by the current time.
You can also customize the background grid via the supplied styles. See the styles in the sample below section. To customize further, you can also define custom layout managers via the horizontalLinesLayout and verticalLinesLayout properties. See default implementation is com.adobe.ac.controls.scheduleClasses.layout.HorizontalLinesLayout and com.adobe.ac.controls.scheduleClasses.layout.VerticalLinesLayout. eg you could add thicker horizontal lines, after certain items.
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2006. Adobe Systems Incorporated.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Adobe Systems Incorporated nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
@ignore
-->
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:controls="com.adobe.ac.controls.*"
creationComplete="onCreationComplete();" verticalGap="0">
<mx:Script>
<![CDATA[
import com.adobe.ac.scheduling.samples.ScheduleData;
import com.adobe.ac.controls.scheduleClasses.SimpleScheduleEntry;
import com.adobe.ac.controls.scheduleClasses.BackgroundItem;
import com.adobe.ac.util.DateUtil;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.ScrollEvent;
import mx.events.ScrollEventDirection;
[Bindable]
private var dataProvider : ArrayCollection;
[Bindable]
private var startDate : Date;
[Bindable]
private var endDate : Date;
[Bindable]
private var zoom : Number;
[Bindable]
private var scheduleViewerWidth : Number = 600;
private function onCreationComplete() : void
{
setTimeframe();
initDataProvider();
initBackgroundColors();
}
private function setTimeframe() : void
{
startDate = DateUtil.clearTime( new Date() );
endDate = getEndDate( startDate );
}
private function getEndDate( startDate : Date ) : Date
{
var duration : Number = DateUtil.DAY_IN_MILLISECONDS * 1;
var endDate : Date = new Date( startDate.getTime() + duration );
return endDate;
}
private function initDataProvider() : void
{
dataProvider = new ScheduleData().createRandomColoredScheduleEntries( 200 );
}
private function onZoom( value : Number ) : void
{
zoom = value;
}
private function onScrollTimeline( position : Number ) : void
{
scheduleViewer.xPosition = position;
}
private function onScrollScheduleViewer( event : ScrollEvent ) : void
{
if( event.direction == ScrollEventDirection.HORIZONTAL )
{
timeline.xPosition = event.position;
}
}
private function gotoNow() : void
{
var time : Date = new Date();
scheduleViewer.moveToTime( time.getTime() - startDate.getTime() );
}
private function gotoSelectedEntry() : void
{
if( scheduleViewer.selectedItem != null )
{
scheduleViewer.moveToEntry( scheduleViewer.selectedItem );
}
else
{
warnAboutNoSelection();
}
}
private function warnAboutNoSelection() : void
{
Alert.show( "Please select an entry." );
}
private function initBackgroundColors() : void
{
var result : ArrayCollection = new ArrayCollection();
var duration : Number = endDate.getTime() - startDate.getTime();
var days : Number = duration / DateUtil.DAY_IN_MILLISECONDS;
for( var i : int; i < days; i++ )
{
var currentDate : Number = DateUtil.DAY_IN_MILLISECONDS * i;
var backgroundItem : BackgroundItem;
backgroundItem = createBackgroundItem( "office closed", 0xD5D4D0,
currentDate, 0, 0, 24, 0 );
result.addItem( backgroundItem );
backgroundItem = createBackgroundItem( "generell office hours", 0xFFFFFF,
currentDate, 9, 0, 17, 0 );
result.addItem( backgroundItem );
backgroundItem = createBackgroundItem( "lunchtime", 0xEEEDE9,
currentDate, 12, 0, 13, 0 );
result.addItem( backgroundItem );
}
scheduleViewer.backgroundItems = result;
}
private function createBackgroundItem( description : String,
color : Number, currentDate : Number,
startHours : Number, startMinutes : Number,
endHours : Number, endMinutes : Number ) : BackgroundItem
{
var backgroundItem : BackgroundItem = new BackgroundItem();
backgroundItem.description = description;
backgroundItem.color = color;
backgroundItem.startDate = new Date( currentDate + createTime( startHours, startMinutes ) );
backgroundItem.endDate = new Date( currentDate + createTime( endHours, endMinutes ) );
return backgroundItem;
}
private function createTime( hours : Number, minutes : Number ) : Number
{
var result : Number = (( hours * 60 ) + minutes ) * 60 * 1000;
return result;
}
]]>
</mx:Script>
<controls:Timeline
id="timeline"
width="{ scheduleViewerWidth }" borderStyle="none"
startDate="{ startDate }" endDate="{ endDate }"
zoom="{ zoom }"
scroll="onScrollTimeline( event.position );"
/>
<controls:ScheduleViewer
id="scheduleViewer"
width="{ scheduleViewerWidth }" height="400" borderStyle="none"
dataProvider="{ dataProvider }"
startDate="{ startDate }" endDate="{ endDate }"
zoom="{ zoom }"
horizontalScrollPolicy="off"
entryRenderer="com.adobe.ac.controls.scheduleClasses.renderers.ColoredSolidScheduleEntryRenderer"
pixelScroll="onScrollScheduleViewer( event );"
/>
<mx:HBox width="{ scheduleViewerWidth }" paddingTop="6">
<mx:Label text="Goto:"/>
<mx:Button label="Now" click="gotoNow();"/>
<mx:Button label="Selected" click="gotoSelectedEntry();"/>
<mx:Spacer width="100%"/>
<mx:Label text="Zoom:"/>
<mx:HSlider
id="zoomSlider"
minimum="0" maximum="1000" value="100"
snapInterval="1" liveDragging="true"
change="onZoom( zoomSlider.value );"
/>
</mx:HBox>
</mx:Application>
