View Javadoc

1   /*
2    * Copyright 2007 - 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: AbstractSubSuper.java,v bc1d5fde7b73 2009/06/01 14:40:54 maxberger $ */
18  
19  package net.sourceforge.jeuclid.elements.presentation.script;
20  
21  import net.sourceforge.jeuclid.LayoutContext;
22  import net.sourceforge.jeuclid.elements.JEuclidElement;
23  import net.sourceforge.jeuclid.layout.LayoutInfo;
24  import net.sourceforge.jeuclid.layout.LayoutStage;
25  import net.sourceforge.jeuclid.layout.LayoutView;
26  
27  import org.apache.batik.dom.AbstractDocument;
28  import org.w3c.dom.mathml.MathMLScriptElement;
29  
30  /**
31   * Generic support for all elements that have a subscript or a superscript
32   * attribute.
33   * <p>
34   * Supported elements: msub, msup, msubsup.
35   * 
36   * @version $Revision: bc1d5fde7b73 $
37   */
38  public abstract class AbstractSubSuper extends AbstractScriptElement implements
39          MathMLScriptElement {
40  
41      /**
42       * Default constructor. Sets MathML Namespace.
43       * 
44       * @param qname
45       *            Qualified name.
46       * @param odoc
47       *            Owner Document.
48       */
49      public AbstractSubSuper(final String qname, final AbstractDocument odoc) {
50          super(qname, odoc);
51      }
52  
53      /** {@inheritDoc} */
54      public abstract JEuclidElement getBase();
55  
56      /** {@inheritDoc} */
57      public abstract JEuclidElement getSuperscript();
58  
59      /** {@inheritDoc} */
60      public abstract JEuclidElement getSubscript();
61  
62      /** {@inheritDoc} */
63      @Override
64      public boolean hasChildPostscripts(final JEuclidElement child,
65              final LayoutContext context) {
66          return child.isSameNode(this.getBase());
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      protected void layoutStageInvariant(final LayoutView view,
72              final LayoutInfo info, final LayoutStage stage,
73              final LayoutContext context) {
74          ScriptSupport.layout(view, info, stage, this
75                  .applyLocalAttributesToContext(context), this, this.getBase(),
76                  this.getSubscript(), this.getSuperscript(), this
77                          .getSubscriptshift(), this.getSuperscriptshift());
78      }
79  }