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
Direct Known Subclasses:
MacOSXMonthViewUI

public class BasicMonthViewUI
extends MonthViewUI


Field Summary
protected static SimpleDateFormat dayOfMonthFormatter
          Formatter used to format the day of the week to a numerical value.
protected  Font derivedFont
          Used as the font for flagged days.
protected  long firstDisplayedDate
           
protected  int firstDisplayedMonth
           
protected  int firstDisplayedYear
           
protected  long lastDisplayedDate
           
protected  Icon monthDownImage
           
protected  Icon monthUpImage
           
protected  JXMonthView monthView
           
protected  SortedSet<Date> selection
           
protected  long today
           
 
Constructor Summary
BasicMonthViewUI()
           
 
Method Summary
 long calculateLastDisplayedDate()
          Calculate the last possible date that can be displayed.
protected  Font createDerivedFont()
          Create a derived font used to when painting various pieces of the month view component.
protected  LayoutManager createLayoutManager()
           
protected  MouseListener createMouseListener()
           
protected  MouseMotionListener createMouseMotionListener()
           
protected  PropertyChangeListener createPropertyChangeListener()
           
static ComponentUI createUI(JComponent c)
           
protected  Point getCalRowColAt(int x, int y)
          Get the row and column for the calendar at the specified coordinates
 long getDayAt(int x, int y)
          Return a long representing the date at the specified x/y position.
protected  int getDayOfTheWeek()
          Convenience method so subclasses can get the currently painted day's day of the week.
protected  int getTraversableButtonAt(int x, int y)
          Returns an index defining which, if any, of the buttons for traversing the month was pressed.
protected  void installComponents()
           
protected  void installDefaults()
           
protected  void installKeyboardActions()
           
protected  void installListeners()
           
 void installUI(JComponent c)
          Configures the specified component appropriate for the look and feel.
protected  boolean isToday(long date)
          Returns true if the date passed in is the same as today.
 boolean isUsingKeyboard()
           
 void paint(Graphics g, JComponent c)
          Paints the specified component appropriate for the look and feel.
protected  void paintBackground(Rectangle clip, Graphics g)
           
protected  void paintDayBackground(Graphics g, int x, int y, int width, int height, long date)
          Paint the background for the specified day.
protected  void paintDayForeground(Graphics g, int x, int y, int width, int height, long date)
          Paint the foreground for the specified day.
protected  void paintDayOfTheWeekBackground(Graphics g, int x, int y, int width, int height)
           
protected  void paintFlaggedDayBackground(Graphics g, int x, int y, int width, int height, long date)
          Paint the background for the specified flagged day.
protected  void paintFlaggedDayForeground(Graphics g, int x, int y, int width, int height, long date)
          Paint the foreground for the specified flagged day.
protected  void paintLeadingDayBackground(Graphics g, int x, int y, int width, int height, long date)
          Paint the background for the specified leading day.
protected  void paintLeadingDayForeground(Graphics g, int x, int y, int width, int height, long date)
          Paint the foreground for the specified leading day.
protected  void paintMonthStringBackground(Graphics g, int x, int y, int width, int height)
          Paints the background of the month string.
protected  void paintMonthStringForeground(Graphics g, int x, int y, int width, int height)
           
protected  void paintTrailingDayBackground(Graphics g, int x, int y, int width, int height, long date)
          Paint the background for the specified trailing day.
protected  void paintTrailingDayForeground(Graphics g, int x, int y, int width, int height, long date)
          Paint the foreground for the specified trailing day.
protected  void paintUnselectableDayBackground(Graphics g, int x, int y, int width, int height, long date)
          Paint the foreground for the specified unselectable day.
protected  void paintUnselectableDayForeground(Graphics g, int x, int y, int width, int height, long date)
          Paint the foreground for the specified unselectable day.
protected  void paintWeekOfYearBackground(Graphics g, int x, int y, int width, int height)
           
protected  void paintWeekOfYearForeground(Graphics g, int x, int y, int width, int height, int weekOfYear)
          Paints the week of the year
 void setUsingKeyboard(boolean val)
           
protected  void uninstallComponents()
           
protected  void uninstallDefaults()
           
protected  void uninstallKeyboardActions()
           
protected  void uninstallListeners()
           
 void uninstallUI(JComponent c)
          Reverses configuration which was done on the specified component during installUI.
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, getPreferredSize, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dayOfMonthFormatter

protected static final SimpleDateFormat dayOfMonthFormatter
Formatter used to format the day of the week to a numerical value.


