001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.components;
019:
020: import java.text.DateFormat;
021:
022: import de.finix.contelligent.AbstractComponent;
023: import de.finix.contelligent.content.ContelligentDateContent;
024: import de.finix.contelligent.content.Content;
025: import de.finix.contelligent.content.ContentProvider;
026: import de.finix.contelligent.content.DateContent;
027: import de.finix.contelligent.logging.LoggingService;
028: import de.finix.contelligent.render.DateRenderer;
029: import de.finix.contelligent.render.Renderable;
030: import de.finix.contelligent.render.Renderer;
031:
032: public class CDate extends AbstractComponent implements
033: ContentProvider, Renderable {
034: final static org.apache.log4j.Logger log = LoggingService
035: .getLogger(CDate.class);
036:
037: private final static String DATE_FORMAT = "dateFormat";
038:
039: private final static String TIME_FORMAT = "timeFormat";
040:
041: private final static int HIDE = 99;
042:
043: private String dateFormat, timeFormat;
044:
045: private int dateStyle = DateFormat.DEFAULT;
046:
047: private int timeStyle = DateFormat.DEFAULT;
048:
049: private DateContent content;
050:
051: private DateRenderer renderer;
052:
053: public void postCreate() throws Exception {
054: content = new ContelligentDateContent(this );
055: renderer = new DateRenderer(content, dateStyle, timeStyle);
056: }
057:
058: public Renderer getRenderer() {
059: return renderer;
060: }
061:
062: public Content getContent() {
063: return content;
064: }
065:
066: public String getDateFormat() {
067: return dateFormat;
068: }
069:
070: public void setDateFormat(String dateFormat) {
071: this .dateFormat = dateFormat;
072: this .dateStyle = parseDateFormat(dateFormat);
073: // On creation, this is called before the content is set
074: if (content != null) {
075: renderer = new DateRenderer(content, dateStyle, timeStyle);
076: }
077: }
078:
079: public String getTimeFormat() {
080: return timeFormat;
081: }
082:
083: public void setTimeFormat(String timeFormat) {
084: this .timeFormat = timeFormat;
085: this .timeStyle = parseDateFormat(timeFormat);
086: // On creation, this is called before the content is set
087: if (content != null) {
088: renderer = new DateRenderer(content, dateStyle, timeStyle);
089: }
090: }
091:
092: private int parseDateFormat(String format) {
093: if (format.equals("short")) {
094: return DateFormat.SHORT;
095: } else if (format.equals("medium")) {
096: return DateFormat.MEDIUM;
097: } else if (format.equals("long")) {
098: return DateFormat.LONG;
099: } else if (format.equals("full")) {
100: return DateFormat.FULL;
101: }
102: return HIDE;
103: }
104:
105: }
|