Skip to content

Commit c59e354

Browse files
committed
Add scale logic to UI
1 parent 610e83f commit c59e354

File tree

7 files changed

+408
-395
lines changed

7 files changed

+408
-395
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
<plugin>
122122
<groupId>com.akathist.maven.plugins.launch4j</groupId>
123123
<artifactId>launch4j-maven-plugin</artifactId>
124-
<version>1.7.21</version>
124+
<version>1.7.24</version>
125125
<executions>
126126
<execution>
127127
<id>l4j-clui</id>

sorting-algorithms.iml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,5 @@
1818
<orderEntry type="library" name="Maven: com.jhlabs:filters:2.0.235" level="project" />
1919
<orderEntry type="library" name="Maven: org.swinglabs:swing-worker:1.1" level="project" />
2020
<orderEntry type="library" name="Maven: org.abego.treelayout:org.abego.treelayout.core:1.0.3" level="project" />
21-
<orderEntry type="library" name="Maven: org.scilab.forge:jlatexmath:1.0.7" level="project" />
22-
<orderEntry type="library" name="Maven: org.scilab.forge:jlatexmath-font-greek:1.0.7" level="project" />
23-
<orderEntry type="library" name="Maven: org.scilab.forge:jlatexmath-font-cyrillic:1.0.7" level="project" />
24-
<orderEntry type="library" name="Maven: org.swinglabs:swingx:1.6.1" level="project" />
25-
<orderEntry type="library" name="Maven: com.jhlabs:filters:2.0.235" level="project" />
26-
<orderEntry type="library" name="Maven: org.swinglabs:swing-worker:1.1" level="project" />
27-
<orderEntry type="library" name="Maven: org.abego.treelayout:org.abego.treelayout.core:1.0.3" level="project" />
2821
</component>
2922
</module>

src/main/java/de/moritzf/sorting/gui/components/HeapSortProtocolPane.java

