KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > format > VerticalAlignment


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 type which describes the vertical alignment of data within a cell
24  */

25 public /*final*/ class VerticalAlignment
26 {
27   /**
28    * The internal binary value which gets written to the generated Excel file
29    */

30   private int value;
31
32   /**
33    * The textual description
34    */

35   private String JavaDoc string;
36
37   /**
38    * The list of alignments
39    */

40   private static VerticalAlignment[] alignments = new VerticalAlignment[0];
41
42   /**
43    * Constructor
44    *
45    * @param val
46    */

47   protected VerticalAlignment(int val, String JavaDoc s)
48   {
49     value = val;
50     string = s;
51
52     VerticalAlignment[] oldaligns = alignments;
53     alignments = new VerticalAlignment[oldaligns.length + 1];
54     System.arraycopy(oldaligns, 0, alignments, 0, oldaligns.length);
55     alignments[oldaligns.length] = this;
56   }
57
58   /**
59    * Accessor for the binary value
60    *
61    * @return the internal binary value
62    */

63   public int getValue()
64   {
65     return value;
66   }
67
68   /**
69    * Gets the textual description
70    */

71   public String JavaDoc getDescription()
72   {
73     return string;
74   }
75
76   /**
77    * Gets the alignment from the value
78    *
79    * @param val
80    * @return the alignment with that value
81    */

82   public static VerticalAlignment getAlignment(int val)
83   {
84     for (int i = 0 ; i < alignments.length ; i++)
85     {
86       if (alignments[i].getValue() == val)
87       {
88         return alignments[i];
89       }
90     }
91
92     return BOTTOM;
93   }
94
95
96   /**
97    * Cells with this specified vertical alignment will have their data
98    * aligned at the top
99    */

100   public static VerticalAlignment TOP = new VerticalAlignment(0, "top");
101   /**
102    * Cells with this specified vertical alignment will have their data
103    * aligned centrally
104    */

105   public static VerticalAlignment CENTRE = new VerticalAlignment(1, "centre");
106   /**
107    * Cells with this specified vertical alignment will have their data
108    * aligned at the bottom
109    */

110   public static VerticalAlignment BOTTOM = new VerticalAlignment(2, "bottom");
111   /**
112    * Cells with this specified vertical alignment will have their data
113    * justified
114    */

115   public static VerticalAlignment JUSTIFY = new VerticalAlignment(3, "Justify");
116 }
117
118
Popular Tags