JIDE 3.5.15

com.jidesoft.combobox
Class MonthChooserPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.jidesoft.combobox.PopupPanel
                      extended by com.jidesoft.combobox.MonthChooserPanel
All Implemented Interfaces:
DateModelListener, ActionListener, ItemListener, MouseListener, MouseWheelListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible

public class MonthChooserPanel
extends PopupPanel
implements ItemListener, ActionListener, MouseListener, MouseWheelListener, DateModelListener

MonthChooserPanel is a popup panel that can choose Date. User can click and select a Month. It also support various operations such as typing year directly, go to next or previous year. It also supports ItemListener. Whenever a Month is selected, itemStateChanged will be fired.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int NAVIGATION_BUTTON_HEIGHT
           
static int NAVIGATION_BUTTON_WIDTH
           
static String VIEWONLY_PROPERTY
          Property of view only.
 
Fields inherited from class com.jidesoft.combobox.PopupPanel
_previousSelectedObject, SELECTED_BY_MOUSE_ROLLOVER
 
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
MonthChooserPanel()
          Creates a new JPanel with a double buffer and a flow layout.
MonthChooserPanel(boolean showNoneButton)
           
MonthChooserPanel(DateModel dateModel)
           
MonthChooserPanel(DateModel dateModel, boolean showNoneButton)
           
MonthChooserPanel(DateModel dateModel, boolean showNoneButton, Locale locale)
           
 
Method Summary
 void actionPerformed(ActionEvent e)
           
protected  void addModelListener()
          Adds DateModelListener to DateModel.
protected  Component createButtonPanel()
           
protected  JComponent createMonthLabel(int i)
           
protected  Component createMonthPanel()
           
protected  Component createMonthsPanel()
           
protected  JComponent createYearLabel()
           
protected  Component createYearPanel()
           
 void dateModelChanged(DateModelEvent e)
          This notification tells listeners the something changed in date model.
 void disableMouseWheel()
           
 void enableMouseWheel()
           
 DateModel getDateModel()
          Gets the DateModel.
 Calendar getDisplayedCalendar()
           
protected  Calendar getMonthCalendar()
          Gets a Calendar representing the month.
 DateFormat getMonthFormatter()
           
protected  String getResourceString(String key)
          Gets the localized string from resource bundle.
 Calendar getSelectedCalendar()
          Gets the selected calendar.
 Date getSelectedDate()
          Gets the selected date.
protected  JTextField getTextField(JSpinner spinner)
          Return the formatted text field used by the editor, or null if the editor doesn't descend from JSpinner.DefaultEditor.
protected  void initCalendar()
           
protected  void initComponents()
           
protected  void initDateFormat(Locale locale)
           
protected  boolean isDateSelected(Calendar calendar)
           
protected  boolean isMonthOutOfRange(Calendar calendar)
          Checks if the month is out of the range of the DateModel.
 boolean isShowNoneButton()
          Checks if none button is visible.
 boolean isShowThisMonthButton()
          Checks if this month button is visible.
protected  boolean isToday(Calendar calendar)
           
 boolean isViewOnly()
          If the DateChooserPanel is view-only.
 void itemStateChanged(ItemEvent e)
           
 void mouseClicked(MouseEvent e)
           
 void mouseEntered(MouseEvent e)
           
 void mouseExited(MouseEvent e)
           
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
 void mouseWheelMoved(MouseWheelEvent e)
           
protected  void registerKeyStrokes()
           
protected  void removeModeListener()
           
 void setDateModel(DateModel dateModel)
          Sets the DateModel.
 boolean setDisplayedYear(int year)
          This method will set the displayed year of MonthChooserPanel.
 void setLocale(Locale locale)
           
 void setMonthFormatter(DateFormat monthFormatter)
           
 void setSelectedCalendar(Calendar selectedCalendar)
          Sets the selected calendar.
 void setSelectedDate(Date selectedDate)
          Sets the selected date.
 void setShowNoneButton(boolean showNoneButton)
          Sets the none button visible.
 void setShowThisMonthButton(boolean showThisMonthButton)
          Sets the this month button visible.
 void setViewOnly(boolean viewOnly)
          Sets the view only attribute.
