All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tea.set.MCalendar

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----tea.set.MCalendar

public class MCalendar
extends Canvas
MCalendar widget provides an interface to manipulate one month calendar. It handles calendar related calculation automatically. There are a number of options to control the apperance of the calendar. Users can interact with the calendar by selecting one day or a day range. One or more days can be highlighted from the program. MCalendar widget calculates the optimum size to display a calendar. But if the widget is resized to a size other than the default, the layout of the calendar is automatically recalculated to lay the days out evenly over the available space. Since setYear() and setMonth() clears all selections, select() should be called after these functions.

MCalendar supports the following properties:
Property NameProperty TypeDescription
Titleint Calendar title option flag.
Yearint Calendar year.
Monthint Calendar month.
Highlightedboolean (Indexed, Readonly) True if the day is highlighted.
HighlightColor Highlight color.
StartDayint (Readonly) Starting day of a selected day range.
EndDayint (Readonly) Ending day of a selected day range.

MCalendar generates the following events:
Event TypeEvent IDGenerated Description
ActionEventActionEvent.ACTION_PERFORMED Day range selected. ActionEvent.getActionCommand() contains "select".


Variable Index

 o ALL
Display year, month name, and weekday.
 o eventMgr
EventMgr object handles added event processing and dispatching.
 o MONTH_WEEK
Display weekday header and month name.
 o NO_TITLE
Display only days.
 o WEEK
Display weekday header (Monday - Sunday).

Constructor Index

 o MCalendar()
Create a new calendar containing the current month.
 o MCalendar(int, int)
Create a monthly calendar for year/month.

Method Index

 o addActionListener(ActionListener)
Add an action listener.
 o clear()
Clear any outstanding selection.
 o compareTo(MCalendar)
Return the difference in month between this and mon.
 o dayOfWeek(int, int, int)
Return the day of week for year/month/day.
 o daysInMonth(int, int)
Return the number of days in month.
 o dehighlight(int)
De-highlight the specified day.
 o dehighlight(int, int)
De-highlight the specified days in the range, inclusive.
 o equals(Object)
Return true if the MCalendars have same year and month.
 o getEndDay()
Return the end day (inclusive) of a selected date range.
 o getMinimumSize()
Return the minimum size of the widget.
 o getMonth()
Return the month of the calendar.
 o getMonthName(int)
Return the three letter month name for month m.
 o getPreferredSize()
Return the preferred size of the widget.
 o getStartDay()
Get the start day of a selected date range.
 o getTitle()
Get the title option.
 o getYear()
Return the year of this calendar.
 o highlight(int)
Highlight the specified day.
 o highlight(int, int)
Highlight the specified days in the range, inclusive.
 o isHighlighted(int)
Return true if the specified day is highlighted.
 o paint(Graphics)
Paint the calendar.
 o processActionEvent(ActionEvent)
Process and dispatch action event.
 o processEvent(AWTEvent)
Process and dispatch event.
 o processMouseEvent(MouseEvent)
Set the starting selection point to the day where the mouse pointer is in.
 o processMouseMotionEvent(MouseEvent)
Day range selection.
 o removeActionListener(ActionListener)
Remove an action listener.
 o select(int)
Select the specified day.
 o select(int, int)
Select the specified day range.
 o selectAll()
Mark the entire month as selected.
 o setHighlight(Color)
Set the highlight color.
 o setMonth(int)
Set the month of the calendar.
 o setTitle(int)
Set the title option to either no title, weekday only, month and weekday, or all.
 o setYear(int)
Set the year of the calendar.
 o toString()
Converts to a string representation.
 o update(Graphics)
For double buffering.

Variables

 o NO_TITLE
 public static final int NO_TITLE
Display only days.

 o WEEK
 public static final int WEEK
Display weekday header (Monday - Sunday).

 o MONTH_WEEK
 public static final int MONTH_WEEK
Display weekday header and month name.

 o ALL
 public static final int ALL
Display year, month name, and weekday.

 o eventMgr
 protected EventMgr eventMgr
EventMgr object handles added event processing and dispatching.

Constructors

 o MCalendar
 public MCalendar()
Create a new calendar containing the current month.

 o MCalendar
 public MCalendar(int year,
                  int month)
Create a monthly calendar for year/month. Year starts from 1900, so pass 96 for 1996. Month starts from 0 to 11, corresponding to Jan to Dec respectively.

Parameters:
year - calendar year, year subtract 1900.
month - calendar month, starts from 0.

Methods

 o setTitle
 public synchronized void setTitle(int flag)
Set the title option to either no title, weekday only, month and weekday, or all. This causes a repaint.

Parameters:
flag - title flag, one of the title option values.
 o getTitle
 public int getTitle()
Get the title option.

Returns:
current title option.
 o setYear
 public synchronized void setYear(int year)
Set the year of the calendar. This causes a repaint.

Parameters:
year - calendar year.
 o getYear
 public int getYear()
Return the year of this calendar.

Returns:
calendar year.
 o setMonth
 public synchronized void setMonth(int month)
