KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nwalsh > saxon > FormatGraphicCallout


1 package com.nwalsh.saxon;
2
3 import org.xml.sax.SAXException JavaDoc;
4 import org.w3c.dom.*;
5
6 import javax.xml.transform.TransformerException JavaDoc;
7
8 import com.icl.saxon.om.NamePool;
9 import com.icl.saxon.output.Emitter;
10 import com.icl.saxon.tree.AttributeCollection;
11
12 import com.nwalsh.saxon.Callout;
13
14 /**
15  * <p>Utility class for the Verbatim extension (ignore this).</p>
16  *
17  * <p>$Id: FormatGraphicCallout.java,v 1.1 2001/07/16 21:23:57 nwalsh Exp $</p>
18  *
19  * <p>Copyright (C) 2000, 2001 Norman Walsh.</p>
20  *
21  * <p><b>Change Log:</b></p>
22  * <dl>
23  * <dt>1.0</dt>
24  * <dd><p>Initial release.</p></dd>
25  * </dl>
26  *
27  * @author Norman Walsh
28  * <a HREF="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
29  *
30  * @see Verbatim
31  *
32  * @version $Id: FormatGraphicCallout.java,v 1.1 2001/07/16 21:23:57 nwalsh Exp $
33  **/

34
35 public class FormatGraphicCallout extends FormatCallout {
36   String JavaDoc graphicsPath = "";
37   String JavaDoc graphicsExt = "";
38   int graphicsMax = 0;
39
40   public FormatGraphicCallout(NamePool nPool, String JavaDoc path, String JavaDoc ext, int max, boolean fo) {
41     super(nPool, fo);
42     graphicsPath = path;
43     graphicsExt = ext;
44     graphicsMax = max;
45   }
46
47   public void formatCallout(Emitter rtfEmitter,
48                 Callout callout) {
49     Element area = callout.getArea();
50     int num = callout.getCallout();
51     String JavaDoc userLabel = areaLabel(area);
52     String JavaDoc label = "(" + num + ")";
53
54     if (userLabel != null) {
55       label = userLabel;
56     }
57
58     try {
59       if (userLabel == null && num <= graphicsMax) {
60     int imgName = 0;
61     AttributeCollection imgAttr = null;
62     int namespaces[] = new int[1];
63
64     if (foStylesheet) {
65       imgName = namePool.allocate("fo", foURI, "external-graphic");
66       imgAttr = new AttributeCollection(namePool);
67       imgAttr.addAttribute("", "", "src", "CDATA",
68                    graphicsPath + num + graphicsExt);
69     } else {
70       imgName = namePool.allocate("", "", "img");
71       imgAttr = new AttributeCollection(namePool);
72       imgAttr.addAttribute("", "", "src", "CDATA",
73                    graphicsPath + num + graphicsExt);
74       imgAttr.addAttribute("", "", "alt", "CDATA", label);
75     }
76
77     startSpan(rtfEmitter);
78     rtfEmitter.startElement(imgName, imgAttr, namespaces, 0);
79     rtfEmitter.endElement(imgName);
80     endSpan(rtfEmitter);
81       } else {
82     formatTextCallout(rtfEmitter, callout);
83       }
84     } catch (TransformerException JavaDoc e) {
85       System.out.println("Transformer Exception in graphic formatCallout");
86     }
87   }
88 }
89
Popular Tags