org.jdesktop.swingx.plaf.basic
Class BasicMonthViewUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by org.jdesktop.swingx.plaf.MonthViewUI
          extended by org.jdesktop.swingx.plaf.basic.BasicMonthViewUI

public class BasicMonthViewUI
extends MonthViewUI

Base implementation of the JXMonthView UI.

Note: The api changed considerably between releases 0.9.4 and 0.9.5. The old methods are still available but deprecated and are no longer maintained.

The general drift of the change was to delegate all text rendering to a dedicated rendering controller (currently named RenderingHandler), similar to the collection view rendering. The UI itself keeps layout and positioning of the rendering components. Plus updating on property changes received from the monthView.

The rendering approach is used by default. Subclass providers can turn it off by overriding createRenderingHandler to return null. This is recommended until the change has stabilized. In future, custom painting will be achieved by implementing custom RenderingHandlers.

Painting: coordinate systems.

On the road to "zoomable" date range views (Vista-style).

Added support (doesn't do anything yet, zoom-logic must yet be defined) by way of an active calendar header which is added to the monthView if zoomable. It is disabled by default. In this mode, the view is always traversable and shows exactly one calendar. It is orthogonal to the classic mode, that is client code should not be effected in any way as long as the mode is not explicitly enabled.


Nested Class Summary
protected static class BasicMonthViewUI.RenderingHandler
          The RenderingHandler responsible for text rendering.
 
Field Summary
protected  java.awt.Rectangle calendarGrid
          The bounding box of the grid of visible months.
protected  java.text.SimpleDateFormat dayOfMonthFormatter
          Deprecated. no longer used in paint/layout with renderer.
protected  java.awt.Font derivedFont
          Deprecated. no longer used in paint/layout with renderer.
protected  boolean isLeftToRight
           
static int MONTH_DOWN
          Return value used to identify when the month down button is pressed.
static int MONTH_UP
          Return value used to identify when the month up button is pressed.
protected  javax.swing.Icon monthDownImage
           
protected  java.lang.String[] monthsOfTheYear
          Deprecated. no longer used in paint/layout with renderer.
protected  javax.swing.Icon monthUpImage
           
protected  JXMonthView monthView
          the component we are installed for.
 
Constructor Summary
BasicMonthViewUI()
           
 
Method Summary
protected  org.jdesktop.swingx.plaf.basic.BasicCalendarHeader createCalendarHeader()
           
protected  java.awt.Font createDerivedFont()
          Deprecated. no longer used in paint/layout with renderer.
protected  java.awt.LayoutManager createLayoutManager()
           
protected  java.awt.event.MouseListener createMouseListener()
           
protected  java.awt.event.MouseMotionListener createMouseMotionListener()
           
protected  java.beans.PropertyChangeListener createPropertyChangeListener()
           
protected  CalendarRenderingHandler createRenderingHandler()
          Returns the RenderingHandler to use.
static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
           
protected  java.util.Calendar getCalendar()
          Returns the monthViews calendar configured to the firstDisplayedDate.
protected  java.util.Calendar getCalendar(java.util.Date date)
          Returns the monthViews calendar configured to the given time.
 java.util.Date getDayAtLocation(int x, int y)
          Returns the Date at the given location.
protected  java.awt.Rectangle getDayBounds(java.util.Date date)
          Returns the bounds of the given day.
protected  java.awt.Rectangle getDayBoundsAtLocation(int x, int y)
          Returns the bounds of the day in the grid of days which contains the given location.
protected  java.awt.Rectangle getDayBoundsInMonth(java.util.Date month, int row, int column)
          Returns the bounds of the day box at logical coordinates in the given month.
protected  java.awt.Point getDayGridPosition(java.util.Date date)
          Returns the given date's position in the grid of the month it is contained in.
protected  java.awt.Point getDayGridPositionAtLocation(int x, int y)
          Returns the logical coordinates of the day which contains the given location.
protected  java.util.Date getDayInMonth(java.util.Date month, int row, int column)
          Returns the Date defined by the logical grid coordinates relative to the given month.
protected  java.awt.Dimension getDaySize()
          Returns the size of a day including the padding.
 java.lang.String[] getDaysOfTheWeek()
          Returns an array of String to use as names for the days of the week.
protected  java.util.Date getFirstDisplayedDay()
           
protected  int getFirstDisplayedMonth()
           
protected  int getFirstDisplayedYear()
           
 java.util.Date getLastDisplayedDay()
          Returns the last possible date that can be displayed.
protected  java.util.Date getMonth(int row, int column)
          Returns the Date representing the start of the month at the given logical position in the grid of months.
protected  java.util.Date getMonthAtLocation(int x, int y)
          Returns the Date representing the start of the month which contains the given location.
protected  java.awt.Rectangle getMonthBounds(java.util.Date date)
          Returns the bounds of the month containing the given date.
protected  java.awt.Rectangle getMonthBounds(int row, int column)
          Returns the bounds of the month at the given logical coordinates in the grid of visible months.
protected  java.awt.Rectangle getMonthBoundsAtLocation(int x, int y)
          Returns the bounds of the month which contains the given location.
protected  java.awt.Point getMonthGridPosition(java.util.Date date)
          Returns the logical grid position of the month containing the given date.
protected  java.awt.Point getMonthGridPositionAtLocation(int x, int y)
          Returns the logical coordinates of the month which contains the given location.
protected  java.awt.Rectangle getMonthHeaderBounds(java.util.Date date, boolean includeInsets)
          Returns the bounds of the month containing the given date.
protected  java.awt.Rectangle getMonthHeaderBoundsAtLocation(int x, int y)
          Returns the bounds of the month header which contains the given location.
protected  int getMonthHeaderHeight()
          Returns the height of the month header.
protected  java.awt.Dimension getMonthSize()
          Returns the size of a month.
protected  java.util.SortedSet<java.util.Date> getSelection()
           
protected  java.util.Date getToday()
           
protected  int getTraversableGridPositionAtLocation(int x, int y)
          Mapping pixel to bounds.
protected  int getWeeks(java.util.Calendar month)
          Returns the number of weeks to paint in the current month, as represented by the given calendar.
protected  void installComponents()
          Creates and configures the calendar header.
protected  void installDefaults()
          Installs default values.
protected  void installDelegate()
          Installs this ui delegates properties.
protected  void installKeyboardActions()
           
protected  void installListeners()
           
 void installUI(javax.swing.JComponent c)
          Installs the component as appropriate for the current lf.
protected  boolean isToday(java.util.Date date)
          Returns true if the date passed in is the same as today.
protected  boolean isUIInstallable(java.lang.Object property)
          Checks and returns whether the given property should be replaced by the UI's default value.
 boolean isUsingKeyboard()
           
protected  boolean isZoomable()
           
 void paint(java.awt.Graphics g, javax.swing.JComponent c)
          
protected  void paintBackground(java.awt.Graphics g)
          Paints the background of the component.
protected  void paintBackground(java.awt.Rectangle clip, java.awt.Graphics g)
          Deprecated. no longer used - it's up to subclasses to implement if they think it's needed.
protected  void paintDay(java.awt.Graphics g, int left, int top, java.util.Calendar calendar)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintDayBackground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintDayForeground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintDayForeground(java.awt.Graphics g, java.lang.String numericDay, int x, int y, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintDayHeader(java.awt.Graphics g, java.util.Calendar calendar)
          Paints the day column header.
protected  void paintDayOfMonth(java.awt.Graphics g, java.awt.Rectangle bounds, java.util.Calendar calendar, CalendarState state)
          Paints a day which is of the current month with the given state.
protected  void paintDayOfTheWeekBackground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintDays(java.awt.Graphics g, java.util.Calendar cal)
          Paints the days of the given month.
protected  void paintDays(java.awt.Graphics g, int left, int top, int width, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintDaysOfTheWeek(java.awt.Graphics g, int x, int y, int width, java.util.Calendar calendar)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintDaysOfWeekSeparator(java.awt.Graphics g, java.util.Calendar cal)
          Paints the separator between column header (days of week) and days.
protected  void paintFlaggedDayBackground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintFlaggedDayForeground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintLeadingDay(java.awt.Graphics g, int left, int top, java.util.Calendar calendar)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintLeadingDayBackground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintLeadingDayForeground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintMonth(java.awt.Graphics g, java.util.Calendar calendar)
          Paints the month represented by the given Calendar.
protected  void paintMonth(java.awt.Graphics g, int left, int top, int width, int height, java.util.Calendar calendar)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintMonthHeader(java.awt.Graphics g, java.util.Calendar calendar)
          Paints the header of a month.
protected  void paintMonthHeader(java.awt.Graphics g, int x, int y, int width, java.util.Calendar calendar)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintMonthStringBackground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated.  
protected  void paintMonthStringForeground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintMonthStringForeground(java.awt.Graphics g, java.lang.String monthName, int monthX, int monthY, java.lang.String yearName, int yearX, int yearY, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintTrailingDay(java.awt.Graphics g, int left, int top, java.util.Calendar calendar)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintTrailingDayBackground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintTrailingDayForeground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintUnselectableDayBackground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintUnselectableDayForeground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintWeekHeader(java.awt.Graphics g, java.util.Calendar cal)
          Paints the day column header.
protected  void paintWeekOfYearBackground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintWeekOfYearForeground(java.awt.Graphics g, int x, int y, int width, int height, java.util.Calendar cal)
          Deprecated. no longer used in paint/layout with renderer.
protected  void paintWeekOfYearSeparator(java.awt.Graphics g, java.util.Calendar cal)
          Paints the separator between row header (weeks of year) and days.
protected  void paintWeeksOfYear(java.awt.Graphics g, int x, int initialY, int width, java.util.Calendar cal)
          Deprecated.  
protected  void setFirstDisplayedDay(java.util.Date firstDisplayedDate)
          Sets the firstDisplayedDate property to the given value.
 void setUsingKeyboard(boolean val)
           
protected  void uninstallComponents()
           
protected  void uninstallDefaults()
           
protected  void uninstallKeyboardActions()
           
protected  void uninstallListeners()
           
 void uninstallUI(javax.swing.JComponent c)
           
 void update(java.awt.Graphics g, javax.swing.JComponent c)
          Overridden to extract the background painting for ease-of-use of subclasses.
protected  void updateComponentInputMap()
          Binds/clears the keystrokes in the component input map, based on the monthView's componentInputMap enabled property.
protected  void updateLocale()
          Deprecated. use updateLocale(boolean)
protected  void updateLocale(boolean revalidate)
          Updates internal state according to monthView's locale.
protected  void updateZoomable()
           
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, getPreferredSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MONTH_DOWN

public static final int MONTH_DOWN
Return value used to identify when the month down button is pressed.

See Also:
Constant Field Values

MONTH_UP

public static final int MONTH_UP
Return value used to identify when the month up button is pressed.

See Also:
Constant Field Values

dayOfMonthFormatter

@Deprecated
protected final java.text.SimpleDateFormat dayOfMonthFormatter
Deprecated. no longer used in paint/layout with renderer.
Formatter used to format the day of the week to a numerical value.


monthsOfTheYear

@Deprecated
protected java.lang.String[] monthsOfTheYear
Deprecated. no longer used in paint/layout with renderer.
localized names of all months. protected for testing only! PENDING: JW - should be property on JXMonthView, for symmetry with daysOfTheWeek?


monthView

protected JXMonthView monthView
the component we are installed for.


derivedFont

@Deprecated
protected java.awt.Font derivedFont
Deprecated. no longer used in paint/layout with renderer.
Used as the font for days of week and title.


isLeftToRight

protected boolean isLeftToRight

monthUpImage

protected javax.swing.Icon monthUpImage

monthDownImage

protected javax.swing.Icon monthDownImage

calendarGrid

protected java.awt.Rectangle calendarGrid
The bounding box of the grid of visible months.

Constructor Detail

BasicMonthViewUI

public BasicMonthViewUI()
Method Detail

createUI

public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)

installUI

public void installUI(javax.swing.JComponent c)
Installs the component as appropriate for the current lf. PENDING JW: clarify sequence of installXX methods.

Overrides:
installUI in class javax.swing.plaf.ComponentUI

uninstallUI

public void uninstallUI(javax.swing.JComponent c)
Overrides:
uninstallUI in class javax.swing.plaf.ComponentUI

installComponents

protected void installComponents()
Creates and configures the calendar header. Adds to the MonthView if zoomable.


uninstallComponents

protected void uninstallComponents()

installDefaults

protected void installDefaults()
Installs default values. This is refactored to only install default properties on the monthView. Extracted install of this delegate's properties into installDelegate.


installDelegate

protected void installDelegate()
Installs this ui delegates properties.


isUIInstallable

protected boolean isUIInstallable(java.lang.Object property)
Checks and returns whether the given property should be replaced by the UI's default value.

Parameters:
property - the property to check.
Returns:
true if the given property should be replaced by the UI#s default value, false otherwise.

uninstallDefaults

protected void uninstallDefaults()

installKeyboardActions

protected void installKeyboardActions()

uninstallKeyboardActions

protected void uninstallKeyboardActions()

installListeners

protected void installListeners()

uninstallListeners

protected void uninstallListeners()

createRenderingHandler

protected CalendarRenderingHandler createRenderingHandler()
Returns the RenderingHandler to use. May return null to indicate that the "old" painting mechanism should be used. This implementation returns an instance of RenderingHandler.

Returns:
the renderingHandler to use for painting the day boxes or null if the old painting mechanism should be used.

updateComponentInputMap

protected void updateComponentInputMap()
Binds/clears the keystrokes in the component input map, based on the monthView's componentInputMap enabled property.

See Also:
JXMonthView.isComponentInputMapEnabled()

updateLocale

@Deprecated
protected void updateLocale()
Deprecated. use updateLocale(boolean)

Updates internal state according to monthView's locale. Revalidates the monthView.


updateLocale

protected void updateLocale(boolean revalidate)
Updates internal state according to monthView's locale. Revalidates the monthView if the boolean parameter is true.

Parameters:
revalidate - a boolean indicating whether the monthView should be revalidated after the change.

getDaysOfTheWeek

public java.lang.String[] getDaysOfTheWeek()
Description copied from class: MonthViewUI
Returns an array of String to use as names for the days of the week.

Specified by:
getDaysOfTheWeek in class MonthViewUI
Returns:
array of names for the days of the week.

createPropertyChangeListener

protected java.beans.PropertyChangeListener createPropertyChangeListener()

createLayoutManager

protected java.awt.LayoutManager createLayoutManager()

createMouseListener

protected java.awt.event.MouseListener createMouseListener()

createMouseMotionListener

protected java.awt.event.MouseMotionListener createMouseMotionListener()

isUsingKeyboard

public boolean isUsingKeyboard()

setUsingKeyboard

public void setUsingKeyboard(boolean val)

getDayBoundsAtLocation

protected java.awt.Rectangle getDayBoundsAtLocation(int x,
                                                    int y)
Returns the bounds of the day in the grid of days which contains the given location. The bounds are in monthView screen coordinate system.

Note: this is a pure geometric mapping. The returned rectangle need not necessarily map to a date in the month which contains the location, it can represent a week-number/column header or a leading/trailing date.

Parameters:
x - the x position of the location in pixel
y - the y position of the location in pixel
Returns:
the bounds of the day which contains the location, or null if outside

getDayGridPositionAtLocation

protected java.awt.Point getDayGridPositionAtLocation(int x,
                                                      int y)
Returns the logical coordinates of the day which contains the given location. The p.x of the returned value represents the day of week, the p.y represents the week of the month. The transformation takes care of ComponentOrientation.

Note: this is a pure geometric mapping. The returned grid position need not necessarily map to a date in the month which contains the location, it can represent a week-number/column header or a leading/trailing date.

Parameters:
x - the x position of the location in pixel
y - the y position of the location in pixel
Returns:
the logical coordinates of the day in the grid of days in a month or null if outside.

getDayGridPosition

protected java.awt.Point getDayGridPosition(java.util.Date date)
Returns the given date's position in the grid of the month it is contained in.

Parameters:
date - the Date to get the logical position for, must not be null.
Returns:
the logical coordinates of the day in the grid of days in a month or null if the Date is not visible.

getDayAtLocation

public java.util.Date getDayAtLocation(int x,
                                       int y)
Returns the Date at the given location. May be null if the coordinates don't map to a day in the month which contains the coordinates. Specifically: hitting leading/trailing dates returns null. Mapping pixel to calendar day.

Specified by:
getDayAtLocation in class MonthViewUI
Parameters:
x - the x position of the location in pixel
y - the y position of the location in pixel
Returns:
the day at the given location or null if the location doesn't map to a day in the month which contains the coordinates.

getDayBounds

protected java.awt.Rectangle getDayBounds(java.util.Date date)
Returns the bounds of the given day. The bounds are in monthView coordinate system.

PENDING JW: this most probably should be public as it is the logical reverse of getDayAtLocation

Parameters:
date - the Date to return the bounds for. Must not be null.
Returns:
the bounds of the given date or null if not visible.

getDayBoundsInMonth

protected java.awt.Rectangle getDayBoundsInMonth(java.util.Date month,
                                                 int row,
                                                 int column)
Returns the bounds of the day box at logical coordinates in the given month. The row's range is from DAY_HEADER to WEEKS_IN_MONTH - 1. Column's range is from WEEK_HEADER to DAYS_IN_WEEK - 1.

Parameters:
month - the month containing the day box
row - the logical row (== week) coordinate in the day grid
column - the logical column (== day) coordinate in the day grid
Returns:
the bounds of the daybox or null if not showing
Throws:
java.lang.IllegalArgumentException - if row or column are out off range.

getDayInMonth

protected java.util.Date getDayInMonth(java.util.Date month,
                                       int row,
                                       int column)
Returns the Date defined by the logical grid coordinates relative to the given month. May be null if the logical coordinates represent a header in the day grid or is outside of the given month. Mapping logical day grid coordinates to Date.

PENDING JW: relax the startOfMonth pre? Why did I require it?

Parameters:
month - a calendar representing the first day of the month, must not be null.
row - the logical row index in the day grid of the month
column - the logical column index in the day grid of the month
Returns:
the day at the logical grid coordinates in the given month or null if the coordinates
Throws:
java.lang.IllegalStateException - if the month is not the start of the month.

getTraversableGridPositionAtLocation

protected int getTraversableGridPositionAtLocation(int x,
                                                   int y)
Mapping pixel to bounds.

PENDING JW: define the "action grid". Currently this replaces the old version to remove all internal usage of deprecated methods.

Parameters:
x - the x position of the location in pixel
y - the y position of the location in pixel
Returns:
the bounds of the active header area in containing the location or null if outside.

getMonthHeaderBoundsAtLocation

protected java.awt.Rectangle getMonthHeaderBoundsAtLocation(int x,
                                                            int y)
Returns the bounds of the month header which contains the given location. The bounds are in monthView coordinate system.

Parameters:
x - the x position of the location in pixel
y - the y position of the location in pixel
Returns:
the bounds of the month which contains the location, or null if outside

getMonthBoundsAtLocation

protected java.awt.Rectangle getMonthBoundsAtLocation(int x,
                                                      int y)
Returns the bounds of the month which contains the given location. The bounds are in monthView coordinate system.

Mapping pixel to bounds.

Parameters:
x - the x position of the location in pixel
y - the y position of the location in pixel
Returns:
the bounds of the month which contains the location, or null if outside

getMonthGridPositionAtLocation

protected java.awt.Point getMonthGridPositionAtLocation(int x,
                                                        int y)
Returns the logical coordinates of the month which contains the given location. The p.x of the returned value represents the column, the p.y represents the row the month is shown in. The transformation takes care of ComponentOrientation.

Mapping pixel to logical grid coordinates.

Parameters:
x - the x position of the location in pixel
y - the y position of the location in pixel
Returns:
the logical coordinates of the month in the grid of month shown by this monthView or null if outside.

getMonthAtLocation

protected java.util.Date getMonthAtLocation(int x,
                                            int y)
Returns the Date representing the start of the month which contains the given location.

Mapping pixel to calendar day.

Parameters:
x - the x position of the location in pixel
y - the y position of the location in pixel
Returns:
the start of the month which contains the given location or null if the location is outside the grid of months.

getMonth

protected java.util.Date getMonth(int row,
                                  int column)
Returns the Date representing the start of the month at the given logical position in the grid of months.

Mapping logical grid coordinates to Calendar.

Parameters:
row - the rowIndex in the grid of months.
column - the columnIndex in the grid months.
Returns:
a Date representing the start of the month at the given logical coordinates.
See Also:
getMonthGridPosition(Date)

getMonthGridPosition

protected java.awt.Point getMonthGridPosition(java.util.Date date)
Returns the logical grid position of the month containing the given date. The Point's x value is the column in the grid of months, the y value is the row in the grid of months. Mapping Date to logical grid position, this is the reverse of getMonth(int, int).

Parameters:
date - the Date to return the bounds for. Must not be null.
Returns:
the postion of the month that contains the given date or null if not visible.
See Also:
getMonth(int, int), getMonthBounds(int, int)

getMonthBounds

protected java.awt.Rectangle getMonthBounds(int row,
                                            int column)
Returns the bounds of the month at the given logical coordinates in the grid of visible months.

Mapping logical grip position to pixel.

Parameters:
row - the rowIndex in the grid of months.
column - the columnIndex in the grid months.
Returns:
the bounds of the month at the given logical logical position.
See Also:
getMonthGridPositionAtLocation(int, int), getMonthBoundsAtLocation(int, int)

getMonthBounds

protected java.awt.Rectangle getMonthBounds(java.util.Date date)
Returns the bounds of the month containing the given date. The bounds are in monthView coordinate system.

Mapping Date to pixel.

Parameters:
date - the Date to return the bounds for. Must not be null.
Returns:
the bounds of the month that contains the given date or null if not visible.
See Also:
getMonthAtLocation(int, int)

getMonthHeaderBounds

protected java.awt.Rectangle getMonthHeaderBounds(java.util.Date date,
                                                  boolean includeInsets)
Returns the bounds of the month containing the given date. The bounds are in monthView coordinate system.

Mapping Date to pixel.

Parameters:
date - the Date to return the bounds for. Must not be null.
Returns:
the bounds of the month that contains the given date or null if not visible.
See Also:
getMonthAtLocation(int, int)

getMonthSize

protected java.awt.Dimension getMonthSize()
Returns the size of a month.

Returns:
the size of a month.

getDaySize

protected java.awt.Dimension getDaySize()
Returns the size of a day including the padding.

Returns:
the size of a month.

getMonthHeaderHeight

protected int getMonthHeaderHeight()
Returns the height of the month header.

Returns:
the height of the month header.

isZoomable

protected boolean isZoomable()
Returns:

update

public void update(java.awt.Graphics g,
                   javax.swing.JComponent c)
Overridden to extract the background painting for ease-of-use of subclasses.

Overrides:
update in class javax.swing.plaf.ComponentUI

paintBackground

protected void paintBackground(java.awt.Graphics g)
Paints the background of the component. This implementation fill the monthView's area with its background color if opaque, does nothing if not opaque. Subclasses can override but must comply to opaqueness contract.

Parameters:
g - the Graphics to fill.

paint

public void paint(java.awt.Graphics g,
                  javax.swing.JComponent c)

Overrides:
paint in class javax.swing.plaf.ComponentUI

paintMonth

protected void paintMonth(java.awt.Graphics g,
                          java.util.Calendar calendar)
Paints the month represented by the given Calendar.

Parameters:
g - the graphics to paint into
calendar - the calendar representing the month to paint.

paintMonthHeader

protected void paintMonthHeader(java.awt.Graphics g,
                                java.util.Calendar calendar)
Paints the header of a month.

Parameters:
g - the graphics to paint into
calendar - the calendar representing the the month to paint, must not be null

paintDayHeader

protected void paintDayHeader(java.awt.Graphics g,
                              java.util.Calendar calendar)
Paints the day column header.

Parameters:
g - the graphics to paint into
calendar - the calendar representing the the month to paint, must not be null

paintWeekHeader

protected void paintWeekHeader(java.awt.Graphics g,
                               java.util.Calendar cal)
Paints the day column header.

Parameters:
g - the graphics to paint into
calendar - the calendar representing the the month to paint, must not be null

paintDays

protected void paintDays(java.awt.Graphics g,
                         java.util.Calendar cal)
Paints the days of the given month.

Parameters:
g - the graphics to paint into
calendar - the calendar representing the the month to paint, must not be null

paintDayOfMonth

protected void paintDayOfMonth(java.awt.Graphics g,
                               java.awt.Rectangle bounds,
                               java.util.Calendar calendar,
                               CalendarState state)
Paints a day which is of the current month with the given state.

PENDING JW: mis-nomer - this is in fact called for rendering any day-related state (including weekOfYear, dayOfWeek headers) and for rendering the month header as well, that is from everywhere. Rename to paintSomethingGeneral. Think about impact for subclasses (what do they really need? feedback please!)

Parameters:
g - the graphics to paint into.
bounds - the rectangle to paint the day into
calendar - the calendar representing the day to paint
state - the calendar state

paintWeekOfYearSeparator

protected void paintWeekOfYearSeparator(java.awt.Graphics g,
                                        java.util.Calendar cal)
Paints the separator between row header (weeks of year) and days.

Parameters:
g - the Graphics to paint into
cal - the calendar representing the month

paintDaysOfWeekSeparator

protected void paintDaysOfWeekSeparator(java.awt.Graphics g,
                                        java.util.Calendar cal)
Paints the separator between column header (days of week) and days.

Parameters:
g - the Graphics to paint into
cal - the calendar representing the month

getWeeks

protected int getWeeks(java.util.Calendar month)
Returns the number of weeks to paint in the current month, as represented by the given calendar. Note: the given calendar must not be changed.

Parameters:
month - the calendar specifying the the first day of the month to paint, must not be null
Returns:
the number of weeks of this month.

getCalendar

protected java.util.Calendar getCalendar()
Returns the monthViews calendar configured to the firstDisplayedDate. NOTE: it's safe to change the calendar state without resetting because it's JXMonthView's responsibility to protect itself.

Returns:
the monthView's calendar, configured with the firstDisplayedDate.

getCalendar

protected java.util.Calendar getCalendar(java.util.Date date)
Returns the monthViews calendar configured to the given time. NOTE: it's safe to change the calendar state without resetting because it's JXMonthView's responsibility to protect itself.

Parameters:
date - the date to configure the calendar with
Returns:
the monthView's calendar, configured with the given date.

getLastDisplayedDay

public java.util.Date getLastDisplayedDay()
Returns the last possible date that can be displayed. This is implemented by the UI since it is in control of layout and may possibly yeild different results based on implementation.

It's up to the UI to keep this property, based on internal state and the firstDisplayed as controlled by the JXMonthView.

Specified by:
getLastDisplayedDay in class MonthViewUI
Returns:
Date The date.

setFirstDisplayedDay

protected void setFirstDisplayedDay(java.util.Date firstDisplayedDate)
Sets the firstDisplayedDate property to the given value. Must update dependent state as well.

Here: updated lastDisplayedDatefirstDisplayedMonth/Year accordingly.

PENDING JW: remove call to repaint() because this method is used both at install and from propertyChange

Parameters:
firstDisplayedDate - the firstDisplayedDate to set

getFirstDisplayedDay

protected java.util.Date getFirstDisplayedDay()
Returns:
the firstDisplayedDate

getFirstDisplayedMonth

protected int getFirstDisplayedMonth()
Returns:
the firstDisplayedMonth

getFirstDisplayedYear

protected int getFirstDisplayedYear()
Returns:
the firstDisplayedYear

getSelection

protected java.util.SortedSet<java.util.Date> getSelection()
Returns:
the selection

getToday

protected java.util.Date getToday()
Returns:
the start of today.

isToday

protected boolean isToday(java.util.Date date)
Returns true if the date passed in is the same as today. PENDING JW: really want the exact test?

Parameters:
date - long representing the date you want to compare to today.
Returns:
true if the date passed is the same as today.

createDerivedFont

@Deprecated
protected java.awt.Font createDerivedFont()
Deprecated. no longer used in paint/layout with renderer.

Create a derived font used to when painting various pieces of the month view component. This method will be called whenever the font on the component is set so a new derived font can be created.


updateZoomable

protected void updateZoomable()

createCalendarHeader

protected org.jdesktop.swingx.plaf.basic.BasicCalendarHeader createCalendarHeader()

paintMonth

@Deprecated
protected void paintMonth(java.awt.Graphics g,
                                     int left,
                                     int top,
                                     int width,
                                     int height,
                                     java.util.Calendar calendar)
Deprecated. no longer used in paint/layout with renderer.

Paints a month. It is assumed the given calendar is already set to the first day of the month to be painted.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object.
left - x location of month
top - y location of month
width - width of month
height - height of month
calendar - the calendar specifying the the first day of the month to paint, must not be null

paintMonthHeader

@Deprecated
protected void paintMonthHeader(java.awt.Graphics g,
                                           int x,
                                           int y,
                                           int width,
                                           java.util.Calendar calendar)
Deprecated. no longer used in paint/layout with renderer.

Paints the header of a month. It is assumed the given calendar is already set to the first day of the month to be painted.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object.
x - x location of month
y - y location of month
width - width of month
height - height of month
calendar - the calendar specifying the the first day of the month to paint, must not be null

paintMonthStringBackground

@Deprecated
protected void paintMonthStringBackground(java.awt.Graphics g,
                                                     int x,
                                                     int y,
                                                     int width,
                                                     int height,
                                                     java.util.Calendar cal)
Deprecated. 

Paints the background of the month string. The bounding box for this background can be modified by setting its insets via setMonthStringInsets. The color of the background can be set via setMonthStringBackground. PENDING JW: switch over to use renderer. Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to.
x - x-coordinate of upper left corner.
y - y-coordinate of upper left corner.
width - width of the bounding box.
height - height of the bounding box.
See Also:
JXMonthView.setMonthStringBackground(java.awt.Color), JXMonthView.setMonthStringInsets(java.awt.Insets)

paintMonthStringForeground

@Deprecated
protected void paintMonthStringForeground(java.awt.Graphics g,
                                                     int x,
                                                     int y,
                                                     int width,
                                                     int height,
                                                     java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

PENDING JW: switch over to use renderer. Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to.
x - x-coordinate of upper left corner.
y - y-coordinate of upper left corner.
width - width of the bounding box.
height - height of the bounding box.
cal - the calendar specifying the day to use, must not be null

paintMonthStringForeground

@Deprecated
protected void paintMonthStringForeground(java.awt.Graphics g,
                                                     java.lang.String monthName,
                                                     int monthX,
                                                     int monthY,
                                                     java.lang.String yearName,
                                                     int yearX,
                                                     int yearY,
                                                     java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paints only text for month and year. No calculations made. Used by custom LAFs.

Note: the given calendar must not be changed.

Parameters:
g - Graphics to paint into.
monthName - Name of the month.
monthX - Month string x coordinate.
monthY - Month string y coordinate.
yearName - Name (number) of the year.
yearX - Year string x coordinate.
yearY - Year string y coordinate.

paintWeekOfYearBackground

@Deprecated
protected void paintWeekOfYearBackground(java.awt.Graphics g,
                                                    int x,
                                                    int y,
                                                    int width,
                                                    int height,
                                                    java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

PENDING JW: this implementation actually only paints the line separating the weekOfYear column from the days.

Parameters:
g -
x -
y -
width -
height -
cal -

paintDays

@Deprecated
protected void paintDays(java.awt.Graphics g,
                                    int left,
                                    int top,
                                    int width,
                                    java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paints all days in the days' grid, that is the month area below the daysOfWeek and to the right/left (depending on the monthView's componentOrientation) of the weekOfYears. The calendar represents the first day of the month to paint.

Note: the calendar must not be changed.

Parameters:
g - Graphics object.
left - the left boundary of the day grid.
top - the upper boundary of the day grid
width - the width of the day grid.
cal - the calendar specifying the the first day of the month to paint, must not be null

paintDayOfTheWeekBackground

@Deprecated
protected void paintDayOfTheWeekBackground(java.awt.Graphics g,
                                                      int x,
                                                      int y,
                                                      int width,
                                                      int height,
                                                      java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

PENDING JW: this implementation actually only paints the line separating the daysOfTheWeek row from the days.

Parameters:
g - Graphics object.
x - x location of day header
y - y location of day header
width - width of day header
height - height day header
calendar - the calendar specifying the the first day of the month to paint, must not be null

paintBackground

@Deprecated
protected void paintBackground(java.awt.Rectangle clip,
                                          java.awt.Graphics g)
Deprecated. no longer used - it's up to subclasses to implement if they think it's needed.

Paints background of the given rectangle. PENDING JW: this is called from paint, which shouldnt do it? It's the responsibility of super update(comp, g).

Parameters:
clip -
g -

paintDaysOfTheWeek

@Deprecated
protected void paintDaysOfTheWeek(java.awt.Graphics g,
                                             int x,
                                             int y,
                                             int width,
                                             java.util.Calendar calendar)
Deprecated. no longer used in paint/layout with renderer.

Paints the row which contains the days of the week.

Parameters:
g -
x -
y -
width -
calendar -

paintDay

@Deprecated
protected void paintDay(java.awt.Graphics g,
                                   int left,
                                   int top,
                                   java.util.Calendar calendar)
Deprecated. no longer used in paint/layout with renderer.

Paints a day the current month, represented by the calendar in a day-box located at left/top. The size of the day-box is defined by fullBoxWidth/Height. The appearance of the day depends on its state (like unselectable, flagged, selected)

Note: the given calendar must not be changed.

Parameters:
g - the Graphics to paint into.
left - the left boundary of the day-box to paint.
top - the upper boundary of the day-box to paint.
calendar - the calendar specifying the the day to paint, must not be null

paintTrailingDay

@Deprecated
protected void paintTrailingDay(java.awt.Graphics g,
                                           int left,
                                           int top,
                                           java.util.Calendar calendar)
Deprecated. no longer used in paint/layout with renderer.

Paints a trailing day of the current month, represented by the calendar, in a day-box located at left/top. The size of the day-box is defined by fullBoxWidth/Height. Does nothing if the monthView's isShowingTrailingDates is false.

Note: the given calendar must not be changed.

Parameters:
g - the Graphics to paint into.
left - the left boundary of the day-box to paint.
top - the upper boundary of the day-box to paint.
calendar - the calendar specifying the the day to paint, must not be null

paintLeadingDay

@Deprecated
protected void paintLeadingDay(java.awt.Graphics g,
                                          int left,
                                          int top,
                                          java.util.Calendar calendar)
Deprecated. no longer used in paint/layout with renderer.

Paints a leading day of the current month, represented by the calendar, in a day-box located at left/top. The size of the day-box is defined by fullBoxWidth/Height. Does nothing if the monthView's isShowingLeadingDates is false.

Note: the given calendar must not be changed.

Parameters:
g - the Graphics to paint into.
left - the left boundary of the day-box to paint.
top - the upper boundary of the day-box to paint.
calendar - the calendar specifying the the day to paint, must not be null

paintWeeksOfYear

@Deprecated
protected void paintWeeksOfYear(java.awt.Graphics g,
                                           int x,
                                           int initialY,
                                           int width,
                                           java.util.Calendar cal)
Deprecated. 

Paints the weeks of year if the showingWeek property is true. Does nothing otherwise. It is assumed the given calendar is already set to the first day of the month. The calendar is unchanged when leaving this method. Note: the given calendar must not be changed. PENDING JW: this implementation doesn't need the height - should it be given anyway for symetry in case subclasses need it?

Parameters:
g - Graphics object.
x - x location of month
initialY - y the upper bound of the "weekNumbers-box"
width - width of month
cal - the calendar specifying the the first day of the month to paint, must not be null

paintWeekOfYearForeground

@Deprecated
protected void paintWeekOfYearForeground(java.awt.Graphics g,
                                                    int x,
                                                    int y,
                                                    int width,
                                                    int height,
                                                    java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paints the week of the year of the week of the year represented by the given calendar.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object
x - x-coordinate of upper left corner.
y - y-coordinate of upper left corner.
width - width of bounding box
height - height of bounding box

paintDayBackground

@Deprecated
protected void paintDayBackground(java.awt.Graphics g,
                                             int x,
                                             int y,
                                             int width,
                                             int height,
                                             java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paint the background for the day specified by the given calendar.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
width - width of bounding box for the day
height - height of bounding box for the day
cal - the calendar specifying the day to paint, must not be null
See Also:
org.jdesktop.swingx.JXMonthView#isSelectedDate, isToday(java.util.Date)

paintDayForeground

@Deprecated
protected void paintDayForeground(java.awt.Graphics g,
                                             int x,
                                             int y,
                                             int width,
                                             int height,
                                             java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paint the foreground for the specified day.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
width - width of bounding box for the day
height - height of bounding box for the day
cal - the calendar specifying the day to paint, must not be null

paintDayForeground

@Deprecated
protected void paintDayForeground(java.awt.Graphics g,
                                             java.lang.String numericDay,
                                             int x,
                                             int y,
                                             java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paints string of the day. No calculations made. Used by LAFs.

Note: the given calendar must not be changed.

Parameters:
g - Graphics to paint on.
numericDay - Text representation of the day.
x - X coordinate of the upper right corner.
y - Y coordinate of the upper right corner.

paintFlaggedDayBackground

@Deprecated
protected void paintFlaggedDayBackground(java.awt.Graphics g,
                                                    int x,
                                                    int y,
                                                    int width,
                                                    int height,
                                                    java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paint the background for the specified flagged day. The default implementation just calls paintDayBackground.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
width - width of bounding box for the day
height - height of bounding box for the day
cal - the calendar specifying the day to paint, must not be null

paintFlaggedDayForeground

@Deprecated
protected void paintFlaggedDayForeground(java.awt.Graphics g,
                                                    int x,
                                                    int y,
                                                    int width,
                                                    int height,
                                                    java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paint the foreground for the specified flagged day.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
width - width of bounding box for the day
height - height of bounding box for the day
cal - the calendar specifying the day to paint, must not be null

paintUnselectableDayBackground

@Deprecated
protected void paintUnselectableDayBackground(java.awt.Graphics g,
                                                         int x,
                                                         int y,
                                                         int width,
                                                         int height,
                                                         java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paint the foreground for the specified unselectable day.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
width - width of bounding box for the day
height - height of bounding box for the day
cal - the calendar specifying the day to paint, must not be null

paintUnselectableDayForeground

@Deprecated
protected void paintUnselectableDayForeground(java.awt.Graphics g,
                                                         int x,
                                                         int y,
                                                         int width,
                                                         int height,
                                                         java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paint the foreground for the specified unselectable day.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
width - width of bounding box for the day
height - height of bounding box for the day
cal - the calendar specifying the day to paint, must not be null

paintLeadingDayBackground

@Deprecated
protected void paintLeadingDayBackground(java.awt.Graphics g,
                                                    int x,
                                                    int y,
                                                    int width,
                                                    int height,
                                                    java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paint the background for the specified leading day.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
width - width of bounding box for the day
height - height of bounding box for the day
cal - the calendar specifying the day to paint, must not be null

paintLeadingDayForeground

@Deprecated
protected void paintLeadingDayForeground(java.awt.Graphics g,
                                                    int x,
                                                    int y,
                                                    int width,
                                                    int height,
                                                    java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paint the foreground for the specified leading day.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
width - width of bounding box for the day
height - height of bounding box for the day
cal - the calendar specifying the day to paint, must not be null

paintTrailingDayBackground

@Deprecated
protected void paintTrailingDayBackground(java.awt.Graphics g,
                                                     int x,
                                                     int y,
                                                     int width,
                                                     int height,
                                                     java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paint the background for the specified trailing day.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
width - width of bounding box for the day
height - height of bounding box for the day
cal - the calendar specifying the day to paint, must not be null

paintTrailingDayForeground

@Deprecated
protected void paintTrailingDayForeground(java.awt.Graphics g,
                                                     int x,
                                                     int y,
                                                     int width,
                                                     int height,
                                                     java.util.Calendar cal)
Deprecated. no longer used in paint/layout with renderer.

Paint the foreground for the specified trailing day.

Note: the given calendar must not be changed.

Parameters:
g - Graphics object to paint to
x - x-coordinate of upper left corner
y - y-coordinate of upper left corner
width - width of bounding box for the day
height - height of bounding box for the day
cal - the calendar specifying the day to paint, must not be null