org.millstone.base.ui
Class CustomComponent

java.lang.Object
  |
  +--org.millstone.base.ui.CustomComponent
All Implemented Interfaces:
Component, java.util.EventListener, Paintable, VariableOwner

public class CustomComponent
extends java.lang.Object
implements Component

Custom component provides simple implementation of Component interface for creation of new UI components by composition of existing components.

The component is used by inheriting the CustomComponent class and setting composite root inside the Custom component. The composite root itself can contain more components, but their interfaces are hidden from the users.

Since:
3.0
Version:
3.0.3
Author:
IT Mill Ltd.

Nested Class Summary
 
Nested classes inherited from class org.millstone.base.ui.Component
Component.Event, Component.Listener
 
Nested classes inherited from class org.millstone.base.terminal.Paintable
Paintable.RepaintRequestEvent, Paintable.RepaintRequestListener
 
Constructor Summary
CustomComponent()
          Construct new custom component.
CustomComponent(Component compositionRoot)
          Construct new custom component.
 
Method Summary
 void addListener(Component.Listener listener)
          Custom component does not implement any component events by default
 void addListener(Paintable.RepaintRequestListener listener)
          Add repaint request listener.
 void attach()
          Notifies the component that it is connected to an application.
 void changeVariables(java.lang.Object source, java.util.Map variables)
          The custom component does not have any variables by default
 void childRequestedRepaint(java.util.Collection alreadyNotified)
          The children must call this method when they need repainting.
 void dependsOn(VariableOwner depended)
          Makes this VariableOwner depend on the given VariableOwner.
 void detach()
          Notifies the component that it is detached from the application.
 Application getApplication()
          Gets the component's parent application.
 java.lang.String getCaption()
          The caption of the custom component is by default the the caption of the root component, or null if the root is not set
 java.lang.String getComponentType()
          Gets the component type.
protected  Component getCompositionRoot()
          Returns the composition root.
 java.util.Set getDirectDependencies()
          Gets the variable change listeners this VariableOwner directly depends on.
 Resource getIcon()
          The icon of the custom component is by default the the icon of the root component, or null if the root is not set
 java.util.Locale getLocale()
          The icon of the custom component is by default the the locale of the parent or null if the parent is not set.
 Component getParent()
          Gets the visual parent of the component.
 java.lang.String getStyle()
          Custom component does not implement custom styles by default and this function returns null.
 Window getWindow()
          Gets the component's parent window.
 boolean isEnabled()
          Custom component is allways enabled by default
 boolean isImmediate()
          Custom component is by default in the non-immediate mode.
 boolean isReadOnly()
          The custom components are not readonly by default.
 boolean isVisible()
          Tests if the component is visible or not.
 void paint(PaintTarget target)
          Paints the paintable into a UIDL stream.
 void removeDirectDependency(VariableOwner depended)
          Removes the given component from this component's dependency list.
 void removeListener(Component.Listener listener)
          Custom component does not implement any component events by default
 void removeListener(Paintable.RepaintRequestListener listener)
          Remove repaint request listener.
 void requestRepaint()
          Requests that the paintable should be repainted as soon as possible.
 void requestRepaintRequests()
          Request sending of repaint events on any further visible changes.
 void setComponentType(java.lang.String componentType)
          Sets the component type.
protected  void setCompositionRoot(Component compositionRoot)
          Sets the compositions root.
 void setEnabled(boolean enabled)
          The custom component is allways enabled by default.
 void setParent(Component parent)
          Sets the component's parent component.
 void setReadOnly(boolean readOnly)
          Changing the read-only mode of the component is not supported by default.
 void setStyle(java.lang.String style)
          Changing the style of the component is not supported by default.
 void setVisible(boolean visible)
          Sets the components visibility status.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomComponent

public CustomComponent()
Construct new custom component.

The component is implemented by wrapping the methods of the composition root component given as parameter. The composition root must be set before the component can be used.


CustomComponent

public CustomComponent(Component compositionRoot)
Construct new custom component.

The component is implemented by wrapping the methods of the composition root component given as parameter. The composition root must not be null and can not be changed after the composition.

Parameters:
compositionRoot - The root of the composition component tree.
Method Detail

getCompositionRoot

protected final Component getCompositionRoot()
Returns the composition root.

Returns:
Component Composition root

setCompositionRoot

protected final void setCompositionRoot(Component compositionRoot)
Sets the compositions root.

The composition root must be set to non-null value before the component can be used. The composition root can only be set once.

Parameters:
compositionRoot - The root of the composition component tree.

