From 1151d9c5e12915d9066e9ef61895db767f138d65 Mon Sep 17 00:00:00 2001 From: Martin Smarda Date: Sun, 12 Dec 2010 17:42:11 +0100 Subject: [PATCH] Coded support for LaTeX rendering --- IndependentModeler/epcXHTMLExportModule.properties | 6 +- .../resources/templates/LaTeXTemplate.tex | 10 +- .../EPC2XHTMLExport/engine/DokuWikiRenderer.java | 2 +- .../EPC2XHTMLExport/engine/ExporterEngine.java | 149 ++++++++++++--------- .../{DokuWikiRenderer.java => LaTeXRenderer.java} | 25 ++-- .../cvut/promod/EPC2XHTMLExport/engine/Table.java | 14 +- 6 files changed, 118 insertions(+), 88 deletions(-) copy Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/{DokuWikiRenderer.java => LaTeXRenderer.java} (67%) diff --git a/IndependentModeler/epcXHTMLExportModule.properties b/IndependentModeler/epcXHTMLExportModule.properties index f54f42d..c4a26df 100644 --- a/IndependentModeler/epcXHTMLExportModule.properties +++ b/IndependentModeler/epcXHTMLExportModule.properties @@ -1,11 +1,11 @@ # -#Wed Dec 08 12:46:23 CET 2010 +#Sun Dec 12 17:40:48 CET 2010 epc.export.xhtml.description=A module for XHTML export (using SVG) of diagrams defined by EPC Notation (EPCNotation plugin). epc.export.xhtml.identifier=EPC2XHTMLExport epc.export.xhtml.config.openwithpath=Choose an application... epc.export.xhtml.config.openwithchoice=1 epc.notation.identifier=f8b79111-ddb3-4c23-8d2d-f9fc687278fb epc.export.xhtml.name=EPC2XHTMLExportModule -epc.export.xhtml.config.format=0 +epc.export.xhtml.config.format=2 epc.export.xhtml.config.theme=0 -epc.export.xhtml.config.notes=0 +epc.export.xhtml.config.notes=1 diff --git a/Plugins/EPC/ModuleEPC2XHTMLExport/resources/templates/LaTeXTemplate.tex b/Plugins/EPC/ModuleEPC2XHTMLExport/resources/templates/LaTeXTemplate.tex index 4077ada..1ea5e30 100644 --- a/Plugins/EPC/ModuleEPC2XHTMLExport/resources/templates/LaTeXTemplate.tex +++ b/Plugins/EPC/ModuleEPC2XHTMLExport/resources/templates/LaTeXTemplate.tex @@ -1,6 +1,8 @@ \documentclass{article} +\usepackage[pdftex]{graphicx} + \title{(title)} \author{Independent Modeler} @@ -9,11 +11,11 @@ \maketitle -(nodeTable) +\begin{center} +\includegraphics{(_imageName)} +\end{center}\label{f-ac} -\newline -\newline -\newline +(nodeTable) (linkTable) diff --git a/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/DokuWikiRenderer.java b/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/DokuWikiRenderer.java index 5ef4713..315004b 100644 --- a/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/DokuWikiRenderer.java +++ b/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/DokuWikiRenderer.java @@ -65,6 +65,6 @@ public class DokuWikiRenderer extends Renderer{ @Override public boolean isColliding() { - return file.exists(); + return file.exists() || plot.exists(); } } diff --git a/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/ExporterEngine.java b/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/ExporterEngine.java index 5fe4bcd..796f19a 100644 --- a/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/ExporterEngine.java +++ b/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/ExporterEngine.java @@ -77,77 +77,25 @@ public class ExporterEngine { } catch (ExporterSettingsModel.ExportThemeException e) {} - //XHTML table delimiters - delimiters.beforeTable = ""; - delimiters.afterTable = "
"; - delimiters.beforeColumn = ""; - delimiters.afterColumn = ""; - delimiters.beforeRow= ""; - delimiters.afterRow= ""; - delimiters.beforeHeaderColumn= ""; - delimiters.afterHeaderColumn= ""; - delimiters.beforeHeaderRow= ""; - delimiters.afterHeaderRow= ""; - delimiters.beforeHeading= ""; - delimiters.afterHeading= ""; - break; case eDokuWiki: renderer = new DokuWikiRenderer(settings.getPath(), settings.getName()); - delimiters.beforeColumn = "| "; - delimiters.afterColumn = " "; - delimiters.afterRow= "|\n"; - delimiters.beforeHeaderColumn= "^ "; - delimiters.afterHeaderColumn= " "; - delimiters.afterHeaderRow= "^\n"; - delimiters.beforeHeading= "=== "; - delimiters.afterHeading= " ===\n"; - break; case eLaTeXFolder: renderer = new LaTeXRenderer(settings.getPath(), settings.getName()); -/* - \begin{center} - \begin{tabular}{ | l | l | l | l |} - \hline - Day & Min Temp & Max Temp & Summary \\ \hline - Monday & 11C & 22C & A clear day with lots of sunshine. - However, the strong breeze will bring down the temperatures. \\ \hline - Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells - across most of Scotland and Northern Ireland, - but rain reaching the far northwest. \\ \hline - Wednesday & 10C & 21C & Rain will still linger for the morning. - Conditions will improve by early afternoon and continue - throughout the evening. \\ - \hline - \end{tabular} -\end{center} -*/ - delimiters.beforeTable = "\\begin{center}\n\\begin{tabular}{ | l | l | l | l |}"; //todo - delimiters.afterTable = "\\end{tabular}\n\\end{center}"; - - delimiters.betweenColumns = " & "; - delimiters.afterRow= "\\\\ \\hline"; - - delimiters.afterHeaderRow= "\\\\ \\hline"; - delimiters.betweenHeaderColumns= " & "; -/* - delimiters.beforeHeading= "=== "; - delimiters.afterHeading= " ===\n";*/ break; } } - protected String generateNodeTable(final Diagram diagram){ - String str = ""; + protected Table generateNodeTable(final Diagram diagram){ + Table nodeTable = new Table(4, new String[] {"Name", "Note", "Condition 1", "Condition 2"}); if(settings.getNotes()){ Iterator it = diagram.getNodes().iterator(); Node tmp; - Table nodeTable = new Table(4, new String[] {"Name", "Note", "Condition 1", "Condition 2"}); while(it.hasNext()){ tmp = it.next(); @@ -172,13 +120,12 @@ public class ExporterEngine { nodeTable.addRow(row); } - str = nodeTable.toString("Nodes", delimiters); } - return str; + return nodeTable; } - protected String generateLinkTable(final Diagram diagram){ + protected Table generateLinkTable(final Diagram diagram){ boolean isNotes = settings.getNotes(); Iterator itn = diagram.getNodes().iterator(); Iterator itl; @@ -205,7 +152,7 @@ public class ExporterEngine { } } - return linkTable.toString("Links", delimiters); + return linkTable; } protected BufferedImage generateImage(final JGraph graph){ @@ -226,12 +173,92 @@ public class ExporterEngine { public void export() throws IOException{ - Diagram diagram = new Diagram(workspace.getGraph().getModel(), settings.getTitle()); Map replacements = new Hashtable(); - replacements.put("nodeTable", generateNodeTable(diagram)); - replacements.put("linkTable", generateLinkTable(diagram)); + Table nodeTable = generateNodeTable(diagram); + Table linkTable = generateLinkTable(diagram); + + //Set table delimiters + switch (settings.getFormat()){ + /* case eXHTMLFile: */ + case eXHTMLFolder: + + delimiters.beforeTable = ""; + delimiters.afterTable = "
"; + delimiters.beforeColumn = ""; + delimiters.afterColumn = ""; + delimiters.beforeRow= ""; + delimiters.afterRow= ""; + delimiters.beforeHeaderColumn= ""; + delimiters.afterHeaderColumn= ""; + delimiters.beforeHeaderRow= ""; + delimiters.afterHeaderRow= ""; + delimiters.beforeHeading= ""; + delimiters.afterHeading= ""; + + break; + case eDokuWiki: + + delimiters.beforeColumn = "| "; + delimiters.afterColumn = " "; + delimiters.afterRow= "|\n"; + delimiters.beforeHeaderColumn= "^ "; + delimiters.afterHeaderColumn= " "; + delimiters.afterHeaderRow= "^\n"; + delimiters.beforeHeading= "=== "; + delimiters.afterHeading= " ===\n"; + + break; + case eLaTeXFolder: + + StringBuffer buf = new StringBuffer(); + buf.append("\\begin{center}\n\\begin{tabular}{ |"); + for(int i = 0; i < nodeTable.optimizeCols(); i++){ + buf.append(" l | "); + } + buf.append(" }\\hline\n"); + + delimiters.beforeTable = buf.toString(); + delimiters.afterTable = "\\end{tabular}\n\\end{center}\n"; + + delimiters.betweenColumns = " & "; + delimiters.afterRow= " \\\\ \\hline\n"; + + delimiters.afterHeaderRow= " \\\\ \\hline\n"; + delimiters.betweenHeaderColumns= " & "; + + delimiters.beforeHeading= "\\multicolumn{" + nodeTable.optimizeCols() + "}{|c|}{"; + delimiters.afterHeading= "} \\\\ \\hline\n"; + + break; + } + + + replacements.put("nodeTable", nodeTable.toString("Nodes", delimiters)); + + //Set table delimiters + switch (settings.getFormat()){ + + case eLaTeXFolder: + + StringBuffer buf = new StringBuffer(); + buf.append("\\begin{center}\n\\begin{tabular}{ |"); + for(int i = 0; i < linkTable.optimizeCols(); i++){ + buf.append(" l | "); + } + buf.append(" }\\hline\n"); + + delimiters.beforeTable = buf.toString(); + + delimiters.beforeHeading= "\\multicolumn{" + linkTable.optimizeCols() + "}{|c|}{"; + delimiters.afterHeading= "} \\\\ \\hline\n"; + + break; + } + + replacements.put("linkTable", linkTable.toString("Links", delimiters)); + replacements.put("title", diagram.getName()); //This was used to give SVG image to renderer diff --git a/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/DokuWikiRenderer.java b/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/LaTeXRenderer.java similarity index 67% copy from Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/DokuWikiRenderer.java copy to Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/LaTeXRenderer.java index 5ef4713..aa2a66e 100644 --- a/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/DokuWikiRenderer.java +++ b/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/LaTeXRenderer.java @@ -12,30 +12,29 @@ import java.util.Map; * Created by IntelliJ IDEA. * User: Rusty Horse * Date: 30.11.2010 - * Time: 23:38:31 + * Time: 23:40:29 * - * - * This is descendant of @see Renderer which provides output to text file of a DokuWiki - * http://www.dokuwiki.org/dokuwiki notation. The PNG image included by the page is saved in same same location. - * Note that you need to change path to the image in output file after uploading it to a webserver. This rendere uses - * the "DokuWikiTemplate.txt" template stored in "resources/templates". The macro meta-chars are the curly brackets {}. + * This is descendant of @see Renderer which provides output to LaTeX file. The PNG image included by the page is saved + * in same same location. This rendere uses the "LaTeXTemplate.tex" template stored in "resources/templates". + * The macro meta-chars are the parentheses (). */ -public class DokuWikiRenderer extends Renderer{ - //file to render content +public class LaTeXRenderer extends Renderer{ + + //file to render content protected File file; protected File plot; - public DokuWikiRenderer(final String path, final String name) { + public LaTeXRenderer(final String path, final String name) { super(path, name); - file = new File(path + name + ".txt"); + file = new File(path + name + ".tex"); plot = new File(path + name + ".png"); } @Override public void render(Map replacements, final BufferedImage image) throws IOException { //Get template - String template = getResourceFileAsString("/templates/DokuWikiTemplate.txt"); + String template = getResourceFileAsString("/templates/LaTeXTemplate.tex"); //Add system replacements Map myReplacements = new Hashtable(replacements); @@ -46,7 +45,7 @@ public class DokuWikiRenderer extends Renderer{ file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); - fos.write(executeReplacements(template, myReplacements).getBytes("UTF-8")); + fos.write(executeReplacements(template, myReplacements, '(', ')').getBytes("UTF-8")); fos.flush(); fos.close(); @@ -65,6 +64,6 @@ public class DokuWikiRenderer extends Renderer{ @Override public boolean isColliding() { - return file.exists(); + return file.exists() || plot.exists(); } } diff --git a/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/Table.java b/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/Table.java index 2c6a08e..3d7e95b 100644 --- a/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/Table.java +++ b/Plugins/EPC/ModuleEPC2XHTMLExport/src/cz/cvut/promod/EPC2XHTMLExport/engine/Table.java @@ -71,6 +71,11 @@ public class Table { public String toString(String heading, TableDelimiters del){ + //delete empty columns and if is none left, return + if(optimizeCols() == 0){ + return ""; + } + StringBuffer buf = new StringBuffer(); buf.append(del.beforeTable); @@ -79,16 +84,13 @@ public class Table { buf.append(heading); buf.append(del.afterHeading); - //delete empty columns andge - optimizeCols(); - //write headers buf.append(del.beforeHeaderRow); - for(int j = 0; j < colunms.size();j++){ + for(int j = 0; j < colunms.size() ;j++){ buf.append(del.beforeHeaderColumn); buf.append(colunms.get(j).header); buf.append(del.afterHeaderColumn); - if(j + 1 < colunms.get(0).values.size()){ + if(j + 1 < colunms.size()){ buf.append(del.betweenHeaderColumns); } } @@ -101,7 +103,7 @@ public class Table { buf.append(del.beforeColumn); buf.append(colunms.get(j).values.get(i)); buf.append(del.afterColumn); - if(j + 1 < colunms.get(0).values.size()){ + if(j + 1 < colunms.size()){ buf.append(del.betweenColumns); } } -- 2.11.4.GIT