001 /* 002 * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 /* $Id: InlineLayoutContext.java,v 601cf72e95bf 2007/09/14 13:49:37 maxberger $ */ 018 019 package net.sourceforge.jeuclid.context; 020 021 import net.sourceforge.jeuclid.LayoutContext; 022 023 /** 024 * @version $Revision: 601cf72e95bf $ 025 */ 026 public class InlineLayoutContext implements LayoutContext { 027 028 private final LayoutContext parentLayoutContext; 029 030 private final boolean increaseIfAlreadyInline; 031 032 /** 033 * Default Constructor. 034 * 035 * @param parent 036 * LayoutContext of parent. 037 */ 038 public InlineLayoutContext(final LayoutContext parent) { 039 this.parentLayoutContext = parent; 040 this.increaseIfAlreadyInline = false; 041 } 042 043 /** 044 * Behavior for mfrac. 045 * 046 * @param parent 047 * LayoutContext of parent. 048 * @param increase 049 * increase scriptlevel if already inline. 050 */ 051 public InlineLayoutContext(final LayoutContext parent, 052 final boolean increase) { 053 this.parentLayoutContext = parent; 054 this.increaseIfAlreadyInline = increase; 055 } 056 057 /** {@inheritDoc} */ 058 public Object getParameter(final Parameter which) { 059 Object retVal; 060 if (Parameter.DISPLAY.equals(which)) { 061 retVal = Display.INLINE; 062 } else if (this.increaseIfAlreadyInline 063 && (Parameter.SCRIPTLEVEL.equals(which)) 064 && (Display.INLINE.equals(this.parentLayoutContext 065 .getParameter(Parameter.DISPLAY)))) { 066 retVal = ((Integer) this.parentLayoutContext 067 .getParameter(Parameter.SCRIPTLEVEL)) + 1; 068 } else { 069 retVal = this.parentLayoutContext.getParameter(which); 070 } 071 return retVal; 072 } 073 }