com.pallas.swing.date
Class DateComboBox

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JComboBox
                          |
                          +--com.pallas.swing.date.DateComboBox
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, javax.swing.event.ListDataListener, java.awt.MenuContainer, java.io.Serializable

public class DateComboBox
extends javax.swing.JComboBox

Title: $FileName: DateComboBox.java$

Version:
$VerNum: 10$
Author:
$AuthorName: Rob MacGrogan$

$Description: A date control that pops up a calendar.$
$KeyWordsOff: $

A date control that pops up a calendar. Derived from code posted at http://softwaredev.earthweb.com/java/article/0,,12082_735291,00.html by Paul Book.

Works under java 1.3 and 1.4.1. A bug in 1.4.0 causes very odd behavior under Windows LAF, but should work fine under other LAFs.
See Also:
Serialized Form

Nested Class Summary
(package private)  class DateComboBox.CBDate
           
(package private)  class DateComboBox.DatePopup
           
(package private)  class DateComboBox.MetalDateComboBoxUI
           
(package private)  class DateComboBox.MotifDateComboBoxUI
           
(package private)  class DateComboBox.WindowsDateComboBoxUI
           
 
Field Summary
protected  java.text.SimpleDateFormat dateFormat
           
private  java.util.ArrayList formats
           
 
Fields inherited from class javax.swing.JComboBox
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder
 
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.Container
 
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
DateComboBox()
          Defaults to null.
DateComboBox(java.util.Date date)
          Sets initial date of combo box.
DateComboBox(java.util.Date date, java.lang.String pattern)
           
DateComboBox(java.lang.String pattern)
           
 
Method Summary
 void addFormat(java.text.DateFormat format)
           
 void addFormat(java.lang.String format)
           
private  javax.swing.Icon getButtonIcon()
           
 java.util.Date getDate()
           
(package private)  java.text.DateFormat getFormat()
           
private  void initializeComponent()
          Initializes the DateComboBox.
static void main(java.lang.String[] args)
           
(package private)  java.util.Date parseDateString(java.lang.String sDate)
          Attempts to parse sDate to a date using all available date formats.
private  void setCalendarIcon()
           
 void setDate(java.util.Date date)
           
 void setDateFormat(java.text.SimpleDateFormat dateFormat)
           
 void setDateFormat(java.lang.String pattern)
           
 void setEditable(boolean editable)
          This method does nothing.
 void setName(java.lang.String s)
           
 void setSelectedItem(java.lang.Object item)
           
static java.util.Date stripTime(java.util.Date dt)
          Returns a new Date with the same calendar date as the Date passed in, but with the time changed to 12:00 AM.
 void updateUI()
           
 
Methods inherited from class javax.swing.JComboBox
actionPerformed, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setUI, showPopup
 
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, 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, 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, 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

dateFormat

protected java.text.SimpleDateFormat dateFormat

formats

private java.util.ArrayList formats
Constructor Detail

DateComboBox

public DateComboBox()
Defaults to null. And MMM d, yyyy pattern.


DateComboBox

public DateComboBox(java.util.Date date)
Sets initial date of combo box. Defaults pattern to MMM d, yyyy.


DateComboBox

public DateComboBox(java.util.Date date,
                    java.lang.String pattern)

DateComboBox

public DateComboBox(java.lang.String pattern)
Method Detail

setName

public void setName(java.lang.String s)
Overrides:
setName in class java.awt.Component

getFormat

java.text.DateFormat getFormat()

addFormat

public void addFormat(java.text.DateFormat format)

addFormat

public void addFormat(java.lang.String format)

initializeComponent

private void initializeComponent()
Initializes the DateComboBox.


parseDateString

java.util.Date parseDateString(java.lang.String sDate)
                         throws java.text.ParseException
Attempts to parse sDate to a date using all available date formats.

java.text.ParseException

setCalendarIcon

private void setCalendarIcon()

getButtonIcon

private javax.swing.Icon getButtonIcon()

setEditable

public void setEditable(boolean editable)
This method does nothing. DateComboBox is always editable.

Overrides:
setEditable in class javax.swing.JComboBox

setDateFormat

public void setDateFormat(java.text.SimpleDateFormat dateFormat)

setDateFormat

public void setDateFormat(java.lang.String pattern)

stripTime

public static java.util.Date stripTime(java.util.Date dt)
Returns a new Date with the same calendar date as the Date passed in, but with the time changed to 12:00 AM.


setDate

public void setDate(java.util.Date date)

getDate

public java.util.Date getDate()

setSelectedItem

public void setSelectedItem(java.lang.Object item)
Overrides:
setSelectedItem in class javax.swing.JComboBox

updateUI

public void updateUI()
Overrides:
updateUI in class javax.swing.JComboBox

main

public static void main(java.lang.String[] args)


Copyright 2003 Pallas Technology.