|
|||||||||
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.JComboBox org.freixas.jcalendar.JCalendarCombo
public class JCalendarCombo
This class is a combo box that allows you to select a date either by typing one in (if the combo box is editable) or through a JCalendar pop-up. Normally, a combo box expects to use a a popup that contains a list. We've perverted this a bit; while you can select a variety of dates, the list always has one item which changes to match the selected date.
You may specify a font for each of the elements that make up the pop-up 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.
The JCalendarCombo uses a non-mutable ComboBoModel. This means that the following methods will generate an exception:
The combo box listeners work pretty much as for normal combo boxes. The item changed event reports the date "unselected" (the previous date) and "selected" (the new date set), but as Strings. It's probably better to add a DateListener and ignore the ItemListener and ActionListener.
The following key bindings should work (some may depend on the selected Look-and-Feel):
This component tries to adapt it's Look-and-Feel to match the current Look-and-Feel. But it can only do so for Look-and-Feels's that it knows about. To adapt it for new Look-and-Feels, create a sub-class:
public class MyCalendarCombo extends JCalendarCombo {
public void updateUI() {
ComboBoxUI cui = (ComboBoxUI)UIManager.getUI(this);
if (cui instanceof SomeLAFComboBoxUI) {
cui = new SomeLAFCalComboBoxUI();
}
else {
super.updateUI();
}
}
private class SomeLAFCalComboBoxUI extends SomeLAFComboBoxUI {
return new CalendarComboPopup();
}
}
If it can't figure out an appropriate Look-and-Feel, it uses the
Metal Look-and-Feel.
Nested Class Summary | |
---|---|
protected class |
JCalendarCombo.CalendarComboBoxModel
|
protected class |
JCalendarCombo.CalendarComboPopup
|
Nested classes/interfaces inherited from class javax.swing.JComboBox |
---|
JComboBox.AccessibleJComboBox, JComboBox.KeySelectionManager |
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.JComboBox |
---|
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder |
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 | |
---|---|
JCalendarCombo()
Create an instance of JCalendarCombo using the default calendar and locale. |
|
JCalendarCombo(Calendar calendar,
Locale locale,
int selectedComponents,
boolean isTodayDisplayed)
Create an instance of JCalendarCombo using the given calendar and locale. |
|
JCalendarCombo(Calendar calendar,
Locale locale,
int selectedComponents,
boolean isTodayDisplayed,
String timePattern)
Create an instance of JCalendarCombo using the given calendar and locale. |
|
JCalendarCombo(int selectedComponents,
boolean isTodayDisplayed)
Create an instance of JCalendarCombo using the default calendar and locale. |
Method Summary | |
---|---|
void |
addDateListener(DateListener listener)
Add a date listener. |
Calendar |
getCalendar()
Get a copy of the calendar used by this JCalendar. |
Date |
getDate()
Get the date currently displayed by the calendar panel. |
DateFormat |
getDateFormat()
Get the date format used to display the selected date in the combo box's text field. |
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. |
Font |
getTimeFont()
Get the time spinner font. |
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 |
setDateFormat(DateFormat dateFormat)
Set the date format used to display the selected date in the combo box's text field. |
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 |
setKeySelectionManager(JComboBox.KeySelectionManager aManager)
This method is ignored. |
void |
setNullAllowed(boolean isNullAllowed)
Set whether a null date is allowed. |
void |
setSelectedItem(Object anObject)
Sets the selected item in the combo box display area to the object in the argument. |
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 Date |
stringToDate(String string)
Given a date in String form, convert it to a Date object. |
void |
updateUI()
Resets the UI property to a value from the current look and feel. |
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 JCalendarCombo()
public JCalendarCombo(int selectedComponents, boolean isTodayDisplayed)
selectedComponents
- Use DISPLAY_DATE, DISPLAY_TIME or
(DISPLAY_DATE | DISPLAY_TIME).isTodayDisplayed
- True if today's date should be displayed.public JCalendarCombo(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.public JCalendarCombo(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.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
- The whether a null date is allowed.public Date getDate()
getCalendar()
public void setDate(Date date)
date
- The date to set.public DateFormat getDateFormat()
public void setDateFormat(DateFormat dateFormat) throws NullPointerException
dateFormat
- The date format used to display the selected date
in the combo box's text field.
NullPointerException
public Calendar getCalendar()
getDate()
public Locale getLocale()
getLocale
in class Component
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 setSelectedItem(Object anObject)
If this constitutes a change in the selected item, ItemListeners added to the combo box will be notified with one or two ItemEvents. If there is a current selected item, an ItemEvent will be fired and the state change will be ItemEvent.DESELECTED. If anObject is in the list and is not currently selected then an ItemEvent will be fired and the state change will be ItemEvent.SELECTED.
ActionListeners added to the combo box will be notified with an ActionEvent when this method is called (assuming the date actually changed).
setSelectedItem
in class JComboBox
anObject
- The object to select.public void setKeySelectionManager(JComboBox.KeySelectionManager aManager)
setKeySelectionManager
in class JComboBox
aManager
- The new key selection manager.public void updateUI()
updateUI
in class JComboBox
protected String paramString()
paramString
in class JComboBox
protected Date stringToDate(String string)
string
- The date in String form.
|
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 |