Packagecom.sibirjak.jakute
Classpublic class JCSS_Adapter

JCSS component adapter.

A JCSS adapter (or sublcass) instance realizes the necessary connection between the independent ui component and the JCSS framework. Each component needs to be registered to JCSS with its own adapter. In the case of a type registration, the adapter is created from the given class template by JCSS automatically.

JCSS callbacks

An adapter provides different settings and operations to control the styling of a component and its children. In addition, the adapter implements three callbacks that are triggered during the component life cycle:

Defining styles

Styles need to be defined using defineStyle() before they are available to the component.



Public Properties
 PropertyDefined by
  component : DisplayObject
[read-only] Returns the component with that the adapter is registered in JCSS.
JCSS_Adapter
  componentRegisteredHandler : Function
[write-only] Sets a custom callback for the registered event.
JCSS_Adapter
  cssClass : String
Sets and returns the component css class.
JCSS_Adapter
  cssID : String
Sets and returns the component selector ID.
JCSS_Adapter
  cssName : String
Sets and returns the component selector name.
JCSS_Adapter
  initialized : Boolean
[read-only] Returns true if styles already have been initialized.
JCSS_Adapter
  stylesChangedHandler : Function
[write-only] Sets a custom callback for the styles changed event.
JCSS_Adapter
  stylesInitializedHandler : Function
[write-only] Sets a custom callback for the initialized event.
JCSS_Adapter
  virtualParent : DisplayObject
Sets and gets the virtual parent of a component.
JCSS_Adapter
Public Methods
 MethodDefined by
  
JCSS_Adapter
JCSS_Adapter
  
childrenEnclosed():Boolean
Returns true, if encloseChildren() is set, else false.
JCSS_Adapter
  
clearStyle(selector:String, styleName:String = null):void
Removes a style that has formerly been set.
JCSS_Adapter
  
Executes a bulk update that was started via startBulkUpdate().
JCSS_Adapter
  
Returns the full selector of a component.
JCSS_Adapter
  
defineStyle(styleName:String, styleValue:String, format:uint, priority:* = 0):void
Defines a style prior to be used with JCSS.
JCSS_Adapter
  
Declares all child component to be selectable only via this component selector.
JCSS_Adapter
  
getState(stateName:String):String
Returns the value of a component state.
JCSS_Adapter
  
getStyle(styleName:String):*
Returns the current value for the given style name.
JCSS_Adapter
  
Returns the JCSS parent chain of a componet.
JCSS_Adapter
  
setState(stateName:String, value:String):void
Sets a component state.
JCSS_Adapter
  
setStyle(selector:String, styleName:String, styleValue:uint, priority:* = 1):void
Sets a style to a component instance.
JCSS_Adapter
  
setStyleSheet(styleSheet:String):void
Sets a style sheet to a component instance.
JCSS_Adapter
  
Starts a bulk update procedure.
JCSS_Adapter
  
Returns a formatted tree of all currently set style rules.
JCSS_Adapter
  
stylesAsString():String
Returns a formatted String with all currently set styles.
JCSS_Adapter
Protected Methods
 MethodDefined by
  
Default handler for the registered event.
JCSS_Adapter
  
onStylesChanged(changedStyles:JCSS_ChangeEvent):void
Default handler for the styles changed event.
JCSS_Adapter
  
Default handler for the initialized event.
JCSS_Adapter
Property detail
componentproperty
component:DisplayObject  [read-only]

Returns the component with that the adapter is registered in JCSS.

Implementation
    public function get component():DisplayObject
componentRegisteredHandlerproperty 
componentRegisteredHandler:Function  [write-only]

Sets a custom callback for the registered event.

The callback is triggered right after the component has been registered in JCSS. The goal of the callback is to enable initial setting for components that are registered with their type. In the case of instance registration, we usually have the full control over the time, the component gets registered, so we could here place the related code right before or after the JCSS::registerComponent() command.

A custom registered handler may be set if the implementation of an adapter can not or should not be changed. Using a custom callback makes the same adapter implementation reusable for different component types.

If not set, onComponentRegistered() is called by default.

