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 Name | Property Type | Description |
Title | int |
Calendar title option flag. |
Year | int |
Calendar year. |
Month | int |
Calendar month. |
Highlighted | boolean (Indexed, Readonly) |
True if the day is highlighted. |
Highlight | Color |
Highlight color. |
StartDay | int (Readonly) |
Starting day of a selected day range. |
EndDay | int (Readonly) |
Ending day of a selected day range. |
MCalendar generates the following events:
Event Type | Event ID | Generated |
Description |
ActionEvent | ActionEvent.ACTION_PERFORMED |
Day range selected. |
ActionEvent.getActionCommand() contains "select". |
-
ALL
- Display year, month name, and weekday.
-
eventMgr
- EventMgr object handles added event processing and dispatching.
-
MONTH_WEEK
- Display weekday header and month name.
-
NO_TITLE
- Display only days.
-
WEEK
- Display weekday header (Monday - Sunday).
-
MCalendar()
- Create a new calendar containing the current month.
-
MCalendar(int, int)
- Create a monthly calendar for year/month.
-
addActionListener(ActionListener)
- Add an action listener.
-
clear()
- Clear any outstanding selection.
-
compareTo(MCalendar)
- Return the difference in month between this and mon.
-
dayOfWeek(int, int, int)
- Return the day of week for year/month/day.
-
daysInMonth(int, int)
- Return the number of days in month.
-
dehighlight(int)
- De-highlight the specified day.
-
dehighlight(int, int)
- De-highlight the specified days in the range, inclusive.
-
equals(Object)
- Return true if the MCalendars have same year and month.
-
getEndDay()
- Return the end day (inclusive) of a selected date range.
-
getMinimumSize()
-
Return the minimum size of the widget.
-
getMonth()
- Return the month of the calendar.
-
getMonthName(int)
- Return the three letter month name for month m.
-
getPreferredSize()
- Return the preferred size of the widget.
-
getStartDay()
- Get the start day of a selected date range.
-
getTitle()
- Get the title option.
-
getYear()
- Return the year of this calendar.
-
highlight(int)
- Highlight the specified day.
-
highlight(int, int)
- Highlight the specified days in the range, inclusive.
-
isHighlighted(int)
- Return true if the specified day is highlighted.
-
paint(Graphics)
- Paint the calendar.
-
processActionEvent(ActionEvent)
- Process and dispatch action event.
-
processEvent(AWTEvent)
- Process and dispatch event.
-
processMouseEvent(MouseEvent)
- Set the starting selection point to the day where the mouse
pointer is in.
-
processMouseMotionEvent(MouseEvent)
- Day range selection.
-
removeActionListener(ActionListener)
- Remove an action listener.
-
select(int)
- Select the specified day.
-
select(int, int)
- Select the specified day range.
-
selectAll()
- Mark the entire month as selected.
-
setHighlight(Color)
- Set the highlight color.
-
setMonth(int)
- Set the month of the calendar.
-
setTitle(int)
- Set the title option to either no title, weekday only,
month and weekday, or all.
-
setYear(int)
- Set the year of the calendar.
-
toString()
- Converts to a string representation.
-
update(Graphics)
- For double buffering.
NO_TITLE
public static final int NO_TITLE
- Display only days.
WEEK
public static final int WEEK
- Display weekday header (Monday - Sunday).
MONTH_WEEK
public static final int MONTH_WEEK
- Display weekday header and month name.
ALL
public static final int ALL
- Display year, month name, and weekday.
eventMgr
protected EventMgr eventMgr
- EventMgr object handles added event processing and dispatching.
MCalendar
public MCalendar()
- Create a new calendar containing the current month.
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.
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.
getTitle
public int getTitle()
- Get the title option.
- Returns:
- current title option.
setYear
public synchronized void setYear(int year)
- Set the year of the calendar. This causes a repaint.
- Parameters:
- year - calendar year.
getYear
public int getYear()
- Return the year of this calendar.
- Returns:
- calendar year.
setMonth
public synchronized void setMonth(int month)
- Set the month of the calendar. This causes a repaint.
- Parameters:
- month - calendar month.
getMonth
public int getMonth()
- Return the month of the calendar.
- Returns:
- calendar month, 0-11.
highlight
public synchronized void highlight(int day)
- Highlight the specified day.
- Parameters:
- day - day number, starts from 1.
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.
dehighlight
public synchronized void dehighlight(int day)
- De-highlight the specified day.
- Parameters:
- day - number starts from 1.
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.
isHighlighted
public boolean isHighlighted(int day)
- Return true if the specified day is highlighted.
- Parameters:
- day - day number starts from 1.
setHighlight
public synchronized void setHighlight(Color c)
- Set the highlight color. Defaults to red.
- Parameters:
- c - highlight color.
getMinimumSize
public Dimension getMinimumSize()
- Return the minimum size of the widget.
- Returns:
- minimum size of calendar.
- Overrides:
- getMinimumSize in class Component
getPreferredSize
public Dimension getPreferredSize()
- Return the preferred size of the widget.
- Parameters:
- preferred - size of calendar.
- Overrides:
- getPreferredSize in class Component
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.
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.
clear
public synchronized void clear()
- Clear any outstanding selection. This could cause a repaint
if there is a range selected.
select
public void select(int day)
- Select the specified day. No event is generated by this function.
- Parameters:
- day - number starts from 1.
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.
selectAll
public synchronized void selectAll()
- Mark the entire month as selected.
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
compareTo
public int compareTo(MCalendar mon)
- Return the difference in month between this and mon.
toString
public String toString()
- Converts to a string representation.
- Returns:
- string representation of canlendar.
- Overrides:
- toString in class Component
update
public void update(Graphics g)
- For double buffering.
- Parameters:
- g - Graphics content of this component.
- Overrides:
- update in class Component
paint
public void paint(Graphics g)
- Paint the calendar.
- Parameters:
- g - Graphics content of this component.
- Overrides:
- paint in class Canvas
addActionListener
public void addActionListener(ActionListener listener)
- Add an action listener.
- Parameters:
- listener - action listener.
removeActionListener
public void removeActionListener(ActionListener listener)
- Remove an action listener.
- Parameters:
- listener - action listener.
processEvent
public void processEvent(AWTEvent e)
- Process and dispatch event.
- Parameters:
- e - event object.
- Overrides:
- processEvent in class Component
processActionEvent
public void processActionEvent(ActionEvent e)
- Process and dispatch action event.
- Parameters:
- e - action event.
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
processMouseMotionEvent
public void processMouseMotionEvent(MouseEvent e)
- Day range selection.
- Parameters:
- e - event object.
- Overrides:
- processMouseMotionEvent in class Component
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.
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.
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