KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > format > Alignment


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 alignments for data within a
24  * cell
25  */

26 public /*final*/ class Alignment
27 {
28   /**
29    * The internal numerical repreentation of the alignment
30    */

31   private int value;
32
33   /**
34    * The string description of this alignment
35    */

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

41   private static Alignment[] alignments = new Alignment[0];
42
43   /**
44    * Private constructor
45    *
46    * @param val
47    * @param string
48    */

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

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

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

87   public static Alignment getAlignment(int val)
88   {
89     for (int i = 0 ; i < alignments.length ; i++)
90     {
91       if (alignments[i].getValue() == val)
92       {
93         return alignments[i];
94       }
95     }
96
97     return GENERAL;
98   }
99   
100   /**
101    * The standard alignment
102    */

103   public static Alignment GENERAL = new Alignment(0, "general");
104   /**
105    * Data cells with this alignment will appear at the left hand edge of the
106    * cell
107    */

108   public static Alignment LEFT = new Alignment(1, "left");
109   /**
110    * Data in cells with this alignment will be centred
111    */

112   public static Alignment CENTRE = new Alignment(2, "centre");
113   /**
114    * Data in cells with this alignment will be right aligned
115    */

116   public static Alignment RIGHT = new Alignment(3, "right");
117   /**
118    * Data in cells with this alignment will fill the cell
119    */

120   public static Alignment FILL = new Alignment(4,"fill");
121   /**
122    * Data in cells with this alignment will be justified
123    */

124   public static Alignment JUSTIFY = new Alignment(5, "justify");
125 }
126
127
Popular Tags