KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > rtf > style > RtfParagraphStyle


1 /*
2  * $Id: RtfParagraphStyle.java 2776 2007-05-23 20:01:40Z hallm $
3  * $Name$
4  *
5  * Copyright 2001, 2002, 2003, 2004 by Mark Hall
6  *
7  * The contents of this file are subject to the Mozilla Public License Version 1.1
8  * (the "License"); you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the License.
14  *
15  * The Original Code is 'iText, a free JAVA-PDF library'.
16  *
17  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19  * All Rights Reserved.
20  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22  *
23  * Contributor(s): all the names of the contributors are added in the source code
24  * where applicable.
25  *
26  * Alternatively, the contents of this file may be used under the terms of the
27  * LGPL license (the ?GNU LIBRARY GENERAL PUBLIC LICENSE?), in which case the
28  * provisions of LGPL are applicable instead of those above. If you wish to
29  * allow use of your version of this file only under the terms of the LGPL
30  * License and not to allow others to use your version of this file under
31  * the MPL, indicate your decision by deleting the provisions above and
32  * replace them with the notice and other provisions required by the LGPL.
33  * If you do not delete the provisions above, a recipient may use your version
34  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Library General Public License as published by the Free Software Foundation;
39  * either version 2 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
44  * details.
45  *
46  * If you didn't download this code from the following link, you should check if
47  * you aren't using an obsolete version:
48  * http://www.lowagie.com/iText/
49  */

50 package com.lowagie.text.rtf.style;
51
52 import java.awt.Color JavaDoc;
53 import java.io.ByteArrayOutputStream JavaDoc;
54 import java.io.IOException JavaDoc;
55 import java.io.OutputStream JavaDoc;
56
57 import com.lowagie.text.Element;
58 import com.lowagie.text.Font;
59 import com.lowagie.text.rtf.RtfBasicElement;
60 import com.lowagie.text.rtf.document.RtfDocument;
61 import com.lowagie.text.rtf.text.RtfParagraph;
62
63 /**
64  * The RtfParagraphStyle stores all style/formatting attributes of a RtfParagraph.
65  * Additionally it also supports the style name system available in RTF. The RtfParagraphStyle
66  * is a Font and can thus be used as such. To use the stylesheet functionality
67  * it needs to be set as the font of a Paragraph. Otherwise it will work like a
68  * RtfFont. It also supports inheritance of styles.
69  *
70  * @version $Id: RtfParagraphStyle.java 2776 2007-05-23 20:01:40Z hallm $
71  * @author Mark Hall (mhall@edu.uni-klu.ac.at)
72  * @author Thomas Bickel (tmb99@inode.at)
73  */