attach

public void attach()
Description copied from interface: Component
Notifies the component that it is connected to an application. This method is always called before the component is first time painted and is suitable to be extended. The getApplication() and getWindow() functions might return null before this method is called.

The caller of this method is Component.setParent(Component) if the parent is already in the application. If the parent is not in the application, it must call the Component.attach() for all its children when it will be added to the application.

Specified by:
attach in interface Component

detach

public void detach()
Description copied from interface: Component
Notifies the component that it is detached from the application.

The Component.getApplication() and Component.getWindow() methods might return null after this method is called.

The caller of this method is Component.setParent(Component) if the parent is in the application. When the parent is detached from the application it is its response to call Component.detach() for all the children and to detach itself from the terminal.

Specified by:
detach in interface Component

getApplication

public Application getApplication()
Description copied from interface: Component
Gets the component's parent application. If the component does not yet belong to a application null is returned.

Specified by:
getApplication in interface Component
Returns:
parent application of the component or null

getCaption

public java.lang.String getCaption()
The caption of the custom component is by default the the caption of the root component, or null if the root is not set

Specified by:
getCaption in interface Component
Returns:
component's caption String

getIcon

public Resource getIcon()
The icon of the custom component is by default the the icon of the root component, or null if the root is not set

Specified by:
getIcon in interface Component
Returns:
the component's icon or null if it not defined.

getLocale

public java.util.Locale getLocale()
The icon of the custom component is by default the the locale of the parent or null if the parent is not set.

Specified by:
getLocale in interface Component
Returns:
This component's locale. If this component does not have a locale, the locale of its parent is returned. Eventually locale of application is returned. If application does not have its own locale the locale is determined by Locale.getDefautl(). Returns null if the component does not have its own locale and has not yet been added to a containment hierarchy such that the locale can be determined from the containing parent.

getParent

public Component getParent()
Description copied from interface: Component
Gets the visual parent of the component. The components can be nested but one component can have only one parent.

Specified by:
getParent in interface Component
Returns:
the parent component

getStyle

public java.lang.String getStyle()
Custom component does not implement custom styles by default and this function returns null.

Specified by:
getStyle in interface Component
Returns:
component's styleValue of property style.

getWindow

public Window getWindow()
Description copied from interface: Component
Gets the component's parent window. If the component does not yet belong to a window null is returned.

Specified by:
getWindow in interface Component
Returns:
parent window of the component or null

isEnabled

public boolean isEnabled()
Custom component is allways enabled by default

Specified by:
isEnabled in interface Component
Returns:
true if the component is enabled, false if not
See Also:
VariableOwner.isEnabled()

isImmediate

public boolean isImmediate()
Custom component is by default in the non-immediate mode. The immediateness of the custom component is defined by the components it is composed of.

Specified by:
isImmediate in interface Component
Returns:
true if the component is in immediate mode, false if not

isReadOnly

public boolean isReadOnly()
The custom components are not readonly by default.

Specified by:
isReadOnly in interface Component
Returns:
true if the component is in read-only mode, false if not

isVisible

public boolean isVisible()
Description copied from interface: Component
Tests if the component is visible or not. Visibility defines if the component is shown in the UI or not. Default is true.

Specified by:
isVisible in interface Component
Returns:
true if the component is visible in the UI, false if not

requestRepaint

public void requestRepaint()
Description copied from interface: Paintable
Requests that the paintable should be repainted as soon as possible.

Specified by:
requestRepaint in interface Paintable

childRequestedRepaint

public void childRequestedRepaint(java.util.Collection alreadyNotified)
Description copied from interface: Component
The children must call this method when they need repainting. The call must be made event in the case the children sent the repaint request themselves.

Specified by:
childRequestedRepaint in interface Component
Parameters:
alreadyNotified - A collection of repaint request listeners that have been already notified by the child. This component should not renotify the listed listeners again. The container given as parameter must be modifiable as the component might modify it and pass it forwards. Null parameter is interpreted as empty collection.

addListener

public void addListener(Paintable.RepaintRequestListener listener)
Description copied from interface: Paintable
Add repaint request listener. In order to assure that no repaint requests are missed, the new repaint listener should paint the paintable right after adding itself as listener.

Specified by:
addListener in interface Paintable
Parameters:
listener - to be added

removeListener

public void removeListener(Paintable.RepaintRequestListener listener)
Description copied from interface: Paintable
Remove repaint request listener.

Specified by:
removeListener in interface Paintable
Parameters:
listener - to be removed

