Class zwt.ui.Widget
Extends
zwt.Object.
This is the base class of all ZWT widgets.
A widget is basically formed by two elements: a container and an element.
- The container is used by the layout management to place and resize the widgets in containers.
- The element is the root element of a widget HTML markup.
When implementing a widget, the implementor must defined the widget's element defining the component UI and append it to the container.
Defined in: Widget.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Construct a widget.
|
Field Attributes | Field Name and Description |
---|---|
<static> |
zwt.ui.Widget.FILL_BOTH
Indicate the Widget should be resized to fill the space both horizontally and vertically
|
<static> |
zwt.ui.Widget.FILL_HORIZONTAL
Indicate the Widget should be resized to fill the space horizontally
|
<static> |
zwt.ui.Widget.FILL_NONE
Indicate the Widget shouldn't be resized
|
<static> |
zwt.ui.Widget.FILL_VERTICAL
Indicate the Widget should be resized to fill the space vertically
|
<static> |
zwt.ui.Widget.RELATIVE_CONTAINER
Indicate that positions should be relative to the parent container
|
<static> |
zwt.ui.Widget.RELATIVE_PART
Indicate that positions should be relative to the parent part
|
<static> |
zwt.ui.Widget.RELATIVE_WINDOW
Indicate that positions should be relative to the window
|
Method Attributes | Method Name and Description |
---|---|
addStyle(string_style)
Add the specified style to the widget element class name if it doesn't already have it.
|
|
draw()
This method is used by containers to resize the widget content to fit in the layout.
|
|
Return the value of the fill property taking the context into account.
|
|
Return the dimension of the widget's container.
|
|
Return the widget's HTML element.
|
|
Return the dimension of the widget's element.
|
|
getFill()
Return the fill property.
|
|
Return the focus event manager attached to the widget.
|
|
getId()
Return the Widget's id.
|
|
Return the keyboard event manager attached to the widget.
|
|
Return the parent widget (likely to be a zwt.ui.container.Container) of the widget.
|
|
getRelativeLeft(int_relativeTo)
Return the top position relative to the container element specified by int_relativeTo.
|
|
getRelativeTop(int_relativeTo)
Return the top position relative to the container element specified by int_relativeTo.
|
|
getStyle()
Return the widget's style class name.
|
|
Return the wheel event manager attached to the widget.
|
|
hasFocus()
Determine whether the widget has the focus.
|
|
hasStyle(string_style)
Determine whether the widget element has the specified style.
|
|
Determine whether this widget is focusable.
|
|
Determine whether this Widget is visible.
|
|
onEvent(zwt_event_Event_event)
Executed by a zwt.event.UIEventManager or directly to handle the specified event in the widget.
|
|
processContentEvent(zwt_ui_container_ContentEvent_event)
Process the specified content event.
|
|
processEvent(zwt_event_Event_event)
Process the specified event.
|
|
processFocusEvent(zwt_event_FocusEvent_event)
Process the specified focus event.
|
|
processKeyboardEvent(zwt_event_KeyboardEvent_event)
Process the specified keyboard event.
|
|
processWheelEvent(zwt_event_WheelEvent_event)
Process the specified wheel event.
|
|
redraw()
This method is called by containers to redraw the widget.
|
|
removeStyle(string_style)
Remove the specified style from the widget element class name.
|
|
replaceStyle(string_style, string_newStyle)
Replace the specified style from the widget element class name by the specified new style if the widget element doesn't already have it.
|
|
setFill(int_fill)
Set the fill property.
|
|
setFocusable(boolean_focusable)
Set the widget focusable flag.
|
|
setId(string_id)
Set the id of the underlying container element.
|
|
setStyle(The)
Set the widget's style class name.
|
|
setVisible(boolean_flag)
Make this widget visible.
|
- Parameters:
- {String} string_style
- The CSS style to add
This method typically resizes the root element of the Widget but not the widget's container which should be resized by the parent widget. If it includes descendant widgets it also resizes the container of the descendant Widgets and calls their redraw method. Calling the draw method instead of the redraw method on descendant widgets may lead to unnecessary processing, it should be up to the redraw method to determine whether a widget needs to be drawn.
You may want to override this method if you want to draw the widget in a specific way.
The parent container always defines the context in which the widget is displayed. Basically there's no point in filling all the vertical space if the parent container is vertically elastic (ie. it takes the height of its content).
For all these reasons, the value returned by this method should always be used in draw operations.
- Returns:
- The fill value to use during draw operations, One of zwt.ui.Widget.FILL_NONE, zwt.ui.Widget.FILL_VERTICAL, zwt.ui.Widget.FILL_HORIZONTAL or zwt.ui.Widget.FILL_BOTH
- Returns:
- The dimension
- Returns:
- The element.
- Returns:
- The element's dimension
The fill property is used during draw operation to determine how the widget should fill the available space. This value is never used directly as it may be overridden depending on the context defined by the parent container.
- Returns:
- The value of the fill property, one of zwt.ui.Widget.FILL_NONE, zwt.ui.Widget.FILL_VERTICAL, zwt.ui.Widget.FILL_HORIZONTAL or zwt.ui.Widget.FILL_BOTH
- Returns:
- The focus event manager
- Returns:
- The id
- Returns:
- The keyboard event manager
- Returns:
- The parent widget
- Parameters:
- {Integer} int_relativeTo
- One of zwt.ui.Widget.RELATIVE_CONTAINER, zwt.ui.Widget.RELATIVE_PART or zwt.ui.Widget.RELATIVE_WINDOW.
- Returns:
- The top position.
- Parameters:
- {Integer} int_relativeTo
- One of zwt.ui.Widget.RELATIVE_CONTAINER, zwt.ui.Widget.RELATIVE_PART or zwt.ui.Widget.RELATIVE_WINDOW.
- Returns:
- The top position.
- Returns:
- The CSS className
- Returns:
- The wheel event manager
It actually tests if the widget's style contains a 'focus' selector.
- Returns:
- true if the widget has the focus, false otherwise
- Parameters:
- {String} string_style
- The CSS style to check
- Returns:
- true if the widget has the specified style
- Returns:
- true if the widget is focusable, false otherwise
- Returns:
- true if the widget and its ancestors are visible, false otherwise
This method touches the event to indicates it has consume it. It then calls the zwt.ui.Widget#processEvent to process the event and finally propagates the event to the parent widget if the event is set to propagate.
This method should never be overridden unless you know what you are doing.
- Parameters:
- {zwt.event.Event} zwt_event_Event_event
- The event
- Parameters:
- {zwt.ui.container.ContentEvent} zwt_ui_container_ContentEvent_event
- The content event to process
This method basically dispatch the specified event to the appropriate processXXXEvent method. You may need to override this method to process other types of event. If you do you should explicitly call this implementation.
This implementation process focus, keyboard and wheel events which are the default ones for any widgets.
It also process content event to flag that the widget's content has changed before the event is propagated to the parent container.
- Parameters:
- {zwt.event.Event} zwt_event_Event_event
- The event to process
This method should always be called when you choose to override it.
- Parameters:
- {zwt.event.FocusEvent} zwt_event_FocusEvent_event
- The focus event to process
- Parameters:
- {zwt.event.KeyboardEvent} zwt_event_KeyboardEvent_event
- The keyboard event to process
- Parameters:
- {zwt.event.WheelEvent} zwt_event_WheelEvent_event
- The wheel event to process
Basically a Widget needs to be resized in the following cases:
- the widget container dimensions has changed.
- the widget fill property has changed.
- the parent widget has forced the redraw. For instance, when the Theme of the page changes, a redraw operation is forced form the window widget.
Note that if the Widget is not visible, it is not redrawn.
- Parameters:
- {String} string_style
- The CSS style to remove
- Parameters:
- {String} string_style
- The CSS style to replace
- {String} string_newStyle
- The new CSS style
- Parameters:
- {Integer} int_fill
- One of zwt.ui.Widget.FILL_NONE, zwt.ui.Widget.FILL_VERTICAL, zwt.ui.Widget.FILL_HORIZONTAL or zwt.ui.Widget.FILL_BOTH
This method actually set the focusable flag, depending on the context other parameters may be considered to determine whether a widget is focusable or not. As a result the value that is set here is not completely linked to the zwt.ui.Widget#isFocusable method.
- Parameters:
- {Boolean} boolean_focusable
- true to make the widget focusable, otherwise false.
- Parameters:
- {String} string_id
- The id
- Parameters:
- {String} The
- CSS className to set
- Parameters:
- {Boolean} boolean_flag
- true to make the widget visible, otherwise false