A custom registered handler has the following signature. Note, that the current adapter is also passed to the method, which might be confusing. However, this enables to reuse the same handler with different adapters.

   theAdapter.componentRegisteredHandler = function(adapter : JCSS_Adapter) : void {
    trace ("registered", Box(adapter.component));
   };
   
Implementation
    public function set componentRegisteredHandler(value:Function):void
cssClassproperty 
cssClass:String  [read-write]

Sets and returns the component css class.

Can be set initially or at runtime.

Implementation
    public function get cssClass():String
    public function set cssClass(value:String):void
cssIDproperty 
cssID:String  [read-write]

Sets and returns the component selector ID.

Can be set only initially (before the initialized event). Otherwise throws an error.

Implementation
    public function get cssID():String
    public function set cssID(value:String):void
cssNameproperty 
cssName:String  [read-write]

Sets and returns the component selector name.

Can be set only initially (before the initialized event). Otherwise throws an error.

Implementation
    public function get cssName():String
    public function set cssName(value:String):void
initializedproperty 
initialized:Boolean  [read-only]

Returns true if styles already have been initialized.

Implementation
    public function get initialized():Boolean
stylesChangedHandlerproperty 
stylesChangedHandler:Function  [write-only]

Sets a custom callback for the styles changed event.

The callback is triggered always a component style has been changed.

A custom changed handler may be set if the implementation of an adapter can not or should not be changed. Using a custom callback makes the same adapter implementation reusable for different component types.

A custom styles changed handler has the following signature. Note, that the current adapter is also passed to the method, which might be confusing. However, this enables to reuse the same handler with different adapters.

   theAdapter.stylesChangedHandler = function(changedStyles : JCSS_ChangedStyles, adapter : JCSS_Adapter) : void {
    if (changedStyles.valueHasChanged("backgroundColor")) {
     Box(adapter.component).updateBackground();
    }
   };
   

If not set, onStylesChanged() is called by default.

Implementation
    public function set stylesChangedHandler(value:Function):void
stylesInitializedHandlerproperty 
stylesInitializedHandler:Function  [write-only]

Sets a custom callback for the initialized event.

The callback is triggered once for a component and after the styles of a component have been calculated the first time. Starting from here, all further changes in JCSS will update the component (incrementally) using notifying the component by the styles changed callback.

A custom initialized handler may be set if the implementation of an adapter can not or should not be changed. Using a custom callback makes the same adapter implementation reusable for different component types.

If not set, onStylesInitialized() is called by default.

A custom initialized handler has the following signature. Note, that the current adapter is also passed to the method, which might be confusing. However, this enables to reuse the same handler with different adapters.

   theAdapter.stylesInitializedHandler = function(allInitialStyles : Object, adapter : JCSS_Adapter) : void {
    Box(adapter.component).draw();
   };
   
Implementation
    public function set stylesInitializedHandler(value:Function):void
virtualParentproperty 
virtualParent:DisplayObject  [read-write]

Sets and gets the virtual parent of a component.

If a virtual parent is set, the component styles are calculated using the virtual parent's display list instead of the physical parent's display list. A virtual parent is a great possibility to connect components that do not have a physical parent-child relation such as tooltips or popups, which usually live in a separated container.

   CSS
   -----------------------------------------------
   Button.red ToolTip {
    color: red;
   }

   Button.blue ToolTip {
    color: blue;
   }

   Pseudo code
   -----------------------------------------------
   redButton.onMouseOver = {
    tooltip.virtualParent = redButton;
    tooltip.show(redButton.position.toGlobal());
   }

   blueButton.onMouseOver = {
    tooltip.virtualParent = blueButton;
    tooltip.show(blueButton.position.toGlobal());
   }
   

Can be set initially or at runtime.

Implementation
    public function get virtualParent():DisplayObject
    public function set virtualParent(value:DisplayObject):void
Constructor detail
JCSS_Adapter()constructor
public function JCSS_Adapter()

JCSS_Adapter

Method detail
childrenEnclosed()method
public function childrenEnclosed():Boolean

Returns true, if encloseChildren() is set, else false.

Returns
Boolean
clearStyle()method 
public function clearStyle(selector:String, styleName:String = null):void

