EchoPoint
1.0

echopoint.ui.util
Class EchoPointComponentPeer

java.lang.Object
  extended bynextapp.echoservlet.ComponentPeer
      extended byechopoint.ui.util.EchoPointComponentPeer
All Implemented Interfaces:
nextapp.echo.event.ChangeListener, java.util.EventListener, nextapp.echo.event.ImageUpdateListener, PeerDelegate, java.beans.PropertyChangeListener, java.io.Serializable
Direct Known Subclasses:
BeepUI, BoxSectionUI, ChartPanelUI, ColorChooserUI, DatePickerUI, DialogPanelUI, EmbeddedObjectUI, EmbeddedPaneUI, ExternalEventMonitorUI, FontChooserUI, GroupBoxUI, HourGlassUI, HtmlContainerUI, ImageIconUI, ImageMapUI, JavaScriptIncludeUI, JspComponentPeer, LabelUI, ListSectionUI, MenuBarUI, PickListUI, PopUpUI, PrintRequestUI, ProgressBarUI, RichTextAreaUI, SelectableTableUI, SeparatorUI, SortableTableUI, TabbedPaneUI, TachometerUI, ThermometerUI, TimerUI, TitleBarUI, TreeUI, WizardPaneUI

public class EchoPointComponentPeer
extends nextapp.echoservlet.ComponentPeer
implements PeerDelegate, java.beans.PropertyChangeListener, nextapp.echo.event.ImageUpdateListener, nextapp.echo.event.ChangeListener

EchoPointComponentPeer is provided as a base class for EchoPoint ComponentPeers. It has a number of methods that are common across a EchoPoint peers. Its also has an lazily created ImageManager and ToolTipPopUpSupportHelper, ready for subclasses to use.

It contains a number of helper methods that perform common tasks done by peers such as tracking image references and updating after property changes.

Author:
Brad Baker
See Also:
Serialized Form

Field Summary
protected  boolean renderedActive
          can be set at render time to getComponent.isEnabled() and then checked at clientInput or clientAction to ensure a disabled component is just that.
 
Constructor Summary
EchoPointComponentPeer()
           
 
Method Summary
static boolean addOnce(nextapp.echoservlet.html.Element parent, nextapp.echoservlet.html.Element child, java.lang.Object marker)
          Adds a child element to the parent element, using a marker to ensure it is added only once.
static boolean addOnce(int index, nextapp.echoservlet.html.Element parent, nextapp.echoservlet.html.Element child, java.lang.Object marker)
          This method adds a child element to a parent element only if the specified marker object is not present as a comment in the parent element.
static void addScriptInclude(nextapp.echoservlet.RenderingContext rc, nextapp.echoservlet.Service service)
          Adds a script service into the HEAD of the HtmlDocument in the order in which they are encountered, as opposed to the Echo Set based approach which is a random order.
static nextapp.echoservlet.ComponentPeer[] copyChildrenExcept(nextapp.echoservlet.ComponentPeer[] children, nextapp.echoservlet.ComponentPeer exception)
          Copies all entries in the children array except the specified exception.
static nextapp.echoservlet.ComponentPeer[] copyChildrenExcept(nextapp.echoservlet.ComponentPeer[] children, nextapp.echoservlet.ComponentPeer[] exceptions)
          Copies all entries in the children array except for the ones in the exceptions array.
 nextapp.echoservlet.ComponentStyle forComponent()
          Synonym for ComponentStyle.forComponent(this);
 nextapp.echoservlet.ComponentStyle forComponent(boolean findBackground)
          Synonym for ComponentStyle.forComponent(this,findBackground);
static nextapp.echoservlet.ComponentStyle forComponent(nextapp.echoservlet.ComponentPeer componentPeer)
          Synonym for ComponentStyle.forComponent(peer);
