KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > format > ScriptStyle


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.format;
21
22 /**
23  * Enumeration class which contains the various script styles available
24  * within the standard Excel ScriptStyle palette
25  *
26  */

27 public final class ScriptStyle
28 {
29   /**
30    * The internal numerical representation of the ScriptStyle
31    */

32   private int value;
33
34   /**
35    * The display string for the script style. Used when presenting the
36    * format information
37    */

38   private String JavaDoc string;
39
40   /**
41    * The list of ScriptStyles
42    */

43   private static ScriptStyle[] styles = new ScriptStyle[0];
44
45
46   /**
47    * Private constructor
48    *
49    * @param val
50    * @param s the display string
51    */

52   protected ScriptStyle(int val, String JavaDoc s)
53   {
54     value = val;
55     string = s;
56
57     ScriptStyle[] oldstyles = styles;
58     styles = new ScriptStyle[oldstyles.length + 1];
59     System.arraycopy(oldstyles, 0, styles, 0, oldstyles.length);
60     styles[oldstyles.length] = this;
61   }
62
63   /**
64    * Gets the value of this style. This is the value that is written to
65    * the generated Excel file
66    *
67    * @return the binary value
68    */

69   public int getValue()
70   {
71     return value;
72   }
73
74   /**
75    * Gets the string description for display purposes
76    *
77    * @return the string description
78    */

79   public String JavaDoc getDescription()
80   {
81     return string;
82   }
83
84   /**
85    * Gets the ScriptStyle from the value
86    *
87    * @param val
88    * @return the ScriptStyle with that value
89    */

90   public static ScriptStyle getStyle(int val)
91   {
92     for (int i = 0 ; i < styles.length ; i++)
93     {
94       if (styles[i].getValue() == val)
95       {
96         return styles[i];
97       }
98     }
99
100     return NORMAL_SCRIPT;
101   }
102
103   // The script styles
104
public static final ScriptStyle NORMAL_SCRIPT = new ScriptStyle(0, "normal");
105   public static final ScriptStyle SUPERSCRIPT = new ScriptStyle(1, "super");
106   public static final ScriptStyle SUBSCRIPT = new ScriptStyle(2, "sub");
107
108
109 }
110
111
112
113
114
115
116
117
118
119
120
121
Popular Tags