echopoint.ui.util
Class EchoPointComponentPeer

java.lang.Object
  extended by nextapp.echoservlet.AbstractComponentPeer
      extended by echopoint.ui.util.EchoPointComponentPeer
All Implemented Interfaces:
PeerDelegate, java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, ChangeListener, ImageUpdateListener, ComponentPeer
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, TimerUI, TitleBarUI, TreeUI, WizardPaneUI

public class EchoPointComponentPeer
extends AbstractComponentPeer
implements PeerDelegate, java.beans.PropertyChangeListener, ImageUpdateListener, 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.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface nextapp.echoservlet.ComponentPeer
IGNORE_PROPERTY_CHANGE
 
Constructor Summary
EchoPointComponentPeer()
           
 
Method Summary
static boolean addOnce(Element parent, 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, Element parent, 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(RenderingContext rc, 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 ComponentPeer[] copyChildrenExcept(ComponentPeer[] children, ComponentPeer exception)
          Copies all entries in the children array except the specified exception.
static ComponentPeer[] copyChildrenExcept(ComponentPeer[] children, ComponentPeer[] exceptions)
          Copies all entries in the children array except for the ones in the exceptions array.
 ComponentStyle forComponent()
          Synonym for ComponentStyle.forComponent(this);
 ComponentStyle forComponent(boolean findBackground)
          Synonym for ComponentStyle.forComponent(this,findBackground);
static ComponentStyle forComponent(ComponentPeer componentPeer)
          Synonym for ComponentStyle.forComponent(peer);
static ComponentStyle forComponent(ComponentPeer componentPeer, boolean findBackground)
          Synonym for ComponentStyle.forComponent(peer,findBackground); Will also set in MouseCursorable style properties if the component implements it.
 ComponentPeer[] getChildren()
          Returns the peers for all of the referenced component's visible children.
 ImageReference getImage(java.lang.String imageName)
          This method returns an ImageReference if the image is currently managed by the ImageManager, or null if not.
 ImageManager getImageManager()
          Returns the ImageManager for this peer.
 java.lang.String getImageUri(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.
 ComponentPeer getPeer(Component c)
          This version of getPeer returns a ComponentPeer for the given Component c or null if one cannot be found.
static ComponentPeer getPeer(InstancePeer instancePeer, 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(RenderingContext rc, Service service)
          Returns the URI string for a given service.
static boolean hasBeenAdded(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(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(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, ImageReference newImage)
          Adds an image to the image manager, identified by imageName.
 void stateChanged(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.AbstractComponentPeer
addAncillaryService, generateId, getCalculatedBackground, getCalculatedFont, getCalculatedForeground, getChildCount, getComponent, getFocusedElementId, getId, getInstancePeer, getParentComponentPeer, redraw, registerAncillaryServices, removeAncillaryService, render, setComponent, setId, setInstancePeer, unregisterAncillaryServices
 
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
 

Constructor Detail

EchoPointComponentPeer

public EchoPointComponentPeer()
Method Detail

getPeer

public ComponentPeer getPeer(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
Specified by:
getPeer in interface ComponentPeer
Overrides:
getPeer in class AbstractComponentPeer
Parameters:
c - The component whose peer is to be returned.
Returns:
The peer of the specified component.

getPeer

public static ComponentPeer getPeer(InstancePeer instancePeer,
                                    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(RenderingContext rc,
                                    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,
                              Element parent,
                              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(Element parent,
                              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(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 ComponentPeer[] copyChildrenExcept(ComponentPeer[] children,
                                                 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 ComponentPeer[] copyChildrenExcept(ComponentPeer[] children,
                                                 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.

Specified by:
registered in interface ComponentPeer
Overrides:
registered in class AbstractComponentPeer

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.

Specified by:
unregistered in interface ComponentPeer
Overrides:
unregistered in class AbstractComponentPeer

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(ChangeEvent e)
Redraws the peer when the state changes.

Specified by:
stateChanged in interface ChangeListener
Parameters:
e - The event describing the state change.
See Also:
ChangeListener.stateChanged(nextapp.echo.event.ChangeEvent)

forComponent

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

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

forComponent

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

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

forComponent

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


forComponent

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


getChildren

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

Specified by:
getChildren in interface PeerDelegate
Overrides:
getChildren in class AbstractComponentPeer
Returns:
The peers of all visible child components of this peer's represented component.
See Also:
PeerDelegate.getChildren()

imageUpdate

public void imageUpdate(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 ImageUpdateListener
Parameters:
e - The event describing the image update.
See Also:
ImageUpdateListener.imageUpdate(nextapp.echo.event.ImageUpdateEvent)

getUri

public static java.lang.String getUri(RenderingContext rc,
                                      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 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(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 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(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,
                     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.