Removes a style that has formerly been set.

If styleName is specified, the style is removed from the style rule specified with the given selector.

The method does nothing if a style rule with the given selector has not been set beforehand or a style with the given styleName has not been declared within the style rule described by the given selector.

Using this method to clear styles set to the component directly (by passing the selector "This" or "") will reset the style to its default value specified by the component.

Parameters
selector:String — A selector that matchs a particular component.
 
styleName:String (default = null) — The name of the style to remove.
commitBulkUpdate()method 
public function commitBulkUpdate():void

Executes a bulk update that was started via startBulkUpdate().

Affected components are notified only once regardless of the specific changes between startBulkUpdate() and this command.

Ancestor components are always notified before their children. A further order is not specified. It can be possible that children of different branches are notified alternating, e.g. C-1, C-2, C-2.1, C-2.2, C-1.3, C-2.4, C-1.1

componentSelectorAsString()method 
public function componentSelectorAsString():String

Returns the full selector of a component.

E.g. Box#mini.highlight

Returns
String — The component selector.
defineStyle()method 
public function defineStyle(styleName:String, styleValue:String, format:uint, priority:* = 0):void

Defines a style prior to be used with JCSS.

Styles need to be defined initially. Not initially defined styles are ignored and never affect the particular component.

Styles can only be defined initially (before the initialized event). Otherwise an error is thrown.

Parameters
styleName:String — The name of the style of a component.
 
styleValue:String — The initial value of the component style.
 
format:uint — The key of the formatter of the style value.
 
priority:* (default = 0) — Style priority (default, fix, important).
encloseChildren()method 
public function encloseChildren():void

Declares all child component to be selectable only via this component selector.

Enclosing children is useful when setting up stateful default styles that should not be overriden by accident. In example, we create a Button with several states and default styles that affect the contained label color. Setting now a global label color would override the Button declarations and make the label state insensitive. Invoking encloseChildren() lets match only styles rules that include this component in the selector chain.:

   Without encloseChildren();
   -----------------------------------------------
   myButton.setStyle(":over Label", "color", "red", "default"); // Button Label is red on mouse over by default.
   JCSS.getInstance().setStyle("Label", "color", "blue"); // Button Label is now blue even on mouse over.
   
   With encloseChildren();
   -----------------------------------------------
   myButton.setStyle(":over Label", "color", "red", "default"); // Button Label is red on mouse over by default.
   myButton.encloseChildren();
   JCSS.getInstance().setStyle("Label", "color", "blue"); // Does not affect the Button Label.
   JCSS.getInstance().setStyle("Button Label", "color", "blue"); // Button Label is now blue, since the selector includes Button.
   

This method can be called only initially (before the initialized event). Otherwise an error is thrown.

getState()method 
public function getState(stateName:String):String

Returns the value of a component state.

Parameters
stateName:String

Returns
String — The state value.
getStyle()method 
public function getStyle(styleName:String):*

Returns the current value for the given style name.

Returns initially (before the initialized event) null, for sure.

Parameters
styleName:String — The name of the style.

Returns
* — The current value of the style.
onComponentRegistered()method 
protected function onComponentRegistered():void

Default handler for the registered event.

Template method, to be overridden in a sub class.

See also

onStylesChanged()method 
protected function onStylesChanged(changedStyles:JCSS_ChangeEvent):void

Default handler for the styles changed event.

Template method, to be overridden in a sub class.

Parameters
changedStyles:JCSS_ChangeEvent — All recently changed styles.

See also

onStylesInitialized()method 
protected function onStylesInitialized():void

Default handler for the initialized event.

Template method, to be overridden in a sub class.

See also

parentChainAsString()method 
public function parentChainAsString():String

Returns the JCSS parent chain of a componet.

E.g. Box#mini.highlight(64) < Box(56) < Box(48) < Box.blue(39)

Returns
String — The parent chain of a component.
setState()method 
public function setState(stateName:String, value:String):void

Sets a component state.

Can be set initially or at runtime.

Parameters
stateName:String — The name of the state.
 
