portal.core.api
Class Component

java.lang.Object
  extended byportal.core.api.Component
All Implemented Interfaces:
Renderable, java.io.Serializable
Direct Known Subclasses:
AbstractButton, ActionLink, Block, CheckBox, ComboBox, ComponentDelegator, Container, Desktop, FileUpload, FormElement, Image, Label, ListBox, PanelDelegator, ProxyComponent, RadioButton, TabbedPane, Tree, Window, Wizard

public class Component
extends java.lang.Object
implements java.io.Serializable, Renderable

This is the super class for all classes that take part in the user interface. An instance of a component can be rendered and (optionally) manipulated by the user.

A component can optionally have a model to store it's internal state. This is not an obligation, some simpler components can choose to store their internal state within the component instance itself. Only components that which to be more generic and extensible by means of implementing the required Model interface, can delegate some of the logic to a model.

Every component has a parent. The only exceptions are top level components like a frame. See the documentation about internal desktop management. Not every component will have children. The Component classes only models the parent relationship. The Container class keeps track of the child relationship. Developers wishing the implement their own container classes will have to make sure the parent - child relationship is consistent.

The component instance can choose to render itself by overriding the draw() method, or it can delegate the rendering to a layout manager. Layout managers can be set using the setLayout()

Since:
0.9
Author:
bavodr
See Also:
Serialized Form

Constructor Summary
Component()
          Creates a new Component instance.
Component(Model model)
          Creates a new Component instance with the given initial model.
Component(java.lang.String name)
          Creates a new Component instance with the given name.
Component(java.lang.String name, Model model)
          Creates a new Component instance with the given name and initial model.
 
Method Summary
 void afterRender()
          This method is called after the actual rendering (either through a layout manager or by the draw method implementation) took place.
 void beforeRender()
          This method is called before the actual rendering takes place.
protected  Model createDefaultModel()
          This method is called by the constructor to create a default model for this component.
protected  void draw(HtmlGraphics htmlGraphics)
          With this method the component can render itself using the passed HtmlGraphics object.
 LayoutManager getLayout()
          Get the layout manager that will render this component, if set.
 Model getModel()
          Returns the current model instance or null when there is no model for this component.
 Component getParent()
          Returns the current parent or null if there is no parent.
 boolean isEnabled()
          Determines whether this component is enabled.
 boolean isVisible()
          Return if this component is visible or not.
 void render(RenderContext renderContext)
          Describe render method here.
 void setEnabled(boolean enabled)
          Enables or disables this component, depending on the value of the parameter enabled.
 void setLayout(LayoutManager layout)
          Set the layout manager for this component.
protected  void setModel(Model model)
          Set a new model for this component.
 void setParent(Component parent)
          Sets a new parent.
 void setVisible(boolean visible)
          Set the visibility for this component.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Component

public Component()

Creates a new Component instance.

Calling this method is equivalent to calling Component(null, null)

See also Component(String,Model).


Component

public Component(java.lang.String name)

Creates a new Component instance with the given name.

Calling this method is equivalent to calling Component(name, null)

See also Component(String,Model).

Parameters:
name - the name of this component or null for no name

Component

public Component(Model model)

Creates a new Component instance with the given initial model.

Calling this method is equivalent to calling Component(null, model)

See also Component(String,Model).

Parameters:
model - the initial value of the model of this instance or null for no initial model

Component

public Component(java.lang.String name,
                 Model model)

Creates a new Component instance with the given name and initial model.

The name is only used in debug output. Both the name and model parameters can be null.

Parameters:
name - the name of this new instance of Component
model - the model of this component
Method Detail

setParent

public final void setParent(Component parent)

Sets a new parent. When the new parent is null, it will reset the parent and make this component top level in the UI tree.

Parameters:
parent - a Component value

getParent

public final Component getParent()

Returns the current parent or null if there is no parent.

Returns:
the reference to the parent or null if no parent

isVisible

public final boolean isVisible()

Return if this component is visible or not. See setVisible(booleaan) for more information.

Specified by:
isVisible in interface Renderable
Returns:
true if visible, false otherwise

setVisible

public final void setVisible(boolean visible)

Set the visibility for this component. Visible means this component will be rendered. When the component is not visible, it will be ignored in the rendering process.

Specified by:
setVisible in interface Renderable
Parameters:
visible - true if this component should be visible, false for not visible

isEnabled

public final boolean isEnabled()

Determines whether this component is enabled. An enabled component can respond to user input and generate events. Components are enabled initially by default.

See also setEnabled(boolean).

Returns:
true when the component is enabled, false otherwise

setEnabled

public final void setEnabled(boolean enabled)

Enables or disables this component, depending on the value of the parameter enabled. An enabled component can respond to user input. Components are enabled initially by default.

Parameters:
enabled - when true, the component is enabled, false if the component should be disabled

beforeRender

public void beforeRender()
                  throws RenderException

This method is called before the actual rendering takes place. This is true both when the draw() or a layout manager is used for rendering.

When this method throws an exception, the render process for the tree rooted at this component is stopped.

Specified by:
beforeRender in interface Renderable
Throws:
RenderException

render

public final void render(RenderContext renderContext)
                  throws RenderException
Describe render method here.

Specified by:
render in interface Renderable
Parameters:
renderContext - the engine render context
Throws:
RenderException - when an error occurs during the rendering

afterRender

public void afterRender()
                 throws RenderException

This method is called after the actual rendering (either through a layout manager or by the draw method implementation) took place. Even when the render() threw an exception.

It is guaranteed that this method is called, even when the previous render step threw an error. However when the beforeRender() method threw an exception, the afterRender() method is not called.

Specified by:
afterRender in interface Renderable
Throws:
RenderException

draw

protected void draw(HtmlGraphics htmlGraphics)
             throws RenderException

With this method the component can render itself using the passed HtmlGraphics object. This method is not called when a layout manager is set since the existence of a layout manager takes precedence above the draw() method.

Parameters:
htmlGraphics - the html graphics instance to use for drawing this component
Throws:
RenderException - when the rendering process could not proceed or encountered an error

getLayout

public final LayoutManager getLayout()

Get the layout manager that will render this component, if set.

Specified by:
getLayout in interface Renderable
Returns:
the current layout manager or null when none is set

setLayout

public final void setLayout(LayoutManager layout)

Set the layout manager for this component. Passing null resets the layout manager.

Specified by:
setLayout in interface Renderable
Parameters:
layout - the new layout manager.

getModel

public final Model getModel()

Returns the current model instance or null when there is no model for this component.

Returns:
the current model or null when there is no model set

setModel

protected final void setModel(Model model)

Set a new model for this component. Passing null will reset the currently set model.

Parameters:
model - the new model or null to reset the current model

createDefaultModel

protected Model createDefaultModel()

This method is called by the constructor to create a default model for this component. If this component type does not use a model or does not have a suitable default model, this method can return null.

The default implementation should return null.

Returns:
an instance of a Model or null when there is no default model

toString

public java.lang.String toString()