setEnabled

public void setEnabled(boolean enabled)
The custom component is allways enabled by default.

Specified by:
setEnabled in interface Component
Parameters:
enabled - boolean value specifying if the component should be enabled after the call or not

setParent

public void setParent(Component parent)
Description copied from interface: Component
Sets the component's parent component.

This method calls automatically Component.attach() if the parent is attached to a window (or is itself a window}, and Component.detach() if parent is set null, but the component was in the application.

This method is rarely called directly. Instead the ComponentContainer.addComponent(Component) method is used to add components to container, which call this method implicitly.

Specified by:
setParent in interface Component
Parameters:
parent - the new parent component

setReadOnly

public void setReadOnly(boolean readOnly)
Changing the read-only mode of the component is not supported by default.

Specified by:
setReadOnly in interface Component
Parameters:
readOnly - boolean value specifying if the component should be in read-only mode after the call or not

setStyle

public void setStyle(java.lang.String style)
Changing the style of the component is not supported by default.

Specified by:
setStyle in interface Component
Parameters:
style - new style of the component

setVisible

public void setVisible(boolean visible)
Description copied from interface: Component
Sets the components visibility status. Visibility defines if the component is shown in the UI or not.

Specified by:
setVisible in interface Component
Parameters:
visible - Boolean value specifying if the component should be visible after the call or not

requestRepaintRequests

public void requestRepaintRequests()
Description copied from interface: Paintable
Request sending of repaint events on any further visible changes. Normally the paintable only send up to one repaint request for listeners after paint as the paintable as the paintable assumes that the listeners already know about the repaint need. This method resets the assumtion. Paint implicitly does the assumtion reset functionality implemented by this method. This method is normally used only by the terminals to note paintables about implicit repaints (painting the component without actually invoking paint method).

Specified by:
requestRepaintRequests in interface Paintable

paint

public void paint(PaintTarget target)
           throws PaintException
Description copied from interface: Paintable

Paints the paintable into a UIDL stream. This method creates the UIDL sequence describing it and outputs it to the given UIDL stream.

It's is called when the contents of the component should be painted in response to the component first being shown or having been altered so that its visual representation is changed.

Specified by:
paint in interface Paintable
Parameters:
target - target UIDL stream where the component should paint itself to
Throws:
PaintException - if the paint operation failed

changeVariables

public void changeVariables(java.lang.Object source,
                            java.util.Map variables)
The custom component does not have any variables by default

Specified by:
changeVariables in interface VariableOwner
Parameters:
source - Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.
variables - Mapping from variable names to new variable values

dependsOn

public void dependsOn(VariableOwner depended)
Description copied from interface: VariableOwner
Makes this VariableOwner depend on the given VariableOwner. This means that any variable change events relating to depended must be sent before any such events that relate to this object.

Specified by:
dependsOn in interface VariableOwner

getDirectDependencies

public java.util.Set getDirectDependencies()
Description copied from interface: VariableOwner
Gets the variable change listeners this VariableOwner directly depends on. This list does not contain any indirect dependencies, for example, if A depends on B and B depends on C, the dependency list of A does not include C.

Specified by:
getDirectDependencies in interface VariableOwner
Returns:
Set of VariableOwners this component directly depend on, null if this component does not depend on anybody.

removeDirectDependency

public void removeDirectDependency(VariableOwner depended)
Description copied from interface: VariableOwner
Removes the given component from this component's dependency list. After the call this component will no longer depend on depended wdepende direct dependency from the component. Indirect dependencies are not removed.

Specified by:
removeDirectDependency in interface VariableOwner

addListener

public void addListener(Component.Listener listener)
Custom component does not implement any component events by default

Specified by:
addListener in interface Component
Parameters:
listener - the new Listener to be registered

removeListener

public void removeListener(Component.Listener listener)
Custom component does not implement any component events by default

Specified by:
removeListener in interface Component
Parameters:
listener - the listener to be removed

getComponentType

public java.lang.String getComponentType()
Gets the component type. The component type is textual type of the component. This is included in the UIDL as component tag attribute. If the component type is null (default), the component tag is not included in the UIDL at all. Returns the componentType.

Returns:
String

setComponentType

public void setComponentType(java.lang.String componentType)
Sets the component type. The component type is textual type of the component. This is included in the UIDL as component tag attribute. If the component type is null (default), the component tag is not included in the UIDL at all.

Parameters:
componentType - The componentType to set


Copyright © 2000,2001,2002 IT Mill Ltd. All Rights Reserved.