forked from Gaming32/ArrayV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSortPrompt_old.java
270 lines (227 loc) · 10.5 KB
/
SortPrompt_old.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package prompts;
import java.io.File;
import javax.swing.JFrame;
import dialogs.ImportSortDialog;
import frames.AppFrame;
import frames.UtilFrame;
import main.ArrayVisualizer;
import main.SortAnalyzer;
import main.SortAnalyzer.SortPair;
import panes.JErrorPane;
import threads.RunAllSorts;
import threads.RunComparisonSort;
import threads.RunDistributionSort;
/*
*
MIT License
Copyright (c) 2019 w0rthy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*
*/
/**
*
* @author S630690
*/
final public class SortPrompt extends javax.swing.JFrame implements AppFrame {
private static final long serialVersionUID = 1L;
private int[] array;
private ArrayVisualizer ArrayVisualizer;
private JFrame Frame;
private UtilFrame UtilFrame;
@SuppressWarnings("unchecked")
public SortPrompt(int[] array, ArrayVisualizer arrayVisualizer, JFrame frame, UtilFrame utilFrame) {
this.array = array;
this.ArrayVisualizer = arrayVisualizer;
this.Frame = frame;
this.UtilFrame = utilFrame;
setAlwaysOnTop(true);
setUndecorated(true);
initComponents();
jList2.setListData(SortPair.getListNames(ArrayVisualizer.getComparisonSorts()));
jList1.setListData(SortPair.getListNames(ArrayVisualizer.getDistributionSorts()));
reposition();
setVisible(true);
}
@Override
public void reposition() {
setLocation(Frame.getX()+(Frame.getWidth()-getWidth())/2,Frame.getY()+(Frame.getHeight()-getHeight())/2);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
this.jLabel1 = new javax.swing.JLabel();
this.jLabel2 = new javax.swing.JLabel();
this.jScrollPane1 = new javax.swing.JScrollPane();
this.jList2 = new javax.swing.JList();
this.jScrollPane2 = new javax.swing.JScrollPane();
this.jList1 = new javax.swing.JList();
this.jButton1 = new javax.swing.JButton();
this.jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Comparative");
jLabel2.setText("Distributive");
jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jList2.setModel(new javax.swing.AbstractListModel() {
private static final long serialVersionUID = 1L;
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
@Override
public int getSize() { return strings.length; }
@Override
public Object getElementAt(int i) { return strings[i]; }
});
jList2.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
@Override
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
jList2ValueChanged(evt);
}
});
jScrollPane1.setViewportView(this.jList2);
jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jList1.setModel(new javax.swing.AbstractListModel() {
private static final long serialVersionUID = 1L;
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
@Override
public int getSize() { return strings.length; }
@Override
public Object getElementAt(int i) { return strings[i]; }
});
jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
@Override
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
jList1ValueChanged(evt);
}
});
jScrollPane2.setViewportView(this.jList1);
jButton1.setText("Run All (approx. 30-90 minutes)");
jButton1.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed();
}
});
jButton2.setText("Import Sort");
jButton2.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed();
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(this.jLabel1)
.addGap(76, 76, 76)
.addComponent(this.jLabel2)
.addGap(35, 35, 35))
.addGroup(layout.createSequentialGroup()
.addComponent(this.jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(this.jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.CENTER, layout.createSequentialGroup()
.addComponent(this.jButton1))
.addGroup(javax.swing.GroupLayout.Alignment.CENTER, layout.createSequentialGroup()
.addComponent(this.jButton2))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(this.jLabel1)
.addComponent(this.jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(this.jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
.addComponent(this.jScrollPane1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(this.jButton1)
.addGap(5, 5, 5)
.addComponent(this.jButton2)
.addGap(0, 0, 0))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed() {//GEN-FIRST:event_jButton1ActionPerformed
new Thread(){
@Override
public void run(){
RunAllSorts RunAllSorts = new RunAllSorts(ArrayVisualizer);
RunAllSorts.reportAllSorts(array);
}
}.start();
UtilFrame.jButton1ResetText();
dispose();
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed() {//GEN-FIRST:event_jButton1ActionPerformed
new Thread(){
@Override
public void run(){
File f = new ImportSortDialog().getFile();
if (f == null) {
return;
}
ArrayVisualizer.getSortAnalyzer().importSort(f);
}
}.start();
UtilFrame.jButton1ResetText();
dispose();
}//GEN-LAST:event_jButton1ActionPerformed
private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
// TODO add your handling code here:
final int selection = evt.getFirstIndex();
new Thread(){
@Override
public void run(){
RunDistributionSort sortThread = new RunDistributionSort(ArrayVisualizer);
sortThread.ReportDistributionSort(array, selection);
}
}.start();
UtilFrame.jButton1ResetText();
dispose();
}//GEN-LAST:event_jList1ValueChanged
private void jList2ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList2ValueChanged
// TODO add your handling code here:
final int selection = evt.getFirstIndex();
new Thread(){
@Override
public void run() {
RunComparisonSort sortThread = new RunComparisonSort(ArrayVisualizer);
sortThread.ReportComparativeSort(array, selection);
}
}.start();
UtilFrame.jButton1ResetText();
dispose();
}//GEN-LAST:event_jList2ValueChanged
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
@SuppressWarnings("rawtypes")
private javax.swing.JList jList1;
@SuppressWarnings("rawtypes")
private javax.swing.JList jList2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
// End of variables declaration//GEN-END:variables
}