# Class SignatureComponent

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Container
com.codename1.components.SignatureComponent

All Implemented Interfaces:
  `Animation, Editable, ActionSource<ActionEvent>, StyleListener, Iterable<Component>`

public class SignatureComponent extends Container implements ActionSource<ActionEvent>

A component to allow a user to enter their signature. This is just a button that, when pressed, will pop up a dialog where the user can draw their signature with their finger. The user is given the option to save/reset/cancel the signature. On save, the `#signatureImage` property will be set with a full-size image of the signature, and the "icon" on the button will show a thumbnail of the image.

Example Usage

    Form hi = new Form("Signature Component");
    hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    hi.add("Enter Your Name:");
    hi.add(new TextField());
    hi.add("Signature:");
    SignatureComponent sig = new SignatureComponent();
    sig.addActionListener((evt)-> {
        System.out.println("The signature was changed");
        Image img = sig.getSignatureImage();
        // Now we can do whatever we want with the image of this signature.
    });
    hi.addComponent(sig);
    hi.show();

Screenshots

Video Demo

Source available here

.

Styles

You can customize the styles of various aspects of the Signature component using the following Styles (UIIDs) in the theme:

- SignatureButton - The style for the main signature component button.

- SignatureButtonBox - A style to specify the "X" and "Box" that is drawn around the signature in the button.

- SignaturePanel - The panel that the user actually draws the signature in.

- SignaturePanelBox - The box and "X" in the SignaturePanel. Uses only the `Style#getFgColor()` property.

- SignaturePanelSignature - The signature that is drawn by the user. Uses only the `Style#getFgColor()` property.

- ## Field Summary

  ### Fields inherited from class Component

  `BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SignatureComponent()`
  Creates a new signature component.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addActionListener(ActionListener<ActionEvent> l)`
  Adds a listener to be notified when the signature image is changed.
  `protected Dimension`
  `calcPreferredSize()`
  Calculates the preferred size of the button itself (not the signature canvas... but the button you press to show the signature panel).
  `void`
  `clearSignaturePanel()`
  Clear the signature image and allow it to draw a new one.
  `protected void`
  `deinitialize()`
  Overridden to deregister the icon animation when the field is removed from the form.
  `protected void`
  `fireActionEvent()`
  Fires an event to all listeners to notify them that the signature image has been changed.
  `Image`
  `getSignatureImage()`
  Gets the image of the signature - or null if no signature has been drawn.
  `Component`
  `getSignaturePanel()`
  Get the component that is the actual panel for drawing a signature.
  `protected void`
  `initComponent()`
  Overridden to register the icon animation when the field is added to the form.
  `protected void`
  `onSignatureReset()`
  A hook that can be overridden by subclasses to be notified when the user resets the signature in the signature dialog.
  `void`
  `removeActionListener(ActionListener<ActionEvent> l)`
  Removes a listener from being notified when signature image is changed.
  `void`
  `setSignatureImage(Image img)`
  Sets the signature image for this field.

  ### Methods inherited from class Container

  `add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndices`

  ### Methods inherited from class Component

  `accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface Iterable

  `forEach`

- ## Constructor Details

  - ### SignatureComponent

    public SignatureComponent()
    Creates a new signature component.

- ## Method Details

  - ### onSignatureReset

    protected void onSignatureReset()

    A hook that can be overridden by subclasses to be notified when the user resets the signature in the signature dialog.

    NOTE: Use of this hook to clear the current image in the signature component is discouraged. The intention of the signature component's internal dialog is to provide a staging area for the user to draw their signature. Changes should only take effect in the app when the user commits their changes by pressing "OK" or "Cancel". The "Reset" button in the signature dialog is intended to only allow the user to fix a mistake and start over. Using this hook to cause a change in application state (by, for example, calling `#setSignatureImage(com.codename1.ui.Image)` with a null argument}) may confuse the user.

    If you want to provide the user with a mechanism to "clear" the signature from the signature component, you should add a button to your form which, when pressed, will remove the image by calling `#setSignatureImage(com.codename1.ui.Image)`.

  - ### addActionListener

    public void addActionListener(ActionListener<ActionEvent> l)

    Adds a listener to be notified when the signature image is changed.

    ###### Parameters

    - `l`
    Specified by:
      `addActionListener` in interface `ActionSource<ActionEvent>`

  - ### removeActionListener

    public void removeActionListener(ActionListener<ActionEvent> l)

    Removes a listener from being notified when signature image is changed.

    ###### Parameters

    - `l`
    Specified by:
      `removeActionListener` in interface `ActionSource<ActionEvent>`

  - ### fireActionEvent

    protected void fireActionEvent()
    Fires an event to all listeners to notify them that the signature image has been changed.

  - ### initComponent

    protected void initComponent()
    Overridden to register the icon animation when the field is added to the form.
    Overrides:
      `initComponent` in class `Component`

  - ### deinitialize

    protected void deinitialize()
    Overridden to deregister the icon animation when the field is removed from the form.
    Overrides:
      `deinitialize` in class `Component`

  - ### calcPreferredSize

    protected Dimension calcPreferredSize()
    Calculates the preferred size of the button itself (not the signature canvas... but the button you press to show the signature panel).
    Overrides:
      `calcPreferredSize` in class `Container`

  - ### getSignatureImage

    public Image getSignatureImage()
    Gets the image of the signature - or null if no signature has been drawn.

  - ### setSignatureImage

    public void setSignatureImage(Image img)

    Sets the signature image for this field. This will also scale the image and show it as the icon for the button.

    ###### Parameters

    - `img`: The image to set as the signature image.

  - ### getSignaturePanel

    public Component getSignaturePanel()

    Get the component that is the actual panel for drawing a signature. The component can be used instead of the SignatureComponent if an embedded signature is needed.

    Use the clearSignaturePanel() and the getSignatureImage() functions to work with this component.

  - ### clearSignaturePanel

    public void clearSignaturePanel()
    Clear the signature image and allow it to draw a new one. Use only if you use the signature panel component from the getSignaturePanel() method.