KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > BuiltInFormat


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.biff;
21
22 import jxl.format.Format;
23
24 /**
25  * The excel string for the various built in formats. Used to present
26  * the cell format information back to the user
27  *
28  * The difference between this class and the various format object contained
29  * in the jxl.write package is that this object contains the Excel strings,
30  * not their java equivalents
31  */

32 final class BuiltInFormat implements Format, DisplayFormat
33 {
34   /**
35    * The excel format string
36    */

37   private String JavaDoc formatString;
38
39   /**
40    * The index
41    */

42   private int formatIndex;
43
44   /**
45    * Constructor
46    *
47    * @param s the format string
48    * @param i the format index
49    */

50   private BuiltInFormat(String JavaDoc s, int i)
51   {
52     formatIndex = i;
53     formatString = s;
54   }
55
56   /**
57    * Accesses the excel format string which is applied to the cell
58    * Note that this is the string that excel uses, and not the java
59    * equivalent
60    *
61    * @return the cell format string
62    */

63   public String JavaDoc getFormatString()
64   {
65     return formatString;
66   }
67
68   /**
69    * Accessor for the index style of this format
70    *
71    * @return the index for this format
72    */

73   public int getFormatIndex()
74   {
75     return formatIndex;
76   }
77   /**
78    * Accessor to see whether this format has been initialized
79    *
80    * @return TRUE if initialized, FALSE otherwise
81    */

82   public boolean isInitialized()
83   {
84     return true;
85   }
86   /**
87    * Initializes this format with the specified index number
88    *
89    * @param pos the position of this format record in the workbook
90    */

91   public void initialize(int pos)
92   {
93   }
94
95   /**
96    * Accessor to determine whether or not this format is built in
97    *
98    * @return TRUE if this format is a built in format, FALSE otherwise
99    */

100   public boolean isBuiltIn()
101   {
102     return true;
103   }
104
105   /**
106    * The list of built in formats
107    */

108   public static BuiltInFormat[] builtIns = new BuiltInFormat[0x32];
109
110   // Populate the built ins
111
static
112   {
113     builtIns[0x0] = new BuiltInFormat("", 0);
114     builtIns[0x1] = new BuiltInFormat("0", 1);
115     builtIns[0x2] = new BuiltInFormat("0.00", 2);
116     builtIns[0x3] = new BuiltInFormat("#,##0", 3);
117     builtIns[0x4] = new BuiltInFormat("#,##0.00", 4);
118     builtIns[0x5] = new BuiltInFormat("($#,##0_);($#,##0)", 5);
119     builtIns[0x6] = new BuiltInFormat("($#,##0_);[Red]($#,##0)", 6);
120     builtIns[0x7] = new BuiltInFormat("($#,##0_);[Red]($#,##0)", 7);
121     builtIns[0x8] = new BuiltInFormat("($#,##0.00_);[Red]($#,##0.00)", 8);
122     builtIns[0x9] = new BuiltInFormat("0%", 9);
123     builtIns[0xa] = new BuiltInFormat("0.00%", 10);
124     builtIns[0xb] = new BuiltInFormat("0.00E+00", 11);
125     builtIns[0xc] = new BuiltInFormat("# ?/?", 12);
126     builtIns[0xd] = new BuiltInFormat("# ??/??", 13);
127     builtIns[0xe] = new BuiltInFormat("dd/mm/yyyy", 14);
128     builtIns[0xf] = new BuiltInFormat("d-mmm-yy", 15);
129     builtIns[0x10] = new BuiltInFormat("d-mmm", 16);
130     builtIns[0x11] = new BuiltInFormat("mmm-yy", 17);
131     builtIns[0x12] = new BuiltInFormat("h:mm AM/PM", 18);
132     builtIns[0x13] = new BuiltInFormat("h:mm:ss AM/PM", 19);
133     builtIns[0x14] = new BuiltInFormat("h:mm", 20);
134     builtIns[0x15] = new BuiltInFormat("h:mm:ss", 21);
135     builtIns[0x16] = new BuiltInFormat("m/d/yy h:mm", 22);
136     builtIns[0x25] = new BuiltInFormat("(#,##0_);(#,##0)", 0x25);
137     builtIns[0x26] = new BuiltInFormat("(#,##0_);[Red](#,##0)", 0x26);
138     builtIns[0x27] = new BuiltInFormat("(#,##0.00_);(#,##0.00)", 0x27);
139     builtIns[0x28] = new BuiltInFormat("(#,##0.00_);[Red](#,##0.00)", 0x28);
140     builtIns[0x29] = new BuiltInFormat
141       ("_(*#,##0_);_(*(#,##0);_(*\"-\"_);(@_)", 0x29);
142     builtIns[0x2a] = new BuiltInFormat
143       ("_($*#,##0_);_($*(#,##0);_($*\"-\"_);(@_)", 0x2a);
144     builtIns[0x2b] = new BuiltInFormat
145       ("_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);(@_)", 0x2b);
146     builtIns[0x2c] = new BuiltInFormat
147       ("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);(@_)", 0x2c);
148     builtIns[0x2d] = new BuiltInFormat("mm:ss", 0x2d);
149     builtIns[0x2e] = new BuiltInFormat("[h]mm:ss", 0x2e);
150     builtIns[0x2f] = new BuiltInFormat("mm:ss.0", 0x2f);
151     builtIns[0x30] = new BuiltInFormat("##0.0E+0", 0x30);
152     builtIns[0x31] = new BuiltInFormat("@", 0x31);
153   }
154 }
155
156
Popular Tags