static nextapp.echoservlet.ComponentStyle forComponent(nextapp.echoservlet.ComponentPeer componentPeer, boolean findBackground)
          Synonym for ComponentStyle.forComponent(peer,findBackground); Will also set in MouseCursorable style properties if the component implements it.
 nextapp.echoservlet.ComponentPeer[] getChildren()
          Returns the peers for all of the referenced component's visible children.
 nextapp.echo.ImageReference getImage(java.lang.String imageName)
          This method returns an ImageReference if the image is currently managed by the ImageManager, or null if not.
 nextapp.echoservlet.image.ImageManager getImageManager()
          Returns the ImageManager for this peer.
 java.lang.String getImageUri(nextapp.echoservlet.RenderingContext rc, java.lang.String imageName)
          This method will return and image URI if the named image is currently managed by ImageManager, or null if not.
 nextapp.echoservlet.ComponentPeer getPeer(nextapp.echo.Component c)
          This version of getPeer returns a ComponentPeer for the given Component c or null if one cannot be found.
static nextapp.echoservlet.ComponentPeer getPeer(nextapp.echoservlet.InstancePeer instancePeer, nextapp.echo.Component c)
          This static version of getPeer will return a peer object, given an InstancePeer.
 ToolTipPopUpSupportHelper getToolTipHelper()
          Returns a ToolTipPopUpSupportHelper for creating tool tips
static java.lang.String getUri(nextapp.echoservlet.RenderingContext rc, nextapp.echoservlet.Service service)
          Returns the URI string for a given service.
static boolean hasBeenAdded(nextapp.echoservlet.html.Element parent, java.lang.Object marker)
          This method returns true if the specified marker object has been added as an HTML comment marker to the specified parent Element.
 void imageUpdate(nextapp.echo.event.ImageUpdateEvent e)
          If an image changes, we redraw() the peer.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          Whenever a property changes, we call redraw() to cause the peer to be repainted.
 void registered()
          This adds itself as a property change listener to the component, which calls redraw(), and then creates a ToolTipPopUpSupportHelper.
 void removeAllImages()
          Removes all images from the image manager, if there is one.
static void removeAllManagedImages(nextapp.echoservlet.image.ImageManager imageManager)
          Removes all the images from an ImageManager in a concurrent modification safe way.
static java.lang.String removeNewLinesAndJSQuote(java.lang.String s, char quoteChar)
          Strips new lines from the string writer and quotes any quoteChar characters for use in JavaScript
static java.lang.String removeNewLinesAndJSQuote(java.io.StringWriter sw, char quoteChar)
          Strips new lines from the string writer and quotes any quoteChar characters for use in JavaScript
 void setImage(java.lang.String imageName, nextapp.echo.ImageReference newImage)
          Adds an image to the image manager, identified by imageName.
 void stateChanged(nextapp.echo.event.ChangeEvent e)
          Redraws the peer when the state changes.
 void trackImage(java.lang.String componentPropertyOrFieldName)
          This method is very similair to setImage(String, ImageReference) except it uses reflection to find the ImageReference property value.
 void unregistered()
          This removes the property change listener and then calls toolTipHelper.unregistered();.
 
Methods inherited from class nextapp.echoservlet.ComponentPeer
addAncillaryService, generateId, getBackground, getChildCount, getComponent, getFont, getForeground, getId, getInstancePeer, getParent, redraw, removeAncillaryService, render
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface echopoint.ui.util.PeerDelegate
getId
 

Field Detail

renderedActive

protected boolean renderedActive
can be set at render time to getComponent.isEnabled() and then checked at clientInput or clientAction to ensure a disabled component is just that.

Constructor Detail

EchoPointComponentPeer

public EchoPointComponentPeer()
Method Detail

getPeer

public nextapp.echoservlet.ComponentPeer getPeer(nextapp.echo.Component c)
This version of getPeer returns a ComponentPeer for the given Component c or null if one cannot be found. This class overrrides the default behaviour and catches any EchoServletExceptions runtime errors that might be thrown.

Specified by:
getPeer in interface PeerDelegate

getPeer

public static nextapp.echoservlet.ComponentPeer getPeer(nextapp.echoservlet.InstancePeer instancePeer,
                                                        nextapp.echo.Component c)
This static version of getPeer will return a peer object, given an InstancePeer. It returns null if no peer could be found

Parameters:
instancePeer - - the instancePeer to search for peers
c - - the component to search for a peer of
Returns:
- a peer or null if it cant be found.

addScriptInclude