protected  void updateButtons()
           
protected  void updateCalendar()
           
protected  void updateDayOfWeekLabel(JComponent dayOfWeekLabel, Calendar calendar)
           
protected  void updateMonthCalendar(Calendar calendar)
          Updates the calendar to represent the month.
protected  void updateMonthLabel(JComponent monthLabel, Calendar date, boolean isSelected, boolean isToday)
           
 void updateUI()
           
protected  void updateYearLabel(JComponent yearLabel, Calendar calendar)
           
 
Methods inherited from class com.jidesoft.combobox.PopupPanel
addItemListener, addItemListener, fireItemStateChanged, getActualPreferredSize, getDefaultFocusComponent, getItemListeners, getMouseListener, getMouseMotionListener, getPreferredSize, getPreviousSelectedObject, getResizableCorners, getSelectedObject, getSelectedObjects, getTitle, isResetButtonVisible, isResizable, isStretchToFit, needsButtons, removeAllListeners, removeItemListener, requestFocus, setDefaultFocusComponent, setNeedButtons, setPreferredSize, setResizable, setResizableCorners, setSelectedObject, setSelectedObject, setSelectedObject, setSelectedObject, setStretchToFit, setTitle
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, 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, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, 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, 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

VIEWONLY_PROPERTY

public static final String VIEWONLY_PROPERTY
Property of view only.

See Also:
Constant Field Values

NAVIGATION_BUTTON_HEIGHT

public static int NAVIGATION_BUTTON_HEIGHT

NAVIGATION_BUTTON_WIDTH

public static int NAVIGATION_BUTTON_WIDTH
Constructor Detail

MonthChooserPanel

public MonthChooserPanel()
Creates a new JPanel with a double buffer and a flow layout.


MonthChooserPanel

public MonthChooserPanel(DateModel dateModel)

MonthChooserPanel

public MonthChooserPanel(boolean showNoneButton)

MonthChooserPanel

public MonthChooserPanel(DateModel dateModel,
                         boolean showNoneButton)

MonthChooserPanel

public MonthChooserPanel(DateModel dateModel,
                         boolean showNoneButton,
                         Locale locale)
Method Detail

getDateModel

public DateModel getDateModel()
Gets the DateModel.

Returns:
DateModel.

setDateModel

public void setDateModel(DateModel dateModel)
Sets the DateModel.

Parameters:
dateModel - the date model

addModelListener

protected void addModelListener()
Adds DateModelListener to DateModel.


removeModeListener

protected void removeModeListener()

dateModelChanged

public void dateModelChanged(DateModelEvent e)
Description copied from interface: DateModelListener
This notification tells listeners the something changed in date model.

Specified by:
dateModelChanged in interface DateModelListener

mouseClicked

public void mouseClicked(MouseEvent e)
Specified by:
mouseClicked in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Specified by:
mouseReleased in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Specified by:
mouseExited in interface MouseListener

mouseWheelMoved

public void mouseWheelMoved(MouseWheelEvent e)
Specified by:
mouseWheelMoved in interface MouseWheelListener

enableMouseWheel

public void enableMouseWheel()

disableMouseWheel

public void disableMouseWheel()

actionPerformed

public void actionPerformed(ActionEvent e)
Specified by:
actionPerformed in interface ActionListener

getSelectedDate

public Date getSelectedDate()
Gets the selected date.

Returns:
the selected date.

getSelectedCalendar

public Calendar getSelectedCalendar()
Gets the selected calendar.

Returns:
the selected calendar

setSelectedDate

public void setSelectedDate(Date selectedDate)
Sets the selected date.

Parameters:
selectedDate - the selected date

getMonthCalendar

protected Calendar getMonthCalendar()
Gets a Calendar representing the month. By default, we use the date of the first day in each month.

