TKComponent Class Reference
[Core Classes]

Base class for all toolkit components and containers. More...

Inheritance diagram for TKComponent:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 __call ($name, $args)
 Implements dynamic function calls for, e.g., setXxx().
 __clone ()
 Clones this component and subcomponents for reuse.
 __construct ()
 INSERT BRIEF DESCRIPTION HERE.
__get ($fldName)
 Allows simpler syntax for getting properties.
 __isset ($fldName)
 Determines whether property or event exists.
 __set ($fldName, $value)
 Allows simpler syntax for setting properties and events.
 __toString ()
 Converts object to a string suitable for debugging purposes.
 append ($fldName, $value, $pre=false)
 Appends a value to a property.
 appendMany ($fields)
 Performs multiple append operations at once.
 eventExists ($eventName)
 Gets whether an event exists on this object.
 exists ($fld)
 Returns whether a property exists.
get ($fldName)
 Retrieves a given property.
 getId ()
 Retrieves the object's unique ID.
 getProperties ($values=false)
 Returns a list of all the properties this object has.
 getTheme ()
 Retrieves the currently active theme for this object.
 getThemeClass ()
 Retrieves the current theme class for this object.
 render ()
 Converts this component (and any children) to HTML.
 set ($fldName, $value)
 Sets a property.
 setAction ($eventName, $action)
 Associates an action with an event.
 setId ($id)
 Sets a new ID for the object.
 setMany ($fields)
 Calls set() many times.
 setTheme ($theme)
 Sets the toolkit theme for this object.
 setThemeClass ($class)
 Sets the theme class for this object.

Public Attributes

const PROP_ARRAY
 Property is an array.
const PROP_BOOLEAN
 Property is a boolean.
const PROP_CLASS
 Property is a class array (flat list of classes).
const PROP_NUMERIC
 Property is numeric (integer or float).
const PROP_OBJECT
 Property is an object.
const PROP_STRING
 Property is a string.
const PROP_STYLE
 Property is a style array (associative array of CSS style => value elements).


Detailed Description

Base class for all toolkit components and containers.

This class is an abstract class and thus cannot be instantiated. It provides most of the functionality used by components and containers, and also some functionality for making the toolkit work with PageRender2.

Properties:
  • class array: CSS class(es) to be used for this object
  • style array: CSS styles in attribute => value pairs to be used for this object
  • alt string: ALT tag text for this object

Events:
  • onclick: JavaScript onclick event
  • ondblclick: JavaScript ondblclick event
  • onmousedown: JavaScript onmousedown event
  • onmouseout: JavaScript onmouseout event
  • onmouseover: JavaScript onmouseover event
  • onmouseup: JavaScript onmouseup event
  • onkeydown: JavaScript onkeydown event
  • onkeypress: JavaScript onkeypress event
  • onkeyup: JavaScript onkeyup event


Constructor & Destructor Documentation

TKComponent::__construct (  ) 

INSERT BRIEF DESCRIPTION HERE.

INSERT FULL DESCRIPTION HERE

Returns:
[TYPE]: RETURN DESCRIPTION

Reimplemented from SObject.

Reimplemented in TKBorderPanel, TKHBox, TKNullBox, TKScrollPane, TKTree, TKVBox, and TKContainer.


Member Function Documentation

TKComponent::__call ( name,
args 
)

Implements dynamic function calls for, e.g., setXxx().

This method allows you to call, e.g., setStyle(...) instead of set('style', ...). See the main documentation for this class for more on the dynamic functions.

This method implements setXxx(), getXxx(), appendXxx() and existsXxx() corresponding to set(), get(), append(), exists().

Parameters:
$name [string]: name of method
$args [array]: arguments to method
Returns:
[mixed]: whatever needs to be returned by set(), get(), append() or exists()

Reimplemented in TKContainer.

TKComponent::__clone (  ) 

Clones this component and subcomponents for reuse.

Once a component has been rendered, it is not safe to re-use the HTML generated because it may contain unique IDs, events, etc. This method attempts to clone this component so that it can be reused with its configuration. It is NOT safe for use at the moment because of many sticky details in properly cloning components and espcially containers.

Reimplemented in TKContainer.

& TKComponent::__get ( fldName  ) 

Allows simpler syntax for getting properties.

This method allows you to say

 $oc = $component->outer_class;
instead of
 $oc = $component->get('outer_class');

The same rules apply for getting via this mechanism as for using the get() method or the dynamic function calls (e.g., getStyle()). If the property given is "html", then render() is called and the HTML for this component is returned.

Parameters:
$fldName [string]: name of parameter
Returns:
[mixed]: value of property

TKComponent::__isset ( fldName  ) 

Determines whether property or event exists.

This method first checks to see if an event by the given name exists, otherwise it checks to see if the property by the given name exists. Don't give events and properties the same names to prevent problems with this mechanism.

Parameters:
$fldName [string]: name of property or event whose existence to check
Returns:
[boolean]: whether property or event exists on this object

TKComponent::__set ( fldName,
value 
)

Allows simpler syntax for setting properties and events.

This method allows you to say

 $component->outer_class = array('whatever');
instead of
 $component->set('outer_class', array('whatever'));

The same rules apply for setting via this mechanism as for using the set() method or the dynamic function calls (e.g., setStyle()). The benefit of this mechanism, though, is that it detects whether the field to set is actually an event, and if so, calls setAction() instead of set().

Parameters:
$fldName [string]: name of parameter or event
$value [mixed]: new value for parameter or event
Returns:
[boolean]: success or failure

