001 /*
002 * Copyright 2007 - 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: AbstractScriptElement.java,v bc1d5fde7b73 2009/06/01 14:40:54 maxberger $ */
018
019 package net.sourceforge.jeuclid.elements.presentation.script;
020
021 import net.sourceforge.jeuclid.Constants;
022 import net.sourceforge.jeuclid.LayoutContext;
023 import net.sourceforge.jeuclid.context.InlineLayoutContext;
024 import net.sourceforge.jeuclid.context.RelativeScriptlevelLayoutContext;
025 import net.sourceforge.jeuclid.elements.AbstractJEuclidElement;
026
027 import org.apache.batik.dom.AbstractDocument;
028
029 /**
030 * Base class for msub, msup, msubsup, and mmultiscripts.
031 *
032 * @version $Revision: bc1d5fde7b73 $
033 */
034 public abstract class AbstractScriptElement extends AbstractJEuclidElement {
035
036 /** attribute for subscriptshift. */
037 public static final String ATTR_SUBSCRIPTSHIFT = "subscriptshift";
038
039 /** attribute for superscriptshift. */
040 public static final String ATTR_SUPERSCRIPTSHIFT = "superscriptshift";
041
042 /**
043 * Default constructor. Sets MathML Namespace.
044 *
045 * @param qname
046 * Qualified name.
047 * @param odoc
048 * Owner Document.
049 */
050 public AbstractScriptElement(final String qname, final AbstractDocument odoc) {
051 super(qname, odoc);
052
053 this.setDefaultMathAttribute(AbstractScriptElement.ATTR_SUBSCRIPTSHIFT,
054 Constants.ZERO);
055 this.setDefaultMathAttribute(
056 AbstractScriptElement.ATTR_SUPERSCRIPTSHIFT, Constants.ZERO);
057 }
058
059 /**
060 * @return attribute subscriptshift.
061 */
062 public String getSubscriptshift() {
063 return this.getMathAttribute(AbstractScriptElement.ATTR_SUBSCRIPTSHIFT);
064 }
065
066 /**
067 * @param subscriptshift
068 * new value for subscriptshift
069 */
070 public void setSubscriptshift(final String subscriptshift) {
071 this.setAttribute(AbstractScriptElement.ATTR_SUBSCRIPTSHIFT,
072 subscriptshift);
073 }
074
075 /**
076 * @return attribtue superscriptshift
077 */
078 public String getSuperscriptshift() {
079 return this
080 .getMathAttribute(AbstractScriptElement.ATTR_SUPERSCRIPTSHIFT);
081 }
082
083 /**
084 * @param superscriptshift
085 * new value for superscriptshift
086 */
087 public void setSuperscriptshift(final String superscriptshift) {
088 this.setAttribute(AbstractScriptElement.ATTR_SUPERSCRIPTSHIFT,
089 superscriptshift);
090 }
091
092 /** {@inheritDoc} */
093 @Override
094 public LayoutContext getChildLayoutContext(final int childNum,
095 final LayoutContext context) {
096 final LayoutContext now = this.applyLocalAttributesToContext(context);
097 if (childNum == 0) {
098 return now;
099 } else {
100 return new RelativeScriptlevelLayoutContext(
101 new InlineLayoutContext(now), 1);
102 }
103 }
104
105 }