Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
();
/** @return An iterator to the calendar table components. */
protected Iterator
getCalendarTables() {
return calendarTables.iterator();
}
/** The date being viewed, not necessarily chosen. */
private Date date;
/** @return The date being viewed, not necessarily chosen. */
public Date getDate() {
return (Date)date.clone();
}
/**
* Sets the date being viewed. A copy will be made of the date before it is stored. This is a bound property.
* @param newDate The date to be viewed, not necessarily chosen.
* @throws NullPointerException if the given date is null.
* @see #DATE_PROPERTY
*/
public void setDate(final Date newDate) {
if(!date.equals(requireNonNull(newDate, "Date cannot be null."))) { //if the value is really changing
final Date oldDate = date; //get the old value
date = (Date)newDate.clone(); //clone the new date and actually change the value
updateDateControls(); //update the calendars based upon the new value
firePropertyChange(DATE_PROPERTY, oldDate, newDate); //indicate that the value changed
}
}
/** Default constructor with a default data model. */
public CalendarControl() {
this(new DefaultValueModel(Date.class)); //construct the class with a default value model
}
/** The property change listener that updates the date controls when a property changes. */
//TODO del protected final GenericPropertyChangeListener> updateDateControlsPropertyChangeListener;
/** The property change listener that updates the visible dates if the year is different than the last one. */
protected final GenericPropertyChangeListener yearPropertyChangeListener;
/**
* Value model constructor.
* @param valueModel The component value model.
* @throws NullPointerException if the given value model is null.
*/
public CalendarControl(final ValueModel valueModel) {
super(new FlowLayout(Flow.PAGE), valueModel); //construct the parent class flowing along the page
final Date selectedDate = valueModel.getValue(); //get the selected date
date = selectedDate != null ? selectedDate : new Date(); //set the currently visible date to the selected date, or the current date if no date is selected
controlContainer = new LayoutPanel(new FlowLayout(Flow.LINE)); //create the control panel
addComponent(controlContainer); //add the control panel
calendarContainer = new LayoutPanel(new FlowLayout(Flow.LINE)); //create the calendar panel
addComponent(calendarContainer); //add the calendar panel
monthListControl = new ListControl(Date.class, new SingleListSelectionPolicy()); //create a list control allowing only single selections of a month
monthListControl.setLabel("Month"); //set the month control label TODO get from resources
monthListControl.setValidator(new ValueRequiredValidator()); //require a locale to be selected in the list control
monthListControl.setRowCount(1); //make this a drop-down list
final Converter monthConverter = new DateStringLiteralConverter(DateStringLiteralStyle.MONTH_OF_YEAR); //get a converter to display the month of the year
monthListControl.setValueRepresentationStrategy(new ListControl.DefaultValueRepresentationStrategy(monthConverter)); //install a month representation strategy
controlContainer.add(monthListControl); //add the month list control
//create a year property change listener before we update the year control
yearPropertyChangeListener = new AbstractGenericPropertyChangeListener() { //create a property change listener to listen for the year changing
@Override
public void propertyChange(final GenericPropertyChangeEvent propertyChangeEvent) { //if the selected year changed
final Integer newYear = propertyChangeEvent.getNewValue(); //get the new selected year
if(newYear != null) { //if a new year was selected (a null value can be sent when the model is cleared)
final Calendar calendar = Calendar.getInstance(getSession().getTimeZone(), getSession().getLocale()); //create a new calendar
calendar.setTime(getDate()); //set the calendar date to our currently displayed date
if(calendar.get(Calendar.YEAR) != newYear) { //if the currently visible date is in another year
calendar.set(Calendar.YEAR, newYear); //change to the given year
setDate(calendar.getTime()); //change the date to the given month, which will update the calenders TODO make sure that going from a 31-day month, for example, to a 28-day month will be OK, if the day is day 31
}
}
}
};
updateYearControl(); //create and install an appropriate year control
updateDateControls(); //update the date controls
//update the calendars if the selected date changes
addPropertyChangeListener(ValueModel.VALUE_PROPERTY, new AbstractGenericPropertyChangeListener() { //create a property change listener to listen for our value changing, so that we can update the date control if needed
@Override
public void propertyChange(final GenericPropertyChangeEvent propertyChangeEvent) { //if the value changed
final Date newDate = propertyChangeEvent.getNewValue(); //get the new date value
if(newDate != null) { //we can't display a null date; if they set the date to null, just continue showing what we were showing
setDate(newDate); //update the currently-displayed date
}
}
});
addPropertyChangeListener(ValueModel.VALIDATOR_PROPERTY, new AbstractGenericPropertyChangeListener>() { //create a property change listener to listen for our validator changing, so that we can update the date control if needed
@Override
public void propertyChange(final GenericPropertyChangeEvent> propertyChangeEvent) { //if the model's validator changed
updateYearControl(); //update the year control (e.g. a drop-down list) to match the new validator (e.g. a range validator), if any
}
});
//TODO important: this is a memory leak---make sure we uninstall the listener when the session goes away
/*TODO fix
getSession().addPropertyChangeListener(GuiseSession.LOCALE_PROPERTY, updateDateControlsPropertyChangeListener); //update the calendars if the locale changes
updateDateControlsPropertyChangeListener=new AbstractGenericPropertyChangeListener