1 | package org.expeditee.io;
|
---|
2 |
|
---|
3 | import java.awt.Image;
|
---|
4 | import java.awt.image.BufferedImage;
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import org.expeditee.actions.Misc;
|
---|
9 | import org.expeditee.gui.FrameIO;
|
---|
10 | import org.expeditee.items.Item;
|
---|
11 | import org.expeditee.items.Picture;
|
---|
12 | import org.expeditee.items.Text;
|
---|
13 |
|
---|
14 | import sun.awt.image.ToolkitImage;
|
---|
15 |
|
---|
16 | public class HTMLBWriter extends AbstractHTMLWriter {
|
---|
17 |
|
---|
18 | @Override
|
---|
19 | protected void writeTitle(Text toWrite, List<Item> items)
|
---|
20 | throws IOException {
|
---|
21 | int indent = getIndent();
|
---|
22 | if(indent == 0)
|
---|
23 | return;
|
---|
24 |
|
---|
25 | String heading = toWrite.getText();
|
---|
26 | String tag = "h" + indent;
|
---|
27 | // indenting for tag
|
---|
28 | indent();
|
---|
29 | _writer.write("<" + tag + ">" + heading + "</" + tag + ">"
|
---|
30 | + ItemWriter.NEW_LINE);
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | protected void writeText(Text text) throws IOException {
|
---|
35 | indent();
|
---|
36 | _writer.write("<p>");
|
---|
37 | _writer.write(text.getText().replace('\n', ' '));
|
---|
38 | _writer.write("</p>" + ItemWriter.NEW_LINE);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | protected void writePicture(Picture pic) throws IOException {
|
---|
43 | //TODO: Deal with cropped images!
|
---|
44 |
|
---|
45 | Image image = pic.getImage();
|
---|
46 | String filesFolder = getFilesFolder();
|
---|
47 | String fileName;
|
---|
48 | // If its a bufferedImage then just write it out to the files directory
|
---|
49 | //This means it is probably a FrameImage
|
---|
50 | if (image instanceof BufferedImage || image instanceof ToolkitImage) {
|
---|
51 | String link = pic.getAbsoluteLink();
|
---|
52 | // Account for the possiblitly of an unlinked buffered image
|
---|
53 | fileName = link == null ? ("Image" + pic.getID()) : link;
|
---|
54 | fileName = Misc.SaveImage((BufferedImage) image, "PNG", FrameIO.EXPORTS_DIR
|
---|
55 | + filesFolder, fileName);
|
---|
56 | } else {//It is a normal Image stored somewhere
|
---|
57 |
|
---|
58 | Text source = pic.getSource();
|
---|
59 |
|
---|
60 | fileName = source.getFirstLine();
|
---|
61 | fileName = fileName.substring(fileName.indexOf(":") + 1).trim();
|
---|
62 |
|
---|
63 | String oldImageName = FrameIO.IMAGES_PATH + fileName;
|
---|
64 | String newImageName = FrameIO.EXPORTS_DIR + filesFolder + fileName;
|
---|
65 | try {
|
---|
66 | FrameIO.copyFile(oldImageName, newImageName);
|
---|
67 | } catch (Exception e) {
|
---|
68 | filesFolder = "";
|
---|
69 | }
|
---|
70 | if (filesFolder.equals("")) {
|
---|
71 | filesFolder = "../" + FrameIO.IMAGES_FOLDER;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | indent();
|
---|
75 | StringBuffer imageTag = new StringBuffer("<img src=\"");
|
---|
76 | imageTag.append(filesFolder).append(fileName);
|
---|
77 | imageTag.append("\" height=").append(pic.getHeight());
|
---|
78 | imageTag.append(" width=").append(pic.getWidth());
|
---|
79 | imageTag.append(" border=1>");
|
---|
80 | _writer.write(imageTag.toString());
|
---|
81 | _writer.write(ItemWriter.NEW_LINE);
|
---|
82 | }
|
---|
83 | }
|
---|