source: trunk/src/org/expeditee/io/HTMLWriter.java@ 1274

Last change on this file since 1274 was 1274, checked in by bln4, 5 years ago

Consistency of FrameIO path names

File size: 3.8 KB
Line 
1/**
2 * HTMLWriter.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.io;
20
21import java.io.IOException;
22import java.util.List;
23
24import org.expeditee.actions.Misc;
25import org.expeditee.core.Dimension;
26import org.expeditee.core.Image;
27import org.expeditee.core.Point;
28import org.expeditee.gio.EcosystemManager;
29import org.expeditee.gio.GraphicsManager;
30import org.expeditee.gui.FrameIO;
31import org.expeditee.items.FramePicture;
32import org.expeditee.items.Item;
33import org.expeditee.items.Picture;
34import org.expeditee.items.Text;
35
36public class HTMLWriter extends AbstractHTMLWriter {
37
38 @Override
39 protected void writeTitle(Text toWrite, List<Item> items)
40 throws IOException {
41 int indent = getIndent();
42 if (indent == 0)
43 return;
44
45 String heading = toWrite.getText();
46 String tag = "h" + indent;
47 // indenting for tag
48 indent();
49 _writer.write("<" + tag + ">" + heading + "</" + tag + ">"
50 + ItemWriter.NEW_LINE);
51 }
52
53 @Override
54 protected void writeText(Text text) throws IOException {
55 indent();
56 _writer.write("<p>");
57 _writer.write(text.getText().replace('\n', ' '));
58 _writer.write("</p>" + ItemWriter.NEW_LINE);
59 }
60
61 @Override
62 protected void writePicture(Picture pic) throws IOException {
63 // TODO handle different colored @f's of the same frame
64 // TODO handle cropped images
65 Image image = null;
66
67 if (pic instanceof FramePicture || pic.isCropped()) {
68 image = pic.getImage();
69 // Crop the image
70 Image bufferedImage = Image.createImage(pic.getUnscaledWidth(), pic.getUnscaledHeight());
71 GraphicsManager g = EcosystemManager.getGraphicsManager();
72 g.pushDrawingSurface(bufferedImage);
73 g.drawImage(image,
74 new Point(0, 0),
75 new Dimension(pic.getUnscaledWidth(), pic.getUnscaledHeight()),
76 0.0,
77 pic.getStart(),
78 new Dimension(pic.getEnd().getX() - pic.getStart().getX(), pic.getEnd().getY() - pic.getStart().getY()));
79 g.popDrawingSurface();
80 image = bufferedImage;
81 } else {
82 image = pic.getImage();
83 }
84
85 String filesFolder = getFilesFolder();
86 String fileName;
87 // If its a bufferedImage then just write it out to the files directory
88 // This means it is probably a FrameImage
89 if (!image.isStoredOnDisk()) {
90 String link = pic.getAbsoluteLink();
91 // Account for the possibility of an unlinked buffered image
92 fileName = link == null ? ("Image" + pic.getID()) : link;
93 fileName = Misc.SaveImage(image, "PNG", FrameIO.EXPORTS_PATH + filesFolder, fileName);
94 } else {// It is a normal Image stored somewhere
95 fileName = pic.getName();
96
97 String oldImageName = FrameIO.IMAGES_PATH + fileName;
98 String newImageName = FrameIO.EXPORTS_PATH + filesFolder + fileName;
99 try {
100 FrameIO.copyFile(oldImageName, newImageName);
101 } catch (Exception e) {
102 filesFolder = "";
103 }
104 if (filesFolder.equals("")) {
105 filesFolder = "../images/";
106 }
107 }
108 indent();
109 StringBuffer imageTag = new StringBuffer("<img src=\"");
110 imageTag.append(filesFolder).append(fileName);
111 imageTag.append("\" height=").append(pic.getHeight());
112 imageTag.append(" width=").append(pic.getWidth());
113 imageTag.append(" border=1>");
114 _writer.write(imageTag.toString());
115 _writer.write(ItemWriter.NEW_LINE);
116 }
117}
Note: See TracBrowser for help on using the repository browser.