Skip to content

Commit 3783682

Browse files
committed
Fixed export of LaTeX-Protocol, Fixed build process for newer Java-versions
1 parent 4f0d7b5 commit 3783682

File tree

5 files changed

+96
-9
lines changed

5 files changed

+96
-9
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.github.moritzfl</groupId>
55
<artifactId>sortingalgorithms</artifactId>
6-
<version>1.4.1</version>
6+
<version>1.4.2</version>
77
<name>sortingalgorithms</name>
88
<prerequisites>
99
<maven>3</maven>
@@ -91,7 +91,7 @@
9191
<plugin>
9292
<groupId>com.akathist.maven.plugins.launch4j</groupId>
9393
<artifactId>launch4j-maven-plugin</artifactId>
94-
<version>1.7.24</version>
94+
<version>2.1.2</version>
9595
<executions>
9696
<execution>
9797
<id>l4j-clui</id>
@@ -115,7 +115,7 @@
115115
<fileVersion>${project.version}.0</fileVersion>
116116
<txtFileVersion>${project.version}</txtFileVersion>
117117
<fileDescription>${project.name}</fileDescription>
118-
<copyright>2015-2017 Moritz Flöter</copyright>
118+
<copyright>2015-2022 Moritz Flöter</copyright>
119119
<productVersion>${project.version}.0</productVersion>
120120
<txtProductVersion>${project.version}.0</txtProductVersion>
121121
<productName>${project.name}</productName>

src/main/java/de/moritzf/sorting/gui/util/SaveFileUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
public class SaveFileUtil {
1818

19-
private static String TEMPLATE_FILE = "export-template.txt";
19+
private static String TEMPLATE_FILE = "/de/moritzf/sorting/io/export-template.txt";
2020

2121
/**
2222
* Saves the String passed to it as LaTeX document

src/main/java/de/moritzf/sorting/logic/sorting/algorithms/HeapSort.java

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,98 @@ public int getInputSize() {
157157
public void reset() {
158158
}
159159

160-
@Override
160+
/**
161+
* Renders the protocol to LaTeX-code.
162+
*
163+
* @return the string
164+
*/
161165
public String protocol2LaTeX() {
162-
return null;
166+
String retString = "";
167+
for (int i = 0; i < protocol.size(); i++) {
168+
retString += " " + this.step2LaTeX(i) + "\n \n";
169+
}
170+
return retString;
171+
}
172+
173+
/**
174+
* Generates a LaTeX-Expression representing one step. This is used for
175+
* export only as JLaTeX-Math does not allow the use of tikz. The GUI uses
176+
* HeapSortPanelExtended as replacement (which uses BinaryTreePanel to
177+
* render the binary tree)
178+
*
179+
* @param chosenStepNumber the chosen step number
180+
* @return the string
181+
*/
182+
public String step2LaTeX(int chosenStepNumber) {
183+
HeapStep chosenStep = this.protocol.get(chosenStepNumber);
184+
String retString = "";
185+
if (chosenStepNumber == 0) {
186+
retString += "\\underline{\\textbf{Heap Creation}}\n\n original binary tree \n\n";
187+
} else if (chosenStepNumber == 1) {
188+
retString += "$\\rhd number\\lhd$ := element that is to be heapified \n\n";
189+
}
190+
191+
final TreeNode<HeapSortNodeValue> renderingTarget = chosenStep.getRootNode();
192+
193+
/*
194+
* Generate elements for the part of the protocol where values get
195+
* removed from the Heap and inserted into the Array
196+
*/
197+
if (chosenStep.getCurrentNode() < 1) {
198+
if (chosenStep.getCurrentNode() == 0) {
199+
retString += "\\underline{\\textbf{Sorting}}\n\n";
200+
}
201+
retString += "sorted array : [";
202+
for (int i = 0; i < chosenStep.getSortedNumbers().size(); i++) {
203+
retString += Integer.toString(chosenStep.getSortedNumbers().get(i));
204+
if (i < chosenStep.getSortedNumbers().size() - 1) {
205+
retString += ", ";
206+
}
207+
}
208+
retString += "]\n\n";
209+
}
210+
211+
212+
if (renderingTarget != null) {
213+
retString += "\\begin{tikzpicture}[very thick,level/.style={sibling distance=60mm/#1}]\n \\"
214+
+ generateLaTeXHeapNode(renderingTarget, chosenStep) + "; \n \\end{tikzpicture}";
215+
} else {
216+
retString += "$\\rightarrow finished \\, sorting$";
217+
}
218+
219+
retString += "\n\n ............................ \n\n";
220+
return retString;
221+
}
222+
223+
/**
224+
* Generate heap node. This generates a node of the binary tree as well as
225+
* all its children by recursively calling this function
226+
*
227+
* @param step the step
228+
* @return the string
229+
*/
230+
private String generateLaTeXHeapNode(TreeNode<HeapSortNodeValue> renderingTarget, HeapStep step) {
231+
String retString = "node [vertex]";
232+
String[] parts = renderingTarget.toString().split("%begin-above-node");
233+
if (parts.length > 1) {
234+
retString += "[label={\\small $" + parts[1].replace("st", "cancel") + "$}] ";
235+
}
236+
retString += "{$" + parts[0].replace("st", "cancel") + "$}";
237+
238+
if (!renderingTarget.getChildren().isEmpty()) {
239+
List<TreeNode<HeapSortNodeValue>> children = renderingTarget.getChildren();
240+
retString += "child{" + generateLaTeXHeapNode(children.get(0), step) + "}";
241+
if (children.size() > 1) {
242+
retString += "\nchild{" + generateLaTeXHeapNode(children.get(1), step) + "}";
243+
} else {
244+
retString += "child[missing]{}";
245+
}
246+
247+
}
248+
return retString;
163249
}
164250

251+
165252
@Override
166253
public boolean undoStep() {
167254
return false;

src/main/resources/de/moritzf/sorting/gui/windows/about-copyright.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
-----------------------------------------------------------------------------
1111
This program is licensed under the terms of the GPL.
1212

13-
Copyright (C) 2015 - 2019 Moritz Floeter
13+
Copyright (C) 2015 - 2022 Moritz Floeter
1414

1515
This program is free software: you can redistribute it and/or modify
1616
it under the terms of the GNU General Public License as published by
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
\text{\textit{Sorting Algorithms V 1.4.1}} \\
2-
\scriptsize \text{© 2015-2019 by Moritz Fl\ddot{o}ter}
1+
\text{\textit{Sorting Algorithms V 1.4.2}} \\
2+
\scriptsize \text{© 2015-2022 by Moritz Fl\ddot{o}ter}

0 commit comments

Comments
 (0)