001: /*
002: * Created on 04/01/2005 Swing Components - visit http://sf.net/projects/gfd Copyright (C) 2004 Igor Regis da
003: * Silva Simões This program is free software; you can redistribute it and/or modify it under the terms of the
004: * GNU General Public License as published by the Free Software Foundation; either version 2 of the License,
005: * or (at your option) any later version. This program is distributed in the hope that it will be useful, but
006: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
007: * PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU
008: * General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59
009: * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
010: */
011:
012: package br.com.gfpshare.beans.property.editor;
013:
014: import java.text.SimpleDateFormat;
015: import java.util.Date;
016: import java.util.Locale;
017:
018: import br.com.gfpshare.beans.ZYearEditor;
019:
020: import com.l2fprod.common.beans.editor.AbstractPropertyEditor;
021:
022: /**
023: * Date Property Editor based on <a href="http://sf.net/projects/gfd">GFP ICalendarChooser </a> component.
024: * <br>
025: */
026: public class IYearPropertyEditor extends AbstractPropertyEditor {
027:
028: /**
029: * Constructor for JCalendarDatePropertyEditor
030: */
031: public IYearPropertyEditor() {
032: editor = new ZYearEditor();
033: }
034:
035: /**
036: * Constructor for JCalendarDatePropertyEditor
037: *
038: * @param dateFormatString string used to format the Date object, see: <b>java.text.SimpleDateFormat </b>
039: * @param locale Locale used to display the Date object
040: */
041: public IYearPropertyEditor(String dateFormatString, Locale locale) {
042: editor = new ZYearEditor();
043: ((ZYearEditor) editor).setLocale(locale);
044: }
045:
046: /**
047: * Constructor for JCalendarDatePropertyEditor
048: *
049: * @param locale Locale used to display the Date object
050: */
051: public IYearPropertyEditor(Locale locale) {
052: editor = new ZYearEditor();
053: ((ZYearEditor) editor).setLocale(locale);
054: }
055:
056: /**
057: * Returns the Date of the Calendar
058: *
059: * @return the date choosed as a <b>java.util.Date </b>b> object or null is the date is not set
060: */
061: @Override
062: public Object getValue() {
063: return ((ZYearEditor) editor).getValue();
064: }
065:
066: /**
067: * Sets the Date of the Calendar
068: *
069: * @param value the Date object
070: */
071: @Override
072: public void setValue(Object value) {
073: if (value != null && value instanceof Date) {
074: ((ZYearEditor) editor).setValue(value);
075: }
076: }
077:
078: /**
079: * Returns the Date formated with the locale and formatString set.
080: *
081: * @return the choosen Date as String
082: */
083: @Override
084: public String getAsText() {
085: return new SimpleDateFormat("YYYY")
086: .format(((ZYearEditor) editor).getValue());
087: }
088:
089: /**
090: * Sets the locale.
091: *
092: * @param l The new locale value
093: */
094: public void setLocale(Locale l) {
095: ((ZYearEditor) editor).setLocale(l);
096: }
097:
098: /**
099: * Returns the Locale used.
100: *
101: * @return the Locale object
102: */
103: public Locale getLocale() {
104: return ((ZYearEditor) editor).getLocale();
105: }
106:
107: }
|