KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > format > Pattern


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 /**
24  * Enumeration class which contains the various patterns available within
25  * the standard Excel pattern palette
26  */

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

32   private int value;
33
34   /**
35    * The textual description
36    */

37   private String JavaDoc string;
38
39   /**
40    * The list of patterns
41    */

42   private static Pattern[] patterns = new Pattern[0];
43
44   /**
45    * Private constructor
46    *
47    * @param val
48    * @param s
49    */

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

67   public int getValue()
68   {
69     return value;
70   }
71
72   /**
73    * Gets the textual description
74    *
75    * @return the string
76    */

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

88   public static Pattern getPattern(int val)
89   {
90     for (int i = 0 ; i < patterns.length ; i++)
91     {
92       if (patterns[i].getValue() == val)
93       {
94         return patterns[i];
95       }
96     }
97
98     return NONE;
99   }
100
101   public final static Pattern NONE = new Pattern(0x0, "None");
102   public final static Pattern SOLID = new Pattern(0x1, "Solid");
103
104   public final static Pattern GRAY_50 = new Pattern(0x2, "Gray 50%");
105   public final static Pattern GRAY_75 = new Pattern(0x3, "Gray 75%");
106   public final static Pattern GRAY_25 = new Pattern(0x4, "Gray 25%");
107
108   public final static Pattern PATTERN1 = new Pattern(0x5, "Pattern 1");
109   public final static Pattern PATTERN2 = new Pattern(0x6, "Pattern 2");
110   public final static Pattern PATTERN3 = new Pattern(0x7, "Pattern 3");
111   public final static Pattern PATTERN4 = new Pattern(0x8, "Pattern 4");
112   public final static Pattern PATTERN5 = new Pattern(0x9, "Pattern 5");
113   public final static Pattern PATTERN6 = new Pattern(0xa, "Pattern 6");
114   public final static Pattern PATTERN7 = new Pattern(0xb, "Pattern 7");
115   public final static Pattern PATTERN8 = new Pattern(0xc, "Pattern 8");
116   public final static Pattern PATTERN9 = new Pattern(0xd, "Pattern 9");
117   public final static Pattern PATTERN10 = new Pattern(0xe, "Pattern 10");
118   public final static Pattern PATTERN11 = new Pattern(0xf, "Pattern 11");
119   public final static Pattern PATTERN12 = new Pattern(0x10, "Pattern 12");
120   public final static Pattern PATTERN13 = new Pattern(0x11, "Pattern 13");
121   public final static Pattern PATTERN14 = new Pattern(0x12, "Pattern 14");
122 }
123
124
125
126
127
128
129
130
131
132
133
134
Popular Tags