]> gerrit.simantics Code Review - simantics/platform.git/blob
a2613c061908e7c06c530088cb0b6b8601cdc802
[simantics/platform.git] /
1 package org.simantics.document.linking.report.html;
2
3 import org.simantics.document.linking.report.DocumentElement;
4 import org.simantics.document.linking.report.TableOfContents;
5
6
7 public class HTMLTocElement extends HTMLStreamElement implements TableOfContents {
8         
9         
10
11         HTMLTable tocTable;
12         
13         public HTMLTocElement(HTMLDocument writer) throws Exception{
14                 super(writer);
15                 this.os.println("<h2>Table of Contents</h2>");
16                 tocTable = new HTMLTable(writer, os, false);
17                 tocTable.setHeaderVisible(false);
18                 tocTable.setLinesVisible(false);
19                 tocTable.addColumn("Name", 1.0);
20         }
21         
22         @Override
23         public void addTocElement(String label, DocumentElement element) throws Exception{
24                 HTMLElement e = (HTMLElement)element;
25                 if (e.getId() == null)
26                         throw new IllegalArgumentException("Element has no id " + element);
27                 //os.println("<a href=\"#" + e.getId() + "\">" + label + "</a><br>");
28                 tocTable.writeRow("<a href=\"#" + e.getId() + "\">" + label + "</a><br>");
29         }
30         
31         public void close() throws Exception{
32                 tocTable.endTable();
33                 os.print("<br>");
34                 super.close();
35         }
36         
37         @Override
38         public String getId() {
39                 return "toc";
40         }
41
42 }