Class BasicMonthViewUI
- java.lang.Object
-
- javax.swing.plaf.ComponentUI
-
- org.jdesktop.swingx.plaf.MonthViewUI
-
- org.jdesktop.swingx.plaf.basic.BasicMonthViewUI
-
public class BasicMonthViewUI extends MonthViewUI
Base implementation of theJXMonthView
UI.Note: The api changed considerably between releases 0.9.4 and 0.9.5.
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.
Painting: coordinate systems.
- Screen coordinates of months/days, accessible via the getXXBounds() methods. These coordinates are absolute in the system of the monthView.
- The grid of visible months with logical row/column coordinates. The logical coordinates are adjusted to ComponentOrientation.
- The grid of days in a month with logical row/column coordinates. The logical coordinates are adjusted to ComponentOrientation. The columns are the (optional) week header and the days of the week. The rows are the day header and the weeks in a month. The day header shows the localized names of the days and has the row coordinate DAY_HEADER_ROW. It is shown always. The row header shows the week number in the year and has the column coordinate WEEK_HEADER_COLUMN. It is shown only if the showingWeekNumber property is true.
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.
NOTE to LAF implementors: the active calendar header is very, very, very raw and sure to change without much notice. Better not yet to support it right now.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
BasicMonthViewUI.Handler
private class
BasicMonthViewUI.KeyboardAction
Class that supports keyboard traversal of the JXMonthView component.protected static class
BasicMonthViewUI.RenderingHandler
Empty subclass for backward compatibility.
-
Field Summary
Fields Modifier and Type Field Description private int
arrowPaddingX
The padding for month traversal icons.private int
arrowPaddingY
private static int
CALENDAR_SPACING
private int
calendarColumnCount
The number of calendars displayed horizontally.protected java.awt.Rectangle
calendarGrid
The bounding box of the grid of visible months.private CalendarHeaderHandler
calendarHeaderHandler
The CalendarHeaderHandler which provides the header component if zoomable.private int
calendarHeight
the height of a single month display.private int
calendarRowCount
The number of calendars displayed vertically.private int
calendarWidth
the width of a single month display.protected static int
DAY_HEADER_ROW
protected static int
DAYS_IN_WEEK
private java.lang.String[]
daysOfTheWeek
The Strings used for the day headers.protected static int
FIRST_DAY_COLUMN
protected static int
FIRST_WEEK_ROW
private int
fullBoxHeight
height of a "day" box including the monthView's box padding this is the same for days-of-the-week, weeks-of-the-year and daysprivate int
fullBoxWidth
width of a "day" box including the monthView's box padding this is the same for days-of-the-week, weeks-of-the-year and daysprivate int
fullCalendarHeight
the height of a single month grid cell, including padding.private int
fullCalendarWidth
the width of a single month grid cell, including padding.private int
fullMonthBoxHeight
height of month header including the monthView's box padding.private BasicMonthViewUI.Handler
handler
protected boolean
isLeftToRight
protected static int
LAST_DAY_COLUMN
protected static int
LAST_WEEK_ROW
private java.util.Date
lastDisplayedDate
end of day of the last visible month.private static java.util.logging.Logger
LOG
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 javax.swing.Icon
monthUpImage
protected JXMonthView
monthView
the component we are installed for.private java.awt.event.MouseListener
mouseListener
private java.awt.event.MouseMotionListener
mouseMotionListener
private java.util.SortedSet<java.util.Date>
originalDateSpan
Date span used by the keyboard actions to track the original selection.private java.util.Date
pivotDate
For interval selections we need to record the date we pivot around.private java.beans.PropertyChangeListener
propertyChangeListener
private javax.swing.CellRendererPane
rendererPane
The CellRendererPane for stamping rendering comps.private CalendarRenderingHandler
renderingHandler
Provider of configured components for text rendering.private boolean
usingKeyboard
//---------- fields related to selection/navigation /** flag indicating keyboard navigation.protected static int
WEEK_HEADER_COLUMN
protected static int
WEEKS_IN_MONTH
-
Constructor Summary
Constructors Constructor Description BasicMonthViewUI()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private int
calculateCalendarGridHeight()
private int
calculateCalendarGridWidth()
private int
calculateCalendarGridX()
private int
calculateCalendarGridY()
private void
calculateMonthGridBounds()
Calculates the bounds of the grid of months.private void
calculateMonthGridLayoutProperties()
Called from layout: calculates properties of grid of months.private void
calculateMonthGridRowColumnCount()
Calculates and updates the numCalCols/numCalRows that determine the number of calendars that can be displayed.private boolean
canSelectByMode()
temporary: removed SelectionMode.NO_SELECTION, replaced all access by this method to enable easy re-adding, if we want it.private void
checkValidRow(int row, int column)
protected CalendarHeaderHandler
createCalendarHeaderHandler()
Creates and returns a calendar header handler which provides and configures a component for use in a zoomable monthView.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 theCalendarRenderingHandler
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.protected CalendarHeaderHandler
getCalendarHeaderHandler()
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()
Returns the first displayed day.protected int
getFirstDisplayedMonth()
protected int
getFirstDisplayedYear()
private BasicMonthViewUI.Handler
getHandler()
protected CalendarHeaderHandler
getHeaderFromUIManager()
Returns a CalendarHeaderHandler looked up in the UIManager.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(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
getMonthBounds(java.util.Date date)
Returns the bounds of the month containing the given date.protected java.awt.Rectangle
getMonthBoundsAtLocation(int x, int y)
Returns the bounds of the month which contains the given location.protected java.awt.Rectangle
getMonthDetailsBoundsAtLocation(int x, int y)
Returns the bounds of the month details 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 CalendarRenderingHandler
getRenderingHandler()
protected java.util.SortedSet<java.util.Date>
getSelection()
private java.awt.Rectangle
getSeparatorBounds(java.util.Calendar month, int row, int column)
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 installs the calendar header handler.protected void
installDefaults()
Installs default values.protected void
installDelegate()
Installs this ui delegate's properties.private void
installKeyBindings(int type)
protected void
installKeyboardActions()
protected void
installListeners()
protected void
installRenderingHandler()
Creates and installs the renderingHandler and infrastructure to use it.void
installUI(javax.swing.JComponent c)
Installs the component as appropriate for the current lf.private CalendarHeaderHandler
instantiateClass(java.lang.Class<?> handlerClass)
private CalendarHeaderHandler
instantiateClass(java.lang.String handlerClassName)
protected boolean
isToday(java.util.Date date)
Returns true if the date passed in is the same as today.boolean
isUsingKeyboard()
private boolean
isVisible(java.util.Date date)
Returns a boolean indicating if the given Date is visible.protected boolean
isZoomable()
private void
nextMonth()
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
paintDayHeader(java.awt.Graphics g, java.util.Calendar month)
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
paintDays(java.awt.Graphics g, java.util.Calendar month)
Paints the days of the given month.protected void
paintDaysOfWeekSeparator(java.awt.Graphics g, java.util.Calendar month)
Paints the separator between column header (days of week) and days.protected void
paintMonth(java.awt.Graphics g, java.util.Calendar month)
Paints the month represented by the given Calendar.protected void
paintMonthHeader(java.awt.Graphics g, java.util.Calendar month)
Paints the header of a month.protected void
paintWeekHeader(java.awt.Graphics g, java.util.Calendar month)
Paints the day column header.protected void
paintWeekOfYearSeparator(java.awt.Graphics g, java.util.Calendar month)
Paints the separator between row header (weeks of year) and days.private void
previousMonth()
protected void
setCalendarHeaderHandler(CalendarHeaderHandler calendarHeaderHandler)
protected void
setFirstDisplayedDay(java.util.Date firstDisplayedDay)
Updates internal state that depends on the MonthView's firstDisplayedDay property.protected void
setRenderingHandler(CalendarRenderingHandler renderingHandler)
void
setUsingKeyboard(boolean val)
private void
traverseMonth(int arrowType)
protected void
uninstallComponents()
Uninstalls the calendar header handler.protected void
uninstallDefaults()
private void
uninstallKeyBindings(int type)
protected void
uninstallKeyboardActions()
protected void
uninstallListeners()
protected void
uninstallRenderingHandler()
Uninstalls the renderingHandler and infrastructure that used it.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.private void
updateLastDisplayedDay(java.util.Date first)
Updates the lastDisplayedDate property based on the given first and visible # of months.protected void
updateLocale(boolean revalidate)
Updates internal state according to monthView's locale.protected void
updateZoomable()
Updates state after the monthView's zoomable property has been changed.
-
-
-
Field Detail
-
LOG
private static final java.util.logging.Logger LOG
-
CALENDAR_SPACING
private static final int CALENDAR_SPACING
- See Also:
- Constant Field Values
-
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
-
WEEK_HEADER_COLUMN
protected static final int WEEK_HEADER_COLUMN
- See Also:
- Constant Field Values
-
DAYS_IN_WEEK
protected static final int DAYS_IN_WEEK
- See Also:
- Constant Field Values
-
FIRST_DAY_COLUMN
protected static final int FIRST_DAY_COLUMN
- See Also:
- Constant Field Values
-
LAST_DAY_COLUMN
protected static final int LAST_DAY_COLUMN
- See Also:
- Constant Field Values
-
DAY_HEADER_ROW
protected static final int DAY_HEADER_ROW
- See Also:
- Constant Field Values
-
WEEKS_IN_MONTH
protected static final int WEEKS_IN_MONTH
- See Also:
- Constant Field Values
-
FIRST_WEEK_ROW
protected static final int FIRST_WEEK_ROW
- See Also:
- Constant Field Values
-
LAST_WEEK_ROW
protected static final int LAST_WEEK_ROW
- See Also:
- Constant Field Values
-
monthView
protected JXMonthView monthView
the component we are installed for.
-
propertyChangeListener
private java.beans.PropertyChangeListener propertyChangeListener
-
mouseListener
private java.awt.event.MouseListener mouseListener
-
mouseMotionListener
private java.awt.event.MouseMotionListener mouseMotionListener
-
handler
private BasicMonthViewUI.Handler handler
-
lastDisplayedDate
private java.util.Date lastDisplayedDate
end of day of the last visible month.
-
usingKeyboard
private boolean usingKeyboard
//---------- fields related to selection/navigation /** flag indicating keyboard navigation.
-
pivotDate
private java.util.Date pivotDate
For interval selections we need to record the date we pivot around.
-
originalDateSpan
private java.util.SortedSet<java.util.Date> originalDateSpan
Date span used by the keyboard actions to track the original selection.
-
isLeftToRight
protected boolean isLeftToRight
-
monthUpImage
protected javax.swing.Icon monthUpImage
-
monthDownImage
protected javax.swing.Icon monthDownImage
-
arrowPaddingX
private int arrowPaddingX
The padding for month traversal icons. PENDING JW: decouple rendering and hit-detection.
-
arrowPaddingY
private int arrowPaddingY
-
fullMonthBoxHeight
private int fullMonthBoxHeight
height of month header including the monthView's box padding.
-
fullBoxWidth
private int fullBoxWidth
width of a "day" box including the monthView's box padding this is the same for days-of-the-week, weeks-of-the-year and days
-
fullBoxHeight
private int fullBoxHeight
height of a "day" box including the monthView's box padding this is the same for days-of-the-week, weeks-of-the-year and days
-
calendarWidth
private int calendarWidth
the width of a single month display.
-
calendarHeight
private int calendarHeight
the height of a single month display.
-
fullCalendarHeight
private int fullCalendarHeight
the height of a single month grid cell, including padding.
-
fullCalendarWidth
private int fullCalendarWidth
the width of a single month grid cell, including padding.
-
calendarRowCount
private int calendarRowCount
The number of calendars displayed vertically.
-
calendarColumnCount
private int calendarColumnCount
The number of calendars displayed horizontally.
-
calendarGrid
protected java.awt.Rectangle calendarGrid
The bounding box of the grid of visible months.
-
daysOfTheWeek
private java.lang.String[] daysOfTheWeek
The Strings used for the day headers. This is the fall-back for the monthView if no custom strings are set. PENDING JW: delegate to RenderingHandler?
-
renderingHandler
private CalendarRenderingHandler renderingHandler
Provider of configured components for text rendering.
-
rendererPane
private javax.swing.CellRendererPane rendererPane
The CellRendererPane for stamping rendering comps.
-
calendarHeaderHandler
private CalendarHeaderHandler calendarHeaderHandler
The CalendarHeaderHandler which provides the header component if zoomable.
-
-
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 classjavax.swing.plaf.ComponentUI
-
uninstallUI
public void uninstallUI(javax.swing.JComponent c)
- Overrides:
uninstallUI
in classjavax.swing.plaf.ComponentUI
-
installComponents
protected void installComponents()
Creates and installs the calendar header handler.
-
uninstallComponents
protected void uninstallComponents()
Uninstalls the calendar header handler.
-
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 delegate's properties.
-
uninstallDefaults
protected void uninstallDefaults()
-
installKeyboardActions
protected void installKeyboardActions()
-
installKeyBindings
private void installKeyBindings(int type)
- Parameters:
inputMap
-
-
uninstallKeyBindings
private void uninstallKeyBindings(int type)
- Parameters:
inputMap
-
-
uninstallKeyboardActions
protected void uninstallKeyboardActions()
-
installListeners
protected void installListeners()
-
uninstallListeners
protected void uninstallListeners()
-
installRenderingHandler
protected void installRenderingHandler()
Creates and installs the renderingHandler and infrastructure to use it.
-
uninstallRenderingHandler
protected void uninstallRenderingHandler()
Uninstalls the renderingHandler and infrastructure that used it.
-
createRenderingHandler
protected CalendarRenderingHandler createRenderingHandler()
Returns theCalendarRenderingHandler
to use. Subclasses may override to plug-in custom implementations.This implementation returns an instance of RenderingHandler.
- Returns:
- the endering handler to use for painting, must not be null
-
setRenderingHandler
protected void setRenderingHandler(CalendarRenderingHandler renderingHandler)
- Parameters:
renderingHandler
- the renderingHandler to set
-
getRenderingHandler
protected CalendarRenderingHandler getRenderingHandler()
- Returns:
- the renderingHandler
-
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
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 classMonthViewUI
- 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()
-
getHandler
private BasicMonthViewUI.Handler getHandler()
-
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 pixely
- the y position of the location in pixel- Returns:
- the bounds of the day which contains the location, or null if outside
-
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_ROW to LAST_WEEK_ROW. Column's range is from WEEK_HEADER_COLUMN to LAST_DAY_COLUMN.- Parameters:
month
- the month containing the day boxrow
- the logical row (== week) coordinate in the day gridcolumn
- 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.- See Also:
getDayGridPositionAtLocation(int, int)
-
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 week header or the day of week, ranging from WEEK_HEADER_COLUMN to LAST_DAY_COLUMN. The p.y represents the day header or week of the month, ranging from DAY_HEADER_ROW to LAST_WEEK_ROW. The transformation takes care of ComponentOrientation.Note: 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 pixely
- 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.
- See Also:
getDayBoundsInMonth(Date, int, int)
-
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 monthcolumn
- 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 are day/week header or leading/trailing dates
- Throws:
java.lang.IllegalStateException
- if the month is not the start of the month.- See Also:
getDayGridPosition(Date)
-
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.
- See Also:
getDayInMonth(Date, int, int)
-
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 classMonthViewUI
- Parameters:
x
- the x position of the location in pixely
- 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.
- See Also:
getDayBounds(Date)
-
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.
- See Also:
getDayAtLocation(int, int)
-
checkValidRow
private void checkValidRow(int row, int column)
- Parameters:
row
-
-
isVisible
private boolean isVisible(java.util.Date date)
Returns a boolean indicating if the given Date is visible. Trailing/leading dates of the last/first displayed month are considered to be invisible.- Parameters:
date
- the Date to check for visibility. Must not be null.- Returns:
- true if the date is visible, false otherwise.
-
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 pixely
- 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 pixely
- the y position of the location in pixel- Returns:
- the bounds of the month which contains the location, or null if outside
-
getMonthDetailsBoundsAtLocation
protected java.awt.Rectangle getMonthDetailsBoundsAtLocation(int x, int y)
Returns the bounds of the month details which contains the given location. The bounds are in monthView coordinate system.- Parameters:
x
- the x position of the location in pixely
- the y position of the location in pixel- Returns:
- the bounds of the details grid in the month at 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 pixely
- 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 pixely
- 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 pixely
- 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.
-
calculateMonthGridLayoutProperties
private void calculateMonthGridLayoutProperties()
Called from layout: calculates properties of grid of months.
-
calculateMonthGridBounds
private void calculateMonthGridBounds()
Calculates the bounds of the grid of months. CalendarRow/ColumnCount and calendarWidth/Height must be initialized before calling this.
-
calculateCalendarGridY
private int calculateCalendarGridY()
-
calculateCalendarGridX
private int calculateCalendarGridX()
-
calculateCalendarGridHeight
private int calculateCalendarGridHeight()
-
calculateCalendarGridWidth
private int calculateCalendarGridWidth()
-
calculateMonthGridRowColumnCount
private void calculateMonthGridRowColumnCount()
Calculates and updates the numCalCols/numCalRows that determine the number of calendars that can be displayed. Updates the last displayed date if appropriate.
-
isZoomable
protected boolean isZoomable()
- Returns:
- true if the month view can be zoomed, false otherwise
-
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 classjavax.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 classjavax.swing.plaf.ComponentUI
-
paintMonth
protected void paintMonth(java.awt.Graphics g, java.util.Calendar month)
Paints the month represented by the given Calendar. Note: the given calendar must not be changed.- Parameters:
g
- the graphics to paint intomonth
- the calendar specifying the first day of the month to paint, must not be null
-
paintMonthHeader
protected void paintMonthHeader(java.awt.Graphics g, java.util.Calendar month)
Paints the header of a month. Note: the given calendar must not be changed.- Parameters:
g
- the graphics to paint intomonth
- the calendar specifying the first day of the month to paint, must not be null
-
paintDayHeader
protected void paintDayHeader(java.awt.Graphics g, java.util.Calendar month)
Paints the day column header. Note: the given calendar must not be changed.- Parameters:
g
- the graphics to paint intomonth
- the calendar specifying the first day of the month to paint, must not be null
-
paintWeekHeader
protected void paintWeekHeader(java.awt.Graphics g, java.util.Calendar month)
Paints the day column header. Note: the given calendar must not be changed.- Parameters:
g
- the graphics to paint intomonth
- the calendar specifying the first day of the month to paint, must not be null
-
paintDays
protected void paintDays(java.awt.Graphics g, java.util.Calendar month)
Paints the days of the given month. Note: the given calendar must not be changed.- Parameters:
g
- the graphics to paint intomonth
- the calendar specifying the first day of 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 intocalendar
- the calendar representing the day to paintstate
- the calendar state
-
paintWeekOfYearSeparator
protected void paintWeekOfYearSeparator(java.awt.Graphics g, java.util.Calendar month)
Paints the separator between row header (weeks of year) and days. Note: the given calendar must not be changed.- Parameters:
g
- the graphics to paint intomonth
- the calendar specifying the first day of the month to paint, must not be null
-
paintDaysOfWeekSeparator
protected void paintDaysOfWeekSeparator(java.awt.Graphics g, java.util.Calendar month)
Paints the separator between column header (days of week) and days. Note: the given calendar must not be changed.- Parameters:
g
- the graphics to paint intomonth
- the calendar specifying the the first day of the month to paint, must not be null
-
getSeparatorBounds
private java.awt.Rectangle getSeparatorBounds(java.util.Calendar month, int row, int column)
- Parameters:
month
-row
-column
-- Returns:
-
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. The calendar is expected to be set to the first of the month. 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.
-
traverseMonth
private void traverseMonth(int arrowType)
-
nextMonth
private void nextMonth()
-
previousMonth
private void previousMonth()
-
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.
-
updateLastDisplayedDay
private void updateLastDisplayedDay(java.util.Date first)
Updates the lastDisplayedDate property based on the given first and visible # of months.- Parameters:
first
- the date of the first visible day.
-
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 classMonthViewUI
- Returns:
- Date The date.
-
setFirstDisplayedDay
protected void setFirstDisplayedDay(java.util.Date firstDisplayedDay)
Updates internal state that depends on the MonthView's firstDisplayedDay property.Here: updates lastDisplayedDay.
- Parameters:
firstDisplayedDay
- the firstDisplayedDate to set
-
getFirstDisplayedDay
protected java.util.Date getFirstDisplayedDay()
Returns the first displayed day. Convenience delegate to- Returns:
- the firstDisplayed
-
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.
-
canSelectByMode
private boolean canSelectByMode()
temporary: removed SelectionMode.NO_SELECTION, replaced all access by this method to enable easy re-adding, if we want it. If not - remove.
-
updateZoomable
protected void updateZoomable()
Updates state after the monthView's zoomable property has been changed. This implementation adds/removes the header component if zoomable is true/false respectively.
-
createCalendarHeaderHandler
protected CalendarHeaderHandler createCalendarHeaderHandler()
Creates and returns a calendar header handler which provides and configures a component for use in a zoomable monthView. Subclasses may override to return a custom handler.This implementation first queries the UIManager for class to use and returns that if available, returns a BasicCalendarHeaderHandler if not.
- Returns:
- a calendar header handler providing a component for use in zoomable monthView.
- See Also:
getHeaderFromUIManager()
,CalendarHeaderHandler
,BasicCalendarHeaderHandler
-
getHeaderFromUIManager
protected CalendarHeaderHandler getHeaderFromUIManager()
Returns a CalendarHeaderHandler looked up in the UIManager. This implementation looks for a String registered with a key of CalendarHeaderHandler.uiControllerID. If found it assumes that the value is the class name of the handler and tries to instantiate the handler.- Returns:
- a CalendarHeaderHandler from the UIManager or null if none available or instantiation failed.
-
instantiateClass
private CalendarHeaderHandler instantiateClass(java.lang.String handlerClassName)
- Parameters:
handlerClassName
-- Returns:
-
instantiateClass
private CalendarHeaderHandler instantiateClass(java.lang.Class<?> handlerClass)
- Parameters:
handlerClass
-- Returns:
-
setCalendarHeaderHandler
protected void setCalendarHeaderHandler(CalendarHeaderHandler calendarHeaderHandler)
- Parameters:
calendarHeaderHandler
- the calendarHeaderHandler to set
-
getCalendarHeaderHandler
protected CalendarHeaderHandler getCalendarHeaderHandler()
- Returns:
- the calendarHeaderHandler
-
-