KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > swing > datefield > DateBlock


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.swing.datefield;
20
21 /**
22  * A DateBlock allows values to be placed in a one-2-one mapping with
23  * {@link org.openharmonise.swing.datefield.DateFormatBlock} objects.
24  * Therefore each element of a date value can be manipulated.
25  *
26  * @author Matthew Large
27  * @version $Revision: 1.1 $
28  *
29  */

30 public class DateBlock {
31     
32     /**
33      * Format block that this DateBlock is associated to.
34      */

35     private DateFormatBlock m_formatBlock = null;
36     
37     /**
38      * Position in date string that this value starts at.
39      */

40     private int m_nStartPos = -1;
41     
42     /**
43      * String length of this value.
44      */

45     private int m_nLength = -1;
46     
47     /**
48      * Current value.
49      */

50     private String JavaDoc m_sValue = "";
51     
52     /**
53      * Previous value for roll backs.
54      */

55     private String JavaDoc m_sPreviousValue = "";
56
57     /**
58      * Constructs a new DateBlock.
59      *
60      * @param formatBlock Format block that this DateBlock is associated to
61      * @param nStartPos Position in date string that this value starts at
62      * @param sValue Current value
63      */

64     public DateBlock(DateFormatBlock formatBlock, int nStartPos, String JavaDoc sValue) {
65         super();
66         this.m_formatBlock = formatBlock;
67         this.m_nStartPos = nStartPos;
68         this.m_sValue = sValue;
69         this.m_sPreviousValue = sValue;
70         
71         this.setup();
72     }
73     
74     /**
75      * Sets the previous value.
76      *
77      * @param sPreviousValue Value
78      */

79     public void setPreviousValue(String JavaDoc sPreviousValue) {
80         this.m_sPreviousValue = sPreviousValue;
81     }
82     
83     /**
84      * Returns the previous value.
85      *
86      * @return Value
87      */

88     public String JavaDoc getPreviousValue() {
89         return this.m_sPreviousValue;
90     }
91     
92     /**
93      * Configures this DateBlock.
94      *
95      */

96     private void setup() {
97     }
98     
99     /**
100      * Returns the position in date string that this value starts at.
101      *
102      * @return Start position in date string
103      */

104     public int getStartPos() {
105         return this.m_nStartPos;
106     }
107     
108     /**
109      * Sets the position in the date string that this value starts at.
110      *
111      * @param nStartPos Start position in date string
112      */

113     public void setStartPos(int nStartPos) {
114         this.m_nStartPos = nStartPos;
115     }
116     
117     /**
118      * Returns the length of this value.
119      *
120      * @return Length
121      */

122     public int getLength() {
123         return this.m_sValue.length();
124     }
125     
126     /**
127      * Returns the current value.
128      *
129      * @return Value
130      */

131     public String JavaDoc getValue() {
132         return this.m_sValue;
133     }
134     
135     /**
136      * Sets the current value.
137      *
138      * @param sValue Value
139      */

140     public void setValue(String JavaDoc sValue) {
141         this.m_sValue = sValue;
142     }
143
144     /**
145      * Returns the format block.
146      *
147      * @return Format block
148      */

149     public DateFormatBlock getFormatBlock() {
150         return this.m_formatBlock;
151     }
152     
153     /**
154      * Checks if this date block has a complete value.
155      *
156      * @return true if this date block has a complete value
157      */

158     public boolean hasValue() {
159         return (!this.getFormatBlock().isActiveBlock() || !this.m_sValue.trim().equalsIgnoreCase(this.m_formatBlock.getEntryFormat().trim()));
160     }
161     
162     /**
163      * Clears the value, resetting it to the format string.
164      *
165      */

166     public void clear() {
167         this.m_sValue = this.m_formatBlock.getClearedValue();
168         this.m_sPreviousValue = this.m_formatBlock.getClearedValue();
169     }
170 }
171
Popular Tags