Email Answering System
Version 1.0

test
Class ConfigurationDialog

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--test.ConfigurationDialog
All Implemented Interfaces:
Accessible, ActionListener, EventListener, ImageObserver, MenuContainer, Serializable, TableModel, WindowListener

public class ConfigurationDialog
extends JPanel
implements TableModel, ActionListener, WindowListener

Create a configuration file for a bean.

Author:
Derrick Oswald
See Also:
Serialized Form

Field Summary
protected  JTable mConfiguration
           
protected  PropertyDescriptor[] mDescriptors
          Cached list of property descriptors introspected from the bean.
protected  String mFile
          The file to store the configuration in.
protected  ArrayList mListeners
          The array of TableModelListeners.
protected  Object mObject
          The bean we're going to configure.
protected  Boolean mResult
          The user action causing the dialog to exit: Boolean.TRUE - user clicked the OK button Boolean.FALSE - user clicked the Cancel button null - user closed window without choosing either button
 
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
ConfigurationDialog(Object bean, String file)
          Creates a new configuration dialog.
 
Method Summary
 void actionPerformed(ActionEvent event)
          Invoked when an action occurs.
 void addTableModelListener(TableModelListener listener)
          Adds a listener to the list that is notified each time a change to the data model occurs.
static void applyConfiguration(Properties properties)
          Apply the configuration to the system properties.
protected  void conditionObject(PropertyDescriptor[] descriptors)
          Apply the configuration stored in the system properties to the object.
static Boolean configure(String cls, String file)
          Perform the configuration.
 Object deStringize(Class cls, String string)
          Convert the given string into an acceptable object for the property setter.
 Class getColumnClass(int index)
          Returns the most specific superclass for all the cell values in the column.
 int getColumnCount()
          Returns the number of columns in the model.
 String getColumnName(int index)
          Returns the name of the column at columnIndex.
protected  PropertyDescriptor[] getDescriptors()
          Get the bean properties we can understand by introspecting the object.
 int getRowCount()
          Returns the number of rows in the model.
 Object getValueAt(int rowIndex, int index)
          Returns the value for the cell at index and rowIndex.
 boolean isCellEditable(int rowIndex, int index)
          Returns true if the cell at rowIndex and index is editable.
static boolean loadConfiguration(String cls, String file)
          Load the configuration.
static void main(String[] args)
          The main line for the configuration dialog.
 String propertyName(PropertyDescriptor descriptor)
          Create the configuration property name from the property descriptor.
protected static Properties readProperties(String file)
          Read the properties file.
 void removeTableModelListener(TableModelListener listener)
          Removes a listener from the list that is notified each time a change to the data model occurs.
protected  void save()
          Save the contents of the object.
 void setValueAt(Object string, int rowIndex, int index)
          Sets the value in the cell at index and rowIndex to aValue.
 void windowActivated(WindowEvent event)
          Invoked when the Window is set to be the active Window.
 void windowClosed(WindowEvent event)
          Invoked when a window has been closed as the result of calling dispose on the window.
 void windowClosing(WindowEvent event)
          Invoked when the user attempts to close the window from the window's system menu.
 void windowDeactivated(WindowEvent event)
          Invoked when a Window is no longer the active Window.
 void windowDeiconified(WindowEvent event)
          Invoked when a window is changed from a minimized to a normal state.
 void windowIconified(WindowEvent event)
          Invoked when a window is changed from a normal to a minimized state.
 void windowOpened(WindowEvent event)
          Invoked the first time a window is made visible.
protected static void writeProperties(String file, Properties properties)
          Write the properties file.
 
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

mObject

protected Object mObject
The bean we're going to configure.


mFile

protected String mFile
The file to store the configuration in.


mDescriptors

protected PropertyDescriptor[] mDescriptors
Cached list of property descriptors introspected from the bean.


mListeners

protected ArrayList mListeners
The array of TableModelListeners.


mResult

