CreditCardPack

com.keyoti.creditCard.display
Class CardElementPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--com.keyoti.creditCard.display.CardElementPanel
Direct Known Subclasses:
CardBillingAddressPanel, CardCommentsPanel, CardExpiryPanel, CardIssueNumberPanel, CardIssuerPanel, CardNamePanel, CardNumberPanel, CardStartPanel, CardTypePanel, CardVerificationNumberPanel

public abstract class CardElementPanel
extends JPanel
implements FocusListener, CaretListener

Abstract base class for card elements (such as the card number field). This class enables the simple creation of custom card field elements, suitable for adding to CreditCardPanel. It provides two JPanels leftPanel and rightPanel, the intention is that a label indicating the field name will be placed in leftPanel and the data entry field(s) in rightPanel.

Example:


	public class CardNamePanel extends CardElementPanel{

		// Labels for the card text field
		protected JLabel label = new JLabel("Name on Card:");

		// card text field
		protected LimitedJTextField cardNameField =
                                  new LimitedJTextField(16, 30);

		// The card name last entered into the text field
		private String cardName = "";


		// Construct a new credit card details panel
		public CardNamePanel()
		{
			label.setFont(labelFont);
			cardNameField.setFont(textFieldFont);
			cardNameField.addFocusListener(this);
			leftPanel.add(label);
			rightPanel.add(cardNameField);
		}

		//required by card element panel
		public void setCreditCard(CreditCard card){}
	}


	

Card element components are built around a Swing style 'separable model' architecture, which has it's roots in MVC. The 'seperable model' design combines the view and the controller into one class, leaving the model seperate. http://java.sun.com/products/jfc/tsc/articles/getting_started/getting_started2.html

In this context com.keyoti.creditCard.logic.CreditCard is the model for all the CardElement sub-classes.

Author:
Keyoti
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent
 
Field Summary
protected  ElementController controller
          Controller part of Swing style separable model design (MVC), each sub class of this class should set this field to a sub class of ElementController to control the events and method calls to and from the elements view and model.
protected  JLabel label
          The field label, that appears in the left panel.
protected  Font labelFont
          The font used for the labels.
protected  JPanel leftPanel
          Left JPanel to add components to, for example a JLabel.
protected  PropertyChangeSupport pcs
          Property change support for sub classes.
protected  JPanel rightPanel
          Right JPanel to add components to, for example a JTextField.
protected  Font textFieldFont
          The font used for the text fields.
 
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
 
Constructor Summary
CardElementPanel()
          Construct a new credit card detail element panel
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
          Adds the supplied PropertyChangeListener object to registry of objects to be notified of changes to properties in the sub-class.
protected  void buildGUI()
          Constructs the GUI.
 void caretUpdate(CaretEvent e)
          Empty caret listener method.
 void focusGained(FocusEvent e)
          Empty focus listener method
 void focusLost(FocusEvent e)
          Empty focus listener method
 String getLabelText()
          Gets the field label text.
 boolean getShowDataInputErrors()
          Gets whether data input errors should be shown to the user when showDataInputError is called.
 void removePropertyChangeListener(PropertyChangeListener l)
          Removes the supplied PropertyChangeListener from the registry of objects notified of property changes.
abstract  void setCreditCard(CreditCard c)
          Sets the credit card used as a model for this view, this method should call setCreditCard in the controller.
 void setLabelText(String l)
          Sets the field label text to l.
 void setShowDataInputErrors(boolean s)
          Sets whether data input errors should be shown to the user when showDataInputError is called.
protected  void showDataInputError(JComboBox combo, String message)
          If getShowDataInputErrors() == true then displays an error message (in a JOptionPane), requests focus to the errored field.
protected  void showDataInputError(JTextField field, String message, String correction)
          If getShowDataInputErrors() == true then displays an error message (in a JOptionPane), clears the field and requests focus to the errored field.
protected  boolean validateFieldForInteger(JTextField field)
          Validates a JTextField, checking if its text can be turned into an Integer, returns true if it can, returns false and shows a JOptionPane error if it can't.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

labelFont

protected Font labelFont
The font used for the labels.

textFieldFont

protected Font textFieldFont
The font used for the text fields.

pcs

protected transient PropertyChangeSupport pcs
Property change support for sub classes.

leftPanel

protected JPanel leftPanel
Left JPanel to add components to, for example a JLabel.

rightPanel

