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: Mroot.java,v bc1d5fde7b73 2009/06/01 14:40:54 maxberger $ */
018
019 package net.sourceforge.jeuclid.elements.presentation.general;
020
021 import java.util.ArrayList;
022 import java.util.List;
023
024 import net.sourceforge.jeuclid.LayoutContext;
025 import net.sourceforge.jeuclid.context.InlineLayoutContext;
026 import net.sourceforge.jeuclid.context.RelativeScriptlevelLayoutContext;
027 import net.sourceforge.jeuclid.layout.LayoutableNode;
028
029 import org.apache.batik.dom.AbstractDocument;
030 import org.w3c.dom.Node;
031 import org.w3c.dom.mathml.MathMLElement;
032
033 /**
034 * This class presents a mathematical root.
035 *
036 * @version $Revision: bc1d5fde7b73 $
037 */
038 public final class Mroot extends AbstractRoot {
039
040 /**
041 * The XML element from this class.
042 */
043 public static final String ELEMENT = "mroot";
044
045 private static final long serialVersionUID = 1L;
046
047 /**
048 * Default constructor. Sets MathML Namespace.
049 *
050 * @param qname
051 * Qualified name.
052 * @param odoc
053 * Owner Document.
054 */
055 public Mroot(final String qname, final AbstractDocument odoc) {
056 super(qname, odoc);
057 }
058
059 /** {@inheritDoc} */
060 @Override
061 protected Node newNode() {
062 return new Mroot(this.nodeName, this.ownerDocument);
063 }
064
065 /** {@inheritDoc} */
066 @Override
067 protected List<LayoutableNode> getContent() {
068 final List<LayoutableNode> mList = new ArrayList<LayoutableNode>(1);
069 mList.add((LayoutableNode) this.getRadicand());
070 return mList;
071 }
072
073 /** {@inheritDoc} */
074 public MathMLElement getIndex() {
075 return this.getMathElement(1);
076 }
077
078 /** {@inheritDoc} */
079 public MathMLElement getRadicand() {
080 return this.getMathElement(0);
081 }
082
083 /** {@inheritDoc} */
084 public void setIndex(final MathMLElement index) {
085 this.setMathElement(1, index);
086 }
087
088 /** {@inheritDoc} */
089 public void setRadicand(final MathMLElement radicand) {
090 this.setMathElement(0, radicand);
091 }
092
093 /** {@inheritDoc} */
094 @Override
095 public LayoutContext getChildLayoutContext(final int childNum,
096 final LayoutContext context) {
097 final LayoutContext now = this.applyLocalAttributesToContext(context);
098 if (childNum == 0) {
099 return now;
100 } else {
101 // As specified in M2 3.3.3.2
102 return new RelativeScriptlevelLayoutContext(
103 new InlineLayoutContext(now), 2);
104 }
105 }
106
107 }