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 com.toedter.calendar.JDateChooser;
023:
024: /**
025: * Date Property Editor based on <a
026: * href="http://www.toedter.com/en/jcalendar/index.html">toedter
027: * JCalendar </a> component. <br>
028: */
029: public class JCalendarDatePropertyEditor extends AbstractPropertyEditor {
030:
031: /**
032: * Constructor for JCalendarDatePropertyEditor
033: */
034: public JCalendarDatePropertyEditor() {
035: editor = new JDateChooser();
036: }
037:
038: /**
039: * Constructor for JCalendarDatePropertyEditor
040: *
041: * @param dateFormatString string used to format the Date object,
042: * see: <b>java.text.SimpleDateFormat </b>
043: *
044: * @param locale Locale used to display the Date object
045: */
046: public JCalendarDatePropertyEditor(String dateFormatString,
047: Locale locale) {
048: editor = new JDateChooser();
049: ((JDateChooser) editor).setDateFormatString(dateFormatString);
050: ((JDateChooser) editor).setLocale(locale);
051: }
052:
053: /**
054: * Constructor for JCalendarDatePropertyEditor
055: *
056: * @param locale Locale used to display the Date object
057: */
058: public JCalendarDatePropertyEditor(Locale locale) {
059: editor = new JDateChooser();
060: ((JDateChooser) editor).setLocale(locale);
061: }
062:
063: /**
064: * Returns the Date of the Calendar
065: *
066: * @return the date choosed as a <b>java.util.Date </b>b> object or
067: * null is the date is not set
068: */
069: public Object getValue() {
070: return ((JDateChooser) editor).getDate();
071: }
072:
073: /**
074: * Sets the Date of the Calendar
075: *
076: * @param value the Date object
077: */
078: public void setValue(Object value) {
079: if (value != null) {
080: ((JDateChooser) editor).setDate((Date) value);
081: }
082: }
083:
084: /**
085: * Returns the Date formated with the locale and formatString set.
086: *
087: * @return the choosen Date as String
088: */
089: public String getAsText() {
090: Date date = (Date) getValue();
091: java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(
092: getDateFormatString());
093: String s = formatter.format(date);
094: return s;
095: }
096:
097: /**
098: * Sets the date format string. E.g "MMMMM d, yyyy" will result in
099: * "July 21, 2004" if this is the selected date and locale is
100: * English.
101: *
102: * @param dateFormatString The dateFormatString to set.
103: */
104: public void setDateFormatString(String dateFormatString) {
105: ((JDateChooser) editor).setDateFormatString(dateFormatString);
106: }
107:
108: /**
109: * Gets the date format string.
110: *
111: * @return Returns the dateFormatString.
112: */
113: public String getDateFormatString() {
114: return ((JDateChooser) editor).getDateFormatString();
115: }
116:
117: /**
118: * Sets the locale.
119: *
120: * @param l The new locale value
121: */
122: public void setLocale(Locale l) {
123: ((JDateChooser) editor).setLocale(l);
124: }
125:
126: /**
127: * Returns the Locale used.
128: *
129: * @return the Locale object
130: */
131: public Locale getLocale() {
132: return ((JDateChooser) editor).getLocale();
133: }
134:
135: }
|