protected JPanel rightPanel
Right JPanel to add components to, for example a JTextField.

controller

protected ElementController controller
Controller part of Swing style separable model design (MVC), each sub class of this class should set this field to a sub class of ElementController to control the events and method calls to and from the elements view and model.
See Also:
ElementController

label

protected JLabel label
The field label, that appears in the left panel.
Constructor Detail

CardElementPanel

public CardElementPanel()
Construct a new credit card detail element panel
Postconditions:
pcs != null
Method Detail

getLabelText

public String getLabelText()
Gets the field label text.

setLabelText

public void setLabelText(String l)
Sets the field label text to l.
Parameters:
l - the text to appear in the field's label.
Throws:
NullPointerException - if l is null

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Adds the supplied PropertyChangeListener object to registry of objects to be notified of changes to properties in the sub-class.
Parameters:
l - an object implementing the PropertyChangeListener interface, to be notified of property change events.
Returns:
void
Throws:
NullPointerException - if l is null.
Preconditions:
l != null
Postconditions:
l will be notified of property change events
Overrides:
addPropertyChangeListener in class JComponent

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Removes the supplied PropertyChangeListener from the registry of objects notified of property changes.
Parameters:
l - an object implementing the PropertyChangeListener interface, will not be notified of property change events in future.
Returns:
void
Throws:
NullPointerException - if l is null
Preconditions:
l != null
Postconditions:
l will not be notified of property change events
Overrides:
removePropertyChangeListener in class JComponent

focusLost

public void focusLost(FocusEvent e)
Empty focus listener method
Specified by:
focusLost in interface FocusListener

focusGained

public void focusGained(FocusEvent e)
Empty focus listener method
Specified by:
focusGained in interface FocusListener

setCreditCard

public abstract void setCreditCard(CreditCard c)
Sets the credit card used as a model for this view, this method should call setCreditCard in the controller.
See Also:
ElementController

caretUpdate

public void caretUpdate(CaretEvent e)
Empty caret listener method.
Specified by:
caretUpdate in interface CaretListener

setShowDataInputErrors

public void setShowDataInputErrors(boolean s)
Sets whether data input errors should be shown to the user when showDataInputError is called.
Parameters:
s - true if data input errors should be shown, false otherwise.
Postconditions:
getShowDataInputErrors() == s

getShowDataInputErrors

public boolean getShowDataInputErrors()
Gets whether data input errors should be shown to the user when showDataInputError is called.

showDataInputError

protected void showDataInputError(JTextField field,
                                  String message,
                                  String correction)
If getShowDataInputErrors() == true then displays an error message (in a JOptionPane), clears the field and requests focus to the errored field.
Parameters:
field - the JTextField that the erroroneous data was entered into.
message - the String to be shown to the user.
correction - the String to be put in the text field as a correction.
Throws:
NullPointerException - if field, message or correction is null
Preconditions:
field != null AND message != null AND correction != null
Postconditions:
JOptionPane indicating error is displayed with focus if getShowDataInputErrors() == true else does nothing

showDataInputError

protected void showDataInputError(JComboBox combo,
                                  String message)
If getShowDataInputErrors() == true then displays an error message (in a JOptionPane), requests focus to the errored field.
Parameters:
combo - the JComboBox that the erroroneous data was selected in.
message - the String to be shown to the user.
Throws:
NullPointerException - if combo or message is null
Preconditions:
combo != null AND message != null
Postconditions:
JOptionPane indicating error is displayed with focus if getShowDataInputErrors() == true else does nothing

validateFieldForInteger

protected boolean validateFieldForInteger(JTextField field)
Validates a JTextField, checking if its text can be turned into an Integer, returns true if it can, returns false and shows a JOptionPane error if it can't.
Parameters:
field - the JTextField that the text originated in.
Returns:
true or false.
Throws:
NullPointerException - if field is null
Preconditions:
field != null
Postconditions:
return == (true AND new Integer(field.getText() !-> NumberFormatException)) OR
(false AND showDataInputError is called)

buildGUI

protected void buildGUI()
Constructs the GUI. Creates leftPanel and rightPanel and lays them out in this JPanel.
Postconditions:
getComponent(getComponentCount()-1) == x AND
x.getComponent(x.getComponentCount()-2) == leftPanel AND
x.getComponent(x.getComponentCount()-1) == rightPanel

CreditCardPack

Copyright © 2002 Keyoti All Rights Reserved.