Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.theotherbell.ui
Class DatePicker  view DatePicker download DatePicker.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended bycom.theotherbell.ui.DatePicker
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public final class DatePicker
extends javax.swing.JPanel

GUI component that allows the user to choose a date from a calendar. Usage is illustrated in the sample code below:

  JDialog dlg = new JDialog(new Frame(), true);
  DatePicker dp = new DatePicker();
  dp.setHideOnSelect(false);
  dlg.getContentPane().add(dp);
  dlg.pack();
  dlg.show();
  System.out.println(dp.getDate().toString());
  dlg.dispose();
  System.exit(0);
 

Version:
1.1a

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
private  javax.swing.JButton backButton
          When clicked, displays the previous month.
private  javax.swing.JButton cancelButton
          When clicked, hides the calendar and sets the selected date to "empty".
private  javax.swing.JTextField[] dayHeadings
          Column headings for the days of the week.
private  javax.swing.JTextField[][] daysInMonth
          2-dimensional array for 6 weeks of 7 days each.
private  javax.swing.JButton forwardButton
          When clicked, displays the next month.
private static java.awt.Color gray
          Disabled color.
private  boolean hideOnSelect
          When true, the panel will be hidden as soon as a day is selected by clicking the day or clicking the Today button.
private static java.awt.Color highlight
          Highlighted color.
private static java.awt.Insets insets
          Insets for day components and small buttons.
private static java.awt.Font largeFont
          Large font.
private  javax.swing.JLabel monthAndYear
          Displays the currently selected month and year.
private  java.util.GregorianCalendar originalDate
          Tracks the original date set when the component was created.
private  java.util.GregorianCalendar selectedDate
          Currently selected date.
private  java.awt.Component selectedDay
          Most recently selected day component.
private static java.awt.Font smallFont
          Small font.
private static int startX
          X coordinate for upper left corner of week 1 day 1.
private static int startY
          Y coordinate for upper left corner of week 1 day 1.
private  javax.swing.JButton todayButton
          When clicked, sets the selected day to the current date.
private static java.awt.Color white
          Enabled color.
 
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
DatePicker()
          Default constructor that sets the currently selected date to the current date.
DatePicker(java.util.Date initialDate)
          Alternate constructor that sets the currently selected date to the specified date if non-null.
 
Method Summary
private  void calculateCalendar()
          Calculates the days of the month.
private static int calculateDaysInMonth(java.util.Calendar c)
          Calculates the number of days in the specified month.
private static java.lang.String formatDateText(java.util.Date dt)
          Returns a short string representation of the specified date (January, 2001).
 java.util.Date getDate()
          Returns the currently selected date.
private static java.util.GregorianCalendar getToday()
          Returns the current date.
private  void init()
          Initializes the panel components according to the current value of selectedDate.
private  void initButtons(boolean firstTime)
          Initializes Today and Cancel buttons dependent on whether hideOnSelect is set; if the panel will stay open, the Cancel button is invisible.
 boolean isHideOnSelect()
          Returns true if the panel will be made invisible after a day is selected.
private  void onBackClicked(java.awt.event.ActionEvent evt)
          Event handler for the back button that decrements the currently selected month.
private  void onCancel(java.awt.event.ActionEvent evt)
          Event handler for the Cancel button that unsets the currently selected date.
private  void onDayClicked(java.awt.event.MouseEvent evt)
          Event handler that sets the currently selected date to the clicked day.
private  void onForwardClicked(java.awt.event.ActionEvent evt)
          Event handler for the forward button that increments the currently selected month.
private  void onToday(java.awt.event.ActionEvent evt)
          Event handler for the Today button that sets the currently selected date to the current date.
 void setHideOnSelect(boolean hideOnSelect)
          Controls whether the panel will be made invisible after a day is selected.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, 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, 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, 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, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, 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, getPropertyChangeListeners, getPropertyChangeListeners, 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, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

startX

private static final int startX
X coordinate for upper left corner of week 1 day 1.

See Also:
Constant Field Values

startY

private static final int startY
Y coordinate for upper left corner of week 1 day 1.

See Also:
Constant Field Values

smallFont

private static final java.awt.Font smallFont
Small font.


largeFont

private static final java.awt.Font largeFont
Large font.


insets

private static final java.awt.Insets insets
Insets for day components and small buttons.


highlight

private static final java.awt.Color highlight
Highlighted color.


white

private static final java.awt.Color white
Enabled color.


gray

private static final java.awt.Color gray
Disabled color.


selectedDay

private java.awt.Component selectedDay
Most recently selected day component.


selectedDate

private java.util.GregorianCalendar selectedDate
Currently selected date.


originalDate

private java.util.GregorianCalendar originalDate
Tracks the original date set when the component was created.


hideOnSelect

private boolean hideOnSelect
When true, the panel will be hidden as soon as a day is selected by clicking the day or clicking the Today button.


backButton

private final javax.swing.JButton backButton
When clicked, displays the previous month.


monthAndYear

private final javax.swing.JLabel monthAndYear
Displays the currently selected month and year.


forwardButton

private final javax.swing.JButton forwardButton
When clicked, displays the next month.


dayHeadings

private final javax.swing.JTextField[] dayHeadings
Column headings for the days of the week.


daysInMonth

private final javax.swing.JTextField[][] daysInMonth
2-dimensional array for 6 weeks of 7 days each.


todayButton

private final javax.swing.JButton todayButton
When clicked, sets the selected day to the current date.


cancelButton

private final javax.swing.JButton cancelButton
When clicked, hides the calendar and sets the selected date to "empty".

Constructor Detail

DatePicker

public DatePicker()
Default constructor that sets the currently selected date to the current date.


DatePicker

public DatePicker(java.util.Date initialDate)
Alternate constructor that sets the currently selected date to the specified date if non-null.

Method Detail

isHideOnSelect

public boolean isHideOnSelect()
Returns true if the panel will be made invisible after a day is selected.


setHideOnSelect

public void setHideOnSelect(boolean hideOnSelect)
Controls whether the panel will be made invisible after a day is selected.


getDate

public java.util.Date getDate()
Returns the currently selected date.


init

private void init()
Initializes the panel components according to the current value of selectedDate.


initButtons

private void initButtons(boolean firstTime)
Initializes Today and Cancel buttons dependent on whether hideOnSelect is set; if the panel will stay open, the Cancel button is invisible.


onToday

private void onToday(java.awt.event.ActionEvent evt)
Event handler for the Today button that sets the currently selected date to the current date.


onCancel

private void onCancel(java.awt.event.ActionEvent evt)
Event handler for the Cancel button that unsets the currently selected date.


onForwardClicked

private void onForwardClicked(java.awt.event.ActionEvent evt)
Event handler for the forward button that increments the currently selected month.


onBackClicked

private void onBackClicked(java.awt.event.ActionEvent evt)
Event handler for the back button that decrements the currently selected month.


onDayClicked

private void onDayClicked(java.awt.event.MouseEvent evt)
Event handler that sets the currently selected date to the clicked day.


getToday

private static java.util.GregorianCalendar getToday()
Returns the current date.


calculateCalendar

private void calculateCalendar()
Calculates the days of the month.


calculateDaysInMonth

private static int calculateDaysInMonth(java.util.Calendar c)
Calculates the number of days in the specified month.


formatDateText

private static java.lang.String formatDateText(java.util.Date dt)
Returns a short string representation of the specified date (January, 2001).