KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > elementprocessor > impl > poi > hssf > elements > VerticalAlignment


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements;
18
19 import org.apache.cocoon.components.elementprocessor.types.NumericConverter;
20 import org.apache.cocoon.components.elementprocessor.types.Validator;
21
22 import java.io.IOException JavaDoc;
23
24 /**
25  * Vertical alignment is written as an integer, and each bit in the
26  * integer specifies a particular boolean attribute. This class deals
27  * with all that information in an easily digested form.
28  *
29  * @author Marc Johnson (marc_johnson27591@hotmail.com)
30  * @version CVS $Id: VerticalAlignment.java 30932 2004-07-29 17:35:38Z vgritsenko $
31  */

32 public class VerticalAlignment {
33     private int _alignment;
34     private static final int _top = 1;
35     private static final int _bottom = 2;
36     private static final int _center = 4;
37     private static final int _justify = 8;
38     private static final Validator _validator = new Validator() {
39         public IOException JavaDoc validate(final Number JavaDoc number) {
40             int value = number.intValue();
41
42             return (value >= 0 && value <= 15) ? null
43                 : new IOException JavaDoc("\"" + number + "\" is out of range");
44         }
45     };
46
47     /**
48      * Create a VerticalAlignment object
49      * @param value the string containing the vertical alignment data
50      * @exception IOException if the data is malformed
51      */

52     public VerticalAlignment(final String JavaDoc value) throws IOException JavaDoc {
53         _alignment =
54             NumericConverter.extractInteger(value, _validator).intValue();
55     }
56
57     /**
58      * @return true if top bit is set
59      */

60     public boolean isTop() {
61         return (_alignment & _top) == _top;
62     }
63
64     /**
65      * @return true if bottom bit is set
66      */

67     public boolean isBottom() {
68         return (_alignment & _bottom) == _bottom;
69     }
70
71     /**
72      * @return true if center bit is set
73      */

74     public boolean isCenter() {
75         return (_alignment & _center) == _center;
76     }
77
78     /**
79      * @return true if justify bit is set
80      */

81     public boolean isJustify() {
82         return (_alignment & _justify) == _justify;
83     }
84
85     public short getCode() {
86         return (short)_alignment;
87     }
88 } // end public class VerticalAlignment
89
Popular Tags