monthView

protected JXMonthView monthView

firstDisplayedDate

protected long firstDisplayedDate

firstDisplayedMonth

protected int firstDisplayedMonth

firstDisplayedYear

protected int firstDisplayedYear

lastDisplayedDate

protected long lastDisplayedDate

today

protected long today

selection

protected SortedSet<Date> selection

derivedFont

protected Font derivedFont
Used as the font for flagged days.


monthUpImage

protected Icon monthUpImage

monthDownImage

protected Icon monthDownImage
Constructor Detail

BasicMonthViewUI

public BasicMonthViewUI()
Method Detail

createUI

public static ComponentUI createUI(JComponent c)

installUI

public void installUI(JComponent c)
Description copied from class: javax.swing.plaf.ComponentUI
Configures the specified component appropriate for the look and feel. This method is invoked when the ComponentUI instance is being installed as the UI delegate on the specified component. This method should completely configure the component for the look and feel, including the following:
  1. Install any default property values for color, fonts, borders, icons, opacity, etc. on the component. Whenever possible, property values initialized by the client program should not be overridden.
  2. Install a LayoutManager on the component if necessary.
  3. Create/add any required sub-components to the component.
  4. Create/install event listeners on the component.
  5. Create/install a PropertyChangeListener on the component in order to detect and respond to component property changes appropriately.
  6. Install keyboard UI (mnemonics, traversal, etc.) on the component.
  7. Initialize any appropriate instance data.

Overrides:
installUI in class ComponentUI
Parameters:
c - the component where this UI delegate is being installed
See Also:
ComponentUI.uninstallUI(javax.swing.JComponent), JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()

uninstallUI

public void uninstallUI(JComponent c)
Description copied from class: javax.swing.plaf.ComponentUI
Reverses configuration which was done on the specified component during installUI. This method is invoked when this UIComponent instance is being removed as the UI delegate for the specified component. This method should undo the configuration performed in installUI, being careful to leave the JComponent instance in a clean state (no extraneous listeners, look-and-feel-specific property objects, etc.). This should include the following:
  1. Remove any UI-set borders from the component.
  2. Remove any UI-set layout managers on the component.
  3. Remove any UI-added sub-components from the component.
  4. Remove any UI-added event/property listeners from the component.
  5. Remove any UI-installed keyboard UI from the component.
  6. Nullify any allocated instance data objects to allow for GC.

Overrides:
uninstallUI in class ComponentUI
Parameters:
c - the component from which this UI delegate is being removed; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
See Also:
ComponentUI.installUI(javax.swing.JComponent), JComponent.updateUI()

installComponents

protected void installComponents()

uninstallComponents

protected void uninstallComponents()

installDefaults

protected void installDefaults()

uninstallDefaults

protected void uninstallDefaults()

installKeyboardActions

protected void installKeyboardActions()

uninstallKeyboardActions

protected void uninstallKeyboardActions()

installListeners

protected void installListeners()

uninstallListeners

protected void uninstallListeners()

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()

createLayoutManager

protected LayoutManager createLayoutManager()

createMouseListener

protected MouseListener createMouseListener()

createMouseMotionListener

protected MouseMotionListener createMouseMotionListener()

createDerivedFont

protected Font createDerivedFont()
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.


isUsingKeyboard

public boolean isUsingKeyboard()

setUsingKeyboard

public void setUsingKeyboard(boolean val)

isToday

protected boolean isToday(long date)
Returns true if the date passed in is the same as today.

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

getDayAt

public long getDayAt(int x,
                     int y)
Description copied from class: MonthViewUI
Return a long representing the date at the specified x/y position. It is expected that the date returned will have a valid day, month and year. All other fields such as hour, minute, second and milli- second will be set to 0.

Specified by:
getDayAt in class MonthViewUI
Parameters:
x - X position
y - Y position
Returns:
long The date, -1 if position does not contain a date.

getDayOfTheWeek

protected int getDayOfTheWeek()
Convenience method so subclasses can get the currently painted day's day of the week. It is assumed the calendar, _cal, is already set to the correct day.

Returns:
day of the week (Calendar.SATURDAY, Calendar.SUNDAY, ...)
See Also:
Calendar

getTraversableButtonAt

protected int getTraversableButtonAt(int x,
                                     int y)
Returns an index defining which, if any, of the buttons for traversing the month was pressed. This method should only be called when setTraversable is set to true.

Parameters:
x - x position of the pointer
y - y position of the pointer
Returns:
MONTH_UP, MONTH_DOWN or -1 when no button is selected.