TKComponent::__toString (  ) 

Converts object to a string suitable for debugging purposes.

All this really does is print out the type of component and its ID. Child classes may (and should) override this method to provide more interesting information.

Returns:
[string]: short debugging string

TKComponent::append ( fldName,
value,
pre = false 
)

Appends a value to a property.

Appending means different things for different types. For numeric types, appending simply adds the two values together. This does not always make sense, so be careful when appending numeric types. Strings are concatenated. Arrays are more complicated. If the value to be appended is an array, then it is array_merge'd with the current value. If the value is not an array, then it is array_push'ed onto the end of the current value. Objects and booleans cannot be appended and an error message will be displayed.

If the $pre parameter is true, then values are prepended to the existing value. For strings, the concatenation order is reversed. Numeric values are added the same as with a false $pre. Arrays are merged or pushed onto at the opposite end, as expected.

Parameters:
$fldName [string]: name of property
$value [mixed]: value to be appended to property
$pre [boolean]: if true, value is prepended, rather than appended
Returns:
[TKComponent] current object

TKComponent::appendMany ( fields  ) 

Performs multiple append operations at once.

Pass in an array of property => value pairs and each pair will result in a call to append(). Note that you cannot affect the $pre flag of append().

Parameters:
$fields [array]: array of property => value pairs
Returns:
[TKComponent] current object

TKComponent::eventExists ( eventName  ) 

Gets whether an event exists on this object.

Parameters:
$eventName [string]: name of event to check for
Returns:
[boolean] whether event exists on this object

TKComponent::exists ( fld  ) 

Returns whether a property exists.

Parameters:
$fld [string]: name of property to check existence for
Returns:
[boolean] whether that property exists

& TKComponent::get ( fldName  ) 

Retrieves a given property.

You can also use $obj->prop instead of $obj->get('prop'). Additionally, there is $obj->getProp().

Parameters:
$fldName [string]: name of property to retrieve
Returns:
[mixed] value of property or null if no such property exists

TKComponent::getId (  ) 

Retrieves the object's unique ID.

Returns:
[string] object's ID

TKComponent::getProperties ( values = false  ) 

Returns a list of all the properties this object has.

Returns:
[array] list of property names

TKComponent::getTheme (  ) 

Retrieves the currently active theme for this object.

Returns:
[TKTheme] the current them object for this class

TKComponent::getThemeClass (  ) 

Retrieves the current theme class for this object.

Returns:
[string] theme class name

TKComponent::render (  ) 

Converts this component (and any children) to HTML.

This will only actually generate the HTML once. If render() has been called before, this will only return the results of the previous render operation.

Returns:
[string] HTML from rendering, or false if there was an error rendering

Reimplemented in TKCSERDClassicReview, TKSDRResourceResultMetadata, and TKSDRResourceResultSet.

TKComponent::set ( fldName,
value 
)

Sets a property.

Each property has a type, of which there are five:

  1. String
  2. Numeric (string representing a number or a numeric value)
  3. Boolean
  4. Array
  5. Object
When setting a property you must provide a value that is of the right type, or an error will be indicated. Setting a property also completely erases the existing value. Use append() to append to or merge an array with the existing value of a property. If the property is an array, but the value is not, then the value is put inside an array and that is assigned to the property.

Parameters:
$fldName [string]: name of property
$value [mixed]: new value of property
Returns:
[TKComponent] this object

TKComponent::setAction ( eventName,
action 
)

Associates an action with an event.

This function sets an action to happen when an event occurs. Read more about events and actions at Themes. Note that more than one action can be associated with an event and multiple actions will be executed in the order that they were assigned with setAction(). You can also use the shorthand notation to set events: $comp->onclick = new TKSomeAction(...) instead of setAction().

The action can be an instance of TKAction or its children, or it can be a string of JavaScript, or an array of two strings. The first string is JavaScript that will be inserted into the header of the page. The second string is JavaScript that will go directly in the event handler.

Parameters:
$eventName [string]: name of event
$action [TKAction]: action to be associated with event (can also be string or array.
Returns:
[boolean] success

TKComponent::setId ( id  ) 

Sets a new ID for the object.

The ID should be unique, or the HTML generated will not be valid (although it will likely work). What won't work is any JavaScript based on the objects that have non-unique IDs. This function will also *try* to update any references to the ID in use. Unfortunately, the ID may be used in places out of direct control of this object, such as generated JS, so it is best to avoid calling this method if you are using strange TK actions or some other strange set up. Be prepared for subtle bugs, as well.

Parameters:
$id [string]: new ID for object

TKComponent::setMany ( fields  ) 

Calls set() many times.

You pass in an array where the keys are properties to set and the values are the new values for those properties.

Parameters:
$fields [array]: property names and the associated values
Returns:
[TKComponent] this object

TKComponent::setTheme ( theme  ) 

Sets the toolkit theme for this object.

To change the theme for all objects, call TKComponent::setDefaultTheme() or PageRender2::setToolkitTheme(). See Themes for more information on themes.

Parameters:
$theme [TKTheme] new theme object

TKComponent::setThemeClass ( class  ) 

Sets the theme class for this object.

The theme class is basically a way of specifying a category of objects within a given component class. For example, while there is only the TKLabel class, we might still want to have multiple types of TKLabel's, for themeing purposes.

Parameters:
$class [string]: theme class name


The documentation for this class was generated from the following file:

Generated on Wed Nov 24 02:04:11 2010 for Common by  doxygen 1.5.6