Name

state (LzState) — A description of an instance hierarchy that can be applied and removed at runtime.

Synopsis

LZX: state
JavaScript: LzState
Type: Class
Access: public
Topic: LFC.Helpers
Declared in: WEB-INF/lps/lfc/helpers/LzState.lzs

Description

A state is an object that holds its children and attributes for creation or application at a later time — when the state's apply method is called. In addition to representing visual state by adding and removing children from a view, states are often used to control constraints which are applied and removed at different times during the run of an application.

For the most part, the declarative style used in OpenLaszlo applications represents an initial state for the application. All modification to application state can be made using the script API's, but it is often convenient to declaratively describe a bit of application state which may be selectively applied or removed at runtime. The state tag is provided for this purpose.

Everything within a state tag acts as if it were written inside the parent when the state is applied. States can contain attributes, methods, and other nodes.

When a state is removed, any children or constraints created when the state was applied are then removed, but attributes that were set by the application of the state are not restored.

Example 12. Using states to represent the min/max state of a window.

 <canvas>
   <window title="state demo" width="400" height="300">
     <state name="max" apply="true">
       <animatorgroup duration="1000" process="simultaneous">
         <animator attribute="width" to="400"/>
         <animator attribute="height" to="300"/>
 
         <animator attribute="x" to="100"/>
         <animator attribute="y" to="100"/>
       </animatorgroup>
       <text align="center" y="20%">M a x i m i z e d</text>
     </state>
 
     <state name="min">
       <animatorgroup duration="1000" process="simultaneous">
         <animator attribute="width" to="170"/>
         <animator attribute="height" to="100"/>
         <animator attribute="x" to="0"/>
         <animator attribute="y" to="0"/>
 
       </animatorgroup>
       <text align="center" valign="middle">Minimized</text>
     </state>
     <button placement="title_area" align="right" height="16"> Toggle
       <attribute name="isMax" value="true"/>
 
       <handler name="onclick">
         if (this.isMax) { parent.max.remove(); parent.min.apply(); }
         else { parent.max.apply(); parent.min.remove(); }
         this.isMax = !this.isMax;
       </handler>
     </button>
   </window>
 </canvas>
 

In addition to any fields documented in the section below, these fields are also available: Boolean isapplied: true if the state is currently applied

Superclass Chain

node (LzNode) » state (LzState)

Known Subclasses

Details

Static Properties (2)

stateevents
static public var stateevents = { ... };
staterefs
static public var staterefs = { ... };

Properties (3)

asyncnew
<attribute name="asyncnew" />
public var asyncnew = false;
pooling
<attribute name="pooling" />
public var pooling = false;
subh
<attribute name="subh" />
public var subh = null;

Setters (5)

Setters for virtual properties, to be used with setAttribute. A setter may or may not have a corresponding getter method; consult the Methods list in this section.

apply
setAttribute('apply', true) will apply the state. setAttribute('apply', false) will remove the state. By default, states are not applied. It is often convenient to assign this attribute as a constraint in the tag. For example: <state name="mystate" apply="parent.opened" will apply the state if parent.opened is true. Note that for any script that is in the tag, the parent is the tag that encloses the script. Any method that is declared within the state can only be called after the state is applied, and upon application this will refer to the view that encloses the state, rather than the state itself.
asyncnew
__LZsourceLocation
When __LZsourceLocation is set, it should only apply to the state, not the parent
pooling
If true, the state will merely hide any views it has created when it is removed, instead of destroying them.
$setters

Methods (12)

apply()
<method name="apply" />
public function apply();
Applies the state to the state's parent. If the state is already applied, has no effect
construct()
<method name="construct" args="parent, args" />
private function construct(parent, args);
createChildren()
<method name="createChildren" args="carr" />
private function createChildren(carr);
destroy()
<method name="destroy" />
private function destroy();
Clean up after yourself
__LZapplyArgs()
<method name="__LZapplyArgs" args="args" />
public function __LZapplyArgs(args);
__LZdetach()
<method name="__LZdetach" args="aview" />
private function __LZdetach(aview);
__LZretach()
<method name="__LZretach" args="aview" />
private function __LZretach(aview);
__LZsetProperty()
<method name="__LZsetProperty" args="prop, propname" />
private function __LZsetProperty(prop, propname);
__LZstoreDelegates()
<method name="__LZstoreDelegates" args="delarr" />
public function __LZstoreDelegates(delarr);
__LZstoreRefs()
<method name="__LZstoreRefs" args="refs, prop" />
public function __LZstoreRefs(refs, prop);
remove()
<method name="remove" />
public function remove();
Removes the constraints and views made when the state was applied. This method does not currently restore the previous values of any attributes that were changed by the state
setApply()
<method name="setApply" args="doapply" />
private function setApply(doapply);

Events (2)

onapply
<attribute name="onapply" />
public event onapply;
Sent when the state is applied.
onremove
<attribute name="onremove" />
public event onremove;
Sent when the state is removed

Prototype Properties (1)

$isstate
<attribute name="$isstate" />
public var $isstate = true;

LZX Synopsis

<class name="LzState" extends=" LzNode ">
  <attribute name=" asyncnew " />
  <attribute name=" pooling " />
  <attribute name=" subh " />
  <method name=" apply " />
  <method name=" construct " args="parent, args" />
  <method name=" createChildren " args="carr" />
  <method name=" destroy " />
  <method name=" __LZapplyArgs " args="args" />
  <method name=" __LZdetach " args="aview" />
  <method name=" __LZretach " args="aview" />
  <method name=" __LZsetProperty " args="prop, propname" />
  <method name=" __LZstoreDelegates " args="delarr" />
  <method name=" __LZstoreRefs " args="refs, prop" />
  <event name=" onapply " />
  <event name=" onremove " />
  <method name=" remove " />
  <method name=" setApply " args="doapply" />
</class>

JavaScript Synopsis

public LzState extends  LzNode  {
  static public var stateevents  = { ... };
  static public var staterefs  = { ... };
  public var asyncnew  = false;
  public var pooling  = false;
  public var subh  = null;
  prototype public function apply ();
  prototype private function construct (parent, args);
  prototype private function createChildren (carr);
  prototype private function destroy ();
  prototype public var $isstate  = true;
  prototype public function __LZapplyArgs (args);
  prototype private function __LZdetach (aview);
  prototype private function __LZretach (aview);
  prototype private function __LZsetProperty (prop, propname);
  prototype public function __LZstoreDelegates (delarr);
  prototype public function __LZstoreRefs (refs, prop);
  prototype public event onapply ;
  prototype public event onremove ;
  prototype public function remove ();
  prototype private function setApply (doapply);
}