KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > write > DateFormats


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.write;
21
22 import jxl.biff.DisplayFormat;
23
24 /**
25  * Static class which contains Excels predefined Date formats
26  */

27 public final class DateFormats
28 {
29   /**
30    * Inner class which holds the format index
31    */

32   private static class BuiltInFormat implements DisplayFormat
33   {
34     /**
35      * The index of this date format
36      */

37     private int index;
38     /**
39      * The excel format
40      */

41     private String JavaDoc formatString;
42
43     /**
44      * Constructor
45      *
46      * @param i the index
47      * @param s the format string
48      */

49     public BuiltInFormat(int i, String JavaDoc s)
50     {
51       index = i;
52       formatString = s;
53     }
54
55     /**
56      * Gets the format index
57      *
58      * @return the format index
59      */

60     public int getFormatIndex()
61     {
62       return index;
63     }
64
65     /**
66      * Interface method which determines whether the index has been set. For
67      * built ins this is always true
68      *
69      * @return TRUE, since this is a built in format
70      */

71     public boolean isInitialized()
72     {
73       return true;
74     }
75     /**
76      * Initialize this format with the specified position. Since this is a
77      * built in format, this is always initialized, so this method body for
78      * this is empty
79      *
80      * @param pos the position in the array
81      */

82     public void initialize(int pos)
83     {
84     }
85     /**
86      * Determines whether this format is a built in format
87      *
88      * @return TRUE, since this is a built in format
89      */

90     public boolean isBuiltIn()
91     {
92       return true;
93     }
94     /**
95      * Accesses the excel format string which is applied to the cell
96      * Note that this is the string that excel uses, and not the java
97      * equivalent
98      *
99      * @return the cell format string
100      */

101     public String JavaDoc getFormatString()
102     {
103       return formatString;
104     }
105
106     /**
107      * Standard equals method
108      *
109      * @param o the object to compare
110      * @return TRUE if the two objects are equal, FALSE otherwise
111      */

112     public boolean equals(Object JavaDoc o)
113     {
114       if (o == this)
115       {
116         return true;
117       }
118
119       if (!(o instanceof BuiltInFormat))
120       {
121         return false;
122       }
123
124       BuiltInFormat bif = (BuiltInFormat) o;
125
126       return index == bif.index;
127     }
128
129     /**
130      * Hash code implementation
131      *
132      * @return the hash code
133      */

134     public int hashCode()
135     {
136       return index;
137     }
138   }
139
140   // The available built in date formats
141

142   /**
143    * The default format. This is equivalent to a date format of "M/d/yy"
144    */

145   public static final DisplayFormat FORMAT1 =
146     new BuiltInFormat(0x0e, "M/d/yy");
147   /**
148    * The default format. This is equivalent to a date format of "M/d/yy"
149    */

150   public static final DisplayFormat DEFAULT = FORMAT1;
151
152   /**
153    * Equivalent to a date format of "d-MMM-yy"
154    */

155   public static final DisplayFormat FORMAT2 =
156     new BuiltInFormat(0xf, "d-MMM-yy");
157
158   /**
159    * Equivalent to a date format of "d-MMM"
160    */

161   public static final DisplayFormat FORMAT3 =
162     new BuiltInFormat(0x10, "d-MMM");
163
164   /**
165    * Equivalent to a date format of "MMM-yy"
166    */

167   public static final DisplayFormat FORMAT4 =
168     new BuiltInFormat(0x11, "MMM-yy");
169
170   /**
171    * Equivalent to a date format of "h:mm a"
172    */

173   public static final DisplayFormat FORMAT5 =
174     new BuiltInFormat(0x12, "h:mm a");
175
176   /**
177    * Equivalent to a date format of "h:mm:ss a"
178    */

179   public static final DisplayFormat FORMAT6 =
180     new BuiltInFormat(0x13, "h:mm:ss a");
181
182   /**
183    * Equivalent to a date format of "H:mm"
184    */

185   public static final DisplayFormat FORMAT7 =
186     new BuiltInFormat(0x14, "H:mm");
187
188   /**
189    * Equivalent to a date format of "H:mm:ss"
190    */

191   public static final DisplayFormat FORMAT8 =
192     new BuiltInFormat(0x15, "H:mm:ss");
193
194   /**
195    * Equivalent to a date format of "M/d/yy H:mm"
196    */

197   public static final DisplayFormat FORMAT9 =
198     new BuiltInFormat(0x16, "M/d/yy H:mm");
199
200   /**
201    * Equivalent to a date format of "mm:ss"
202    */

203   public static final DisplayFormat FORMAT10 =
204     new BuiltInFormat(0x2d, "mm:ss");
205
206   /**
207    * Equivalent to a date format of "H:mm:ss"
208    */

209   public static final DisplayFormat FORMAT11 =
210     new BuiltInFormat(0x2e, "H:mm:ss");
211
212   /**
213    * Equivalent to a date format of "mm:ss.S"
214    */

215   public static final DisplayFormat FORMAT12 =
216     new BuiltInFormat(0x2f, "H:mm:ss");
217 }
218
219
220
221
Popular Tags