KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > area > inline > TextArea


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

17
18 /* $Id: TextArea.java 453920 2006-10-07 14:29:54Z spepping $ */
19
20 package org.apache.fop.area.inline;
21
22 /**
23  * A text inline area.
24  */

25 public class TextArea extends AbstractTextArea {
26
27     /**
28      * Create a text inline area
29      */

30     public TextArea() {
31     }
32
33     /**
34      * Constructor with extra parameters:
35      * create a TextAdjustingInfo object
36      * @param stretch the available stretch of the text
37      * @param shrink the available shrink of the text
38      * @param adj the current total adjustment
39      */

40     public TextArea(int stretch, int shrink, int adj) {
41         super(stretch, shrink, adj);
42     }
43
44     /**
45      * Remove the old text
46      */

47     public void removeText() {
48         inlines.clear();
49     }
50     
51     /**
52      * Create and add a WordArea child to this TextArea.
53      *
54      * @param word the word string
55      * @param offset the offset for the next area
56      */

57     public void addWord(String JavaDoc word, int offset) {
58         addWord(word, offset, null);
59     }
60     
61     /**
62      * Create and add a WordArea child to this TextArea.
63      *
64      * @param word the word string
65      * @param offset the offset for the next area
66      */

67     public void addWord(String JavaDoc word, int offset, int[] letterAdjust) {
68         WordArea wordArea = new WordArea(word, offset, letterAdjust);
69         addChildArea(wordArea);
70         wordArea.setParentArea(this);
71     }
72     
73     /**
74      * Create and add a SpaceArea child to this TextArea
75      *
76      * @param space the space character
77      * @param offset the offset for the next area
78      * @param adjustable is this space adjustable?
79      */

80     public void addSpace(char space, int offset, boolean adjustable) {
81         SpaceArea spaceArea = new SpaceArea(space, offset, adjustable);
82         addChildArea(spaceArea);
83         spaceArea.setParentArea(this);
84     }
85     
86     /**
87      * Get the whole text string.
88      * Renderers whose space adjustment handling is not affected
89      * by multi-byte characters can use this method to render the
90      * whole TextArea at once; the other renderers (for example
91      * PDFRenderer) have to implement renderWord(WordArea) and
92      * renderSpace(SpaceArea) in order to correctly place each
93      * text fragment.
94      *
95      * @return the text string
96      */

97     public String JavaDoc getText() {
98         StringBuffer JavaDoc text = new StringBuffer JavaDoc();
99         InlineArea child;
100         // assemble the text
101
for (int i = 0; i < inlines.size(); i ++) {
102             child = (InlineArea) inlines.get(i);
103             if (child instanceof WordArea) {
104                 text.append(((WordArea) child).getWord());
105             } else {
106                 text.append(((SpaceArea) child).getSpace());
107             }
108         }
109         return text.toString();
110     }
111
112 }
113
114
Popular Tags