001: /**
002: * L2FProd.com Common Components 7.3 License.
003: *
004: * Copyright 2005-2007 L2FProd.com
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package com.l2fprod.common.beans.editor;
018:
019: import java.util.Date;
020: import java.util.Locale;
021:
022: import net.sf.nachocalendar.CalendarFactory;
023: import net.sf.nachocalendar.components.DateField;
024:
025: /**
026: * Date Property Editor based on <a
027: * href="http://nachocalendar.sf.net">NachoCalendar</a> component.
028: * <br>
029: */
030: public class NachoCalendarDatePropertyEditor extends
031: AbstractPropertyEditor {
032:
033: private String dateFormatString;
034:
035: /**
036: * Constructor for NachoCalendarDatePropertyEditor
037: */
038: public NachoCalendarDatePropertyEditor() {
039: editor = CalendarFactory.createDateField();
040: ((DateField) editor).setValue(new Date());
041: }
042:
043: /**
044: * Constructor for NachoCalendarDatePropertyEditor
045: *
046: * @param dateFormatString string used to format the Date object,
047: * see: <b>java.text.SimpleDateFormat </b>
048: *
049: * @param locale Locale used to display the Date object
050: */
051: public NachoCalendarDatePropertyEditor(String dateFormatString,
052: Locale locale) {
053: editor = CalendarFactory.createDateField();
054: ((DateField) editor).setValue(new Date());
055: }
056:
057: /**
058: * Constructor for NachoCalendarDatePropertyEditor
059: *
060: * @param locale Locale used to display the Date object
061: */
062: public NachoCalendarDatePropertyEditor(Locale locale) {
063: editor = CalendarFactory.createDateField();
064: ((DateField) editor).setValue(new Date());
065: ((DateField) editor).setLocale(locale);
066: }
067:
068: /**
069: * Returns the Date of the Calendar
070: *
071: * @return the date choosed as a <b>java.util.Date </b>b> object or
072: * null is the date is not set
073: */
074: public Object getValue() {
075: return ((DateField) editor).getValue();
076: }
077:
078: /**
079: * Sets the Date of the Calendar
080: *
081: * @param value the Date object
082: */
083: public void setValue(Object value) {
084: if (value != null) {
085: ((DateField) editor).setValue(value);
086: }
087: }
088:
089: /**
090: * Returns the Date formated with the locale and formatString set.
091: *
092: * @return the choosen Date as String
093: */
094: public String getAsText() {
095: Date date = (Date) getValue();
096: java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(
097: getDateFormatString());
098: String s = formatter.format(date);
099: return s;
100: }
101:
102: /**
103: * Sets the date format string. E.g "MMMMM d, yyyy" will result in
104: * "July 21, 2004" if this is the selected date and locale is
105: * English.
106: *
107: * @param dateFormatString The dateFormatString to set.
108: */
109: public void setDateFormatString(String dateFormatString) {
110: this .dateFormatString = dateFormatString;
111: }
112:
113: /**
114: * Gets the date format string.
115: *
116: * @return Returns the dateFormatString.
117: */
118: public String getDateFormatString() {
119: return dateFormatString;
120: }
121:
122: /**
123: * Sets the locale.
124: *
125: * @param l The new locale value
126: */
127: public void setLocale(Locale l) {
128: ((DateField) editor).setLocale(l);
129: }
130:
131: /**
132: * Returns the Locale used.
133: *
134: * @return the Locale object
135: */
136: public Locale getLocale() {
137: return ((DateField) editor).getLocale();
138: }
139:
140: }
|