scaffold.libs_as.feathers.controls.popups.CalloutPopUpContentManager.as Maven / Gradle / Ivy
/*
Feathers
Copyright 2012-2015 Bowler Hat LLC. All Rights Reserved.
This program is free software. You can redistribute and/or modify it in
accordance with the terms of the accompanying license agreement.
*/
package feathers.controls.popups
{
import feathers.controls.Callout;
import flash.errors.IllegalOperationError;
import starling.display.DisplayObject;
import starling.events.Event;
import starling.events.EventDispatcher;
/**
* Dispatched when the pop-up content opens.
*
* The properties of the event object have the following values:
*
* Property Value
* bubbles
false
* currentTarget
The Object that defines the
* event listener that handles the event. For example, if you use
* myButton.addEventListener()
to register an event listener,
* myButton is the value of the currentTarget
.
* data
null
* target
The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* currentTarget
property to always access the Object
* listening for the event.
*
*
* @eventType starling.events.Event.OPEN
*/
[Event(name="open",type="starling.events.Event")]
/**
* Dispatched when the pop-up content closes.
*
* The properties of the event object have the following values:
*
* Property Value
* bubbles
false
* currentTarget
The Object that defines the
* event listener that handles the event. For example, if you use
* myButton.addEventListener()
to register an event listener,
* myButton is the value of the currentTarget
.
* data
null
* target
The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* currentTarget
property to always access the Object
* listening for the event.
*
*
* @eventType starling.events.Event.CLOSE
*/
[Event(name="close",type="starling.events.Event")]
/**
* Displays pop-up content (such as the List in a PickerList) in a Callout.
*
* @see feathers.controls.PickerList
* @see feathers.controls.Callout
*/
public class CalloutPopUpContentManager extends EventDispatcher implements IPopUpContentManager
{
/**
* Constructor.
*/
public function CalloutPopUpContentManager()
{
}
/**
* The factory used to create the Callout
instance. If
* null
, Callout.calloutFactory()
will be used.
*
* Note: If you change this value while a callout is open, the new
* value will not go into effect until the callout is closed and a new
* callout is opened.
*
* @see feathers.controls.Callout#calloutFactory
*
* @default null
*/
public var calloutFactory:Function;
/**
* The direction of the callout.
*
* Note: If you change this value while a callout is open, the new
* value will not go into effect until the callout is closed and a new
* callout is opened.
*
* In the following example, the callout direction is restricted to down:
*
*
* manager.direction = Callout.DIRECTION_DOWN;
*
* @see feathers.controls.Callout#DIRECTION_ANY
* @see feathers.controls.Callout#DIRECTION_UP
* @see feathers.controls.Callout#DIRECTION_DOWN
* @see feathers.controls.Callout#DIRECTION_LEFT
* @see feathers.controls.Callout#DIRECTION_RIGHT
*
* @default Callout.DIRECTION_ANY
*/
public var direction:String = Callout.DIRECTION_ANY;
/**
* Determines if the callout will be modal or not.
*
* Note: If you change this value while a callout is open, the new
* value will not go into effect until the callout is closed and a new
* callout is opened.
*
* In the following example, the callout is not modal:
*
*
* manager.isModal = false;
*
* @default true
*/
public var isModal:Boolean = true;
/**
* @private
*/
protected var content:DisplayObject;
/**
* @private
*/
protected var callout:Callout;
/**
* @inheritDoc
*/
public function get isOpen():Boolean
{
return this.content !== null;
}
/**
* @inheritDoc
*/
public function open(content:DisplayObject, source:DisplayObject):void
{
if(this.isOpen)
{
throw new IllegalOperationError("Pop-up content is already open. Close the previous content before opening new content.");
}
this.content = content;
this.callout = Callout.show(content, source, this.direction, this.isModal, this.calloutFactory);
this.callout.addEventListener(Event.REMOVED_FROM_STAGE, callout_removedFromStageHandler);
this.dispatchEventWith(Event.OPEN);
}
/**
* @inheritDoc
*/
public function close():void
{
if(!this.isOpen)
{
return;
}
this.callout.close();
}
/**
* @inheritDoc
*/
public function dispose():void
{
this.close();
}
/**
* @private
*/
protected function cleanup():void
{
this.content = null;
this.callout.content = null;
this.callout.removeEventListener(Event.REMOVED_FROM_STAGE, callout_removedFromStageHandler);
this.callout = null;
}
/**
* @private
*/
protected function callout_removedFromStageHandler(event:Event):void
{
this.cleanup();
this.dispatchEventWith(Event.CLOSE);
}
}
}