001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.swing.datefield;
020:
021: /**
022: * Represents a date field base on a parsed date format. For example if
023: * the date format string was "yyy-MM-dd" you would end up with 5 date format
024: * blocks;
025: *
026: * 3 active ones: "yyyy", "MM" and "dd"
027: * 2 inactive ones: "-" and "-"
028: *
029: * @author Matthew Large
030: * @version $Revision: 1.1 $
031: *
032: */
033: public class DateFormatBlock {
034:
035: /**
036: * Format string, based on the {@link java.text.SimpleDateFormat} format strings.
037: */
038: private String m_sFormat = null;
039:
040: /**
041: * true if this is an active block, i.e. is not a separator such as "-" or "/".
042: */
043: private boolean m_bIsActiveBlock = false;
044:
045: /**
046: * Length that the input value for this block should be.
047: */
048: private int m_nInputLength = -1;
049:
050: /**
051: * Position in date string that this block starts at.
052: */
053: private int m_nStartPosition = -1;
054:
055: /**
056: * Value for when the block is cleared.
057: */
058: private String m_sClearedValue = null;
059:
060: /**
061: * Calendar field that this block represents. Uses the {@link java.util.Calendar} field identifiers.
062: */
063: private int m_nCalendarField = -1;
064:
065: /**
066: * The format string to be displayed, this may be different from the {@link java.text.SimpleDateFormat} based string, e.g. "yyyy" will be displayed as "ccyy" which is more acceptable to general users.
067: */
068: private String m_sEntryFormat = null;
069:
070: /**
071: * Constructs a new date format block.
072: *
073: * @param sFormat Format string
074: * @param bIsActiveBlock true if this is an active block
075: * @param nStartPosition Position in value string that this block starts at
076: * @param nInputLength Length of input value
077: * @param sClearedValue Value for when this block is cleared
078: * @param nCalendarField {@link java.util.Calendar} field that this block represents
079: * @param sEntryFormat Format string to be displayed
080: */
081: public DateFormatBlock(String sFormat, boolean bIsActiveBlock,
082: int nStartPosition, int nInputLength, String sClearedValue,
083: int nCalendarField, String sEntryFormat) {
084: super ();
085: this .m_sFormat = sFormat;
086: this .m_bIsActiveBlock = bIsActiveBlock;
087: this .m_nStartPosition = nStartPosition;
088: this .m_nInputLength = nInputLength;
089: this .m_sClearedValue = sClearedValue;
090: this .m_nCalendarField = nCalendarField;
091: this .m_sEntryFormat = sEntryFormat;
092: }
093:
094: /**
095: * Returns the {@link java.util.Calendar} date field that this block
096: * represents.
097: *
098: * @return Date field
099: */
100: public int getCalendarField() {
101: return this .m_nCalendarField;
102: }
103:
104: /**
105: * Returns the cleared value.
106: *
107: * @return Value
108: */
109: public String getClearedValue() {
110: return this .m_sClearedValue;
111: }
112:
113: /**
114: * Sets the cleared value.
115: *
116: * @param sClearedValue Value
117: */
118: public void setClearedValue(String sClearedValue) {
119: this .m_sClearedValue = sClearedValue;
120: }
121:
122: /**
123: * Returns the format string.
124: *
125: * @return Format string
126: */
127: public String getFormat() {
128: return this .m_sFormat;
129: }
130:
131: /**
132: * Returns the length for the input value.
133: *
134: * @return Length
135: */
136: public int getInputLength() {
137: return m_nInputLength;
138: }
139:
140: /**
141: * Returns the position in the date string that this block starts at.
142: *
143: * @return Start position
144: */
145: public int getStartPosition() {
146: return this .m_nStartPosition;
147: }
148:
149: /**
150: * Checks if this is an active block.
151: *
152: * @return true if this is an active block
153: */
154: public boolean isActiveBlock() {
155: return this .m_bIsActiveBlock;
156: }
157:
158: /**
159: * Returns the format string to be displayed.
160: *
161: * @return Displayable format string
162: */
163: public String getEntryFormat() {
164: return this .m_sEntryFormat;
165: }
166:
167: /* (non-Javadoc)
168: * @see java.lang.Object#toString()
169: */
170: public String toString() {
171: StringBuffer sBuff = new StringBuffer("[\"");
172: sBuff.append(this .m_sFormat).append("\"(").append(
173: m_bIsActiveBlock).append(")]");
174: return sBuff.toString();
175: }
176: }
|