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 |
|
---|
19 | package org.expeditee.io;
|
---|
20 |
|
---|
21 | import java.io.IOException;
|
---|
22 | import java.util.List;
|
---|
23 |
|
---|
24 | import org.expeditee.actions.Misc;
|
---|
25 | import org.expeditee.core.Dimension;
|
---|
26 | import org.expeditee.core.Image;
|
---|
27 | import org.expeditee.core.Point;
|
---|
28 | import org.expeditee.gio.EcosystemManager;
|
---|
29 | import org.expeditee.gio.GraphicsManager;
|
---|
30 | import org.expeditee.gio.swing.SwingMiscManager;
|
---|
31 | import org.expeditee.gui.FrameIO;
|
---|
32 | import org.expeditee.items.FramePicture;
|
---|
33 | import org.expeditee.items.Item;
|
---|
34 | import org.expeditee.items.Picture;
|
---|
35 | import org.expeditee.items.Text;
|
---|
36 |
|
---|
37 | public class HTMLWriter extends AbstractHTMLWriter {
|
---|
38 |
|
---|
39 | @Override
|
---|
40 | protected void writeTitle(Text toWrite, List<Item> items)
|
---|
41 | throws IOException {
|
---|
42 | int indent = getIndent();
|
---|
43 | if (indent == 0)
|
---|
44 | return;
|
---|
45 |
|
---|
46 | String heading = toWrite.getText();
|
---|
47 | String tag = "h" + indent;
|
---|
48 | // indenting for tag
|
---|
49 | indent();
|
---|
50 | _writer.write("<" + tag + ">" + heading + "</" + tag + ">"
|
---|
51 | + ItemWriter.NEW_LINE);
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | protected void writeText(Text text) throws IOException {
|
---|
56 | indent();
|
---|
57 | _writer.write("<p>");
|
---|
58 | _writer.write(text.getText().replace('\n', ' '));
|
---|
59 | _writer.write("</p>" + ItemWriter.NEW_LINE);
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | protected void writePicture(Picture pic) throws IOException {
|
---|
64 | // TODO handle different colored @f's of the same frame
|
---|
65 | // TODO handle cropped images
|
---|
66 | Image image = null;
|
---|
67 |
|
---|
68 | if (pic instanceof FramePicture || pic.isCropped()) {
|
---|
69 | image = pic.getImage();
|
---|
70 | // Crop the image
|
---|
71 | Image bufferedImage = Image.createImage(pic.getUnscaledWidth(), pic.getUnscaledHeight());
|
---|
72 | GraphicsManager g = EcosystemManager.getGraphicsManager();
|
---|
73 | g.pushDrawingSurface(bufferedImage);
|
---|
74 | g.drawImage(image,
|
---|
75 | new Point(0, 0),
|
---|
76 | new Dimension(pic.getUnscaledWidth(), pic.getUnscaledHeight()),
|
---|
77 | 0.0,
|
---|
78 | pic.getStart(),
|
---|
79 | new Dimension(pic.getEnd().x - pic.getStart().x, pic.getEnd().y - pic.getStart().y));
|
---|
80 | g.popDrawingSurface();
|
---|
81 | image = bufferedImage;
|
---|
82 | } else {
|
---|
83 | image = pic.getImage();
|
---|
84 | }
|
---|
85 |
|
---|
86 | String filesFolder = getFilesFolder();
|
---|
87 | String fileName;
|
---|
88 | // If its a bufferedImage then just write it out to the files directory
|
---|
89 | // This means it is probably a FrameImage
|
---|
90 | if (!image.isStoredOnDisk()) {
|
---|
91 | String link = pic.getAbsoluteLink();
|
---|
92 | // Account for the possibility of an unlinked buffered image
|
---|
93 | fileName = link == null ? ("Image" + pic.getID()) : link;
|
---|
94 | fileName = Misc.SaveImage(image, "PNG", FrameIO.EXPORTS_DIR + filesFolder, fileName);
|
---|
95 | } else {// It is a normal Image stored somewhere
|
---|
96 | fileName = pic.getName();
|
---|
97 |
|
---|
98 | String oldImageName = FrameIO.IMAGES_PATH + fileName;
|
---|
99 | String newImageName = FrameIO.EXPORTS_DIR + filesFolder + fileName;
|
---|
100 | try {
|
---|
101 | FrameIO.copyFile(oldImageName, newImageName);
|
---|
102 | } catch (Exception e) {
|
---|
103 | filesFolder = "";
|
---|
104 | }
|
---|
105 | if (filesFolder.equals("")) {
|
---|
106 | filesFolder = "../" + FrameIO.IMAGES_FOLDER;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | indent();
|
---|
110 | StringBuffer imageTag = new StringBuffer("<img src=\"");
|
---|
111 | imageTag.append(filesFolder).append(fileName);
|
---|
112 | imageTag.append("\" height=").append(pic.getHeight());
|
---|
113 | imageTag.append(" width=").append(pic.getWidth());
|
---|
114 | imageTag.append(" border=1>");
|
---|
115 | _writer.write(imageTag.toString());
|
---|
116 | _writer.write(ItemWriter.NEW_LINE);
|
---|
117 | }
|
---|
118 | }
|
---|