01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * Singelton.
47: *
48: * @return The instance of ParagraphKeeptogetherContext
49: */
50: public static ParagraphKeeptogetherContext getInstance() {
51: if (instance == null) {
52: instance = new ParagraphKeeptogetherContext();
53: }
54: return instance;
55: }
56:
57: /**
58: * @return the level of current "keep whith next" paragraph
59: */
60: public static int getKeepTogetherOpenValue() {
61: return paraKeepTogetherOpen;
62: }
63:
64: /** Open a new "keep with next" paragraph */
65: public static void keepTogetherOpen() {
66: paraKeepTogetherOpen++;
67: }
68:
69: /** Close a "keep with next" paragraph */
70: public static void keepTogetherClose() {
71: if (paraKeepTogetherOpen > 0) {
72: paraKeepTogetherOpen--;
73:
74: //If the \pard control word is not present, the current paragraph
75: //inherits all paragraph properties.
76: //Also the next paragraph must reset the properties otherwise the \keepn don't stop.
77: paraResetProperties = (paraKeepTogetherOpen == 0);
78: }
79: }
80:
81: /**
82: * @return true if the next paragraph must reset the properties
83: */
84: public static boolean paragraphResetProperties() {
85: return paraResetProperties;
86: }
87:
88: /** Reset the flag if the paragraph properties have been resested */
89: public static void setParagraphResetPropertiesUsed() {
90: paraResetProperties = false;
91: }
92:
93: }
|