KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Represents a date field base on a parsed date format. For example if
23  * the date format string was "yyy-MM-dd" you would end up with 5 date format
24  * blocks;
25  *
26  * 3 active ones: "yyyy", "MM" and "dd"
27  * 2 inactive ones: "-" and "-"
28  *
29  * @author Matthew Large
30  * @version $Revision: 1.1 $
31  *
32  */

33 public class DateFormatBlock {
34     
35     /**
36      * Format string, based on the {@link java.text.SimpleDateFormat} format strings.
37      */

38     private String JavaDoc m_sFormat = null;
39     
40     /**
41      * true if this is an active block, i.e. is not a separator such as "-" or "/".
42      */

43     private boolean m_bIsActiveBlock = false;
44     
45     /**
46      * Length that the input value for this block should be.
47      */

48     private int m_nInputLength = -1;
49     
50     /**
51      * Position in date string that this block starts at.
52      */

53     private int m_nStartPosition = -1;
54     
55     /**
56      * Value for when the block is cleared.
57      */

58     private String JavaDoc m_sClearedValue = null;
59     
60     /**
61      * Calendar field that this block represents. Uses the {@link java.util.Calendar} field identifiers.
62      */

63     private int m_nCalendarField = -1;
64
65     /**
66      * 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.
67      */

68     private String JavaDoc m_sEntryFormat = null;
69
70     /**
71      * Constructs a new date format block.
72      *
73      * @param sFormat Format string
74      * @param bIsActiveBlock true if this is an active block
75      * @param nStartPosition Position in value string that this block starts at
76      * @param nInputLength Length of input value
77      * @param sClearedValue Value for when this block is cleared
78      * @param nCalendarField {@link java.util.Calendar} field that this block represents
79      * @param sEntryFormat Format string to be displayed
80      */

81     public DateFormatBlock(String JavaDoc sFormat, boolean bIsActiveBlock, int nStartPosition, int nInputLength, String JavaDoc sClearedValue, int nCalendarField, String JavaDoc sEntryFormat) {
82         super();
83         this.m_sFormat = sFormat;
84         this.m_bIsActiveBlock = bIsActiveBlock;
85         this.m_nStartPosition = nStartPosition;
86         this.m_nInputLength = nInputLength;
87         this.m_sClearedValue = sClearedValue;
88         this.m_nCalendarField = nCalendarField;
89         this.m_sEntryFormat = sEntryFormat;
90     }
91     
92     /**
93      * Returns the {@link java.util.Calendar} date field that this block
94      * represents.
95      *
96      * @return Date field
97      */

98     public int getCalendarField() {
99         return this.m_nCalendarField;
100     }
101     
102     /**
103      * Returns the cleared value.
104      *
105      * @return Value
106      */

107     public String JavaDoc getClearedValue() {
108         return this.m_sClearedValue;
109     }
110     
111     /**
112      * Sets the cleared value.
113      *
114      * @param sClearedValue Value
115      */

116     public void setClearedValue(String JavaDoc sClearedValue) {
117         this.m_sClearedValue = sClearedValue;
118     }
119     
120     /**
121      * Returns the format string.
122      *
123      * @return Format string
124      */

125     public String JavaDoc getFormat() {
126         return this.m_sFormat;
127     }
128     
129     /**
130      * Returns the length for the input value.
131      *
132      * @return Length
133      */

134     public int getInputLength() {
135         return m_nInputLength;
136     }
137     
138     /**
139      * Returns the position in the date string that this block starts at.
140      *
141      * @return Start position
142      */

143     public int getStartPosition() {
144         return this.m_nStartPosition;
145     }
146     
147     /**
148      * Checks if this is an active block.
149      *
150      * @return true if this is an active block
151      */

152     public boolean isActiveBlock() {
153         return this.m_bIsActiveBlock;
154     }
155     
156     /**
157      * Returns the format string to be displayed.
158      *
159      * @return Displayable format string
160      */

161     public String JavaDoc getEntryFormat() {
162         return this.m_sEntryFormat;
163     }
164
165     /* (non-Javadoc)
166      * @see java.lang.Object#toString()
167      */

168     public String JavaDoc toString() {
169         StringBuffer JavaDoc sBuff = new StringBuffer JavaDoc("[\"");
170         sBuff.append(this.m_sFormat)
171              .append("\"(")
172              .append(m_bIsActiveBlock)
173              .append(")]");
174         return sBuff.toString();
175     }
176 }
177
Popular Tags