com.ca.commons.cbutil
Class CBSaveLoadTemplate

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--com.ca.commons.cbutil.CBSaveLoadTemplate
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class CBSaveLoadTemplate
extends javax.swing.JPanel

An object of this cunning class can be added as is to any container containing user-input components such as text fields, check boxes and so forth. When it is asked to 'save' a template, it scans through its parent container, identifies user-input components, and saves their data to a properties file with the name 'template name' + 'component number'.These can be automatically read back later.

At the moment it only handles the *swing* components:
JTextField, CBJComboBox, JCheckBox, but it could easily be modified (would need to change JContainer checks to Container).

It will iterate through sub-components, but since there is no "JContainer" class, all sub-components must be explicitly listed in the code; at the moment it only handles JPanel.

The fact that it does not handle JPasswordField is considered a feature.

Warning This class is unlikely to correctly handle non-string data; i.e. combo boxes with icons etc.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  javax.swing.JButton delete
           
protected  CBJComboBox loadops
           
protected  javax.swing.JButton makeDefault
           
protected  javax.swing.JButton save
           
 java.lang.String saveFileName
           
 java.util.Properties templates
           
 
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
CBSaveLoadTemplate(java.lang.String fileName)
          Each CBSaveLoadTemplate object must have a file name to read and load data from...
 
Method Summary
 void addIllegalComponent(java.awt.Component c)
           
 void delete()
           
 void deleteComponentInfo(java.awt.Container myContainer, java.lang.String templateName)
           
 void deleteComponentInfo(java.lang.String templateName)
          Deletes a template that is saved in the property file.
 java.lang.String getComponentText(java.awt.Component c)
          this ftn returns the text to save for a given component, and is the sister ftn to 'loadComponentText'.
 java.lang.String getCurrentTemplateName()
           
 CBJComboBox getLoadComboBox()
          Expose the root combo box for the use of adding listeners 'n stuff.
 void load()
          Takes a template name, and attempts to read all the (string) values belonging to that template, and toss them in the appropriate numbered component.
protected  void loadComponent(java.awt.Component c, int componentNo, java.lang.String templateName)
          This method handles the loading of a particular component.
 void loadComponentText(java.awt.Component c, java.lang.String text)
           
 void loadContainerInfo(java.awt.Container myContainer, java.lang.String templateName)
           
 void loadDefault()
          Loads the dafault set up (if one has been saved)
 void loadTemplateName(java.lang.String templateName)
           
 void makeDefault()
           
protected  void parseFile(java.lang.String fileName)
           
 void save()
          saves a dialog windows state by working through all the components held by the parent container, and if they are (selected) User Input objects (TextFields etc.) saving their contents to a properties list.
protected  void saveComponent(java.awt.Component c, int componentNo, java.lang.String templateName)
          This method handles the saving of a particular component.
 void saveContainerInfo(java.awt.Container myContainer, java.lang.String templateName)
          iterates through a container, saving user-entry components as it goes.
 void saveTemplateName(java.lang.String templateName)
           
 int showMessage()
          Opens an dialog that asks if the user wants to delete the template.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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

save

protected javax.swing.JButton save

delete

protected javax.swing.JButton delete

makeDefault

protected javax.swing.JButton makeDefault

loadops

protected CBJComboBox loadops

saveFileName

public java.lang.String saveFileName

templates

public java.util.Properties templates
Constructor Detail

CBSaveLoadTemplate

public CBSaveLoadTemplate(java.lang.String fileName)
Each CBSaveLoadTemplate object must have a file name to read and load data from...

Method Detail

getLoadComboBox

public CBJComboBox getLoadComboBox()
Expose the root combo box for the use of adding listeners 'n stuff.


showMessage

public int showMessage()
Opens an dialog that asks if the user wants to delete the template.

Returns:
the user response as an integer (see JOptionPane)

loadDefault

public void loadDefault()
Loads the dafault set up (if one has been saved). - equivalent to manually loading the template named 'default'.


parseFile

protected void parseFile(java.lang.String fileName)

getCurrentTemplateName

public java.lang.String getCurrentTemplateName()

save

public void save()
saves a dialog windows state by working through all the components held by the parent container, and if they are (selected) User Input objects (TextFields etc.) saving their contents to a properties list.


saveTemplateName

public void saveTemplateName(java.lang.String templateName)

saveContainerInfo

public void saveContainerInfo(java.awt.Container myContainer,
                              java.lang.String templateName)
iterates through a container, saving user-entry components as it goes.

Parameters:
myContainer - container to save
templateName - unique name for this template and component

saveComponent

protected void saveComponent(java.awt.Component c,
                             int componentNo,
                             java.lang.String templateName)
This method handles the saving of a particular component. If the class needs to be extended, extra handling for particular components may need to be added, in which case this method can be extended.

Parameters:
c - the component to save
componentNo - the index of the component
templateName - the name of the template being saved to.

getComponentText

public java.lang.String getComponentText(java.awt.Component c)
this ftn returns the text to save for a given component, and is the sister ftn to 'loadComponentText'. New components (including awt components) can be added here, by extracting their value as text, and making sure that loadComponentText correctly translates that value when loading.

Parameters:
c - the component to retrieve a text value for.
Returns:
the text value of the component.

load

public void load()
Takes a template name, and attempts to read all the (string) values belonging to that template, and toss them in the appropriate numbered component.


loadTemplateName

public void loadTemplateName(java.lang.String templateName)

loadContainerInfo

public void loadContainerInfo(java.awt.Container myContainer,
                              java.lang.String templateName)

loadComponent

protected void loadComponent(java.awt.Component c,
                             int componentNo,
                             java.lang.String templateName)
This method handles the loading of a particular component. If the class needs to be extended, extra handling for particular components may need to be added, in which case this method can be extended.

Parameters:
c - the component to load
componentNo - the index of the component
templateName - the name of the template being loaded from.

loadComponentText

public void loadComponentText(java.awt.Component c,
                              java.lang.String text)

delete

public void delete()

deleteComponentInfo

public void deleteComponentInfo(java.awt.Container myContainer,
                                java.lang.String templateName)

deleteComponentInfo

public void deleteComponentInfo(java.lang.String templateName)
Deletes a template that is saved in the property file. Can be extended to account for individual component handling e.g. combo box visibility.

Parameters:
templateName - the name of the template that is to be deleted from the property file.

makeDefault

public void makeDefault()

addIllegalComponent

public void addIllegalComponent(java.awt.Component c)