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