JIDE 3.5.15

com.jidesoft.field.creditcard
Class CreditCardTextField

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.jidesoft.swing.LabeledTextField
                      extended by com.jidesoft.field.creditcard.CreditCardTextField
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class CreditCardTextField
extends LabeledTextField

CreditCardTextField is a LabeledTextField which can accept and verify credit card numbers. After user enters the number, it has method to verify if the number is a valid credit card number. If validated, what type of credit card it is and then display an icon for the credit card type next to it.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jidesoft.swing.LabeledTextField
LabeledTextField.PopupMenuCustomizer
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String PROPERTY_MASK_ENABLED
           
static String PROPERTY_VALIDATE_ON_FLY
           
 
Fields inherited from class com.jidesoft.swing.LabeledTextField
_button, _contextMenuKeyStroke, _customizer, _hintLabel, _hintText, _icon, _label, _labelText, _showHintTextWhenFocused, _textField
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CreditCardTextField()
           
CreditCardTextField(Icon icon)
           
CreditCardTextField(Icon icon, String labelText)
           
 
Method Summary
protected  JTextField createTextField()
          Creates the text field.
 String[] getAllowedCardIssuerNames()
          Gets allowed credit card issuers' name in an array.
 CardIssuer getCardIssuer()
          Get issuer of the card number if valid.
 Icon getCreditCardIcon()
          Get the icon which is displayed when there is no input number.
 CreditCardMask getCreditCardMask()
          Gets the credit card mask.
 String getCreditCardNumber()
          Get the credit card number
 Icon getInvalidCreditCardIcon()
          Gets the icon which is displayed when the input number is invalid.
 boolean isMaskEnabled()
          Checks if the mask feature is enabled.
 boolean isValidateOnFly()
          Checks if we will validate the credit card number on fly.
 void maskCardNumber()
          Masks the card number so that the actual number is not displayed.
 void setAllowedCardIssuerNames(String[] allowedCardIssuerNames)
          Set the allowed credit card issuer names.
 void setCreditCardIcon(Icon icon)
          Sets the icon which is displayed when the input number is invalid.
 void setCreditCardMask(CreditCardMask mask)
          Sets CreditCardMask.
 void setInvalidCreditCardIcon(Icon icon)
          set the icon which is displayed when the input number is invalid.
 void setMaskEnabled(boolean enabled)
          Enables/disables the mask feature.
 void setValidateOnFly(boolean validateOnFly)
          Enables/disables the validate on fly feature
 void unmaskCardNumber()
          Displays the actual card number.
 boolean validateCardNumber()
          Checks if the input number is a valid credit card number.
 
Methods inherited from class com.jidesoft.swing.LabeledTextField
calculateContextMenuLocation, createButton, createContextMenu, createLabel, customizePopupMenu, getBaseline, getButton, getContextMenuKeyStroke, getHintText, getIcon, getLabel, getLabelText, getPopupMenuCustomizer, getText, getTextField, initComponent, initLayout, isShowHintTextWhenFocused, setColumns, setContextMenuKeyStroke, setEnabled, setHintText, setIcon, setLabelText, setPopupMenuCustomizer, setShowHintTextWhenFocused, setText, showContextMenu, updateUI
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_VALIDATE_ON_FLY

public static final String PROPERTY_VALIDATE_ON_FLY
See Also:
Constant Field Values

PROPERTY_MASK_ENABLED

public static final String PROPERTY_MASK_ENABLED
See Also:
Constant Field Values
Constructor Detail

CreditCardTextField

public CreditCardTextField()

CreditCardTextField

public CreditCardTextField(Icon icon)

CreditCardTextField

public CreditCardTextField(Icon icon,
                           String labelText)
Method Detail

createTextField

protected JTextField createTextField()
Creates the text field. We override to set the columns of the text field to 16 which is enough for most credit card numbers.

Overrides:
createTextField in class LabeledTextField
Returns:
text field.

setAllowedCardIssuerNames

public void setAllowedCardIssuerNames(String[] allowedCardIssuerNames)
Set the allowed credit card issuer names. Only those card issuers are allowed when doing the validation.

Parameters:
allowedCardIssuerNames - the allowed credit card issuers names

getAllowedCardIssuerNames

public String[] getAllowedCardIssuerNames()
Gets allowed credit card issuers' name in an array.

Returns:
credit card issuers' name

getCreditCardNumber

public String getCreditCardNumber()
Get the credit card number

Returns:
the input card number which is valid.

getCardIssuer

public CardIssuer getCardIssuer()
Get issuer of the card number if valid. This method will call validateCardNumber() first.

Returns:
the CardIssuer.

getCreditCardMask

public CreditCardMask getCreditCardMask()
Gets the credit card mask. This mask is used to hide certain digits of the credit card number when the field is not in focus.

Returns:
the CreditCardMask

setCreditCardMask

public void setCreditCardMask(CreditCardMask mask)
Sets CreditCardMask. This mask is used to hide certain digits of the credit card number when the field is not in focus.

Parameters:
mask - a new CreditCardMask

setMaskEnabled

public void setMaskEnabled(boolean enabled)
Enables/disables the mask feature. If enabled, we will use the CreditCardMask to hide certain digits of the credit card number when the field is not in focus.

Parameters:
enabled - true to enable the mask feature and false to disable it.

isMaskEnabled

public boolean isMaskEnabled()
Checks if the mask feature is enabled.

Returns:
true or false.

isValidateOnFly

public boolean isValidateOnFly()
Checks if we will validate the credit card number on fly. It is true by default.

Returns:
true or false.

setValidateOnFly

public void setValidateOnFly(boolean validateOnFly)
Enables/disables the validate on fly feature

Parameters:
validateOnFly - true or false.

getCreditCardIcon

public Icon getCreditCardIcon()
Get the icon which is displayed when there is no input number.

Returns:
the icon which is displayed when there is no input number.

setCreditCardIcon

public void setCreditCardIcon(Icon icon)
Sets the icon which is displayed when the input number is invalid.

Parameters:
icon - a new icon which will be displayed when there is no input number.

getInvalidCreditCardIcon

public Icon getInvalidCreditCardIcon()
Gets the icon which is displayed when the input number is invalid.

Returns:
the icon which is displayed when the input number is invalid.

setInvalidCreditCardIcon

public void setInvalidCreditCardIcon(Icon icon)
set the icon which is displayed when the input number is invalid.

Parameters:
icon - the icon which is displayed when the input number is invalid.

validateCardNumber

public boolean validateCardNumber()
Checks if the input number is a valid credit card number.

Returns:
true if the number is valid, false if invalid.

unmaskCardNumber

public void unmaskCardNumber()
Displays the actual card number.


maskCardNumber

public void maskCardNumber()
Masks the card number so that the actual number is not displayed.


JIDE 3.5.15