// Copyright 2007. Adobe Systems Incorporated. All Rights Reserved. package fl.controls.dataGridClasses { import fl.controls.DataGrid; import fl.controls.listClasses.ICellRenderer; import fl.core.InvalidationType; import fl.controls.dataGridClasses.DataGridCellEditor; /** * The student_ar_fl_controls_dataGridClasses_DataGridColumn class describes a column in a DataGrid component. There * is one student_ar_fl_controls_dataGridClasses_DataGridColumn object for every column that could be displayed on * the screen, even for columns that are currently hidden or off-screen. The * data provider items that belong to a DataGrid component can contain properties * that are not displayed; such properties do not require a student_ar_fl_controls_dataGridClasses_DataGridColumn. * *
You can specify the kind of component that displays the data for a student_ar_fl_controls_dataGridClasses_DataGridColumn. * The characteristics that can be specified include the text that appears in the * column header and whether the column can be edited, sorted, or resized.
* * @see fl.controls.DataGrid * * @includeExample examples/student_ar_fl_controls_dataGridClasses_DataGridColumnExample.as * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ public class student_ar_fl_controls_dataGridClasses_DataGridColumn { /** * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ private var _columnName:String; /** * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ private var _headerText:String; /** * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0 * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ private var _minWidth:Number = 20; /** * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ private var _width:Number = 100; /** * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ private var _visible:Boolean = true; /** * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ private var _cellRenderer:Object; /** * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ private var _headerRenderer:Object; /** * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ private var _labelFunction:Function; /** * @private * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ private var _sortCompareFunction:Function; /** * @private * Storage for theimeMode
property.
*/
private var _imeMode:String;
/**
* @private (internal)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public var owner:DataGrid; // mx_internal
/**
* @private (internal)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public var colNum:Number; // mx_internal
/**
* @private (internal)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public var explicitWidth:Number; // mx_internal
/**
* Indicates whether the user can click on the header of the current column
* to sort the data provider. A value of true
indicates that
* the column can be sorted by clicking on its header; a value of false
* indicates that it cannot be sorted by clicking on its header.
*
* @default true
*
* @includeExample examples/student_ar_fl_controls_dataGridClasses_DataGridColumn.sortable.1.as -noswf
* @includeExample examples/student_ar_fl_controls_dataGridClasses_DataGridColumn.sortable.2.as -noswf
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public var sortable:Boolean = true;
/**
* Indicates whether the user is allowed to change the width of the
* column. A value of true
indicates that the user can
* change the column width; a value of false
indicates that
* the user cannot change the column width.
*
* @default true
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public var resizable:Boolean = true;
/**
* Indicates whether the items in the column can be edited. A value of true
* indicates that the column items can be edited; a value of false
indicates
* that they cannot be edited.
*
* If this property is set to true
and the editable
* property of the DataGrid is also true
, the items in a column are
* editable and can be individually edited by clicking an item
* or by navigating to the item by using the Tab and arrow keys.
For example, the default itemEditor
is
* TextInput, so the default value of the editorDataField
* property is "text"
. This value specifies the
* text
property of the TextInput component.
true
indicates that the
* student_ar_fl_controls_dataGridClasses_DataGridColumn is sorted in descending order; a value of false
* indicates that the DataGridColum is sorted in ascending order.
*
* @default false
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public var sortDescending:Boolean = false;
/**
* One or more defined constants, identified by name or number and separated
* by the bitwise OR (|) operator. These constants are used to specify
* the sort operation.
*
* @default 0
*
* @includeExample examples/student_ar_fl_controls_dataGridClasses_DataGridColumn.sortOptions.1.as -noswf
*
* @see Array#sort()
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public var sortOptions:uint = 0;
/**
* @private
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
private var forceImport:DataGridCellEditor;
/**
* Creates a new student_ar_fl_controls_dataGridClasses_DataGridColumn instance.
*
* @param columnName The column name to display in the column header. If
* no name is specified, the dataField
value is used.
*
* @default null
*
* @see student_ar_fl_controls_dataGridClasses_DataGridColumn#headerText
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function student_ar_fl_controls_dataGridClasses_DataGridColumn(columnName:String = null) {
if (columnName) {
dataField = columnName;
headerText = columnName;
}
}
/**
* The class that is used to render the items in this column.
*
* The type of this property can be Class, Sprite or String.
* If the property type is String, the String value must be a
* fully qualified class name.
*
* @default null
*
* @includeExample examples/student_ar_fl_controls_dataGridClasses_DataGridColumn.cellRenderer.1.as -noswf
*
* @see #headerRenderer student_ar_fl_controls_dataGridClasses_DataGridColumn.headerRenderer
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get cellRenderer():Object {
return _cellRenderer;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set cellRenderer(value:Object):void {
_cellRenderer = value;
if (owner) {
owner.invalidate(InvalidationType.DATA);
}
}
/**
* The class that is used to render the header of this column.
*
* The type of this property can be Class, Sprite or String. * If the property type is String, the string value must be a * fully qualified class name.
* * @default null * * @see #cellRenderer student_ar_fl_controls_dataGridClasses_DataGridColumn.cellRenderer * @see HeaderRenderer * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ public function get headerRenderer():Object { return _headerRenderer; } /** * @private (setter) * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ public function set headerRenderer(value:Object):void { _headerRenderer = value; if (owner) { owner.invalidate(InvalidationType.DATA); } } /** * The column name to be displayed in the column header. * By default, the DataGrid component uses the value of thedataField
* property as the column name.
*
* @includeExample examples/student_ar_fl_controls_dataGridClasses_DataGridColumn.headerText.1.as -noswf
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get headerText():String {
return (_headerText != null) ? _headerText : dataField;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set headerText(value:String):void {
_headerText = value;
if (owner) {
owner.invalidate(InvalidationType.DATA);
}
}
/**
* The mode of the input method editor (IME). The IME enables users to
* enter text in Chinese, Japanese, and Korean. The flash.system.IMEConversionMode
* class defines constants to be used as the valid values for this property.
*
* If this property is null
, the mode of the IME is
* set to the value of the imeMode
property of the DataGrid
* component.
labelFunction
property to specify a callback function.
*
* If both the labelFunction
and labelField
properties
* are defined, the labelFunction
takes precedence.
sortOptions
property.
* When specified, the sortCompareFunction
property allows you to create
* your own custom sorting method for the current data grid column.
*
* @default null
*
* @see #sortOptions
*
* @includeExample examples/student_ar_fl_controls_dataGridClasses_DataGridColumn.sortCompareFunction.1.as -noswf
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
* @internal [kenos] More information here on what the callback is used to do? Sounds like
* it supplants the sortOptions but is it used to specify any particular type of
* sort?
*/
public function get sortCompareFunction():Function {
return _sortCompareFunction;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set sortCompareFunction(value:Function):void {
_sortCompareFunction = value;
}
/**
* Indicates whether the column is visible. A value of true
indicates
* that the column is visible; a value of false
indicates that the column
* is invisible.
*
* @includeExample examples/student_ar_fl_controls_dataGridClasses_DataGridColumn.visible.1.as -noswf
*
* @default true
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get visible():Boolean {
return _visible;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set visible(value:Boolean):void {
if (_visible != value) {
_visible = value;
if (owner) {
owner.invalidate(InvalidationType.SIZE);
}
}
}
/**
* The width of the column, in pixels.
*
* @default 100
*
* @see #minWidth student_ar_fl_controls_dataGridClasses_DataGridColumn.minWidth
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function get width():Number {
return _width;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function set width(value:Number):void {
// remove any queued equal spacing commands
explicitWidth = value;
if (owner != null) {
// if we aren't resizing as part of grid layout, resize it's column
var oldVal:Boolean = resizable;
// anchor this column to not accept any overflow width for accurate sizing
resizable = false;
owner.resizeColumn(colNum, value);
resizable = oldVal;
} else {
// otherwise, just store the size
_width = value;
}
}
/**
* @private
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function setWidth(value:Number):void {
_width = value;
}
//--------------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------------
/**
* Returns the string that the item renderer displays for the given data object.
* If the student_ar_fl_controls_dataGridClasses_DataGridColumn or its DataGrid component has a non-null labelFunction
* property, it applies the function to the data object. Otherwise, the method extracts
* the contents of the field that is specified by the dataField
property, or gets the
* string value of the data object. If the method cannot convert the parameter to a string,
* it returns a single space.
*
* @param data The Object to be rendered.
*
* @return Displayable string based on the specified data
object.
*
* @internal
* dg.addEventListener("itemClick", itemClickHandler);
* function itemClickHandler(evt:ListEvent):void {
* var col:student_ar_fl_controls_dataGridClasses_DataGridColumn = dg.getColumnAt(evt.columnIndex);
* trace(col.itemToLabel(evt.item));
* }
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function itemToLabel(data:Object):String {
if (!data) {
return " ";
}
if (labelFunction != null) {
return labelFunction(data);
}
if (owner.labelFunction != null) {
return owner.labelFunction(data, this);
}
if (typeof(data) == "object" || typeof(data) == "xml") {
try {
data = data[dataField];
} catch(e:Error) {
data = null;
}
}
if (data is String) {
return String(data);
}
try {
return data.toString();
} catch(e:Error) {
}
return " ";
}
/**
* Returns a string representation of the student_ar_fl_controls_dataGridClasses_DataGridColumn object.
*
* @return "[object student_ar_fl_controls_dataGridClasses_DataGridColumn]"
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
public function toString():String {
return "[object student_ar_fl_controls_dataGridClasses_DataGridColumn]";
}
}
}