KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Horizontal 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: HorizontalAlignment.java 30932 2004-07-29 17:35:38Z vgritsenko $
31  */

32 public class HorizontalAlignment {
33     private int _alignment;
34     private static final int _general = 1;
35     private static final int _left = 2;
36     private static final int _right = 4;
37     private static final int _center = 8;
38     private static final int _fill = 16;
39     private static final int _justify = 32;
40     private static final int _center_across_selection = 64;
41     private static final Validator _validator = new Validator() {
42         public IOException JavaDoc validate(final Number JavaDoc number) {
43             int value = number.intValue();
44
45             return ((value >= 0) && (value <= 127)) ? null
46                 : new IOException JavaDoc("\"" + number + "\" is out of range");
47         }
48     };
49
50     /**
51      * Create an HorizontalAlignment object
52      * @param value the string containing the horizontal alignment data
53      * @exception IOException if the data is malformed
54      */

55     public HorizontalAlignment(final String JavaDoc value) throws IOException JavaDoc {
56         _alignment =
57             NumericConverter.extractInteger(value, _validator).intValue();
58     }
59
60     /**
61      * @return true if general bit is set
62      */

63     public boolean isGeneral() {
64         return (_alignment & _general) == _general;
65     }
66
67     /**
68      * @return true if left bit is set
69      */

70     public boolean isLeft() {
71         return (_alignment & _left) == _left;
72     }
73
74     /**
75      * @return true if right bit is set
76      */

77     public boolean isRight() {
78         return (_alignment & _right) == _right;
79     }
80
81     /**
82      * @return true if center bit is set
83      */

84     public boolean isCenter() {
85         return (_alignment & _center) == _center;
86     }
87
88     /**
89      * @return true if fill bit is set
90      */

91     public boolean isFill() {
92         return (_alignment & _fill) == _fill;
93     }
94
95     /**
96      * @return true if justify bit is set
97      */

98     public boolean isJustify() {
99         return (_alignment & _justify) == _justify;
100     }
101
102     /**
103      * @return true if center across selection bit is set
104      */

105     public boolean isCenterAcrossSelection() {
106         return (_alignment & _center_across_selection)
107             == _center_across_selection;
108     }
109
110     short getCode() {
111         return (short)_alignment;
112     }
113 } // end public class HorizontalAlignment
114
Popular Tags