KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xtpdoc > Figure


1 /*
2  * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Emil Ong
28  */

29
30 package com.caucho.xtpdoc;
31 import javax.xml.stream.XMLStreamException;
32 import javax.xml.stream.XMLStreamWriter;
33 import java.io.IOException JavaDoc;
34 import java.io.PrintWriter JavaDoc;
35
36 public class Figure implements ContentItem {
37   private int _height = -1;
38   private int _width = -1;
39   private String JavaDoc _source;
40   private Document _document;
41
42   public Figure(Document document)
43   {
44     _document = document;
45   }
46
47   public Document getDocument()
48   {
49     return _document;
50   }
51
52   public void setHeight(int height)
53   {
54     _height = height;
55   }
56
57   public void setWidth(int width)
58   {
59     _width = width;
60   }
61
62   public void setSrc(String JavaDoc source)
63   {
64     _source = source;
65   }
66
67   public void writeHtml(XMLStreamWriter out)
68     throws XMLStreamException
69   {
70     out.writeStartElement("center");
71
72     out.writeEmptyElement("img");
73
74     if (_height >= 0)
75       out.writeAttribute("height", Integer.toString(_height));
76
77     if (_width >= 0)
78       out.writeAttribute("width", Integer.toString(_width));
79
80     out.writeAttribute("src",
81                        _document.getContextPath() + "/images/" + _source);
82
83     out.writeEndElement(); // center
84
}
85
86   public void writeLaTeX(PrintWriter JavaDoc out)
87     throws IOException JavaDoc
88   {
89     //out.println("\\begin{figure}[h]");
90

91     int dot = _source.lastIndexOf('.');
92
93     String JavaDoc basename = _source.substring(0, dot);
94
95     int lastSlash = basename.lastIndexOf('/');
96
97     if (lastSlash >= 0)
98       basename = basename.substring(lastSlash + 1);
99
100     out.println();
101     out.println();
102     out.println("\\noindent");
103     out.println("\\epsfig{file=../images/" + basename + ",width=\\linewidth}");
104     out.println();
105     out.println();
106
107     /*
108     if (_height >= 0)
109       out.print(",height=" + _height);
110
111     if (_width >= 0)
112       out.print(",width=" + _width);
113
114     out.println("}");
115     */

116
117     //out.println("\\end{figure}");
118
}
119
120   public void writeLaTeXEnclosed(PrintWriter JavaDoc out)
121     throws IOException JavaDoc
122   {
123     writeLaTeX(out);
124   }
125
126   public void writeLaTeXTop(PrintWriter JavaDoc out)
127     throws IOException JavaDoc
128   {
129     writeLaTeX(out);
130   }
131 }
132
Popular Tags