| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 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 | |
|
| 46 | |
|
| 47 | |
|
| 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 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
public DocumentElement() { |
| 59 | 1079 | this(null); |
| 60 | 1079 | } |
| 61 | |
|
| 62 | 15760 | |
| 63 | 15760 | |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 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 | |
| 75 | 15760 | public String getDomain() { |
| 76 | 0 | throw new UnsupportedOperationException(); |
| 77 | |
} |
| 78 | |
|
| 79 | 0 | |
| 80 | |
public String getReferrer() { |
| 81 | 0 | throw new UnsupportedOperationException(); |
| 82 | |
} |
| 83 | |
|
| 84 | 0 | |
| 85 | |
public String getURI() { |
| 86 | 0 | throw new UnsupportedOperationException(); |
| 87 | |
} |
| 88 | |
|
| 89 | 0 | |
| 90 | |
public LayoutContext getChildLayoutContext(final int childNum, |
| 91 | |
final LayoutContext context) { |
| 92 | 560 | return context; |
| 93 | |
} |
| 94 | |
|
| 95 | 9062 | |
| 96 | |
|
| 97 | |
public JEuclidView getDefaultView() { |
| 98 | |
|
| 99 | 72 | return new JEuclidView(this, |
| 100 | |
LayoutContextImpl.getDefaultLayoutContext(), null); |
| 101 | |
} |
| 102 | 1182 | |
| 103 | |
|
| 104 | 1182 | public List<LayoutableNode> getChildrenToLayout() { |
| 105 | 2334 | return ElementListSupport.createListOfLayoutChildren(this); |
| 106 | |
} |
| 107 | |
|
| 108 | |
|
| 109 | |
public List<LayoutableNode> getChildrenToDraw() { |
| 110 | 228 | return ElementListSupport.createListOfLayoutChildren(this); |
| 111 | 18518 | } |
| 112 | |
|
| 113 | |
|
| 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 | |
|
| 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 | |
| 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 | |
|
| 138 | 4137 | @Override |
| 139 | |
protected Node newNode() { |
| 140 | 4137 | return new DocumentElement(); |
| 141 | 4137 | } |
| 142 | |
|
| 143 | |
|
| 144 | |
@Override |
| 145 | |
public Element createElement(final String tagName) { |
| 146 | 516 | return JEuclidElementFactory.elementFromName(null, tagName, this); |
| 147 | |
} |
| 148 | |
|
| 149 | |
|
| 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 | } |