public class SignatureComponent

  1. Object
  2. Component
  3. Container
  4. SignatureComponent

ImplementsActionSource<ActionEvent>, Animation, Editable, Iterable<Component>, StyleListener

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.

Constructors

public SignatureComponent()Creates a new signature component.

Methods

protected void onSignatureReset()A hook that can be overridden by subclasses to be notified when the user resets the signature in the signature dialog.
public void addActionListener(ActionListener<ActionEvent> l)Adds a listener to be notified when the signature image is changed.
public void removeActionListener(ActionListener<ActionEvent> l)Removes a listener from being notified when signature image is changed.
protected void fireActionEvent()Fires an event to all listeners to notify them that the signature image has been changed.
protected void initComponent()Overridden to register the icon animation when the field is added to the form.
protected void deinitialize()Overridden to deregister the icon animation when the field is removed from the form.
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).
public Image getSignatureImage()Gets the image of the signature - or null if no signature has been drawn.
public void setSignatureImage(Image img)Sets the signature image for this field.
public Component getSignaturePanel()Get the component that is the actual panel for drawing a signature.
public void clearSignaturePanel()Clear the signature image and allow it to draw a new one.

Inherited fields

Inherited methods

From Container

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

From Component

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

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.

removeActionListener

public void removeActionListener(ActionListener<ActionEvent> l)
Removes a listener from being notified when signature image is changed.

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.

deinitialize

protected void deinitialize()
Overridden to deregister the icon animation when the field is removed from the form.

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).

Returns

the calculated preferred size based on component content

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 Image
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.