74 public class RtfParagraphStyle extends RtfFont {
75
76     /**
77      * Constant for left alignment
78      */

79     public static final byte[] ALIGN_LEFT = "\\ql".getBytes();
80     /**
81      * Constant for right alignment
82      */

83     public static final byte[] ALIGN_RIGHT = "\\qr".getBytes();
84     /**
85      * Constant for center alignment
86      */

87     public static final byte[] ALIGN_CENTER = "\\qc".getBytes();
88     /**
89      * Constant for justified alignment
90      */

91     public static final byte[] ALIGN_JUSTIFY = "\\qj".getBytes();
92     /**
93      * Constant for the first line indentation
94      */

95     public static final byte[] FIRST_LINE_INDENT = "\\fi".getBytes();
96     /**
97      * Constant for left indentation
98      */

99     public static final byte[] INDENT_LEFT = "\\li".getBytes();
100     /**
101      * Constant for right indentation
102      */

103     public static final byte[] INDENT_RIGHT = "\\ri".getBytes();
104     /**
105      * Constant for keeping the paragraph together on one page
106      */

107     public static final byte[] KEEP_TOGETHER = "\\keep".getBytes();
108     /**
109      * Constant for keeping the paragraph toghether with the next one on one page
110      */

111     public static final byte[] KEEP_TOGETHER_WITH_NEXT = "\\keepn".getBytes();
112     /**
113      * Constant for the space after the paragraph.
114      */

115     public static final byte[] SPACING_AFTER = "\\sa".getBytes();
116     /**
117      * Constant for the space before the paragraph.
118      */

119     public static final byte[] SPACING_BEFORE = "\\sb".getBytes();
120
121     /**
122      * The NORMAL/STANDARD style.
123      */

124     public static final RtfParagraphStyle STYLE_NORMAL = new RtfParagraphStyle("Normal", "Arial", 12, Font.NORMAL, Color.black);
125     /**
126      * The style for level 1 headings.
127      */

128     public static final RtfParagraphStyle STYLE_HEADING_1 = new RtfParagraphStyle("heading 1", "Normal");
129     /**
130      * The style for level 2 headings.
131      */

132     public static final RtfParagraphStyle STYLE_HEADING_2 = new RtfParagraphStyle("heading 2", "Normal");
133     /**
134      * The style for level 3 headings.
135      */

136     public static final RtfParagraphStyle STYLE_HEADING_3 = new RtfParagraphStyle("heading 3", "Normal");
137
138     /**
139      * Initialises the properties of the styles.
140      */

141     static {
142         STYLE_HEADING_1.setSize(16);
143         STYLE_HEADING_1.setStyle(Font.BOLD);
144         STYLE_HEADING_2.setSize(14);
145         STYLE_HEADING_2.setStyle(Font.BOLDITALIC);
146         STYLE_HEADING_3.setSize(13);
147         STYLE_HEADING_3.setStyle(Font.BOLD);
148     }
149     
150     /**
151      * No modification has taken place when compared to the RtfParagraphStyle this RtfParagraphStyle
152      * is based on. These modification markers are used to determine what needs to be
153      * inherited and what not from the parent RtfParagraphStyle.
154      */

155     private static final int MODIFIED_NONE = 0;
156     /**
157      * The alignment has been modified.
158      */

159     private static final int MODIFIED_ALIGNMENT = 1;
160     /**
161      * The left indentation has been modified.
162      */

163     private static final int MODIFIED_INDENT_LEFT = 2;
164     /**
165      * The right indentation has been modified.
166      */

167     private static final int MODIFIED_INDENT_RIGHT = 4;
168     /**
169      * The spacing before a paragraph has been modified.
170      */

171     private static final int MODIFIED_SPACING_BEFORE = 8;
172     /**
173      * The spacing after a paragraph has been modified.
174      */

175     private static final int MODIFIED_SPACING_AFTER = 16;
176     /**
177      * The font name has been modified.
178      */

179     private static final int MODIFIED_FONT_NAME = 32;
180     /**
181      * The font style has been modified.
182      */

183     private static final int MODIFIED_FONT_SIZE = 64;
184     /**
185      * The font size has been modified.
186      */

187     private static final int MODIFIED_FONT_STYLE = 128;
188     /**
189      * The font colour has been modified.
190      */

191     private static final int MODIFIED_FONT_COLOR = 256;
192     /**
193      * The line leading has been modified.
194      */

195     private static final int MODIFIED_LINE_LEADING = 512;
196     /**
197      * The paragraph keep together setting has been modified.
198      */

199     private static final int MODIFIED_KEEP_TOGETHER = 1024;
200     /**
201      * The paragraph keep together with next setting has been modified.
202      */

203     private static final int MODIFIED_KEEP_TOGETHER_WITH_NEXT = 2048;
204     
205     /**
206      * The alignment of the paragraph.
207      */

208     private int alignment = Element.ALIGN_LEFT;
209     /**
210      * The indentation for the first line
211      */

212     private int firstLineIndent = 0;
213     /**
214      * The left indentation of the paragraph.
215      */

216     private int indentLeft = 0;
217     /**
218      * The right indentation of the paragraph.
219      */

220     private int indentRight = 0;
221     /**
222      * The spacing before a paragraph.
223      */

224     private int spacingBefore = 0;
225     /**
226      * The spacing after a paragraph.
227      */

228     private int spacingAfter = 0;
229     /**
230      * The line leading of the paragraph.
231      */

232     private int lineLeading = 0;
233     /**
234      * Whether this RtfParagraph must stay on one page.
235      */

236     private boolean keepTogether = false;
237     /**
238      * Whether this RtfParagraph must stay on the same page as the next paragraph.
239      */

240     private boolean keepTogetherWithNext = false;
241     /**
242      * The name of this RtfParagraphStyle.
243      */

244     private String JavaDoc styleName = "";
245     /**
246      * The name of the RtfParagraphStyle this RtfParagraphStyle is based on.
247      */

248     private String JavaDoc basedOnName = null;
249     /**
250      * The RtfParagraphStyle this RtfParagraphStyle is based on.
251      */

252     private RtfParagraphStyle baseStyle = null;
253     /**
254      * Which properties have been modified when compared to the base style.
255      */

256     private int modified = MODIFIED_NONE;
257     /**
258      * The number of this RtfParagraphStyle in the stylesheet list.
259      */

260     private int styleNumber = -1;
261     
262     /**
263      * Constructs a new RtfParagraphStyle with the given attributes.
264      *
265      * @param styleName The name of this RtfParagraphStyle.
266      * @param fontName The name of the font to use for this RtfParagraphStyle.
267      * @param fontSize The size of the font to use for this RtfParagraphStyle.
268      * @param fontStyle The style of the font to use for this RtfParagraphStyle.
269      * @param fontColor The colour of the font to use for this RtfParagraphStyle.
270      */

271     public RtfParagraphStyle(String JavaDoc styleName, String JavaDoc fontName, int fontSize, int fontStyle, Color JavaDoc fontColor) {
272         super(null, new RtfFont(fontName, fontSize, fontStyle, fontColor));
273         this.styleName = styleName;
274     }
275     
276     /**
277      * Constructs a new RtfParagraphStyle that is based on an existing RtfParagraphStyle.
278      *
279      * @param styleName The name of this RtfParagraphStyle.
280      * @param basedOnName The name of the RtfParagraphStyle this RtfParagraphStyle is based on.
281      */

282     public RtfParagraphStyle(String JavaDoc styleName, String JavaDoc basedOnName) {
283         super(null, new Font());
284         this.styleName = styleName;
285         this.basedOnName = basedOnName;
286     }
287     
288     /**
289      * Constructs a RtfParagraphStyle from another RtfParagraphStyle.
290      *
291      * INTERNAL USE ONLY
292      *
293      * @param doc The RtfDocument this RtfParagraphStyle belongs to.
294      * @param style The RtfParagraphStyle to copy settings from.
295      */

296     public RtfParagraphStyle(RtfDocument doc, RtfParagraphStyle style) {
297         super(doc, style);
298         this.document = doc;
299         this.styleName = style.getStyleName();
300         this.alignment = style.getAlignment();
301         this.indentLeft = (int) (style.getIndentLeft() * RtfBasicElement.TWIPS_FACTOR);
302         this.indentRight = (int) (style.getIndentRight() * RtfBasicElement.TWIPS_FACTOR);
303         this.spacingBefore = (int) (style.getSpacingBefore() * RtfBasicElement.TWIPS_FACTOR);
304         this.spacingAfter = (int) (style.getSpacingAfter() * RtfBasicElement.TWIPS_FACTOR);
305         this.lineLeading = (int) (style.getLineLeading() * RtfBasicElement.TWIPS_FACTOR);
306         this.keepTogether = style.getKeepTogether();
307         this.keepTogetherWithNext = style.getKeepTogetherWithNext();
308         this.basedOnName = style.basedOnName;
309         this.modified = style.modified;
310         this.styleNumber = style.getStyleNumber();
311
312         if(this.document != null) {
313             setRtfDocument(this.document);
314         }
315     }
316
317     /**
318      * Gets the name of this RtfParagraphStyle.
319      *
320      * @return The name of this RtfParagraphStyle.
321      */

322     public String JavaDoc getStyleName() {
323         return this.styleName;
324     }
325     
326     /**
327      * Gets the name of the RtfParagraphStyle this RtfParagraphStyle is based on.
328      *
329      * @return The name of the base RtfParagraphStyle.
330      */

331     public String JavaDoc getBasedOnName() {
332         return this.basedOnName;
333     }
334     
335     /**
336      * Gets the alignment of this RtfParagraphStyle.
337      *
338      * @return The alignment of this RtfParagraphStyle.
339      */

340     public int getAlignment() {
341         return this.alignment;
342     }
343
344     /**
345      * Sets the alignment of this RtfParagraphStyle.
346      *
347      * @param alignment The alignment to use.
348      */

349     public void setAlignment(int alignment) {
350         this.modified = this.modified | MODIFIED_ALIGNMENT;
351         this.alignment = alignment;
352     }
353     
354     /**
355      * Gets the first line indentation of this RtfParagraphStyle.
356      *
357      * @return The first line indentation of this RtfParagraphStyle.
358      */

359     public int getFirstLineIndent() {
360         return this.firstLineIndent;
361     }
362     
363     /**
364      * Sets the first line indententation of this RtfParagraphStyle. It
365      * is relative to the left indentation.
366      *
367      * @param firstLineIndent The first line indentation to use.
368      */

369     public void setFirstLineIndent(int firstLineIndent) {
370         this.firstLineIndent = firstLineIndent;
371     }
372     
373     /**
374      * Gets the left indentation of this RtfParagraphStyle.
375      *
376      * @return The left indentation of this RtfParagraphStyle.
377      */

378     public int getIndentLeft() {
379         return this.indentLeft;
380     }
381
382     /**
383      * Sets the left indentation of this RtfParagraphStyle.
384      *
385      * @param indentLeft The left indentation to use.
386      */

387     public void setIndentLeft(int indentLeft) {
388         this.modified = this.modified | MODIFIED_INDENT_LEFT;
389         this.indentLeft = indentLeft;
390     }
391     
392     /**
393      * Gets the right indentation of this RtfParagraphStyle.
394      *
395      * @return The right indentation of this RtfParagraphStyle.
396      */

397     public int getIndentRight() {
398         return this.indentRight;
399     }
400
401     /**
402      * Sets the right indentation of this RtfParagraphStyle.
403      *
404      * @param indentRight The right indentation to use.
405      */

406     public void setIndentRight(int indentRight) {
407         this.modified = this.modified | MODIFIED_INDENT_RIGHT;
408         this.indentRight = indentRight;
409     }
410     
411     /**
412      * Gets the space before the paragraph of this RtfParagraphStyle..
413      *
414      * @return The space before the paragraph.
415      */

416     public int getSpacingBefore() {
417         return this.spacingBefore;
418     }
419
420     /**
421      * Sets the space before the paragraph of this RtfParagraphStyle.
422      *
423      * @param spacingBefore The space before to use.
424      */

425     public void setSpacingBefore(int spacingBefore) {
426         this.modified = this.modified | MODIFIED_SPACING_BEFORE;
427         this.spacingBefore = spacingBefore;
428     }
429     
430     /**
431      * Gets the space after the paragraph of this RtfParagraphStyle.
432      *
433      * @return The space after the paragraph.
434      */

435     public int getSpacingAfter() {
436         return this.spacingAfter;
437     }
438     
439     /**
440      * Sets the space after the paragraph of this RtfParagraphStyle.
441      *
442      * @param spacingAfter The space after to use.
443      */

444     public void setSpacingAfter(int spacingAfter) {
445         this.modified = this.modified | MODIFIED_SPACING_AFTER;
446         this.spacingAfter = spacingAfter;
447     }
448     
449     /**
450      * Sets the font name of this RtfParagraphStyle.
451      *
452      * @param fontName The font name to use
453      */

454     public void setFontName(String JavaDoc fontName) {
455         this.modified = this.modified | MODIFIED_FONT_NAME;
456         super.setFontName(fontName);
457     }
458     
459     /**
460      * Sets the font size of this RtfParagraphStyle.
461      *
462      * @param fontSize The font size to use.
463      */

464     public void setSize(float fontSize) {
465         this.modified = this.modified | MODIFIED_FONT_SIZE;
466         super.setSize(fontSize);
467     }
468     
469     /**
470      * Sets the font style of this RtfParagraphStyle.
471      *
472      * @param fontStyle The font style to use.
473      */

474     public void setStyle(int fontStyle) {
475         this.modified = this.modified | MODIFIED_FONT_STYLE;
476         super.setStyle(fontStyle);
477     }
478     
479     /**
480      * Sets the colour of this RtfParagraphStyle.
481      *
482      * @param color The Color to use.
483      */

484     public void setColor(Color JavaDoc color) {
485         this.modified = this.modified | MODIFIED_FONT_COLOR;
486         super.setColor(color);
487     }
488     
489     /**
490      * Gets the line leading of this RtfParagraphStyle.
491      *
492      * @return The line leading of this RtfParagraphStyle.
493      */

494     public int getLineLeading() {
495         return this.lineLeading;
496     }
497     
498     /**
499      * Sets the line leading of this RtfParagraphStyle.
500      *
501      * @param lineLeading The line leading to use.
502      */

503     public void setLineLeading(int lineLeading) {
504         this.lineLeading = lineLeading;
505         this.modified = this.modified | MODIFIED_LINE_LEADING;
506     }
507     
508     /**
509      * Gets whether the lines in the paragraph should be kept together in
510      * this RtfParagraphStyle.
511      *
512      * @return Whether the lines in the paragraph should be kept together.
513      */

514     public boolean getKeepTogether() {
515         return this.keepTogether;
516     }
517     
518     /**
519      * Sets whether the lines in the paragraph should be kept together in
520      * this RtfParagraphStyle.
521      *
522      * @param keepTogether Whether the lines in the paragraph should be kept together.
523      */

524     public void setKeepTogether(boolean keepTogether) {
525         this.keepTogether = keepTogether;
526         this.modified = this.modified | MODIFIED_KEEP_TOGETHER;
527     }
528     
529     /**
530      * Gets whether the paragraph should be kept toggether with the next in
531      * this RtfParagraphStyle.
532      *
533      * @return Whether the paragraph should be kept together with the next.
534      */

535     public boolean getKeepTogetherWithNext() {
536         return this.keepTogetherWithNext;
537     }
538     
539     /**
540      * Sets whether the paragraph should be kept together with the next in
541      * this RtfParagraphStyle.
542      *
543      * @param keepTogetherWithNext Whether the paragraph should be kept together with the next.
544      */

545     public void setKeepTogetherWithNext(boolean keepTogetherWithNext) {
546         this.keepTogetherWithNext = keepTogetherWithNext;
547         this.modified = this.modified | MODIFIED_KEEP_TOGETHER_WITH_NEXT;
548     }
549     
550     /**
551      * Handles the inheritance of paragraph style settings. All settings that
552      * have not been modified will be inherited from the base RtfParagraphStyle.
553      * If this RtfParagraphStyle is not based on another one, then nothing happens.
554      */

555     public void handleInheritance() {
556         if(this.basedOnName != null && this.document.getDocumentHeader().getRtfParagraphStyle(this.basedOnName) != null) {
557             this.baseStyle = this.document.getDocumentHeader().getRtfParagraphStyle(this.basedOnName);
558             this.baseStyle.handleInheritance();
559             if(!((this.modified & MODIFIED_ALIGNMENT) == MODIFIED_ALIGNMENT)) {
560                 this.alignment = this.baseStyle.getAlignment();
561             }
562             if(!((this.modified & MODIFIED_INDENT_LEFT) == MODIFIED_INDENT_LEFT)) {
563                 this.indentLeft = this.baseStyle.getIndentLeft();
564             }
565             if(!((this.modified & MODIFIED_INDENT_RIGHT) == MODIFIED_INDENT_RIGHT)) {
566                 this.indentRight = this.baseStyle.getIndentRight();
567             }
568             if(!((this.modified & MODIFIED_SPACING_BEFORE) == MODIFIED_SPACING_BEFORE)) {
569                 this.spacingBefore = this.baseStyle.getSpacingBefore();
570             }
571             if(!((this.modified & MODIFIED_SPACING_AFTER) == MODIFIED_SPACING_AFTER)) {
572                 this.spacingAfter = this.baseStyle.getSpacingAfter();
573             }
574             if(!((this.modified & MODIFIED_FONT_NAME) == MODIFIED_FONT_NAME)) {
575                 setFontName(this.baseStyle.getFontName());
576             }
577             if(!((this.modified & MODIFIED_FONT_SIZE) == MODIFIED_FONT_SIZE)) {
578                 setSize(this.baseStyle.getFontSize());
579             }
580             if(!((this.modified & MODIFIED_FONT_STYLE) == MODIFIED_FONT_STYLE)) {
581                 setStyle(this.baseStyle.getFontStyle());
582             }
583             if(!((this.modified & MODIFIED_FONT_COLOR) == MODIFIED_FONT_COLOR)) {
584                 setColor(this.baseStyle.getColor());
585             }
586             if(!((this.modified & MODIFIED_LINE_LEADING) == MODIFIED_LINE_LEADING)) {
587                 setLineLeading(this.baseStyle.getLineLeading());
588             }
589             if(!((this.modified & MODIFIED_KEEP_TOGETHER) == MODIFIED_KEEP_TOGETHER)) {
590                 setKeepTogether(this.baseStyle.getKeepTogether());
591             }
592             if(!((this.modified & MODIFIED_KEEP_TOGETHER_WITH_NEXT) == MODIFIED_KEEP_TOGETHER_WITH_NEXT)) {
593                 setKeepTogetherWithNext(this.baseStyle.getKeepTogetherWithNext());
594             }
595         }
596     }
597     
598     /**
599      * Writes the settings of this RtfParagraphStyle.
600      *
601      * @return A byte array with the settings of this RtfParagraphStyle.
602      */

603     private byte[] writeParagraphSettings() {
604         ByteArrayOutputStream JavaDoc result = new ByteArrayOutputStream JavaDoc();
605         try {
606             if(this.keepTogether) {
607                 result.write(RtfParagraphStyle.KEEP_TOGETHER);
608             }
609             if(this.keepTogetherWithNext) {
610                 result.write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT);
611             }
612             switch (alignment) {
613                 case Element.ALIGN_LEFT:
614                     result.write(RtfParagraphStyle.ALIGN_LEFT);
615                     break;
616                 case Element.ALIGN_RIGHT:
617                     result.write(RtfParagraphStyle.ALIGN_RIGHT);
618                     break;
619                 case Element.ALIGN_CENTER:
620                     result.write(RtfParagraphStyle.ALIGN_CENTER);
621                     break;
622                 case Element.ALIGN_JUSTIFIED:
623                 case Element.ALIGN_JUSTIFIED_ALL:
624                     result.write(RtfParagraphStyle.ALIGN_JUSTIFY);
625                     break;
626             }
627             result.write(FIRST_LINE_INDENT);
628             result.write(intToByteArray(this.firstLineIndent));
629             result.write(RtfParagraphStyle.INDENT_LEFT);
630             result.write(intToByteArray(indentLeft));
631             result.write(RtfParagraphStyle.INDENT_RIGHT);
632             result.write(intToByteArray(indentRight));
633             if(this.spacingBefore > 0) {
634                 result.write(RtfParagraphStyle.SPACING_BEFORE);
635                 result.write(intToByteArray(this.spacingBefore));
636             }
637             if(this.spacingAfter > 0) {
638                 result.write(RtfParagraphStyle.SPACING_AFTER);
639                 result.write(intToByteArray(this.spacingAfter));
640             }
641             if(this.lineLeading > 0) {
642                 result.write(RtfParagraph.LINE_SPACING);
643                 result.write(intToByteArray(this.lineLeading));
644             }
645         } catch(IOException JavaDoc ioe) {
646             ioe.printStackTrace();
647         }
648         return result.toByteArray();
649     }
650     
651     /**
652      * Writes the definition of this RtfParagraphStyle for the stylesheet list.
653      * @deprecated replaced by {@link #writeDefinition(OutputStream)}
654      */

