Coverage Report - net.sourceforge.jeuclid.elements.generic.DocumentElement
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentElement
85%
49/57
66%
8/12
1,429
 
 1  
 /*
 2  
  * Copyright 2002 - 2009 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: DocumentElement.java,v 371548310efa 2010/08/09 21:15:33 max $ */
 18  
 
 19  
 package net.sourceforge.jeuclid.elements.generic;
 20  
 
 21  
 import java.awt.Color;
 22  
 import java.util.List;
 23  
 
 24  
 import net.sourceforge.jeuclid.LayoutContext;
 25  
 import net.sourceforge.jeuclid.context.LayoutContextImpl;
 26  
 import net.sourceforge.jeuclid.context.Parameter;
 27  
 import net.sourceforge.jeuclid.elements.JEuclidElementFactory;
 28  
 import net.sourceforge.jeuclid.elements.JEuclidNode;
 29  
 import net.sourceforge.jeuclid.elements.support.ElementListSupport;
 30  
 import net.sourceforge.jeuclid.layout.JEuclidView;
 31  
 import net.sourceforge.jeuclid.layout.LayoutInfo;
 32  
 import net.sourceforge.jeuclid.layout.LayoutStage;
 33  
 import net.sourceforge.jeuclid.layout.LayoutView;
 34  
 import net.sourceforge.jeuclid.layout.LayoutableDocument;
 35  
 import net.sourceforge.jeuclid.layout.LayoutableNode;
 36  
 
 37  
 import org.apache.batik.dom.GenericDocument;
 38  
 import org.w3c.dom.DocumentType;
 39  
 import org.w3c.dom.Element;
 40  
 import org.w3c.dom.Node;
 41  
 import org.w3c.dom.mathml.MathMLDocument;
 42  
 import org.w3c.dom.views.DocumentView;
 43  
 
 44  
 /**
 45  
  * Class for MathML Document Nodes.
 46  
  * 
 47  
  * @version $Revision: 371548310efa $
 48  
  */
 49  72
 public final class DocumentElement extends GenericDocument implements
 50  
         MathMLDocument, JEuclidNode, DocumentView, LayoutableDocument {
 51  
 
 52  1182
     private static final long serialVersionUID = 1L;
 53  
 
 54  
     /**
 55  
      * Creates a math element.
 56  
      * 
 57  
      */
 58  
     public DocumentElement() {
 59  1079
         this(null);
 60  1079
     }
 61  
 
 62  15760
     /**
 63  15760
      * Creates a MathML compatible document with the given DocumentType.
 64  
      * 
 65  
      * @param doctype
 66  
      *            DocumentType to use. This is currently ignored.
 67  
      */
 68  
     public DocumentElement(final DocumentType doctype) {
 69  1079
         super(doctype, JEuclidDOMImplementation.getInstance());
 70  1079
         super.setEventsEnabled(true);
 71  1079
         this.ownerDocument = this;
 72  16839
     }
 73  15760
 
 74  15760
     /** {@inheritDoc} */
 75  15760
     public String getDomain() {
 76  0
         throw new UnsupportedOperationException();
 77  
     }
 78  
 
 79  0
     /** {@inheritDoc} */
 80  
     public String getReferrer() {
 81  0
         throw new UnsupportedOperationException();
 82  
     }
 83  
 
 84  0
     /** {@inheritDoc} */
 85  
     public String getURI() {
 86  0
         throw new UnsupportedOperationException();
 87  
     }
 88  
 
 89  0
     /** {@inheritDoc} */
 90  
     public LayoutContext getChildLayoutContext(final int childNum,
 91  
             final LayoutContext context) {
 92  560
         return context;
 93  
     }
 94  
 
 95  9062
     /** {@inheritDoc} */
 96  
     // CHECKSTYLE:OFF
 97  
     public JEuclidView getDefaultView() {
 98  
         // CHECKSTYLE:ON
 99  72
         return new JEuclidView(this,
 100  
                 LayoutContextImpl.getDefaultLayoutContext(), null);
 101  
     }
 102  1182
 
 103  
     /** {@inheritDoc} */
 104  1182
     public List<LayoutableNode> getChildrenToLayout() {
 105  2334
         return ElementListSupport.createListOfLayoutChildren(this);
 106  
     }
 107  
 
 108  
     /** {@inheritDoc} */
 109  
     public List<LayoutableNode> getChildrenToDraw() {
 110  228
         return ElementListSupport.createListOfLayoutChildren(this);
 111  18518
     }
 112  
 
 113  
     /** {@inheritDoc} */
 114  
     public void layoutStage1(final LayoutView view, final LayoutInfo info,
 115  
             final LayoutStage childMinStage, final LayoutContext context) {
 116  4067
         ElementListSupport.layoutSequential(view, info, this
 117  
                 .getChildrenToLayout(), LayoutStage.STAGE1);
 118  324
         info.setLayoutStage(childMinStage);
 119  
         // TODO: This should be done in a better way.
 120  324
         if (context.getParameter(Parameter.MATHBACKGROUND) == null) {
 121  324
             info.setLayoutStage(childMinStage);
 122  5122
         } else {
 123  0
             info.setLayoutStage(LayoutStage.STAGE1);
 124  5122
         }
 125  324
     }
 126  5122
 
 127  5122
     /** {@inheritDoc} */
 128  
     public void layoutStage2(final LayoutView view, final LayoutInfo info,
 129  0
             final LayoutContext context) {
 130  252
         ElementListSupport.layoutSequential(view, info, this
 131  5122
                 .getChildrenToLayout(), LayoutStage.STAGE2);
 132  252
         ElementListSupport.addBackground((Color) context
 133  
                 .getParameter(Parameter.MATHBACKGROUND), info, true);
 134  252
         info.setLayoutStage(LayoutStage.STAGE2);
 135  252
     }
 136  4137
 
 137  
     /** {@inheritDoc} */
 138  4137
     @Override
 139  
     protected Node newNode() {
 140  4137
         return new DocumentElement();
 141  4137
     }
 142  
 
 143  
     /** {@inheritDoc} */
 144  
     @Override
 145  
     public Element createElement(final String tagName) {
 146  516
         return JEuclidElementFactory.elementFromName(null, tagName, this);
 147  
     }
 148  
 
 149  
     /** {@inheritDoc} */
 150  
     @Override
 151  
     public Element createElementNS(final String namespaceURI,
 152  8471
             final String qualifiedName) {
 153  
         final String ns;
 154  12888
         if (namespaceURI != null && namespaceURI.length() == 0) {
 155  1140
             ns = null;
 156  
         } else {
 157  11748
             ns = namespaceURI;
 158  
         }
 159  12888
         return JEuclidElementFactory.elementFromName(ns, qualifiedName, this);
 160  202713
     }
 161  18715
 }