value:String — The value of the state.
setStyle()method 
public function setStyle(selector:String, styleName:String, styleValue:uint, priority:* = 1):void

Sets a style to a component instance.

It is possible to repeatedly invoke this method with equal style rules. They are then merged together for performance reasons, no worries, too.

Parameters
selector:String — A selector that matchs a particular component.
 
styleName:String — The name of the style to set.
 
styleValue:uint — The value of the style to set.
 
priority:* (default = 1) — The style priority (null, "!important" or "default").
setStyleSheet()method 
public function setStyleSheet(styleSheet:String):void

Sets a style sheet to a component instance.

The style sheet can be loaded from an external source or created at runtime.

   var styleSheet : String = <styles><![CDATA[
    Box {
     backgroundColor: 0xFF0000;
    }
   ]]></styles>.toString()
   

It is possible to repeatedly invoke this method with different style sheets. Equal style rules in different or the same sheet are merged together for performance reasons, no worries.

Parameters
styleSheet:String — The stylesheet to set.
startBulkUpdate()method 
public function startBulkUpdate():void

Starts a bulk update procedure.

If invoked, affected components are buffered and notified only once after a later call of commitBulkUpdate(). If there are different styles or state to set, that might affect a particular multiple times, it is recommended to wrap the update in the bulk transaction.

styleRuleTreeAsString()method 
public function styleRuleTreeAsString():String

Returns a formatted tree of all currently set style rules.

The following example shows a style sheet and its tree representation.

   var styleSheet : String = <styles><![CDATA[
   
       ToolTip {
           borderSize: 0;
       }
   
       Blue {
           backgroundColor: #0000CC;
           borderColor: #000066;
           color: #FFFFFF;
       }
   
       Blue ToolTip {
           backgroundColor: #6666FF;
           color: #FFFFFF;
       }
   
       Red {
           backgroundColor: #CC0000;
           borderColor: #660000;
           color: #FFFFFF;
       }
   
       Red ToolTip {
           backgroundColor: #FF6666;
           color: #FFFFFF;
       }
   
       Yellow {
           backgroundColor: #CCCC00;
           borderColor: #666600;
       }
   
       Yellow ToolTip {
           backgroundColor: #FFFF66;
       }
   
   ]]></styles>.toString();
   
   [This 2]
   |_____[Yellow 22]
       | >This Yellow specifity:2 {
       |    backgroundColor: #CCCC00 (12);
       |    borderColor: #666600 (13);
       | }
       |_____[ToolTip 26]
           | >This Yellow ToolTip specifity:3 {
           |    backgroundColor: #FFFF66 (14);
           | }
   |_____[Blue 8]
       | >This Blue specifity:2 {
       |    backgroundColor: #0000CC (2);
       |    color: #FFFFFF (4);
       |    borderColor: #000066 (3);
       | }
       |_____[ToolTip 12]
           | >This Blue ToolTip specifity:3 {
           |    backgroundColor: #6666FF (5);
           |    color: #FFFFFF (6);
           | }
   |_____[ToolTip 5]
       | >This ToolTip specifity:2 {
       |    borderSize: 0 (1);
       | }
   |_____[Red 15]
       | >This Red specifity:2 {
       |    backgroundColor: #CC0000 (7);
       |    color: #FFFFFF (9);
       |    borderColor: #660000 (8);
       | }
       |_____[ToolTip 19]
           | >This Red ToolTip specifity:3 {
           |    backgroundColor: #FF6666 (10);
           |    color: #FFFFFF (11);
           | }
   

Returns
String
stylesAsString()method 
public function stylesAsString():String

Returns a formatted String with all currently set styles.

   Styles for Box#mini.highlight(64) < Box(56) < Box(48) < Box.blue(39)

   borderColor: 255;
   ------------------------------ specifity:103 timestamp:7
   backgroundColor: 16777215;
   ------------------------------ specifity:3 timestamp:11
   borderAlpha: 0.5;
   ------------------------------ specifity:2 timestamp:2
   color: 0 default;
   ------------------------------ specifity:40001 timestamp:35
   borderSize: 1;
   ------------------------------ specifity:2 timestamp:1
   

Returns
String — Currently set styles in a formatted string.