Returns:
a Calendar representing the month

updateMonthCalendar

protected void updateMonthCalendar(Calendar calendar)
Updates the calendar to represent the month. By default, we will set the calendar to the first date of each month.

Parameters:
calendar - the calendar to represent to the month.

setSelectedCalendar

public void setSelectedCalendar(Calendar selectedCalendar)
Sets the selected calendar.

Parameters:
selectedCalendar - the selected calendar

setDisplayedYear

public boolean setDisplayedYear(int year)
This method will set the displayed year of MonthChooserPanel.

Parameters:
year - Year to be viewed
Returns:
true if set successfully. Otherwise false.

itemStateChanged

public void itemStateChanged(ItemEvent e)
Specified by:
itemStateChanged in interface ItemListener

createMonthsPanel

protected Component createMonthsPanel()

createMonthPanel

protected Component createMonthPanel()

createMonthLabel

protected JComponent createMonthLabel(int i)

getTextField

protected JTextField getTextField(JSpinner spinner)
Return the formatted text field used by the editor, or null if the editor doesn't descend from JSpinner.DefaultEditor.

Parameters:
spinner - the spinner
Returns:
the text field

createYearPanel

protected Component createYearPanel()

createButtonPanel

protected Component createButtonPanel()

initCalendar

protected void initCalendar()

updateUI

public void updateUI()
Overrides:
updateUI in class JPanel

initComponents

protected void initComponents()

updateCalendar

protected void updateCalendar()

isViewOnly

public boolean isViewOnly()
If the DateChooserPanel is view-only.

Returns:
true if the DateChooserPanel is view-only

setViewOnly

public void setViewOnly(boolean viewOnly)
Sets the view only attribute. If the DateChooserPanel is view-only, user will not be able to change the month or year once it's set.

Parameters:
viewOnly - the flag

updateDayOfWeekLabel

protected void updateDayOfWeekLabel(JComponent dayOfWeekLabel,
                                    Calendar calendar)

updateMonthLabel

protected void updateMonthLabel(JComponent monthLabel,
                                Calendar date,
                                boolean isSelected,
                                boolean isToday)

updateYearLabel

protected void updateYearLabel(JComponent yearLabel,
                               Calendar calendar)

createYearLabel

protected JComponent createYearLabel()

registerKeyStrokes

protected void registerKeyStrokes()

updateButtons

protected void updateButtons()

isShowNoneButton

public boolean isShowNoneButton()
Checks if none button is visible.

Returns:
true if none button is visible.

setShowNoneButton

public void setShowNoneButton(boolean showNoneButton)
Sets the none button visible.

Parameters:
showNoneButton - the flag

isShowThisMonthButton

public boolean isShowThisMonthButton()
Checks if this month button is visible.

Returns:
true if this month button is visible.

setShowThisMonthButton

public void setShowThisMonthButton(boolean showThisMonthButton)
Sets the this month button visible.

Parameters:
showThisMonthButton - the flag

isDateSelected

protected boolean isDateSelected(Calendar calendar)

isToday

protected boolean isToday(Calendar calendar)

getResourceString

protected String getResourceString(String key)
Gets the localized string from resource bundle. Subclass can override it to provide its own string. Available keys are defined in swing.properties that begin with "Date.".

Parameters:
key - the key to get resource string
Returns:
the localized string.

initDateFormat

protected void initDateFormat(Locale locale)

setLocale

public void setLocale(Locale locale)
Overrides:
setLocale in class Component

isMonthOutOfRange

protected boolean isMonthOutOfRange(Calendar calendar)
Checks if the month is out of the range of the DateModel. If true, it will call beep to notify user.

Parameters:
calendar - the calendar.
Returns:
true if the calendar is out of the range. Otherwise false.

getDisplayedCalendar

public Calendar getDisplayedCalendar()

getMonthFormatter

public DateFormat getMonthFormatter()

setMonthFormatter

public void setMonthFormatter(DateFormat monthFormatter)

JIDE 3.5.15