| .. | .. |
|---|
| 9 | 9 | |
|---|
| 10 | 10 | public class HtmlFormat implements Export |
|---|
| 11 | 11 | { |
|---|
| 12 | | - TFModel model; |
|---|
| 13 | | - java.util.List<Field> fields; |
|---|
| 14 | | - Field title; |
|---|
| 15 | | - |
|---|
| 16 | | - public HtmlFormat() {} |
|---|
| 17 | | - |
|---|
| 18 | | - public HtmlFormat(TFModel model) |
|---|
| 19 | | - { |
|---|
| 20 | | - setModel(model); |
|---|
| 21 | | - } |
|---|
| 22 | | - |
|---|
| 23 | | - public void setModel(TFModel model) |
|---|
| 24 | | - { |
|---|
| 25 | | - this.model=model; |
|---|
| 26 | | - fields=model.getDB().getFields(); |
|---|
| 27 | | - title=model.getDB().getField(VirtualField.LABEL); |
|---|
| 28 | | - } |
|---|
| 29 | | - |
|---|
| 30 | | - @Override |
|---|
| 31 | | - public void export(TFModel model, BufferedWriter out) throws Exception { |
|---|
| 32 | | - setModel(model); |
|---|
| 33 | | - out.write(makeHeader()); |
|---|
| 34 | | - for (Act a: model.getDB()) |
|---|
| 35 | | - out.write(makeItem(a)); |
|---|
| 36 | | - out.write(makeFooter()); |
|---|
| 37 | | - out.flush(); |
|---|
| 38 | | - } |
|---|
| 39 | | - |
|---|
| 40 | | - public void append(ActList acts, int start, int end, StringBuffer b) |
|---|
| 41 | | - { |
|---|
| 42 | | - for (int i=start; i<end; i++) |
|---|
| 43 | | - { |
|---|
| 44 | | - Act a=acts.get(i); |
|---|
| 45 | | - b.append(makeItem(a,i)); |
|---|
| 46 | | - } |
|---|
| 47 | | - } |
|---|
| 48 | | - |
|---|
| 49 | | - private String makeItem(Act act) |
|---|
| 50 | | - { |
|---|
| 51 | | - return makeItem(act, -1); |
|---|
| 52 | | - } |
|---|
| 53 | | - |
|---|
| 54 | | - public String makeItem(Act act, int id) |
|---|
| 55 | | - { |
|---|
| 56 | | - StringBuffer page=new StringBuffer(); |
|---|
| 57 | | - |
|---|
| 58 | | - |
|---|
| 59 | | - page.append("<tr><td valign=top align=left width=200><b>"); |
|---|
| 60 | | - if (title!=null) |
|---|
| 61 | | - { |
|---|
| 62 | | - Field f=model.getColorField(); |
|---|
| 63 | | - Color c=Color.black; |
|---|
| 64 | | - if (f!=null) |
|---|
| 65 | | - { |
|---|
| 66 | | - if (f.getType()==String.class) |
|---|
| 67 | | - c=model.getDisplay().makeColor(act.getString(f)); |
|---|
| 68 | | - else |
|---|
| 69 | | - { |
|---|
| 70 | | - String[] tags=act.getTextList(f); |
|---|
| 71 | | - if (tags.length==0) |
|---|
| 72 | | - c=Color.gray; |
|---|
| 73 | | - else |
|---|
| 74 | | - c=model.getDisplay().makeColor(tags[0]); |
|---|
| 75 | | - } |
|---|
| 76 | | - } |
|---|
| 77 | | - |
|---|
| 78 | | - page.append("<font size=+1 color="+htmlColor(c)+">"+act.getString(title)+"</font><br>"); |
|---|
| 79 | | - } |
|---|
| 80 | | - |
|---|
| 81 | | - Field startField=model.getDB().getField(VirtualField.START); |
|---|
| 82 | | - |
|---|
| 83 | | - if (startField!=null) |
|---|
| 84 | | - { |
|---|
| 85 | | - page.append("<font color=#999999>"+model.getDisplay().format( |
|---|
| 86 | | - act.getTime(startField))+"</font>"); |
|---|
| 87 | | - } |
|---|
| 88 | | - page.append("</b><br>"); |
|---|
| 89 | | - if (id>=0) |
|---|
| 90 | | - page.append("<a href=\"e"+id+"\">EDIT</a>"); |
|---|
| 91 | | - page.append("<br></td><td valign=top>"); |
|---|
| 92 | | - for (Field f: fields) |
|---|
| 93 | | - { |
|---|
| 94 | | - page.append("<b><font color=#003399>"+f.getName()+"</font></b> "); |
|---|
| 95 | | - Object val=act.get(f); |
|---|
| 96 | | - if (val instanceof URL) |
|---|
| 97 | | - { |
|---|
| 98 | | - page.append("<a href=\""+val+"\">"+val+"</a>"); |
|---|
| 99 | | - } |
|---|
| 100 | | - else |
|---|
| 101 | | - page.append(model.getDisplay().toString(val)); |
|---|
| 102 | | - page.append("<br>"); |
|---|
| 12 | + TimeflowModel model; |
|---|
| 13 | + java.util.List<Field> fields; |
|---|
| 14 | + Field title; |
|---|
| 103 | 15 | |
|---|
| 104 | | - } |
|---|
| 105 | | - page.append("<br></td></tr>"); |
|---|
| 16 | + public HtmlFormat() |
|---|
| 17 | + { |
|---|
| 18 | + } |
|---|
| 106 | 19 | |
|---|
| 107 | | - return page.toString(); |
|---|
| 108 | | - } |
|---|
| 109 | | - |
|---|
| 110 | | - public String makeHeader() |
|---|
| 111 | | - { |
|---|
| 112 | | - StringBuffer page=new StringBuffer(); |
|---|
| 113 | | - page.append("<html><body><blockquote>"); |
|---|
| 114 | | - page.append("<br>File: "+model.getDbFile()+"<br>"); |
|---|
| 115 | | - page.append("Source: "+model.getDB().getSource()+"<br><br>"); |
|---|
| 116 | | - page.append("<br><br>"); |
|---|
| 117 | | - page.append("<table border=0>"); |
|---|
| 20 | + public HtmlFormat(TimeflowModel model) |
|---|
| 21 | + { |
|---|
| 22 | + setModel(model); |
|---|
| 23 | + } |
|---|
| 118 | 24 | |
|---|
| 119 | | - return page.toString(); |
|---|
| 120 | | - } |
|---|
| 121 | | - |
|---|
| 122 | | - public String makeFooter() |
|---|
| 123 | | - { |
|---|
| 124 | | - return "</table></blockquote></body></html>"; |
|---|
| 125 | | - } |
|---|
| 126 | | - |
|---|
| 127 | | - |
|---|
| 128 | | - static String htmlColor(Color c) |
|---|
| 129 | | - { |
|---|
| 130 | | - return '#'+hex2(c.getRed())+hex2(c.getGreen())+hex2(c.getBlue()); |
|---|
| 131 | | - } |
|---|
| 132 | | - |
|---|
| 133 | | - private static final String hexDigits="0123456789ABCDEF"; |
|---|
| 134 | | - private static String hex2(int n) |
|---|
| 135 | | - { |
|---|
| 136 | | - return hexDigits.charAt((n/16)%16)+""+hexDigits.charAt(n%16); |
|---|
| 137 | | - } |
|---|
| 138 | | - @Override |
|---|
| 139 | | - public String getName() { |
|---|
| 140 | | - return "HTML List"; |
|---|
| 141 | | - } |
|---|
| 25 | + public void setModel(TimeflowModel model) |
|---|
| 26 | + { |
|---|
| 27 | + this.model = model; |
|---|
| 28 | + fields = model.getDB().getFields(); |
|---|
| 29 | + title = model.getDB().getField(VirtualField.LABEL); |
|---|
| 30 | + } |
|---|
| 142 | 31 | |
|---|
| 32 | + @Override |
|---|
| 33 | + public void export(TimeflowModel model, BufferedWriter out) throws Exception |
|---|
| 34 | + { |
|---|
| 35 | + setModel(model); |
|---|
| 36 | + out.write(makeHeader()); |
|---|
| 37 | + for (Act a : model.getDB()) |
|---|
| 38 | + { |
|---|
| 39 | + out.write(makeItem(a)); |
|---|
| 40 | + } |
|---|
| 41 | + out.write(makeFooter()); |
|---|
| 42 | + out.flush(); |
|---|
| 43 | + } |
|---|
| 44 | + |
|---|
| 45 | + public void append(ActList acts, int start, int end, StringBuffer b) |
|---|
| 46 | + { |
|---|
| 47 | + for (int i = start; i < end; i++) |
|---|
| 48 | + { |
|---|
| 49 | + Act a = acts.get(i); |
|---|
| 50 | + b.append(makeItem(a, i)); |
|---|
| 51 | + } |
|---|
| 52 | + } |
|---|
| 53 | + |
|---|
| 54 | + private String makeItem(Act act) |
|---|
| 55 | + { |
|---|
| 56 | + return makeItem(act, -1); |
|---|
| 57 | + } |
|---|
| 58 | + |
|---|
| 59 | + public String makeItem(Act act, int id) |
|---|
| 60 | + { |
|---|
| 61 | + StringBuffer page = new StringBuffer(); |
|---|
| 62 | + |
|---|
| 63 | + page.append("<tr><td valign=top align=left width=200><b>"); |
|---|
| 64 | + if (title != null) |
|---|
| 65 | + { |
|---|
| 66 | + Field f = model.getColorField(); |
|---|
| 67 | + Color c = Color.black; |
|---|
| 68 | + if (f != null) |
|---|
| 69 | + { |
|---|
| 70 | + if (f.getType() == String.class) |
|---|
| 71 | + { |
|---|
| 72 | + c = model.getDisplay().makeColor(act.getString(f)); |
|---|
| 73 | + } else |
|---|
| 74 | + { |
|---|
| 75 | + String[] tags = act.getTextList(f); |
|---|
| 76 | + if (tags.length == 0) |
|---|
| 77 | + { |
|---|
| 78 | + c = Color.gray; |
|---|
| 79 | + } else |
|---|
| 80 | + { |
|---|
| 81 | + c = model.getDisplay().makeColor(tags[0]); |
|---|
| 82 | + } |
|---|
| 83 | + } |
|---|
| 84 | + } |
|---|
| 85 | + |
|---|
| 86 | + page.append("<font size=+1 color=" + htmlColor(c) + ">" + act.getString(title) + "</font><br>"); |
|---|
| 87 | + } |
|---|
| 88 | + |
|---|
| 89 | + Field startField = model.getDB().getField(VirtualField.START); |
|---|
| 90 | + |
|---|
| 91 | + if (startField != null) |
|---|
| 92 | + { |
|---|
| 93 | + page.append("<font color=#999999>" + model.getDisplay().format(act.getTime(startField)) + "</font>"); |
|---|
| 94 | + } |
|---|
| 95 | + page.append("</b><br>"); |
|---|
| 96 | + if (id >= 0) |
|---|
| 97 | + { |
|---|
| 98 | + page.append("<a href=\"e" + id + "\">EDIT</a>"); |
|---|
| 99 | + } |
|---|
| 100 | + page.append("<br></td><td valign=top>"); |
|---|
| 101 | + for (Field f : fields) |
|---|
| 102 | + { |
|---|
| 103 | + page.append("<b><font color=#003399>" + f.getName() + "</font></b> "); |
|---|
| 104 | + Object val = act.get(f); |
|---|
| 105 | + if (val instanceof URL) |
|---|
| 106 | + { |
|---|
| 107 | + page.append("<a href=\"" + val + "\">" + val + "</a>"); |
|---|
| 108 | + } else |
|---|
| 109 | + { |
|---|
| 110 | + page.append(model.getDisplay().toString(val)); |
|---|
| 111 | + } |
|---|
| 112 | + page.append("<br>"); |
|---|
| 113 | + |
|---|
| 114 | + } |
|---|
| 115 | + page.append("<br></td></tr>"); |
|---|
| 116 | + |
|---|
| 117 | + return page.toString(); |
|---|
| 118 | + } |
|---|
| 119 | + |
|---|
| 120 | + public String makeHeader() |
|---|
| 121 | + { |
|---|
| 122 | + StringBuffer page = new StringBuffer(); |
|---|
| 123 | + page.append("<html><body><blockquote>"); |
|---|
| 124 | + page.append("<br>File: " + model.getDbFile() + "<br>"); |
|---|
| 125 | + page.append("Source: " + model.getDB().getSource() + "<br><br>"); |
|---|
| 126 | + page.append("<br><br>"); |
|---|
| 127 | + page.append("<table border=0>"); |
|---|
| 128 | + |
|---|
| 129 | + return page.toString(); |
|---|
| 130 | + } |
|---|
| 131 | + |
|---|
| 132 | + public String makeFooter() |
|---|
| 133 | + { |
|---|
| 134 | + return "</table></blockquote></body></html>"; |
|---|
| 135 | + } |
|---|
| 136 | + |
|---|
| 137 | + static String htmlColor(Color c) |
|---|
| 138 | + { |
|---|
| 139 | + return '#' + hex2(c.getRed()) + hex2(c.getGreen()) + hex2(c.getBlue()); |
|---|
| 140 | + } |
|---|
| 141 | + private static final String hexDigits = "0123456789ABCDEF"; |
|---|
| 142 | + |
|---|
| 143 | + private static String hex2(int n) |
|---|
| 144 | + { |
|---|
| 145 | + return hexDigits.charAt((n / 16) % 16) + "" + hexDigits.charAt(n % 16); |
|---|
| 146 | + } |
|---|
| 147 | + |
|---|
| 148 | + @Override |
|---|
| 149 | + public String getName() |
|---|
| 150 | + { |
|---|
| 151 | + return "HTML List"; |
|---|
| 152 | + } |
|---|
| 143 | 153 | } |
|---|