public class BasicMonthViewUI extends MonthViewUI
JXMonthView
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.
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.
Modifier and Type | Class and 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.
|
Modifier and Type | Field and 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 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 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 days
|
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
|
private 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 Date |
lastDisplayedDate
end of day of the last visible month.
|
private static 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 Icon |
monthDownImage |
protected Icon |
monthUpImage |
protected JXMonthView |
monthView
the component we are installed for.
|
private MouseListener |
mouseListener |
private MouseMotionListener |
mouseMotionListener |
private SortedSet<Date> |
originalDateSpan
Date span used by the keyboard actions to track the original selection.
|
private Date |
pivotDate
For interval selections we need to record the date we pivot around.
|
private PropertyChangeListener |
propertyChangeListener |
private 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 and Description |
---|
BasicMonthViewUI() |
Modifier and Type | Method and 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 LayoutManager |
createLayoutManager() |
protected MouseListener |
createMouseListener() |
protected MouseMotionListener |
createMouseMotionListener() |
protected PropertyChangeListener |
createPropertyChangeListener() |
protected CalendarRenderingHandler |
createRenderingHandler()
Returns the
CalendarRenderingHandler to use. |
static ComponentUI |
createUI(JComponent c) |
protected Calendar |
getCalendar()
Returns the monthViews calendar configured to the firstDisplayedDate.
|
protected Calendar |
getCalendar(Date date)
Returns the monthViews calendar configured to the given time.
|
protected CalendarHeaderHandler |
getCalendarHeaderHandler() |
Date |
getDayAtLocation(int x,
int y)
Returns the Date at the given location.
|
protected Rectangle |
getDayBounds(Date date)
Returns the bounds of the given day.
|
protected Rectangle |
getDayBoundsAtLocation(int x,
int y)
Returns the bounds of the day in the grid of days which contains the
given location.
|
protected Rectangle |
getDayBoundsInMonth(Date month,
int row,
int column)
Returns the bounds of the day box at logical coordinates in the given month.
|
protected Point |
getDayGridPosition(Date date)
Returns the given date's position in the grid of the month it is contained in.
|
protected Point |
getDayGridPositionAtLocation(int x,
int y)
Returns the logical coordinates of the day which contains the given
location.
|
protected Date |
getDayInMonth(Date month,
int row,
int column)
Returns the Date defined by the logical
grid coordinates relative to the given month.
|
protected Dimension |
getDaySize()
Returns the size of a day including the padding.
|
String[] |
getDaysOfTheWeek()
Returns an array of String to use as names for the days of the week.
|
protected 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.
|
Date |
getLastDisplayedDay()
Returns the last possible date that can be displayed.
|
protected 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 Date |
getMonthAtLocation(int x,
int y)
Returns the Date representing the start of the month which
contains the given location.
|
protected Rectangle |
getMonthBounds(Date date)
Returns the bounds of the month containing the given date.
|
protected Rectangle |
getMonthBounds(int row,
int column)
Returns the bounds of the month at the given logical coordinates
in the grid of visible months.
|
protected Rectangle |
getMonthBoundsAtLocation(int x,
int y)
Returns the bounds of the month which contains the
given location.
|
protected Rectangle |
getMonthDetailsBoundsAtLocation(int x,
int y)
Returns the bounds of the month details which contains the
given location.
|
protected Point |
getMonthGridPosition(Date date)
Returns the logical grid position of the month containing the given date.
|
protected Point |
getMonthGridPositionAtLocation(int x,
int y)
Returns the logical coordinates of the month which contains
the given location.
|
protected Rectangle |
getMonthHeaderBounds(Date date,
boolean includeInsets)
Returns the bounds of the month containing the given date.
|
protected 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 Dimension |
getMonthSize()
Returns the size of a month.
|
protected CalendarRenderingHandler |
getRenderingHandler() |
protected SortedSet<Date> |
getSelection() |
private Rectangle |
getSeparatorBounds(Calendar month,
int row,
int column) |
protected Date |
getToday() |
protected int |
getTraversableGridPositionAtLocation(int x,
int y)
Mapping pixel to bounds.
|
protected int |
getWeeks(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(JComponent c)
Installs the component as appropriate for the current lf.
|
private CalendarHeaderHandler |
instantiateClass(Class<?> handlerClass) |
private CalendarHeaderHandler |
instantiateClass(String handlerClassName) |
protected boolean |
isToday(Date date)
Returns true if the date passed in is the same as today.
|
boolean |
isUsingKeyboard() |
private boolean |
isVisible(Date date)
Returns a boolean indicating if the given Date is visible.
|
protected boolean |
isZoomable() |
private void |
nextMonth() |
void |
paint(Graphics g,
JComponent c) |
protected void |
paintBackground(Graphics g)
Paints the background of the component.
|
protected void |
paintDayHeader(Graphics g,
Calendar month)
Paints the day column header.
|
protected void |
paintDayOfMonth(Graphics g,
Rectangle bounds,
Calendar calendar,
CalendarState state)
Paints a day which is of the current month with the given state.
|
protected void |
paintDays(Graphics g,
Calendar month)
Paints the days of the given month.
|
protected void |
paintDaysOfWeekSeparator(Graphics g,
Calendar month)
Paints the separator between column header (days of week) and days.
|
protected void |
paintMonth(Graphics g,
Calendar month)
Paints the month represented by the given Calendar.
|
protected void |
paintMonthHeader(Graphics g,
Calendar month)
Paints the header of a month.
|
protected void |
paintWeekHeader(Graphics g,
Calendar month)
Paints the day column header.
|
protected void |
paintWeekOfYearSeparator(Graphics g,
Calendar month)
Paints the separator between row header (weeks of year) and days.
|
private void |
previousMonth() |
protected void |
setCalendarHeaderHandler(CalendarHeaderHandler calendarHeaderHandler) |
protected void |
setFirstDisplayedDay(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(JComponent c) |
void |
update(Graphics g,
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(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.
|
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, getPreferredSize
private static final int CALENDAR_SPACING
public static final int MONTH_DOWN
public static final int MONTH_UP
protected static final int WEEK_HEADER_COLUMN
protected static final int DAYS_IN_WEEK
protected static final int FIRST_DAY_COLUMN
protected static final int LAST_DAY_COLUMN
protected static final int DAY_HEADER_ROW
protected static final int WEEKS_IN_MONTH
protected static final int FIRST_WEEK_ROW
protected static final int LAST_WEEK_ROW
protected JXMonthView monthView
private PropertyChangeListener propertyChangeListener
private MouseListener mouseListener
private MouseMotionListener mouseMotionListener
private BasicMonthViewUI.Handler handler
private Date lastDisplayedDate
private boolean usingKeyboard
private Date pivotDate
private SortedSet<Date> originalDateSpan
protected boolean isLeftToRight
protected Icon monthUpImage
protected Icon monthDownImage
private int arrowPaddingX
private int arrowPaddingY
private int fullMonthBoxHeight
private int fullBoxWidth
private int fullBoxHeight
private int calendarWidth
private int calendarHeight
private int fullCalendarHeight
private int fullCalendarWidth
private int calendarRowCount
private int calendarColumnCount
protected Rectangle calendarGrid
private String[] daysOfTheWeek
private CalendarRenderingHandler renderingHandler
private CellRendererPane rendererPane
private CalendarHeaderHandler calendarHeaderHandler
public BasicMonthViewUI()
public static ComponentUI createUI(JComponent c)
public void installUI(JComponent c)
installUI
in class ComponentUI
public void uninstallUI(JComponent c)
uninstallUI
in class ComponentUI
protected void installComponents()
protected void uninstallComponents()
protected void installDefaults()
This is refactored to only install default properties on the monthView. Extracted install of this delegate's properties into installDelegate.
protected void installDelegate()
protected void uninstallDefaults()
protected void installKeyboardActions()
private void installKeyBindings(int type)
inputMap
- private void uninstallKeyBindings(int type)
inputMap
- protected void uninstallKeyboardActions()
protected void installListeners()
protected void uninstallListeners()
protected void installRenderingHandler()
protected void uninstallRenderingHandler()
protected CalendarRenderingHandler createRenderingHandler()
CalendarRenderingHandler
to use. Subclasses may override to
plug-in custom implementations. This implementation returns an instance of RenderingHandler.
protected void setRenderingHandler(CalendarRenderingHandler renderingHandler)
renderingHandler
- the renderingHandler to setprotected CalendarRenderingHandler getRenderingHandler()
protected void updateComponentInputMap()
JXMonthView.isComponentInputMapEnabled()
protected void updateLocale(boolean revalidate)
revalidate
- a boolean indicating whether the monthView should be
revalidated after the change.public String[] getDaysOfTheWeek()
MonthViewUI
getDaysOfTheWeek
in class MonthViewUI
protected PropertyChangeListener createPropertyChangeListener()
protected LayoutManager createLayoutManager()
protected MouseListener createMouseListener()
protected MouseMotionListener createMouseMotionListener()
private BasicMonthViewUI.Handler getHandler()
public boolean isUsingKeyboard()
public void setUsingKeyboard(boolean val)
protected Rectangle getDayBoundsAtLocation(int x, int y)
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.
x
- the x position of the location in pixely
- the y position of the location in pixelprotected Rectangle getDayBoundsInMonth(Date month, int row, int column)
month
- the month containing the day boxrow
- the logical row (== week) coordinate in the day gridcolumn
- the logical column (== day) coordinate in the day gridIllegalArgumentException
- if row or column are out off range.getDayGridPositionAtLocation(int, int)
protected Point getDayGridPositionAtLocation(int x, int y)
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.
x
- the x position of the location in pixely
- the y position of the location in pixelgetDayBoundsInMonth(Date, int, int)
protected Date getDayInMonth(Date month, int row, int column)
PENDING JW: relax the startOfMonth pre? Why did I require it?
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 monthIllegalStateException
- if the month is not the start of the month.getDayGridPosition(Date)
protected Point getDayGridPosition(Date date)
date
- the Date to get the logical position for, must not be null.getDayInMonth(Date, int, int)
public Date getDayAtLocation(int x, int y)
getDayAtLocation
in class MonthViewUI
x
- the x position of the location in pixely
- the y position of the location in pixelgetDayBounds(Date)
protected Rectangle getDayBounds(Date date)
PENDING JW: this most probably should be public as it is the logical reverse of getDayAtLocation
date
- the Date to return the bounds for. Must not be null.getDayAtLocation(int, int)
private void checkValidRow(int row, int column)
row
- private boolean isVisible(Date date)
date
- the Date to check for visibility. Must not be null.protected int getTraversableGridPositionAtLocation(int x, int y)
PENDING JW: define the "action grid". Currently this replaces the old version to remove all internal usage of deprecated methods.
x
- the x position of the location in pixely
- the y position of the location in pixelprotected Rectangle getMonthHeaderBoundsAtLocation(int x, int y)
x
- the x position of the location in pixely
- the y position of the location in pixelprotected Rectangle getMonthDetailsBoundsAtLocation(int x, int y)
x
- the x position of the location in pixely
- the y position of the location in pixelprotected Rectangle getMonthBoundsAtLocation(int x, int y)
Mapping pixel to bounds.
x
- the x position of the location in pixely
- the y position of the location in pixelprotected Point getMonthGridPositionAtLocation(int x, int y)
Mapping pixel to logical grid coordinates.
x
- the x position of the location in pixely
- the y position of the location in pixelprotected Date getMonthAtLocation(int x, int y)
Mapping pixel to calendar day.
x
- the x position of the location in pixely
- the y position of the location in pixelprotected Date getMonth(int row, int column)
Mapping logical grid coordinates to Calendar.
row
- the rowIndex in the grid of months.column
- the columnIndex in the grid months.getMonthGridPosition(Date)
protected Point getMonthGridPosition(Date date)
date
- the Date to return the bounds for. Must not be null.getMonth(int, int)
,
getMonthBounds(int, int)
protected Rectangle getMonthBounds(int row, int column)
Mapping logical grip position to pixel.
row
- the rowIndex in the grid of months.column
- the columnIndex in the grid months.getMonthGridPositionAtLocation(int, int)
,
getMonthBoundsAtLocation(int, int)
protected Rectangle getMonthBounds(Date date)
Mapping Date to pixel.
date
- the Date to return the bounds for. Must not be null.getMonthAtLocation(int, int)
protected Rectangle getMonthHeaderBounds(Date date, boolean includeInsets)
Mapping Date to pixel.
date
- the Date to return the bounds for. Must not be null.getMonthAtLocation(int, int)
protected Dimension getMonthSize()
protected Dimension getDaySize()
protected int getMonthHeaderHeight()
private void calculateMonthGridLayoutProperties()
private void calculateMonthGridBounds()
private int calculateCalendarGridY()
private int calculateCalendarGridX()
private int calculateCalendarGridHeight()
private int calculateCalendarGridWidth()
private void calculateMonthGridRowColumnCount()
protected boolean isZoomable()
public void update(Graphics g, JComponent c)
update
in class ComponentUI
protected void paintBackground(Graphics g)
g
- the Graphics to fill.public void paint(Graphics g, JComponent c)
paint
in class ComponentUI
protected void paintMonth(Graphics g, Calendar month)
g
- the graphics to paint intomonth
- the calendar specifying the first day of the month to
paint, must not be nullprotected void paintMonthHeader(Graphics g, Calendar month)
g
- the graphics to paint intomonth
- the calendar specifying the first day of the month to
paint, must not be nullprotected void paintDayHeader(Graphics g, Calendar month)
g
- the graphics to paint intomonth
- the calendar specifying the first day of the month to
paint, must not be nullprotected void paintWeekHeader(Graphics g, Calendar month)
g
- the graphics to paint intomonth
- the calendar specifying the first day of the month to
paint, must not be nullprotected void paintDays(Graphics g, Calendar month)
g
- the graphics to paint intomonth
- the calendar specifying the first day of the month to
paint, must not be nullprotected void paintDayOfMonth(Graphics g, Rectangle bounds, Calendar calendar, CalendarState 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!)
g
- the graphics to paint into.bounds
- the rectangle to paint the day intocalendar
- the calendar representing the day to paintstate
- the calendar stateprotected void paintWeekOfYearSeparator(Graphics g, Calendar month)
g
- the graphics to paint intomonth
- the calendar specifying the first day of the month to
paint, must not be nullprotected void paintDaysOfWeekSeparator(Graphics g, Calendar month)
g
- the graphics to paint intomonth
- the calendar specifying the the first day of the month to
paint, must not be nullprivate Rectangle getSeparatorBounds(Calendar month, int row, int column)
month
- row
- column
- protected int getWeeks(Calendar month)
month
- the calendar specifying the the first day of the month to
paint, must not be nullprivate void traverseMonth(int arrowType)
private void nextMonth()
private void previousMonth()
protected Calendar getCalendar()
protected Calendar getCalendar(Date date)
date
- the date to configure the calendar withprivate void updateLastDisplayedDay(Date first)
first
- the date of the first visible day.public Date getLastDisplayedDay()
It's up to the UI to keep this property, based on internal state and the firstDisplayed as controlled by the JXMonthView.
getLastDisplayedDay
in class MonthViewUI
protected void setFirstDisplayedDay(Date firstDisplayedDay)
Here: updates lastDisplayedDay.
firstDisplayedDay
- the firstDisplayedDate to setprotected Date getFirstDisplayedDay()
protected int getFirstDisplayedMonth()
protected int getFirstDisplayedYear()
protected SortedSet<Date> getSelection()
protected boolean isToday(Date date)
date
- long representing the date you want to compare to today.private boolean canSelectByMode()
protected void updateZoomable()
protected CalendarHeaderHandler createCalendarHeaderHandler()
This implementation first queries the UIManager for class to use and returns that if available, returns a BasicCalendarHeaderHandler if not.
getHeaderFromUIManager()
,
CalendarHeaderHandler
,
BasicCalendarHeaderHandler
protected CalendarHeaderHandler getHeaderFromUIManager()
private CalendarHeaderHandler instantiateClass(String handlerClassName)
handlerClassName
- private CalendarHeaderHandler instantiateClass(Class<?> handlerClass)
handlerClass
- protected void setCalendarHeaderHandler(CalendarHeaderHandler calendarHeaderHandler)
calendarHeaderHandler
- the calendarHeaderHandler to setprotected CalendarHeaderHandler getCalendarHeaderHandler()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses