KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > plan > PlanElement


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: PlanElement.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.plan;
21
22 import java.awt.geom.Point2D JavaDoc;
23
24 import org.apache.fop.apps.FOPException;
25 import org.apache.fop.fo.FONode;
26 import org.apache.fop.fo.PropertyList;
27
28 import org.w3c.dom.Document JavaDoc;
29 import org.xml.sax.Attributes JavaDoc;
30 import org.xml.sax.Locator JavaDoc;
31
32 /**
33  * This class defines the plan element.
34  */

35 public class PlanElement extends PlanObj {
36
37     private Document JavaDoc svgDoc = null;
38     private float width;
39     private float height;
40     private boolean converted;
41
42     /**
43      * @see org.apache.fop.fo.FONode#FONode(FONode)
44      */

45     public PlanElement(FONode parent) {
46         super(parent);
47     }
48
49     /**
50      * @see org.apache.fop.fo.FONode#processNode
51      */

52     public void processNode(String JavaDoc elementName, Locator JavaDoc locator,
53                             Attributes JavaDoc attlist, PropertyList propertyList)
54         throws FOPException {
55         super.processNode(elementName, locator, attlist, propertyList);
56         createBasicDocument();
57     }
58
59     /**
60      * Converts the element to SVG.
61      */

62     public void convertToSVG() {
63         try {
64             if (!converted) {
65                 converted = true;
66                 PlanRenderer pr = new PlanRenderer();
67                 pr.setFontInfo("Helvetica", 12);
68                 svgDoc = pr.createSVGDocument(doc);
69                 width = pr.getWidth();
70                 height = pr.getHeight();
71     
72                 doc = svgDoc;
73             }
74         } catch (Throwable JavaDoc t) {
75             getLogger().error("Could not convert Plan to SVG", t);
76             width = 0;
77             height = 0;
78         }
79
80     }
81
82     /**
83      * @see org.apache.fop.fo.XMLObj#getDOMDocument()
84      */

85     public Document JavaDoc getDOMDocument() {
86         convertToSVG();
87         return doc;
88     }
89
90     /** @see org.apache.fop.fo.FONode#getNamespaceURI() */
91     public String JavaDoc getNamespaceURI() {
92         if (svgDoc == null) {
93             return PlanElementMapping.NAMESPACE;
94         }
95         return "http://www.w3.org/2000/svg";
96     }
97
98     /**
99      * @see org.apache.fop.fo.XMLObj#getDimension(Point2D)
100      */

101     public Point2D JavaDoc getDimension(Point2D JavaDoc view) {
102         convertToSVG();
103         return new Point2D.Float JavaDoc(width, height);
104     }
105 }
106
107
Popular Tags