protected Boolean mResult
The user action causing the dialog to exit:
  • Boolean.TRUE - user clicked the OK button
  • Boolean.FALSE - user clicked the Cancel button
  • null - user closed window without choosing either button

  • mConfiguration

    protected JTable mConfiguration
    Constructor Detail

    ConfigurationDialog

    public ConfigurationDialog(Object bean,
                               String file)
    Creates a new configuration dialog.

    Parameters:
    bean - The object to get the configuration data for.
    file - The name of a file to write the configuration to, or null if the configuration is to be sent to System.out.
    Method Detail

    deStringize

    public Object deStringize(Class cls,
                              String string)
    Convert the given string into an acceptable object for the property setter.

    Parameters:
    cls - The class determined from the bean information.
    string - The value to be assigned to the property (as a String).
    Returns:
    An object suitable for assignment that has the implied value of the string, or null if no conversion was possible.

    conditionObject

    protected void conditionObject(PropertyDescriptor[] descriptors)
    Apply the configuration stored in the system properties to the object.

    Parameters:
    descriptors - The list of bean properties that can be set.

    getDescriptors

    protected PropertyDescriptor[] getDescriptors()
    Get the bean properties we can understand by introspecting the object. These are cached so it is only performed once.

    Returns:
    The descriptors for bean properties of String or primitive types.

    readProperties

    protected static Properties readProperties(String file)
    Read the properties file.

    Parameters:
    file - The properties file to read.
    Returns:
    The contents of the configuration file as a set of properties.

    writeProperties

    protected static void writeProperties(String file,
                                          Properties properties)
    Write the properties file.

    Parameters:
    file - The name of the file to write.
    properties - The property set to store in the file.

    propertyName

    public String propertyName(PropertyDescriptor descriptor)
    Create the configuration property name from the property descriptor.

    Parameters:
    descriptor - The property descriptor (with the name of the property).
    Returns:
    A string composed of the class name of the object with the property name as a suffix.

    save

    protected void save()
    Save the contents of the object. The configuration file is rewritten so the contents matching the property names of the object match the values of the objects properties.


    addTableModelListener

    public void addTableModelListener(TableModelListener listener)
    Adds a listener to the list that is notified each time a change to the data model occurs.

    Specified by:
    addTableModelListener in interface TableModel
    Parameters:
    listener - The TableModelListener.

    getColumnClass

    public Class getColumnClass(int index)
    Returns the most specific superclass for all the cell values in the column. This is used by the JTable to set up a default renderer and editor for the column.

    Specified by:
    getColumnClass in interface TableModel
    Parameters:
    index - The index of the column.
    Returns:
    The common ancestor class of the object values in the model.

    getColumnCount

    public int getColumnCount()
    Returns the number of columns in the model. A JTable uses this method to determine how many columns it should create and display by default.

    Specified by:
    getColumnCount in interface TableModel
    Returns:
    the number of columns in the model
    See Also:
    getRowCount()

    getColumnName

    public String getColumnName(int index)
    Returns the name of the column at columnIndex. This is used to initialize the table's column header name. Note: this name does not need to be unique; two columns in a table can have the same name.

    Specified by:
    getColumnName in interface TableModel
    Parameters:
    index - The index of the column.
    Returns:
    The name of the column.

    getRowCount

    public int getRowCount()
    Returns the number of rows in the model. A JTable uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.

    Specified by:
    getRowCount in interface TableModel
    Returns:
    the number of rows in the model
    See Also:
    getColumnCount()

    getValueAt

    public Object getValueAt(int rowIndex,
                             int index)
    Returns the value for the cell at index and rowIndex.

    Specified by:
    getValueAt in interface TableModel
    Parameters:
    rowIndex - The row whose value is to be queried.
    index - The column whose value is to be queried.
    Returns:
    The value Object at the specified cell.

    isCellEditable

    public boolean isCellEditable(int rowIndex,
                                  int index)
    Returns true if the cell at rowIndex and index is editable. Otherwise, setValueAt on the cell will not change the value of that cell.

    Specified by:
    isCellEditable in interface TableModel
    Parameters:
    rowIndex - The row whose value to be queried.
    index - The column whose value to be queried.
    Returns:
    true if the cell is editable.
    See Also:
    setValueAt(java.lang.Object, int, int)

    removeTableModelListener

    public void removeTableModelListener(TableModelListener listener)
    Removes a listener from the list that is notified each time a change to the data model occurs.

    Specified by:
    removeTableModelListener in interface TableModel
    Parameters:
    listener - The TableModelListener

    setValueAt

    public void setValueAt(Object string,
                           int rowIndex,
                           int index)
    Sets the value in the cell at index and rowIndex to aValue.

    Specified by:
    setValueAt in interface TableModel
    Parameters:
    string - The new value (as a string).
    rowIndex - The row whose value is to be changed.
    index - The column whose value is to be changed.
    See Also:
    getValueAt(int, int), isCellEditable(int, int)

    actionPerformed

    public void actionPerformed(ActionEvent event)
    Invoked when an action occurs.

    Specified by:
    actionPerformed in interface ActionListener
    Parameters:
    event - The event triggering the action.

    windowActivated

    public void windowActivated(WindowEvent event)
    Invoked when the Window is set to be the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.

    Specified by:
    windowActivated in interface WindowListener
    Parameters:
    event - The event on the window.

    windowClosed

    public void windowClosed(WindowEvent event)
    Invoked when a window has been closed as the result of calling dispose on the window.

    Specified by:
    windowClosed in interface WindowListener
    Parameters:
    event - The event on the window.

    windowClosing

    public void windowClosing(WindowEvent event)
    Invoked when the user attempts to close the window from the window's system menu. If the program does not explicitly hide or dispose the window while processing this event, the window close operation will be cancelled.

    Specified by:
    windowClosing in interface WindowListener
    Parameters:
    event - The event on the window.

    windowDeactivated

    public void windowDeactivated(WindowEvent event)
    Invoked when a Window is no longer the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.

    Specified by:
    windowDeactivated in interface WindowListener
    Parameters:
    event - The event on the window.

    windowDeiconified

    public void windowDeiconified(WindowEvent event)
    Invoked when a window is changed from a minimized to a normal state.

    Specified by:
    windowDeiconified in interface WindowListener
    Parameters:
    event - The event on the window.

    windowIconified

    public void windowIconified(WindowEvent event)
    Invoked when a window is changed from a normal to a minimized state. For many platforms, a minimized window is displayed as the icon specified in the window's iconImage property.

    Specified by:
    windowIconified in interface WindowListener
    Parameters:
    event - The event on the window.
    See Also:
    Frame.setIconImage(java.awt.Image)

    windowOpened

    public void windowOpened(WindowEvent event)
    Invoked the first time a window is made visible.

    Specified by:
    windowOpened in interface WindowListener
    Parameters:
    event - The event on the window.

    configure

    public static Boolean configure(String cls,
                                    String file)
    Perform the configuration.

    Parameters:
    cls - The class name of the bean to configure.
    file - The name of the file to read/write.
    Returns:
    The user action causing the dialog to exit:
  • Boolean.TRUE - the user clicked the OK button
  • Boolean.FALSE - the user clicked the Cancel button
  • null - the user closed window without choosing either button, or a problem occured in configuring the bean

  • applyConfiguration

    public static void applyConfiguration(Properties properties)
    Apply the configuration to the system properties.

    Parameters:
    properties - The properties file containing configuration parameters.

    loadConfiguration

    public static boolean loadConfiguration(String cls,
                                            String file)
                                     throws IllegalStateException
    Load the configuration.

    Parameters:
    cls - The class name of the bean to configure. This is only used if the file specified is not found, otherwise all the properties from that file are loaded.
    file - The name of the file to load from.
    Returns:
    true if the file was successfully loaded, false otherwise.
    Throws:
    IllegalArgumentException - If the file name is null or cannot be loaded.
    IllegalStateException

    main

    public static void main(String[] args)
    The main line for the configuration dialog.

    Parameters:
    args - Command line arguments. args[0] is the class name of a bean to edit, while args[1] is an optional file name to save the configuration in.

    Email Answering System
    Version 1.0

    Copyright © 2003 Derrick Oswald. All rights reserved.