getCalRowColAt

protected Point getCalRowColAt(int x,
                               int y)
Get the row and column for the calendar at the specified coordinates

Parameters:
x - x location
y - y location
Returns:
a new Point object containing the row as the x value and column as the y value

calculateLastDisplayedDate

public long calculateLastDisplayedDate()
Description copied from class: MonthViewUI
Calculate 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.

Specified by:
calculateLastDisplayedDate in class MonthViewUI
Returns:
long The date.

paint

public void paint(Graphics g,
                  JComponent c)
Description copied from class: javax.swing.plaf.ComponentUI
Paints the specified component appropriate for the look and feel. This method is invoked from the ComponentUI.update method when the specified component is being painted. Subclasses should override this method and use the specified Graphics object to render the content of the component.

Overrides:
paint in class ComponentUI
Parameters:
g - the Graphics context in which to paint
c - the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
See Also:
ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)

paintDayOfTheWeekBackground

protected void paintDayOfTheWeekBackground(Graphics g,
                                           int x,
                                           int y,
                                           int width,
                                           int height)

paintWeekOfYearBackground

protected void paintWeekOfYearBackground(Graphics g,
                                         int x,
                                         int y,
                                         int width,
                                         int height)

paintWeekOfYearForeground

protected void paintWeekOfYearForeground(Graphics g,
                                         int x,
                                         int y,
                                         int width,
                                         int height,
                                         int weekOfYear)
Paints the week of the year

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
weekOfYear - week of the year

paintMonthStringBackground

protected void paintMonthStringBackground(Graphics g,
                                          int x,
                                          int y,
                                          int width,
                                          int height)
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.

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

protected void paintMonthStringForeground(Graphics g,
                                          int x,
                                          int y,
                                          int width,
                                          int height)

paintDayBackground

protected void paintDayBackground(Graphics g,
                                  int x,
                                  int y,
                                  int width,
                                  int height,
                                  long date)
Paint the background for the specified day.

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
date - long value representing the day being painted
See Also:
JXMonthView.isSelectedDate(long), isToday(long)

paintDayForeground

protected void paintDayForeground(Graphics g,
                                  int x,
                                  int y,
                                  int width,
                                  int height,
                                  long date)
Paint the foreground for the specified day.

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
date - long value representing the day being painted

paintFlaggedDayBackground

protected void paintFlaggedDayBackground(Graphics g,
                                         int x,
                                         int y,
                                         int width,
                                         int height,
                                         long date)
Paint the background for the specified flagged day. The default implementation just calls paintDayBackground.

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
date - long value representing the flagged day being painted

paintFlaggedDayForeground

protected void paintFlaggedDayForeground(Graphics g,
                                         int x,
                                         int y,
                                         int width,
                                         int height,
                                         long date)
Paint the foreground for the specified flagged day.

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
date - long value representing the flagged day being painted

paintUnselectableDayBackground

protected void paintUnselectableDayBackground(Graphics g,
                                              int x,
                                              int y,
                                              int width,
                                              int height,
                                              long date)
Paint the foreground for the specified unselectable day.

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
date - long value representing the flagged day being painted

paintUnselectableDayForeground

protected void paintUnselectableDayForeground(Graphics g,
                                              int x,
                                              int y,
                                              int width,
                                              int height,
                                              long date)
Paint the foreground for the specified unselectable day.

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
date - long value representing the flagged day being painted

paintLeadingDayBackground

protected void paintLeadingDayBackground(Graphics g,
                                         int x,
                                         int y,
                                         int width,
                                         int height,
                                         long date)
Paint the background for the specified leading day.

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
date - long value representing the leading day being painted

paintLeadingDayForeground

protected void paintLeadingDayForeground(Graphics g,
                                         int x,
                                         int y,
                                         int width,
                                         int height,
                                         long date)
Paint the foreground for the specified leading day.

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
date - long value representing the leading day being painted

paintTrailingDayBackground

protected void paintTrailingDayBackground(Graphics g,
                                          int x,
                                          int y,
                                          int width,
                                          int height,
                                          long date)
Paint the background for the specified trailing day.

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
date - long value representing the leading day being painted

paintTrailingDayForeground

protected void paintTrailingDayForeground(Graphics g,
                                          int x,
                                          int y,
                                          int width,
                                          int height,
                                          long date)
Paint the foreground for the specified trailing day.

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
date - long value representing the leading day being painted

paintBackground

protected void paintBackground(Rectangle clip,
                               Graphics g)