655     public byte[] writeDefinition() {
656         ByteArrayOutputStream JavaDoc result = new ByteArrayOutputStream JavaDoc();
657         try {
658             writeDefinition(result);
659         } catch(IOException JavaDoc ioe) {
660             ioe.printStackTrace();
661         }
662         return result.toByteArray();
663     }
664     /**
665      * Writes the definition of this RtfParagraphStyle for the stylesheet list.
666      */

667     public void writeDefinition(final OutputStream JavaDoc result) throws IOException JavaDoc
668     {
669         result.write("{".getBytes());
670         result.write("\\style".getBytes());
671         result.write("\\s".getBytes());
672         result.write(intToByteArray(this.styleNumber));
673         result.write(RtfBasicElement.DELIMITER);
674         result.write(writeParagraphSettings());
675         result.write(super.writeBegin());
676         result.write(RtfBasicElement.DELIMITER);
677         result.write(this.styleName.getBytes());
678         result.write(";".getBytes());
679         result.write("}".getBytes());
680         if(this.document.getDocumentSettings().isOutputDebugLineBreaks()) {
681             result.write('\n');
682         }
683     }
684     
685     /**
686      * Writes the start information of this RtfParagraphStyle.
687      */

688     public byte[] writeBegin() {
689         ByteArrayOutputStream JavaDoc result = new ByteArrayOutputStream JavaDoc();
690         try {
691             result.write("\\s".getBytes());
692             result.write(intToByteArray(this.styleNumber));
693             result.write(writeParagraphSettings());
694         } catch(IOException JavaDoc ioe) {
695             ioe.printStackTrace();
696         }
697         return result.toByteArray();
698     }
699     
700     /**
701      * Unused
702      * @return An empty byte array.
703      */

