|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JPanel org.freixas.jcalendar.JCalendar
public class JCalendar
This class displays a panel through which a user can select a date and/or time. A time-only selection can be used to select a duration, as long as the duration is no longer than 23 hours, 59 minutes and 59 seconds.
The date is selected using a calendar display. The time is selected using a date spinner.
In reality, both date and time are part of the same Date returned by getDate() or getCalendar(). If you are selecting only the date, you should ignore the time portion of the Date or Calendar. If you are selecting only the time, ignore the date portion.
You can set the pattern used to display the time in the date spinner. The pattern is the same as used by SimpleDateFormat. The default format displays hours, minutes and seconds in a locale-specific way (some locales use AM/PM, some use a 24-hour clock). If you want to get a time duration, you will want to use a pattern such as "HH:mm:ss" to eliminate the possibility of an AM/PM field appearing. You can also use setTimePattern() to reduce the precision of the time obtained (e.g. "HH:mm").
You may specify a font for each of the elements that make up the calendar. If you do not specify a font (or specify a null font), a reasonable default will be generated based on the current Look & Feel.
When the calendar has focus, the following key bindings are supported:
The time field is divided into hour, minute, second and AM/PM portions. You can select any portion and use the spinner arrows on the right side of the field to increment or decrement that portion. However, the entire time is being incremented or decremented, so that incrementing 1:59:59 by one second will generate 2:00:00.
Due to a design limitation in JFormatedTextField, incrementing 24:59:59 will not increment the day. A value in a JFormatedTextField (which is what the time field is), only calculates a date from the fields displayed. Since usually we display a HH:mm:ss pattern, the JFormattedTextField will set the date to a default value, not influenced by the date in the calendar
It is possible to pass in a time pattern that displays more than just the time -- this is not advisable since the date portion displayed in the JFormatedTextField will be ignored by the JCalendar component.
When the time field has focus, the up/down arrow keys increment or decrement the currently selected time portion, just like the spinner keys. The left and right arrow keys can be used to move to the next or previous portion.
Calendar
,
Date
,
DateFormat
,
SimpleDateFormat
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JPanel |
---|
JPanel.AccessibleJPanel |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
static int |
DISPLAY_DATE
Used to indicate that this component should display the date. |
static int |
DISPLAY_TIME
Used to indicate that this component should display the time. |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JCalendar()
Create an instance of JCalendar using the default calendar and locale. |
|
JCalendar(Calendar calendar,
Locale locale,
int selectedComponents,
boolean isTodayDisplayed)
Create an instance of JCalendar using the given calendar and locale. |
|
JCalendar(Calendar calendar,
Locale locale,
int selectedComponents,
boolean isTodayDisplayed,
String timePattern)
Create an instance of JCalendar using the given calendar and locale. |
|
JCalendar(int selectedComponents,
boolean isTodayDisplayed)
Create an instance of JCalendar using the default calendar and locale. |
Method Summary | |
---|---|
void |
addDateListener(DateListener listener)
Add a date listener. |
void |
addNotify()
|
protected void |
fireDateChange()
Fire a date change. |
Calendar |
getCalendar()
Get a copy of the calendar used by this JCalendar. |
Date |
getDate()
Get the date currently displayed by the calendar panel. |
Font |
getDayFont()
Get the day font. |
Font |
getDayOfWeekFont()
Get the day-of-week font (Mon, Tue, etc.). |
Locale |
getLocale()
Return the locale used by this JCalendar. |
int |
getSelectedComponents()
Return the components being displayed:
(getSelectedComponents() & DISPLAY_DATE) > 0
means that the date calendar is being displayed. |
Font |
getTimeFont()
Get the time spinner font. |
String |
getTimePattern()
Get the pattern used to display the time in the time selection spinner. |
Font |
getTitleFont()
Get the title font. |
Font |
getTodayFont()
Get the font used to display today's date as text. |
boolean |
isNullAllowed()
Get whether a null date is allowed. |
boolean |
isTodayDisplayed()
Returns true if today's date is displayed at the bottom of the calendar. |
protected String |
paramString()
|
void |
removeDateListener(DateListener listener)
Remove a date listener. |
void |
setDate(Date date)
Set the calendar panel to display the given date. |
void |
setDayFont(Font font)
If the font is set to null, then the day font will default to 9/11th's of the L&F's Button default font. |
void |
setDayOfWeekFont(Font font)
If the font is set to null, then the day-of-week font (Mon, Tue, etc.) will default to 9/11th's of the L&F's Label default font. |
void |
setDisplayDate(Date date)
Reset the displayed date without changing the selected date. |
void |
setEnabled(boolean b)
|
void |
setNullAllowed(boolean isNullAllowed)
Set whether a null date is allowed. |
void |
setTimeFont(Font font)
If the font is set to null, then the time spinner font will default to the L&F's Spinner default font. |
void |
setTitleFont(Font font)
If the font is set to null, then the title font (for the Month Year title) will default to the L&F's Label default font. |
void |
setTodayFont(Font font)
If the font is set to null, then the font used to display today's date as text will default to the L&F's Label default font. |
protected void |
setupDayFonts()
Set the day labels' font. |
protected void |
setupDayOfWeekFonts()
Set the day-of-week labels' font. |
protected void |
setupTimeFont()
Set the time spinner's font. |
protected void |
setupTitleFont()
Set the title's font. |
protected void |
setupTodayFont()
Set the font used to display today's date as text. |
Methods inherited from class javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, setUI, updateUI |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DISPLAY_DATE
public static final int DISPLAY_TIME
Constructor Detail |
---|
public JCalendar()
public JCalendar(int selectedComponents, boolean isTodayDisplayed)
selectedComponents
- Use DISPLAY_DATE, DISPLAY_TIME or
(DISPLAY_DATE | DISPLAY_TIME).isTodayDisplayed
- True if today's date should be displayed at
the bottom of the panel.public JCalendar(Calendar calendar, Locale locale, int selectedComponents, boolean isTodayDisplayed)
calendar
- The calendar to use.locale
- The locale to use.selectedComponents
- Use DISPLAY_DATE, DISPLAY_TIME or
(DISPLAY_DATE | DISPLAY_TIME).isTodayDisplayed
- True if today's date should be displayed at
the bottom of the panel.public JCalendar(Calendar calendar, Locale locale, int selectedComponents, boolean isTodayDisplayed, String timePattern)
calendar
- The calendar to use.locale
- The locale to use.selectedComponents
- Use DISPLAY_DATE, DISPLAY_TIME or
(DISPLAY_DATE | DISPLAY_TIME).isTodayDisplayed
- True if today's date should be displayed at
the bottom of the panel.timePattern
- The pattern used to display the time in the time
spinner field.DateFormat
,
SimpleDateFormat
Method Detail |
---|
public void addDateListener(DateListener listener)
listener
- The date listener to add.public void removeDateListener(DateListener listener)
listener
- The date listener to remove.public boolean isNullAllowed()
public void setNullAllowed(boolean isNullAllowed)
If nulls are not allowed, a setDate(null) will be ignored without error. The DELETE key will do nothing.
If you switch from allowing nulls to not allowing nulls and the current date is null, it will remain null until a date is selected.
The component default is to allow nulls.
isNullAllowed
- Whether a null date is allowed.public Date getDate()
getCalendar()
public void setDate(Date date)
date
- The date to set.public void setDisplayDate(Date date)
date
- The date to display.public String getTimePattern()
public Calendar getCalendar()
getDate()
public Locale getLocale()
getLocale
in class Component
public int getSelectedComponents()
(getSelectedComponents() & DISPLAY_DATE) > 0
means that the date calendar is being displayed.
(getSelectedComponents() & DISPLAY_TIME) > 0
menas that the time spinner field is being displayed.
public boolean isTodayDisplayed()
public Font getTitleFont()
public void setTitleFont(Font font)
Otherwise, the title font is set as given.
font
- The font to set.public Font getDayOfWeekFont()
public void setDayOfWeekFont(Font font)
Otherwise, the day-of-week font is set as given.
font
- The font to set.public Font getDayFont()
public void setDayFont(Font font)
Otherwise, the day font is set as given.
font
- The font to set.public Font getTimeFont()
public void setTimeFont(Font font)
Otherwise, the time spinner font is set as given.
font
- The font to set.public Font getTodayFont()
public void setTodayFont(Font font)
Otherwise, the font used to display today's date is set as given.
font
- The font to set.public void setEnabled(boolean b)
setEnabled
in class JComponent
public void addNotify()
addNotify
in class JComponent
protected String paramString()
paramString
in class JPanel
protected void fireDateChange()
protected void setupTitleFont()
protected void setupDayOfWeekFonts()
protected void setupDayFonts()
protected void setupTimeFont()
protected void setupTodayFont()
|
Copyright © 2004-2005 Antonio Freixas Licensed under the Artistic License |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |