eu.livotov.tpt.gui.widgets
Class TPTCaptcha

java.lang.Object
  extended by com.vaadin.ui.AbstractComponent
      extended by com.vaadin.ui.Embedded
          extended by eu.livotov.tpt.gui.widgets.TPTCaptcha
All Implemented Interfaces:
com.vaadin.event.MethodEventSource, com.vaadin.terminal.Paintable, com.vaadin.terminal.Sizeable, com.vaadin.terminal.StreamResource.StreamSource, com.vaadin.terminal.VariableOwner, com.vaadin.ui.Component, java.io.Serializable, java.util.EventListener

public class TPTCaptcha
extends com.vaadin.ui.Embedded
implements com.vaadin.terminal.StreamResource.StreamSource

This component represents a captcha image that can be displayed for some form validations. You can provide your own text for captcha image or let the component to automatically generat it to you.

See Also:
Serialized Form

Nested Class Summary
static interface TPTCaptcha.CaptchaImageProvider
          API for connecting custom image generators.
private  class TPTCaptcha.DefaultCaptchaImageGenerator
           
 
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent
com.vaadin.ui.AbstractComponent.ComponentErrorEvent, com.vaadin.ui.AbstractComponent.ComponentErrorHandler
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
com.vaadin.ui.Component.ErrorEvent, com.vaadin.ui.Component.ErrorListener, com.vaadin.ui.Component.Event, com.vaadin.ui.Component.Focusable, com.vaadin.ui.Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.terminal.Paintable
com.vaadin.terminal.Paintable.RepaintRequestEvent, com.vaadin.terminal.Paintable.RepaintRequestListener
 
Field Summary
private  java.lang.String captchaCode
          Current captcha code
private  TPTCaptcha.CaptchaImageProvider imageProvider
          Image provider for captcha
 
Fields inherited from class com.vaadin.ui.Embedded
TYPE_BROWSER, TYPE_IMAGE, TYPE_OBJECT
 
Fields inherited from interface com.vaadin.terminal.Sizeable
SIZE_UNDEFINED, UNIT_SYMBOLS, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
TPTCaptcha()
          Creates a captcha component with random 5-letter code generated
TPTCaptcha(java.lang.String code)
          Creates a captcha component with the specified text to be used as captcha code
 
Method Summary
 java.lang.String generateCaptchaCode(int charactersCount)
          Generates and sets a random captcha code with the specified characters length.
 java.lang.String getCaptchaCode()
          Provides the current captcha code that is displayed in the component
 java.io.InputStream getStream()
           
private  void refreshCaptchaImageSource(com.vaadin.Application app)
           
 void setCaptchaCode(java.lang.String code)
          Sets the new captcha code.
 void setCaptchaCode(java.lang.String code, com.vaadin.Application app)
          Sets the new captcha code.
 void setCaptchaImageProvider(TPTCaptcha.CaptchaImageProvider provider)
          Sets the new image provider, that is responsible for creating captcha images.
 void setCaptchaImageProvider(TPTCaptcha.CaptchaImageProvider provider, com.vaadin.Application app)
          Sets the new image provider, that is responsible for creating captcha images.
 boolean verifyCaptchaCode(java.lang.String sample)
          Verifies the given code agains current captcha code.
 
Methods inherited from class com.vaadin.ui.Embedded
addListener, changeVariables, getArchive, getClassId, getCodebase, getCodetype, getMimeType, getParameter, getParameterNames, getSource, getStandby, getType, paintContent, removeListener, removeParameter, setArchive, setClassId, setCodebase, setCodetype, setMimeType, setParameter, setSource, setStandby, setType
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addListener, addListener, addListener, addListener, addStyleName, attach, childRequestedRepaint, detach, fireComponentErrorEvent, fireComponentEvent, fireEvent, focus, getApplication, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getErrorMessage, getHeight, getHeightUnits, getIcon, getLocale, getParent, getStyle, getStyleName, getTag, getWidth, getWidthUnits, getWindow, handleError, isEnabled, isImmediate, isReadOnly, isVisible, paint, removeListener, removeListener, removeListener, removeListener, removeListener, removeListener, removeStyleName, requestRepaint, requestRepaintRequests, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setErrorHandler, setHeight, setHeight, setHeight, setHeightUnits, setIcon, setImmediate, setLocale, setParent, setReadOnly, setSizeFull, setSizeUndefined, setStyle, setStyleName, setVisible, setWidth, setWidth, setWidth, setWidthUnits
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imageProvider

private TPTCaptcha.CaptchaImageProvider imageProvider
Image provider for captcha


captchaCode

private java.lang.String captchaCode
Current captcha code

Constructor Detail

TPTCaptcha

public TPTCaptcha()
Creates a captcha component with random 5-letter code generated


TPTCaptcha

public TPTCaptcha(java.lang.String code)
Creates a captcha component with the specified text to be used as captcha code

Parameters:
code - captcha code
Method Detail

setCaptchaCode

public void setCaptchaCode(java.lang.String code)
Sets the new captcha code. Image will be regenerated automatically.

Parameters:
code - new captcha code

setCaptchaCode

public void setCaptchaCode(java.lang.String code,
                           com.vaadin.Application app)
Sets the new captcha code. Image will be regenerated automatically. Use this method when you're using this widget without the using TPTApplication class.

Parameters:
code - new code to generate
app - Vaadin application instance. Required to generate a new StreamSource

getCaptchaCode

public java.lang.String getCaptchaCode()
Provides the current captcha code that is displayed in the component

Returns:
current captcha code

verifyCaptchaCode

public boolean verifyCaptchaCode(java.lang.String sample)
Verifies the given code agains current captcha code.

Parameters:
sample - sample text to compare with the current captcha component
Returns:
true if provided code matches the captcha (uses case-insensitive comparison)

generateCaptchaCode

public java.lang.String generateCaptchaCode(int charactersCount)
Generates and sets a random captcha code with the specified characters length.

Parameters:
charactersCount - number of characters in the new code
Returns:
generated code. Note, that this method will also set the newly generated code to a component.

setCaptchaImageProvider

public void setCaptchaImageProvider(TPTCaptcha.CaptchaImageProvider provider)
Sets the new image provider, that is responsible for creating captcha images. TPTCaptcha compnent has its own default image generator, but you may specify your own implementation if you wish.

Parameters:
provider - new image provider to use. Captcha code will be regenerated using this new image provider immideately.

setCaptchaImageProvider

public void setCaptchaImageProvider(TPTCaptcha.CaptchaImageProvider provider,
                                    com.vaadin.Application app)
Sets the new image provider, that is responsible for creating captcha images. TPTCaptcha compnent has its own default image generator, but you may specify your own implementation if you wish.

Parameters:
provider - new image provider to use. Captcha code will be regenerated using this new image provider immideately.

getStream

public java.io.InputStream getStream()
Specified by:
getStream in interface com.vaadin.terminal.StreamResource.StreamSource

refreshCaptchaImageSource

private void refreshCaptchaImageSource(com.vaadin.Application app)