KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > format > Orientation


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 orientation of data within a cell
24  */

25 public final class Orientation
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 Orientation[] orientations = new Orientation[0];
41
42   /**
43    * Constructor
44    *
45    * @param val
46    */

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

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

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

81   public static Orientation getOrientation(int val)
82   {
83     for (int i = 0 ; i < orientations.length ; i++)
84     {
85       if (orientations[i].getValue() == val)
86       {
87         return orientations[i];
88       }
89     }
90
91     return HORIZONTAL;
92   }
93
94
95   /**
96    * Cells with this specified orientation will be horizontal
97    */

98   public static Orientation HORIZONTAL = new Orientation(0, "horizontal");
99   /**
100    * Cells with this specified orientation have their data
101    * presented vertically
102    */

103   public static Orientation VERTICAL = new Orientation(0xff, "vertical");
104   /**
105    * Cells with this specified orientation will have their data
106    * presented with a rotation of 90 degrees upwards
107    */

108   public static Orientation PLUS_90 = new Orientation(90, "up 90");
109   /**
110    * Cells with this specified orientation will have their data
111    * presented with a rotation of 90 degrees downwards
112    */

113   public static Orientation MINUS_90 = new Orientation(180, "down 90");
114   /**
115    * Cells with this specified orientation will have their data
116    * presented with a rotation 45 degrees upwards
117    */

118   public static Orientation PLUS_45 = new Orientation(45, "up 45");
119   /**
120    * Cells with this specified orientation will have their data
121    * presented with a rotation 45 degrees downwards
122    */

123   public static Orientation MINUS_45 = new Orientation(135, "down 45");
124   /**
125    * Cells with this specified orientation will have their text stacked
126    * downwards, but not rotated
127    */

128   public static Orientation STACKED = new Orientation(255, "stacked");
129
130 }
131
132
133
134
135
136
137
138
139
140
Popular Tags