704     public byte[] writeEnd() {
705         return new byte[0];
706     }
707     
708     /**
709      * unused
710      * @deprecated replaced by {@link #writeContent(OutputStream)}
711      */

712     public byte[] write()
713     {
714         return(new byte[0]);
715     }
716     /**
717      * unused
718      */

719     public void writeContent(final OutputStream JavaDoc out) throws IOException JavaDoc
720     {
721     }
722     
723     /**
724      * Tests whether two RtfParagraphStyles are equal. Equality
725      * is determined via the name.
726      */

727     public boolean equals(Object JavaDoc o) {
728         if(!(o instanceof RtfParagraphStyle)) {
729             return false;
730         }
731         RtfParagraphStyle paragraphStyle = (RtfParagraphStyle) o;
732         boolean result = this.getStyleName().equals(paragraphStyle.getStyleName());
733         return result;
734     }
735     
736     /**
737      * Gets the hash code of this RtfParagraphStyle.
738      */

739     public int hashCode() {
740         return this.styleName.hashCode();
741     }
742     
743     /**
744      * Gets the number of this RtfParagraphStyle in the stylesheet list.
745      *
746      * @return The number of this RtfParagraphStyle in the stylesheet list.
747      */

748     private int getStyleNumber() {
749         return this.styleNumber;
750     }
751     
752     /**
753      * Sets the number of this RtfParagraphStyle in the stylesheet list.
754      *
755      * @param styleNumber The number to use.
756      */

757     protected void setStyleNumber(int styleNumber) {
758         this.styleNumber = styleNumber;
759     }
760 }
761
Popular Tags