KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > rtf > Alignment


1 /*
2  * ====================================================================
3  *
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if
22  * any, must include the following acknowlegement:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "The Jakarta Project", "Jakarta Element Construction Set",
29  * "Jakarta ECS" , and "Apache Software Foundation" must not be used
30  * to endorse or promote products derived
31  * from this software without prior written permission. For written
32  * permission, please contact apache@apache.org.
33  *
34  * 5. Products derived from this software may not be called "Apache",
35  * "Jakarta Element Construction Set" nor "Jakarta ECS" nor may "Apache"
36  * appear in their names without prior written permission of the Apache Group.
37  *
38  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
42  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49  * SUCH DAMAGE.
50  * ====================================================================
51  *
52  * This software consists of voluntary contributions made by many
53  * individuals on behalf of the Apache Software Foundation. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  *
57  */

58 package org.apache.ecs.rtf;
59
60 import java.io.OutputStream JavaDoc;
61 import java.io.Writer JavaDoc;
62 import java.io.PrintWriter JavaDoc;
63
64 import java.util.Hashtable JavaDoc;
65 import java.util.Enumeration JavaDoc;
66
67 import org.apache.ecs.Element;
68 import org.apache.ecs.ConcreteElement;
69
70 public class Alignment extends RTFElement
71 {
72     private RTFElement type = new Justified();
73     private static Hashtable JavaDoc _lookup = new Hashtable JavaDoc();
74     private static final int CENTERED = 1;
75     private static final int JUSTIFIED = 2;
76     private static final int RIGHT = 3;
77     private static final int LEFT = 4;
78
79     public Alignment()
80     {
81     }
82
83     /*
84         Registers an element in the head element list
85         @param element element to be added to the registry.
86     */

87     public Element addElementToRegistry(Element element)
88     {
89         type.addElementToRegistry(element);
90         return type;
91     }
92
93     /**
94         Registers an element in the head element list
95         @param hashcode internal name of element
96         @param element element to be added to the registry.
97     */

98     public Element addElementToRegistry(String JavaDoc hashcode,Element element)
99     {
100         type.addElementToRegistry(hashcode,element);
101         return type;
102     }
103
104     /**
105         Registers an element in the head element list
106         @hashcode named element for hashcode
107         @param element element to be added to the registry.
108         @param filter does this need to be filtered?
109     */

110     public Element addElementToRegistry(Element element,boolean filter)
111     {
112         type.addElementToRegistry(element,filter);
113         return type;
114     }
115
116     /**
117         Registers an element in the head element list
118         @param element element to be added to the registry.
119         @param filter should we filter this element?
120     */

121     public Element addElementToRegistry(String JavaDoc hashcode, Element element,boolean filter)
122     {
123         type.addElementToRegistry(hashcode,element,filter);
124         return type;
125     }
126
127     /**
128         Registers an element in the head element list
129         @param element element to be added to the registry.
130         @param filter does this need to be filtered?
131     */

132     public Element addElementToRegistry(String JavaDoc value,boolean filter)
133     {
134         type.addElementToRegistry(value,filter);
135         return type;
136     }
137
138     /**
139         Registers an element in the head element list
140         @hashcode named element for hashcode
141         @param element element to be added to the registry.
142         @param filter does this need to be filtered?
143     */

144     public Element addElementToRegistry(String JavaDoc hashcode, String JavaDoc value,boolean filter)
145     {
146         type.addElementToRegistry(hashcode,value,filter);
147         return type;
148     }
149
150     /**
151         Registers an element in the head element list
152         @param element element to be added to the registry.
153     */

154     public Element addElementToRegistry(String JavaDoc value)
155     {
156         type.addElementToRegistry(value);
157         return type;
158     }
159
160     /**
161         Registers an element in the head element list
162         @param element element to be added to the registry.
163     */

164     public Element addElementToRegistry(String JavaDoc hashcode,String JavaDoc value)
165     {
166         type.addElementToRegistry(hashcode,value);
167         return type;
168     }
169
170     /**
171         Removes an element from the element registry
172         @param element element to be added to the registry.
173     */

174     public Element removeElementFromRegistry(Element element)
175     {
176         type.removeElementFromRegistry(Integer.toString(element.hashCode()));
177         return(type);
178     }
179
180     /**
181         Removes an element from the head element registry
182         @param hashcode element to be added to the registry.
183     */

184     public Element removeElementFromRegistry(String JavaDoc hashcode)
185     {
186         type.removeElementFromRegistry(hashcode);
187         return(type);
188     }
189
190     /**
191         Find out if this element is in the element registry.
192         @param element find out if this element is in the registry
193     */

194     public boolean registryHasElement(Element element)
195     {
196         return(type.registryHasElement(element));
197     }
198
199     /**
200         Get an enumeration of the elements that this element contains.
201     */

202     public Enumeration JavaDoc elements()
203     {
204         return(type.elements());
205     }
206
207     /**
208         Find out if this element is in the element registry.
209         @param element find out if this element is in the registry
210     */

211     public boolean registryHasElement(String JavaDoc hashcode)
212     {
213         return(type.registryHasElement(hashcode));
214     }
215
216     public Alignment setType(String JavaDoc type)
217     {
218         if(type.equals("centered"))
219         {
220             this.type = new Centered();
221         }
222         else if(type.equals("justified"))
223         {
224             this.type = new Justified();
225         }
226         else if(type.equals("right"))
227         {
228             this.type = new Right();
229         }
230         else if(type.equals("left"))
231         {
232             this.type = new Left();
233         }
234         return this;
235     }
236
237     public void output(OutputStream JavaDoc out)
238     {
239         type.output(out);
240     }
241
242     public void output(Writer JavaDoc out)
243     {
244         type.output(out);
245     }
246
247     public void output(PrintWriter JavaDoc out)
248     {
249         type.output(out);
250     }
251
252     // Static initializer
253
{
254         _lookup.put("centered",Integer.toString(CENTERED));
255         _lookup.put("justified",Integer.toString(JUSTIFIED));
256         _lookup.put("right",Integer.toString(RIGHT));
257         _lookup.put("left",Integer.toString(LEFT));
258     }
259 }
260
Popular Tags