View Javadoc

1   /*
2    * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /* $Id: InlineLayoutContext.java,v 601cf72e95bf 2007/09/14 13:49:37 maxberger $ */
18  
19  package net.sourceforge.jeuclid.context;
20  
21  import net.sourceforge.jeuclid.LayoutContext;
22  
23  /**
24   * @version $Revision: 601cf72e95bf $
25   */
26  public class InlineLayoutContext implements LayoutContext {
27  
28      private final LayoutContext parentLayoutContext;
29  
30      private final boolean increaseIfAlreadyInline;
31  
32      /**
33       * Default Constructor.
34       * 
35       * @param parent
36       *            LayoutContext of parent.
37       */
38      public InlineLayoutContext(final LayoutContext parent) {
39          this.parentLayoutContext = parent;
40          this.increaseIfAlreadyInline = false;
41      }
42  
43      /**
44       * Behavior for mfrac.
45       * 
46       * @param parent
47       *            LayoutContext of parent.
48       * @param increase
49       *            increase scriptlevel if already inline.
50       */
51      public InlineLayoutContext(final LayoutContext parent,
52              final boolean increase) {
53          this.parentLayoutContext = parent;
54          this.increaseIfAlreadyInline = increase;
55      }
56  
57      /** {@inheritDoc} */
58      public Object getParameter(final Parameter which) {
59          Object retVal;
60          if (Parameter.DISPLAY.equals(which)) {
61              retVal = Display.INLINE;
62          } else if (this.increaseIfAlreadyInline
63                  && (Parameter.SCRIPTLEVEL.equals(which))
64                  && (Display.INLINE.equals(this.parentLayoutContext
65                          .getParameter(Parameter.DISPLAY)))) {
66              retVal = ((Integer) this.parentLayoutContext
67                      .getParameter(Parameter.SCRIPTLEVEL)) + 1;
68          } else {
69              retVal = this.parentLayoutContext.getParameter(which);
70          }
71          return retVal;
72      }
73  }