com.ca.directory.jxplorer.editor
Class GeneralizedTimeEditor

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Dialog
                          |
                          +--javax.swing.JDialog
                                |
                                +--com.ca.commons.cbutil.CBDialog
                                      |
                                      +--com.ca.directory.jxplorer.editor.GeneralizedTimeEditor
All Implemented Interfaces:
AbstractStringEditor, javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants

public class GeneralizedTimeEditor
extends CBDialog
implements AbstractStringEditor

The GeneralizedTimeEditor used for editing generalizedTime attributes within the directory. It is initiated when the user clicks on a generalizedTime attribute in the Table Editor of JXplorer.

The GeneralizedTimeEditor displays a date/time dialog with combo boxes for the following:

Milli seconds (possible values: 0-999). Seconds of the minute (possible values: 0-59). Minutes of the hour (possible values: 0-59). Hour of the day (possible values: 0-23). Day of the month (possible values: --, 1-31). Month of the year (possible values: --, January - Decemeber inclusive).

Note: it is possible to enter the following generalizedTime 000000000000, this is why a value of -- (0) is included in day of the month and month of the year combos.

The year is displayed and edited through a restricted (whole number) field. Year can only be of 4 characters. The UTC (or GTM or zulu) is selected via a check box.

This class follows the generalizedTime format of year-month-day-hour-minute (yyyymmddhhmm) as manditory. Optional values in the generalizedTime are second-millisecond-UTC (ss.mmmZ). Milliseconds require seconds to be added. Examples of a correct generalizeTime are

20011231235959.999Z 20011231235959.999 20011231235959.99Z 20011231235959.99 20011231235959.9Z 20011231235959.9 19960229235959 19960229235959Z 199702282359 199702282359Z

The dialog has a 'Now' button for displaying the current date/time of the user's machine.

The dialog enforces date constraints such as leap years. For example if a leap year is entered in the year field and february is selected, the days displayed will be 0-29. The correct days for the month that is selected will be displayed also. For example if April is selected the days will be 0-30.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JDialog
javax.swing.JDialog.AccessibleJDialog
 
Nested classes inherited from class java.awt.Dialog
java.awt.Dialog.AccessibleAWTDialog
 
Nested classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
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
 
Fields inherited from class com.ca.commons.cbutil.CBDialog
buttonPanel, Cancel, display, Help, OK, owner
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GeneralizedTimeEditor(java.awt.Frame owner, java.lang.String value, boolean isTableEditor)
          Sets up the dialog components, displaying the supplied attribute value.
 
Method Summary
protected  void displayCurrent()
          Gets the current date and time from the user's machine and displays it.
 void doCancel()
          When the user hits 'cancel', the window is shut down.
 void doOK()
          Sets the changed (or unchanged) attribute value from the attribute editor in the table.
protected  int getDaysInMonth(int month)
          Returns the days in the month that is supplied.
protected  java.lang.String getSelectedDay()
          Returns a string representation of the day as entered in the day combo.
protected  java.lang.String getSelectedHour()
          Returns a string representation of the hour as entered in the hour combo.
protected  java.lang.String getSelectedMilliSecond()
          Returns a string representation of the milliSecond as entered in the milliSecond combo.
protected  java.lang.String getSelectedMinute()
          Returns a string representation of the minute as entered in the minute combo.
protected  java.lang.String getSelectedMonth()
          Returns a string representation of the month as entered in the month combo.
protected  java.lang.String getSelectedSecond()
          Returns a string representation of the second as entered in the second combo.
protected  java.lang.String getSelectedYear()
          Returns a string representation of the year as entered in the year field.
 java.lang.String getTime()
          Returns the time set in the GUI.
protected  int getUserYear()
          Returns the year from the year field as an integer.
protected  void initDateTimeVariables()
          Initialises the date and time variables depending on the current attribute value.
protected  void initDays(int days)
          Initialises the second combo with integers from 0-31, 0-30, 0-29 or 0-28 depending on the number of days supplied.
protected  void initHours()
          Initialises the hour combo with integers from 0-23.
protected  void initMilliSeconds()
          Initialises the milli-second combo with integers from 0-999.
protected  void initMinutes()
          Initialises the minute combo with integers from 0-59.
protected  void initMonths()
          Initialises the month combo with months of the year.
protected  void initSeconds()
          Initialises the second combo with integers from 0-59.
 boolean isLeapYear(int year)
          Determines if given year is a leap year.
protected  void setDayComboSelectedIndex(int index)
          Displays the value in the day combo at the index supplied.
protected  void setSelectedIndexes()
          Sets the index of the combo boxes and the year field to the already initiated date an time variables.
 void setStringValue(EditableString editString)
          Sets the EditableString of this class to the supplied EditableString.
protected  void updateDayCombo()
          Re-populates the day combo to reflect the number of days of the month that is selected in the month combo.
 
Methods inherited from class com.ca.commons.cbutil.CBDialog
add, addln, escKeyCheck, getDisplayPanel, makeHeavy, makeLight, makeWide, quit, setHelpLink, wasCancelled
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Dialog
addNotify, dispose, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, finalize, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, removeNotify, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeneralizedTimeEditor

public GeneralizedTimeEditor(java.awt.Frame owner,
                             java.lang.String value,
                             boolean isTableEditor)
Sets up the dialog components, displaying the supplied attribute value. If there is no value to display, the fields are all set to zero.

Parameters:
owner - the parent frame, usually JXplorer.
isTableEditor - this class is normally used by the table editor. If used elsewhere set this to false and get the time value from the getTime() method.
Method Detail

initDateTimeVariables

protected void initDateTimeVariables()
Initialises the date and time variables depending on the current attribute value. For example: 20010920235959.999 would display... year - 2001 month - September day - 20 hour - 23 (11pm) minute - 59 second - 59 millisecond - 999 If there is no value the date and time variables default to zero (0).


getDaysInMonth

protected int getDaysInMonth(int month)
Returns the days in the month that is supplied.

Parameters:
month - an integer representation of the month for example: 1 = Jan, 2 = Feb...12 = Dec. 0 = an unspecified month which has 0 days.
Returns:
the days in the month for example: Jan = 31, Feb = 28 (29 if leap) etc.

displayCurrent

protected void displayCurrent()
Gets the current date and time from the user's machine and displays it.


setSelectedIndexes

protected void setSelectedIndexes()
Sets the index of the combo boxes and the year field to the already initiated date an time variables.


initMilliSeconds

protected void initMilliSeconds()
Initialises the milli-second combo with integers from 0-999.


initSeconds

protected void initSeconds()
Initialises the second combo with integers from 0-59.


initMinutes

protected void initMinutes()
Initialises the minute combo with integers from 0-59.


initHours

protected void initHours()
Initialises the hour combo with integers from 0-23.


initDays

protected void initDays(int days)
Initialises the second combo with integers from 0-31, 0-30, 0-29 or 0-28 depending on the number of days supplied.

Parameters:
days - the maximum number of days to display. Can be 0, 28, 29, 30 ,31.

initMonths

protected void initMonths()
Initialises the month combo with months of the year. For example: --, January, Febuarary...December.


updateDayCombo

protected void updateDayCombo()
Re-populates the day combo to reflect the number of days of the month that is selected in the month combo. Accounts for leap year also.


getUserYear

protected int getUserYear()
Returns the year from the year field as an integer. If there is a problem parsing the value (which there shouldn't be because the year field is restricted to whole numbers), the year is set to zero (0).

Returns:
the year as displayed in the year field.

setDayComboSelectedIndex

protected void setDayComboSelectedIndex(int index)
Displays the value in the day combo at the index supplied. If there is a problem with the index being out of bounds (or the like), the index displayed is the last available in the combo.

Parameters:
index - the index of the value to display in the day combo.

isLeapYear

public boolean isLeapYear(int year)
Determines if given year is a leap year.

Parameters:
year - = given year after 1582 (start of the Gregorian calendar).
Returns:
TRUE if given year is leap year, FALSE if not.

getSelectedYear

protected java.lang.String getSelectedYear()
Returns a string representation of the year as entered in the year field. The year can only have four characters therefore any characters after the first for are ignored. If there is less than four characters the space(s) to the left are filled with a zero (0).

Returns:
the year as a string for example 2001.

getSelectedMonth

protected java.lang.String getSelectedMonth()
Returns a string representation of the month as entered in the month combo.

Returns:
the month as a string for example 01 (January).

getSelectedDay

protected java.lang.String getSelectedDay()
Returns a string representation of the day as entered in the day combo.

Returns:
the day as a string for example 31.

getSelectedHour

protected java.lang.String getSelectedHour()
Returns a string representation of the hour as entered in the hour combo.

Returns:
the hour as a string for example 23.

getSelectedMinute

protected java.lang.String getSelectedMinute()
Returns a string representation of the minute as entered in the minute combo.

Returns:
the minute as a string for example 59.

getSelectedSecond

protected java.lang.String getSelectedSecond()
Returns a string representation of the second as entered in the second combo.

Returns:
the second as a string for example 59.

getSelectedMilliSecond

protected java.lang.String getSelectedMilliSecond()
Returns a string representation of the milliSecond as entered in the milliSecond combo.

Returns:
the milliSecond as a string for example 999.

setStringValue

public void setStringValue(EditableString editString)
Sets the EditableString of this class to the supplied EditableString.

Specified by:
setStringValue in interface AbstractStringEditor

doOK

public void doOK()
Sets the changed (or unchanged) attribute value from the attribute editor in the table. Disposes of the dialog.

Overrides:
doOK in class CBDialog

doCancel

public void doCancel()
When the user hits 'cancel', the window is shut down. Sets the 'time' (accessable via getTime()) to the initial 'value'.

Overrides:
doCancel in class CBDialog

getTime

public java.lang.String getTime()
Returns the time set in the GUI. This is a hack so that the Search dialog can use this editor for time attributes. Instead of setting the value via editableString.setStringValue(), a global variable should have been set with the date/time.

Returns:
the date/time set by the user.