public static void addScriptInclude(nextapp.echoservlet.RenderingContext rc,
                                    nextapp.echoservlet.Service service)
Adds a script service into the HEAD of the HtmlDocument in the order in which they are encountered, as opposed to the Echo Set based approach which is a random order.

Parameters:
rc - - the RenderingContext
service - - the Service to include

addOnce

public static boolean addOnce(int index,
                              nextapp.echoservlet.html.Element parent,
                              nextapp.echoservlet.html.Element child,
                              java.lang.Object marker)
This method adds a child element to a parent element only if the specified marker object is not present as a comment in the parent element.

If it the marker is not present then the child is added to the parent element and a HTML comment is added as well for marker.toString(). In this way it can be detected if the child has been been added before.

An appropriate marker object is probably the Id() of the component peer or a string based on this Id().

Parameters:
index - - the index where to add the element
parent - - the parent Element to add the child to
child - - the child Element to add to the parent
marker - - an object on which .toString() will be applied.
Returns:
true if the marker was not present and the child was added
See Also:
Id

addOnce

public static boolean addOnce(nextapp.echoservlet.html.Element parent,
                              nextapp.echoservlet.html.Element child,
                              java.lang.Object marker)
Adds a child element to the parent element, using a marker to ensure it is added only once.

See Also:
addOnce(int, Element, Element, Object)

hasBeenAdded

public static boolean hasBeenAdded(nextapp.echoservlet.html.Element parent,
                                   java.lang.Object marker)
This method returns true if the specified marker object has been added as an HTML comment marker to the specified parent Element.

Parameters:
parent - - the Element to check for the marker
marker - - an object on which .toString() will be applied.
Returns:
true if the marker was present
See Also:
addOnce(int, Element, Element, Object)

copyChildrenExcept

public static nextapp.echoservlet.ComponentPeer[] copyChildrenExcept(nextapp.echoservlet.ComponentPeer[] children,
                                                                     nextapp.echoservlet.ComponentPeer exception)
Copies all entries in the children array except the specified exception. It returns an array of ComponentPeers wihtout the exception. This may in fact be the original array.

Parameters:
children - - the children to copy
exception - - the one not to copy into the new array
Returns:
a copy of the child peers

copyChildrenExcept

public static nextapp.echoservlet.ComponentPeer[] copyChildrenExcept(nextapp.echoservlet.ComponentPeer[] children,
                                                                     nextapp.echoservlet.ComponentPeer[] exceptions)
Copies all entries in the children array except for the ones in the exceptions array. It returns an array of ComponentPeers wihtout the exceptions. This may in fact be the original array.

Parameters:
children - - the children to copy
exceptions - - the children not to copy into the new array
Returns:
a copy of the child peers

removeNewLinesAndJSQuote

public static java.lang.String removeNewLinesAndJSQuote(java.io.StringWriter sw,
                                                        char quoteChar)
Strips new lines from the string writer and quotes any quoteChar characters for use in JavaScript


removeNewLinesAndJSQuote

public static java.lang.String removeNewLinesAndJSQuote(java.lang.String s,
                                                        char quoteChar)
Strips new lines from the string writer and quotes any quoteChar characters for use in JavaScript


registered

public void registered()
This adds itself as a property change listener to the component, which calls redraw(), and then creates a ToolTipPopUpSupportHelper.


unregistered

public void unregistered()
This removes the property change listener and then calls toolTipHelper.unregistered();. If there is an ImageManager, then all images are removed.


propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Whenever a property changes, we call redraw() to cause the peer to be repainted.

In 99% of cases, this is actually what you want to do.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
See Also:
PropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)

stateChanged

public void stateChanged(nextapp.echo.event.ChangeEvent e)
Redraws the peer when the state changes.

Specified by:
stateChanged in interface nextapp.echo.event.ChangeListener
See Also:
ChangeListener.stateChanged(nextapp.echo.event.ChangeEvent)

forComponent

public nextapp.echoservlet.ComponentStyle forComponent()
Synonym for ComponentStyle.forComponent(this);

Specified by:
forComponent in interface PeerDelegate
See Also:
PeerDelegate.forComponent()

forComponent

