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: * A DateBlock allows values to be placed in a one-2-one mapping with
023: * {@link org.openharmonise.swing.datefield.DateFormatBlock} objects.
024: * Therefore each element of a date value can be manipulated.
025: *
026: * @author Matthew Large
027: * @version $Revision: 1.1 $
028: *
029: */
030: public class DateBlock {
031:
032: /**
033: * Format block that this DateBlock is associated to.
034: */
035: private DateFormatBlock m_formatBlock = null;
036:
037: /**
038: * Position in date string that this value starts at.
039: */
040: private int m_nStartPos = -1;
041:
042: /**
043: * String length of this value.
044: */
045: private int m_nLength = -1;
046:
047: /**
048: * Current value.
049: */
050: private String m_sValue = "";
051:
052: /**
053: * Previous value for roll backs.
054: */
055: private String m_sPreviousValue = "";
056:
057: /**
058: * Constructs a new DateBlock.
059: *
060: * @param formatBlock Format block that this DateBlock is associated to
061: * @param nStartPos Position in date string that this value starts at
062: * @param sValue Current value
063: */
064: public DateBlock(DateFormatBlock formatBlock, int nStartPos,
065: String sValue) {
066: super ();
067: this .m_formatBlock = formatBlock;
068: this .m_nStartPos = nStartPos;
069: this .m_sValue = sValue;
070: this .m_sPreviousValue = sValue;
071:
072: this .setup();
073: }
074:
075: /**
076: * Sets the previous value.
077: *
078: * @param sPreviousValue Value
079: */
080: public void setPreviousValue(String sPreviousValue) {
081: this .m_sPreviousValue = sPreviousValue;
082: }
083:
084: /**
085: * Returns the previous value.
086: *
087: * @return Value
088: */
089: public String getPreviousValue() {
090: return this .m_sPreviousValue;
091: }
092:
093: /**
094: * Configures this DateBlock.
095: *
096: */
097: private void setup() {
098: }
099:
100: /**
101: * Returns the position in date string that this value starts at.
102: *
103: * @return Start position in date string
104: */
105: public int getStartPos() {
106: return this .m_nStartPos;
107: }
108:
109: /**
110: * Sets the position in the date string that this value starts at.
111: *
112: * @param nStartPos Start position in date string
113: */
114: public void setStartPos(int nStartPos) {
115: this .m_nStartPos = nStartPos;
116: }
117:
118: /**
119: * Returns the length of this value.
120: *
121: * @return Length
122: */
123: public int getLength() {
124: return this .m_sValue.length();
125: }
126:
127: /**
128: * Returns the current value.
129: *
130: * @return Value
131: */
132: public String getValue() {
133: return this .m_sValue;
134: }
135:
136: /**
137: * Sets the current value.
138: *
139: * @param sValue Value
140: */
141: public void setValue(String sValue) {
142: this .m_sValue = sValue;
143: }
144:
145: /**
146: * Returns the format block.
147: *
148: * @return Format block
149: */
150: public DateFormatBlock getFormatBlock() {
151: return this .m_formatBlock;
152: }
153:
154: /**
155: * Checks if this date block has a complete value.
156: *
157: * @return true if this date block has a complete value
158: */
159: public boolean hasValue() {
160: return (!this .getFormatBlock().isActiveBlock() || !this .m_sValue
161: .trim().equalsIgnoreCase(
162: this .m_formatBlock.getEntryFormat().trim()));
163: }
164:
165: /**
166: * Clears the value, resetting it to the format string.
167: *
168: */
169: public void clear() {
170: this.m_sValue = this.m_formatBlock.getClearedValue();
171: this.m_sPreviousValue = this.m_formatBlock.getClearedValue();
172: }
173: }
|