Set the month of the calendar. This causes a repaint.

Parameters:
month - calendar month.
 o getMonth
 public int getMonth()
Return the month of the calendar.

Returns:
calendar month, 0-11.
 o highlight
 public synchronized void highlight(int day)
Highlight the specified day.

Parameters:
day - day number, starts from 1.
 o highlight
 public synchronized void highlight(int sday,
                                    int eday)
Highlight the specified days in the range, inclusive.

Parameters:
sday - starting day of highlight range, starts from 1.
eday - ending day of highlight range, starts from 1.
 o dehighlight
 public synchronized void dehighlight(int day)
De-highlight the specified day.

Parameters:
day - number starts from 1.
 o dehighlight
 public synchronized void dehighlight(int sday,
                                      int eday)
De-highlight the specified days in the range, inclusive.

Parameters:
sday - starting day number of range, starts from 1.
eday - ending day number of range, starts from 1.
 o isHighlighted
 public boolean isHighlighted(int day)
Return true if the specified day is highlighted.

Parameters:
day - day number starts from 1.
 o setHighlight
 public synchronized void setHighlight(Color c)
Set the highlight color. Defaults to red.

Parameters:
c - highlight color.
 o getMinimumSize
 public Dimension getMinimumSize()
Return the minimum size of the widget.

Returns:
minimum size of calendar.
Overrides:
getMinimumSize in class Component
 o getPreferredSize
 public Dimension getPreferredSize()
Return the preferred size of the widget.

Parameters:
preferred - size of calendar.
Overrides:
getPreferredSize in class Component
 o getStartDay
 public int getStartDay()
Get the start day of a selected date range. Return -1 if no selection is made. Day number starts at 1.

Returns:
day number of the starting point of selected day range. -1 if no selection is made.
 o getEndDay
 public int getEndDay()
Return the end day (inclusive) of a selected date range. Return -1 if no selection is made. Day number starts at 1.

Returns:
day number of the ending point of selected day range. -1 if no selection is made.
 o clear
 public synchronized void clear()
Clear any outstanding selection. This could cause a repaint if there is a range selected.

 o select
 public void select(int day)
Select the specified day. No event is generated by this function.

Parameters:
day - number starts from 1.
 o select
 public synchronized void select(int sday,
                                 int eday)
Select the specified day range. No event is generated by this funciton.

Parameters:
sday - starting day of range, starts from 1.
eday - ending day of range, starts from 1.
 o selectAll
 public synchronized void selectAll()
Mark the entire month as selected.

 o equals
 public boolean equals(Object mon)
Return true if the MCalendars have same year and month.

Parameters:
mon - MCalendar object for comparison.
Returns:
true if calendar year and month are same.
Overrides:
equals in class Object
 o compareTo
 public int compareTo(MCalendar mon)
Return the difference in month between this and mon.

 o toString
 public String toString()
Converts to a string representation.

Returns:
string representation of canlendar.
Overrides:
toString in class Component
 o update
 public void update(Graphics g)
For double buffering.

Parameters:
g - Graphics content of this component.
Overrides:
update in class Component
 o paint
 public void paint(Graphics g)
Paint the calendar.

Parameters:
g - Graphics content of this component.
Overrides:
paint in class Canvas
 o addActionListener
 public void addActionListener(ActionListener listener)
Add an action listener.

Parameters:
listener - action listener.
 o removeActionListener
 public void removeActionListener(ActionListener listener)
Remove an action listener.

Parameters:
listener - action listener.
 o processEvent
 public void processEvent(AWTEvent e)
Process and dispatch event.

Parameters:
e - event object.
Overrides:
processEvent in class Component
 o processActionEvent
 public void processActionEvent(ActionEvent e)
Process and dispatch action event.

Parameters:
e - action event.
 o processMouseEvent
 public void processMouseEvent(MouseEvent e)
Set the starting selection point to the day where the mouse pointer is in. Set the ending point of the selection to the day where the mouse pointer is in.

Parameters:
e - event object.
Overrides:
processMouseEvent in class Component
 o processMouseMotionEvent
 public void processMouseMotionEvent(MouseEvent e)
Day range selection.

Parameters:
e - event object.
Overrides:
processMouseMotionEvent in class Component
 o daysInMonth
 public static int daysInMonth(int year,
                               int month)
Return the number of days in month. Month starts from zero(0).

Parameters:
year - year is the year minus 1900.
month - month starts from 0-11.
Returns:
number of days in the month.
 o dayOfWeek
 public static int dayOfWeek(int year,
                             int month,
                             int day)
Return the day of week for year/month/day. Sunday is 0.

Parameters:
year - year is the year minus 1900.
month - month starts from 0-11.
day - day starts from 1.
Returns:
0 for Sunday, 1 for monday, and so on.
 o getMonthName
 public static String getMonthName(int m)
Return the three letter month name for month m. Month starts from 0.

Parameters:
m - month number, starts from 0.
Returns:
month name.

All Packages  Class Hierarchy  This Package  Previous  Next  Index