15
15
*/
16
16
public class HeapSortProtocolPane extends JPanel implements ResizableComponent {
17
17
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
+ }
67
86
}
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
- }
91
87
}
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