////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package spark.components {
import flash.display.Sprite;
import flash.events.EventPhase;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
import mx.core.FlexGlobals;
import mx.core.IFlexDisplayObject;
import mx.core.IFlexModule;
import mx.core.IFlexModuleFactory;
import mx.core.UIComponent;
import mx.events.CloseEvent;
import mx.events.FlexEvent;
import mx.managers.IActiveWindowManager;
import mx.managers.ISystemManager;
import mx.managers.PopUpManager;
import mx.resources.ResourceManager;
import spark.components.supportClasses.TextBase;
//--------------------------------------
// Styles
//--------------------------------------
/**
* Name of the CSS style declaration that specifies
* styles for the Alert buttons.
*
* @default "alertButtonStyle"
*
* @langversion 3.0
* @playerversion Flash 10.1
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
[Style(name="buttonStyleName", type="String", inherit="no")]
/**
* Name of the CSS style declaration that specifies
* styles for the Alert message text.
*
*
You only set this style by using a type selector, which sets the style
* for all Alert controls in your application.
* If you set it on a specific instance of the Alert control, it can cause the control to
* size itself incorrectly.
*
* @default undefined
*
* @langversion 3.0
* @playerversion Flash 10.1
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
[Style(name="messageStyleName", type="String", inherit="no")]
//--------------------------------------
// Other metadata
//--------------------------------------
[RequiresDataBinding(true)]
[ResourceBundle("alert")]
/**
* The Alert control is a pop-up dialog box that can contain a message,
* a title, buttons (any combination of OK, Cancel, Yes, and No) and an icon.
* The Alert control is modal, which means it will retain focus until the user closes it.
*
*
Import the spark.components.spark.components.alert.Alert class into your application,
* and then call the static show() method in ActionScript to display
* an Alert control. You cannot create an Alert control in MXML.
*
*
The Alert control closes when you select a button in the control,
* or press the Escape key.
*
*
*
* @langversion 3.0
* @playerversion Flash 10.1
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/ /**
* @author Bogdan Dinu (http://www.badu.ro)
*/ public class Alert extends Panel {
[SkinPart(required="false")]
public var messageDisplay:TextBase;
[SkinPart(required="false")]
public var buttonGroup:Group;
[SkinPart(required="false")]
public var iconGroup:Group;
//----------------------------------
// buttonHeight
//----------------------------------
[Inspectable(category="Size")]
/**
* Height of each Alert button, in pixels.
* All buttons must be the same height.
*
* @default 24
*
* @langversion 3.0
* @playerversion Flash 10.1
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/ public static var buttonHeight:Number = 24;
//----------------------------------
// buttonWidth
//----------------------------------
[Inspectable(category="Size")]
/**
* Width of each Alert button, in pixels.
* All buttons must be the same width.
*
* @default 65
*
* @langversion 3.0
* @playerversion Flash 10.1
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/ public static var buttonWidth:Number = 65;
/**
* Value that enables a Yes button on the Alert control when passed
* as the flags parameter of the show() method.
* You can use the | operator to combine this bitflag
* with the OK, CANCEL,
* NO, and NONMODAL flags.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public static const YES:uint = 0x0001;
/**
* Value that enables a No button on the Alert control when passed
* as the flags parameter of the show() method.
* You can use the | operator to combine this bitflag
* with the OK, CANCEL,
* YES, and NONMODAL flags.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public static const NO:uint = 0x0002;
/**
* Value that enables an OK button on the Alert control when passed
* as the flags parameter of the show() method.
* You can use the | operator to combine this bitflag
* with the CANCEL, YES,
* NO, and NONMODAL flags.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public static const OK:uint = 0x0004;
/**
* Value that enables a Cancel button on the Alert control when passed
* as the flags parameter of the show() method.
* You can use the | operator to combine this bitflag
* with the OK, YES,
* NO, and NONMODAL flags.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public static const CANCEL:uint = 0x0008;
/**
* Value that makes an Alert nonmodal when passed as the
* flags parameter of the show() method.
* You can use the | operator to combine this bitflag
* with the OK, CANCEL,
* YES, and NO flags.
*
* @langversion 3.0
* @playerversion Flash 9
* @playerversion AIR 1.1
* @productversion Flex 3
*/
public static const NONMODAL:uint = 0x8000;
/**
* The label for the Yes button.
*
*
If you use a different label, you may need to adjust the
* buttonWidth property to fully display the label.
*
* The English resource bundle sets this property to "YES".
*
* @langversion 3.0
* @playerversion Flash 10.1
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
private static var _yesLabel:String;
private static var _yesLabelOverride:String;
[Inspectable(category="General")]
public static function get YES_LABEL():String {
if (!_yesLabel) {
_yesLabel = ResourceManager.getInstance().getString('alert', 'YesLabel');
}
return _yesLabelOverride ? _yesLabelOverride : _yesLabel;
}
public static function set YES_LABEL(value:String):void {
_yesLabelOverride = value;
}
/**
* The label for the No button.
*
*
If you use a different label, you may need to adjust the
* buttonWidth property to fully display it.
*
* The English resource bundle sets this property to "NO".
*
* @langversion 3.0
* @playerversion Flash 10.1
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
private static var _noLabel:String;
private static var _noLabelOverride:String;
[Inspectable(category="General")]
public static function get NO_LABEL():String {
if (!_noLabel) {
_noLabel = ResourceManager.getInstance().getString('alert', 'NoLabel');
}
return _noLabelOverride ? _noLabelOverride : _noLabel;
}
public static function set NO_LABEL(value:String):void {
_noLabelOverride = value;
}
/**
* The label for the OK button.
*
*
If you use a different label, you may need to adjust the
* buttonWidth property to fully display the label.
*
* The English resource bundle sets this property to "OK".
*
* @langversion 3.0
* @playerversion Flash 10.1
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
private static var _okLabel:String;
private static var _okLabelOverride:String;
[Inspectable(category="General")]
public static function get OK_LABEL():String {
if (!_okLabel) {
_okLabel = ResourceManager.getInstance().getString('alert', 'OkLabel');
}
return _okLabelOverride ? _okLabelOverride : _okLabel;
}
public static function set OK_LABEL(value:String):void {
_okLabelOverride = value;
}
/**
* The label for the Cancel button.
*
*
If you use a different label, you may need to adjust the
* buttonWidth property to fully display it.
*
* The English resource bundle sets this property to "CANCEL".
*
* @langversion 3.0
* @playerversion Flash 10.1
* @playerversion AIR 2.5
* @productversion Flex 4.5
*/
private static var _cancelLabel:String;
private static var _cancelLabelOverride:String;
[Inspectable(category="General")]
public static function get CANCEL_LABEL():String {
if (!_cancelLabel) {
_cancelLabel = ResourceManager.getInstance().getString('alert', 'CancelLabel');
}
return _cancelLabelOverride ? _cancelLabelOverride : _cancelLabel;
}
public static function set CANCEL_LABEL(value:String):void {
_cancelLabelOverride = value;
}
private var _message:String;
private var _defaultButtonFlag:uint = 0;
private var _buttons:Vector.