public nextapp.echoservlet.ComponentStyle forComponent(boolean findBackground)
Synonym for ComponentStyle.forComponent(this,findBackground);

Specified by:
forComponent in interface PeerDelegate
See Also:
PeerDelegate.forComponent(boolean)

forComponent

public static nextapp.echoservlet.ComponentStyle forComponent(nextapp.echoservlet.ComponentPeer componentPeer)
Synonym for ComponentStyle.forComponent(peer);


forComponent

public static nextapp.echoservlet.ComponentStyle forComponent(nextapp.echoservlet.ComponentPeer componentPeer,
                                                              boolean findBackground)
Synonym for ComponentStyle.forComponent(peer,findBackground); Will also set in MouseCursorable style properties if the component implements it.


getChildren

public nextapp.echoservlet.ComponentPeer[] getChildren()
Description copied from interface: PeerDelegate
Returns the peers for all of the referenced component's visible children.

Specified by:
getChildren in interface PeerDelegate
See Also:
PeerDelegate.getChildren()

imageUpdate

public void imageUpdate(nextapp.echo.event.ImageUpdateEvent e)
If an image changes, we redraw() the peer.

In 99% of cases, this is actually what you want to do.

Specified by:
imageUpdate in interface nextapp.echo.event.ImageUpdateListener
See Also:
ImageUpdateListener.imageUpdate(nextapp.echo.event.ImageUpdateEvent)

getUri

public static java.lang.String getUri(nextapp.echoservlet.RenderingContext rc,
                                      nextapp.echoservlet.Service service)
Returns the URI string for a given service.

Parameters:
rc - - the rendering context in play
service - - the service to find the URI for
Returns:
a String URI for the service

getToolTipHelper

public ToolTipPopUpSupportHelper getToolTipHelper()
Description copied from interface: PeerDelegate
Returns a ToolTipPopUpSupportHelper for creating tool tips

Specified by:
getToolTipHelper in interface PeerDelegate
Returns:
a ToolTipPopUpSupportHelper for creating tool tips
See Also:
PeerDelegate.getToolTipHelper()

getImageManager

public nextapp.echoservlet.image.ImageManager getImageManager()
Returns the ImageManager for this peer. The ImageManager is lazilly created the first time it is requested.

Returns:
the ImageManager for this peer

getImageUri

public java.lang.String getImageUri(nextapp.echoservlet.RenderingContext rc,
                                    java.lang.String imageName)
This method will return and image URI if the named image is currently managed by ImageManager, or null if not.

Parameters:
imageName - - the name of the managed image
Returns:
the image URI

getImage

public nextapp.echo.ImageReference getImage(java.lang.String imageName)
This method returns an ImageReference if the image is currently managed by the ImageManager, or null if not.

Parameters:
imageName - - the name of the managed image
Returns:
the ImageReference for the managed image or null

removeAllImages

public void removeAllImages()
Removes all images from the image manager, if there is one.


removeAllManagedImages

public static void removeAllManagedImages(nextapp.echoservlet.image.ImageManager imageManager)
Removes all the images from an ImageManager in a concurrent modification safe way. This is needed until the bug in Echo 1.0.x is fixed.

Parameters:
imageManager - the imageManager to remove all images from.

setImage

public void setImage(java.lang.String imageName,
                     nextapp.echo.ImageReference newImage)
Adds an image to the image manager, identified by imageName. To remove an image, set the newImage to null.

Parameters:
imageName - A identifier that will be used for the added image.
newImage - The new image to be added.
See Also:
ImageManager.setImage(String, ImageReference)

trackImage

public void trackImage(java.lang.String componentPropertyOrFieldName)
This method is very similair to setImage(String, ImageReference) except it uses reflection to find the ImageReference property value.

It allows for a shorthand method of setting an ImageReference property into the peer's ImageManager.

It also adds a PropertyChangeListener that "sets" the image into the image manager when a property change event happens with the same name.

So with one statement at say peer registration time, the image property is set into the ImageManager and tracked over time.

Parameters:
componentPropertyOrFieldName - - the name of the ImageReference property to track.
Throws:
java.lang.RuntimeException - - if the property name cannot be found or its illegal to retrive its value.

EchoPoint
1.0