Lines changed: 80 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -15,79 +15,85 @@
1515
*/
1616
public class HeapSortProtocolPane extends JPanel implements ResizableComponent {
1717

18-
private HeapSort algorithm;
19-
private JPanel protocolPanel;
20-
21-
/**
22-
* Instantiates a new Heap sort protocol pane.
23-
*
24-
* @param heapSort the heap sort
25-
*/
26-
public HeapSortProtocolPane(HeapSort heapSort) {
27-
28-
this.setLayout(new BorderLayout());
29-
protocolPanel = new JPanel();
30-
this.setBackground(Color.white);
31-
protocolPanel.setBackground(Color.white);
32-
protocolPanel.setLayout(new BoxLayout(protocolPanel, BoxLayout.Y_AXIS));
33-
34-
this.add(protocolPanel, BorderLayout.NORTH);
35-
this.algorithm = heapSort;
36-
this.generateProtocol();
37-
}
38-
39-
@Override
40-
public void resetScale() {}
41-
42-
@Override
43-
public void increaseScale() {}
44-
45-
@Override
46-
public void decreaseScale() {}
47-
48-
private void addToProtocol(Component comp) {
49-
JPanel pushLeft = new JPanel();
50-
pushLeft.setBackground(Color.white);
51-
pushLeft.setLayout(new BorderLayout());
52-
pushLeft.add(comp, BorderLayout.WEST);
53-
protocolPanel.add(pushLeft);
54-
}
55-
56-
/** Generate protocol. */
57-
public void generateProtocol() {
58-
protocolPanel.removeAll();
59-
60-
for (int i = 0; i < this.algorithm.getProtocol().size(); i++) {
61-
HeapStep step = this.algorithm.getProtocol().get(i);
62-
63-
if (i == 0) {
64-
String heapType = "Maxheap";
65-
if (!algorithm.isMaxHeap()) {
66-
heapType = "Minheap";
18+
private HeapSort algorithm;
19+
private JPanel protocolPanel;
20+
private double scale = 1d;
21+
22+
/**
23+
* Instantiates a new Heap sort protocol pane.
24+
*
25+
* @param heapSort the heap sort
26+
*/
27+
public HeapSortProtocolPane(HeapSort heapSort) {
28+
29+
this.setLayout(new BorderLayout());
30+
protocolPanel = new JPanel();
31+
this.setBackground(Color.white);
32+
protocolPanel.setBackground(Color.white);
33+
protocolPanel.setLayout(new BoxLayout(protocolPanel, BoxLayout.Y_AXIS));
34+
35+
this.add(protocolPanel, BorderLayout.NORTH);
36+
this.algorithm = heapSort;
37+
this.generateProtocol();
38+
}
39+
40+
41+
private void addToProtocol(Component comp) {
42+
JPanel pushLeft = new JPanel();
43+
pushLeft.setBackground(Color.white);
44+
pushLeft.setLayout(new BorderLayout());
45+
pushLeft.add(comp, BorderLayout.WEST);
46+
protocolPanel.add(pushLeft);
47+
}
48+
49+
/**
50+
* Generate protocol.
51+
*/
52+
public void generateProtocol() {
53+
protocolPanel.removeAll();
54+
55+
for (int i = 0; i < this.algorithm.getProtocol().size(); i++) {
56+
HeapStep step = this.algorithm.getProtocol().get(i);
57+
58+
if (i == 0) {
59+
String heapType = "Maxheap";
60+
if (!algorithm.isMaxHeap()) {
61+
heapType = "Minheap";
62+
}
63+
addToProtocol(
64+
new LatexPanel("\\huge{\\text{\\underline{Heap Creation (" + heapType + ")}}} ", scale));
65+
addToProtocol(new LatexPanel("\\text{original binary tree}", scale));
66+
}
67+
if (i == 1) {
68+
addToProtocol(new LatexPanel("\\text{\\rhd \\lhd: heapified element} ", scale));
69+
}
70+
71+
if (step.getCurrentNode() == -1) {
72+
addToProtocol(new LatexPanel("\\huge{\\text{\\underline{Sorting}}} ", scale));
73+
}
74+
75+
if (step.getSortedNumbers().size() > 0) {
76+
String listAsString = Arrays.toString(step.getSortedNumbers().toArray());
77+
addToProtocol(new LatexPanel("sorted\\, array: " + listAsString, scale));
78+
}
79+
80+
if (step.getRootNode() != null) {
81+
addToProtocol(new TreeNodePane(step.getRootNode(), scale));
82+
addToProtocol(new LatexPanel("..................................", scale));
83+
} else {
84+
addToProtocol(new LatexPanel("\\text{finished sorting!} ", scale));
85+
}
6786
}
68-
addToProtocol(
69-
new LatexPanel("\\huge{\\text{\\underline{Heap Creation (" + heapType + ")}}} "));
70-
addToProtocol(new LatexPanel("\\text{original binary tree}"));
71-
}
72-
if (i == 1) {
73-
addToProtocol(new LatexPanel("\\text{\\rhd \\lhd: heapified element} "));
74-
}
75-
76-
if (step.getCurrentNode() == -1) {
77-
addToProtocol(new LatexPanel("\\huge{\\text{\\underline{Sorting}}} "));
78-
}
79-
80-
if (step.getSortedNumbers().size() > 0) {
81-
String listAsString = Arrays.toString(step.getSortedNumbers().toArray());
82-
addToProtocol(new LatexPanel("sorted\\, array: " + listAsString));
83-
}
84-
85-
if (step.getRootNode() != null) {
86-
addToProtocol(new TreeNodePane(step.getRootNode()));
87-
addToProtocol(new LatexPanel(".................................."));
88-
} else {
89-
addToProtocol(new LatexPanel("\\text{finished sorting!} "));
90-
}
9187
}
92-
}
93-
}
88+
89+
@Override
90+
public void setScale(double scale) {
91+
this.scale = scale;
92+
this.generateProtocol();
93+
}
94+
95+
@Override
96+
public double getScale() {
97+
return this.scale;
98+
}
99+
}

0 commit comments

Comments
 (0)