KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > rtf > rtflib > rtfdoc > ParagraphKeeptogetherContext


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: ParagraphKeeptogetherContext.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.rtf.rtflib.rtfdoc;
21
22 /*
23  * This file is part of the RTF library of the FOP project, which was originally
24  * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
25  * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
26  * the FOP project.
27  */

28
29 /**
30  *
31  * This context is used to manage the "keepn" RTF attribute
32  * Used by ParagraphBuilder and JforCmd
33  *
34  */

35
36 public class ParagraphKeeptogetherContext {
37
38     private static int paraKeepTogetherOpen = 0;
39     private static boolean paraResetProperties = false;
40     private static ParagraphKeeptogetherContext instance = null;
41
42     ParagraphKeeptogetherContext() {
43     }
44
45
46     /**
47      * Singelton.
48      *
49      * @return The instance of ParagraphKeeptogetherContext
50      */

51     public static ParagraphKeeptogetherContext getInstance() {
52         if (instance == null) {
53             instance = new ParagraphKeeptogetherContext();
54         }
55         return instance;
56     }
57
58     /**
59      * @return the level of current "keep whith next" paragraph
60      */

61     public static int getKeepTogetherOpenValue() {
62         return paraKeepTogetherOpen;
63     }
64
65     /** Open a new "keep with next" paragraph */
66     public static void keepTogetherOpen() {
67         paraKeepTogetherOpen++;
68     }
69
70     /** Close a "keep with next" paragraph */
71     public static void keepTogetherClose() {
72         if (paraKeepTogetherOpen > 0) {
73             paraKeepTogetherOpen--;
74
75             //If the \pard control word is not present, the current paragraph
76
//inherits all paragraph properties.
77
//Also the next paragraph must reset the properties otherwise the \keepn don't stop.
78
paraResetProperties = (paraKeepTogetherOpen == 0);
79         }
80     }
81
82     /**
83      * @return true if the next paragraph must reset the properties
84      */

85     public static boolean paragraphResetProperties() {
86         return paraResetProperties;
87     }
88
89     /** Reset the flag if the paragraph properties have been resested */
90     public static void setParagraphResetPropertiesUsed() {
91         paraResetProperties = false;
92     }
93
94 }
95
Popular Tags