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  public final class DocumentElement extends GenericDocument implements
50          MathMLDocument, JEuclidNode, DocumentView, LayoutableDocument {
51  
52      private static final long serialVersionUID = 1L;
53  
54      
55  
56  
57  
58      public DocumentElement() {
59          this(null);
60      }
61  
62      
63  
64  
65  
66  
67  
68      public DocumentElement(final DocumentType doctype) {
69          super(doctype, JEuclidDOMImplementation.getInstance());
70          super.setEventsEnabled(true);
71          this.ownerDocument = this;
72      }
73  
74      
75      public String getDomain() {
76          throw new UnsupportedOperationException();
77      }
78  
79      
80      public String getReferrer() {
81          throw new UnsupportedOperationException();
82      }
83  
84      
85      public String getURI() {
86          throw new UnsupportedOperationException();
87      }
88  
89      
90      public LayoutContext getChildLayoutContext(final int childNum,
91              final LayoutContext context) {
92          return context;
93      }
94  
95      
96      
97      public JEuclidView getDefaultView() {
98          
99          return new JEuclidView(this,
100                 LayoutContextImpl.getDefaultLayoutContext(), null);
101     }
102 
103     
104     public List<LayoutableNode> getChildrenToLayout() {
105         return ElementListSupport.createListOfLayoutChildren(this);
106     }
107 
108     
109     public List<LayoutableNode> getChildrenToDraw() {
110         return ElementListSupport.createListOfLayoutChildren(this);
111     }
112 
113     
114     public void layoutStage1(final LayoutView view, final LayoutInfo info,
115             final LayoutStage childMinStage, final LayoutContext context) {
116         ElementListSupport.layoutSequential(view, info, this
117                 .getChildrenToLayout(), LayoutStage.STAGE1);
118         info.setLayoutStage(childMinStage);
119         
120         if (context.getParameter(Parameter.MATHBACKGROUND) == null) {
121             info.setLayoutStage(childMinStage);
122         } else {
123             info.setLayoutStage(LayoutStage.STAGE1);
124         }
125     }
126 
127     
128     public void layoutStage2(final LayoutView view, final LayoutInfo info,
129             final LayoutContext context) {
130         ElementListSupport.layoutSequential(view, info, this
131                 .getChildrenToLayout(), LayoutStage.STAGE2);
132         ElementListSupport.addBackground((Color) context
133                 .getParameter(Parameter.MATHBACKGROUND), info, true);
134         info.setLayoutStage(LayoutStage.STAGE2);
135     }
136 
137     
138     @Override
139     protected Node newNode() {
140         return new DocumentElement();
141     }
142 
143     
144     @Override
145     public Element createElement(final String tagName) {
146         return JEuclidElementFactory.elementFromName(null, tagName, this);
147     }
148 
149     
150     @Override
151     public Element createElementNS(final String namespaceURI,
152             final String qualifiedName) {
153         final String ns;
154         if (namespaceURI != null && namespaceURI.length() == 0) {
155             ns = null;
156         } else {
157             ns = namespaceURI;
158         }
159         return JEuclidElementFactory.elementFromName(ns, qualifiedName, this);
160     }
161 }