001: /*
002: * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.xtpdoc;
031:
032: import javax.xml.stream.XMLStreamException;
033: import javax.xml.stream.XMLStreamWriter;
034: import java.io.IOException;
035: import java.io.PrintWriter;
036:
037: public class Figure implements ContentItem {
038: private int _height = -1;
039: private int _width = -1;
040: private String _source;
041: private String _title;
042: private Document _document;
043:
044: public Figure(Document document) {
045: _document = document;
046: }
047:
048: public Document getDocument() {
049: return _document;
050: }
051:
052: public void setHeight(int height) {
053: _height = height;
054: }
055:
056: public void setWidth(int width) {
057: _width = width;
058: }
059:
060: public void setSrc(String source) {
061: _source = source;
062: }
063:
064: public void setTitle(String title) {
065: _title = title;
066: }
067:
068: public void writeHtml(XMLStreamWriter out)
069: throws XMLStreamException {
070: out.writeStartElement("center");
071:
072: out.writeEmptyElement("img");
073:
074: if (_height >= 0)
075: out.writeAttribute("height", Integer.toString(_height));
076:
077: if (_title != null)
078: out.writeAttribute("title", _title);
079:
080: if (_width >= 0)
081: out.writeAttribute("width", Integer.toString(_width));
082:
083: out.writeAttribute("src", _document.getContextPath()
084: + "/images/" + _source);
085:
086: out.writeEndElement(); // center
087: }
088:
089: public void writeLaTeX(PrintWriter out) throws IOException {
090: //out.println("\\begin{figure}[h]");
091:
092: int dot = _source.lastIndexOf('.');
093:
094: String basename = _source.substring(0, dot);
095:
096: int lastSlash = basename.lastIndexOf('/');
097:
098: if (lastSlash >= 0)
099: basename = basename.substring(lastSlash + 1);
100:
101: out.println();
102: out.println();
103: out.println("\\noindent");
104: out.println("\\epsfig{file=../images/" + basename
105: + ",width=\\linewidth}");
106: out.println();
107: out.println();
108:
109: /*
110: if (_height >= 0)
111: out.print(",height=" + _height);
112:
113: if (_width >= 0)
114: out.print(",width=" + _width);
115:
116: out.println("}");
117: */
118:
119: //out.println("\\end{figure}");
120: }
121:
122: public void writeLaTeXEnclosed(PrintWriter out) throws IOException {
123: writeLaTeX(out);
124: }
125:
126: public void writeLaTeXTop(PrintWriter out) throws IOException {
127: writeLaTeX(out);
128: }
129: }
|