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: AbstractSubSuper.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.LayoutContext;
022    import net.sourceforge.jeuclid.elements.JEuclidElement;
023    import net.sourceforge.jeuclid.layout.LayoutInfo;
024    import net.sourceforge.jeuclid.layout.LayoutStage;
025    import net.sourceforge.jeuclid.layout.LayoutView;
026    
027    import org.apache.batik.dom.AbstractDocument;
028    import org.w3c.dom.mathml.MathMLScriptElement;
029    
030    /**
031     * Generic support for all elements that have a subscript or a superscript
032     * attribute.
033     * <p>
034     * Supported elements: msub, msup, msubsup.
035     * 
036     * @version $Revision: bc1d5fde7b73 $
037     */
038    public abstract class AbstractSubSuper extends AbstractScriptElement implements
039            MathMLScriptElement {
040    
041        /**
042         * Default constructor. Sets MathML Namespace.
043         * 
044         * @param qname
045         *            Qualified name.
046         * @param odoc
047         *            Owner Document.
048         */
049        public AbstractSubSuper(final String qname, final AbstractDocument odoc) {
050            super(qname, odoc);
051        }
052    
053        /** {@inheritDoc} */
054        public abstract JEuclidElement getBase();
055    
056        /** {@inheritDoc} */
057        public abstract JEuclidElement getSuperscript();
058    
059        /** {@inheritDoc} */
060        public abstract JEuclidElement getSubscript();
061    
062        /** {@inheritDoc} */
063        @Override
064        public boolean hasChildPostscripts(final JEuclidElement child,
065                final LayoutContext context) {
066            return child.isSameNode(this.getBase());
067        }
068    
069        /** {@inheritDoc} */
070        @Override
071        protected void layoutStageInvariant(final LayoutView view,
072                final LayoutInfo info, final LayoutStage stage,
073                final LayoutContext context) {
074            ScriptSupport.layout(view, info, stage, this
075                    .applyLocalAttributesToContext(context), this, this.getBase(),
076                    this.getSubscript(), this.getSuperscript(), this
077                            .getSubscriptshift(), this.getSuperscriptshift());
078        }
079    }