forked from setmind/SACDExtractGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuiControl.java
918 lines (826 loc) · 33.9 KB
/
GuiControl.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.io.File;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.InetSocketAddress;
import java.net.InetAddress;
import java.awt.FileDialog;
import java.io.FilenameFilter;
public class GuiControl implements ExecThread.Callback{
private JFrame frame;
private ProgramPanel programPanel;
private InputPanel inputPanel;
private ProcessingPanel processingPanel;
private OutputPanel outputPanel;
private String inputDirectory = null;
private CheckBoxState checkBoxState_unselected_disabled = new CheckBoxState(false, false);
private CheckBoxState checkBoxState_unselected_enabled = new CheckBoxState(false, true);
private CheckBoxState checkBoxState_selected_disabled = new CheckBoxState(true, false);
private CheckBoxState checkBoxState_selected_enabled = new CheckBoxState(true, true);
ExecThread execThread;
private void ExecButtonSetEnabled(boolean e){
inputPanel.setEnabledButtonPing(e);
inputPanel.setEnabledButtonTest(e);
outputPanel.setEnabledButtonRun(e);
outputPanel.setEnabledButtonStop(!e);
outputPanel.setEnabledButtonClear(e);
}
public void processExit(boolean s){
outputPanel.freshLineTextArea();
if(s){
printLog("[DONE]");
outputPanel.appendTextArea("\n");
}
ExecButtonSetEnabled(true);
}
public void printLog(String s){
if(s.contains("Completed:") || s.contains("Processing ")){
outputPanel.replacePrevLineTextArea(s);
}
else{
outputPanel.appendTextArea(s + "\n");
}
}
public void printStatus(String s){
outputPanel.setTextLabelStatus(s);
}
public void buttonClear(){
outputPanel.clearTextAreaLog();
outputPanel.setTextLabelStatus("");
}
public void buttonBrowseProgram(){
if(OSDetect.isMac()){
buttonBrowseProgramFD();
}
else{
// On Ubuntu, FileDialog is extremely slow on a NAS with many ISO files.
buttonBrowseProgramJFC();
}
}
public void buttonBrowseProgramJFC(){
int ret;
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Select a sacd_extract program");
fileChooser.setApproveButtonText("Add");
ret = fileChooser.showOpenDialog(frame);
if(ret == JFileChooser.APPROVE_OPTION){
programPanel.setTextTextFieldProgram(fileChooser.getSelectedFile().getPath());
}
}
public void buttonBrowseProgramFD(){
File files[];
FileDialog fileDialog = new FileDialog(frame, "Select a sacd_extract program", FileDialog.LOAD);
fileDialog.setMultipleMode(false);
fileDialog.setVisible(true);
files = fileDialog.getFiles();
if(files.length > 0){
for(File file : files){
programPanel.setTextTextFieldProgram(file.getPath());
}
}
}
public void setInputDirectory(String s){
inputDirectory = s;
}
public String getInputDirectory(){
return inputDirectory;
}
public void buttonBrowseFile(){
if(OSDetect.isMac()){
buttonBrowseFileFD();
}
else{
// On Ubuntu, FileDialog is extremely slow on a NAS with many ISO files.
buttonBrowseFileJFC();
}
}
public void buttonBrowseFileJFC(){
int ret;
JFileChooser fileChooser = new JFileChooser();
FileFilter fileFilter = new FileNameExtensionFilter("ISO file", "iso");
fileChooser.addChoosableFileFilter(fileFilter);
fileChooser.setFileFilter(fileFilter);
fileChooser.setDialogTitle("Select an ISO file");
fileChooser.setApproveButtonText("Add");
if(inputDirectory != null){
fileChooser.setCurrentDirectory(new File(inputDirectory));
}
ret = fileChooser.showOpenDialog(frame);
if(ret == JFileChooser.APPROVE_OPTION){
inputPanel.setTextTextFieldPath(fileChooser.getSelectedFile().getPath());
setInputDirectory(fileChooser.getCurrentDirectory().toString());
}
}
public void buttonBrowseFileFD(){
File files[];
FileDialog fileDialog = new FileDialog(frame, "Select an ISO file", FileDialog.LOAD);
fileDialog.setMultipleMode(false);
if(inputDirectory != null){
fileDialog.setDirectory(inputDirectory);
}
fileDialog.setFilenameFilter(new FilenameFilter (){
public boolean accept(File f, String name){
return name.toLowerCase().endsWith(".iso");
}
});
fileDialog.setVisible(true);
files = fileDialog.getFiles();
if(files.length > 0){
for(File file : files){
inputPanel.setTextTextFieldPath(file.getPath());
}
setInputDirectory(fileDialog.getDirectory());
}
}
public void buttonAdd(){
if(OSDetect.isMac()){
buttonAddFD();
}
else{
// On Ubuntu, FileDialog is extremely slow on a NAS with many ISO files.
buttonAddJFC();
}
}
public void buttonAddJFC(){
int ret;
JFileChooser fileChooser = new JFileChooser();
FileFilter fileFilter = new FileNameExtensionFilter("ISO file", "iso");
fileChooser.addChoosableFileFilter(fileFilter);
fileChooser.setFileFilter(fileFilter);
fileChooser.setDialogTitle("Select ISO files");
fileChooser.setApproveButtonText("Add");
fileChooser.setMultiSelectionEnabled(true);
if(inputDirectory != null){
fileChooser.setCurrentDirectory(new File(inputDirectory));
}
ret = fileChooser.showOpenDialog(frame);
if(ret == JFileChooser.APPROVE_OPTION){
for(File f : fileChooser.getSelectedFiles()){
inputPanel.addFile(f.getPath());
}
setInputDirectory(fileChooser.getCurrentDirectory().toString());
}
}
public void buttonAddFD(){
File files[];
FileDialog fileDialog = new FileDialog(frame, "Select ISO files", FileDialog.LOAD);
fileDialog.setMultipleMode(true);
if(inputDirectory != null){
fileDialog.setDirectory(inputDirectory);
}
fileDialog.setFilenameFilter(new FilenameFilter (){
public boolean accept(File f, String name){
return name.toLowerCase().endsWith(".iso");
}
});
fileDialog.setVisible(true);
files = fileDialog.getFiles();
if(files.length > 0){
for(File file : files){
inputPanel.addFile(file.getPath());
}
setInputDirectory(fileDialog.getDirectory());
}
}
public void buttonOutput1(){
int ret;
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Select a directory");
fileChooser.setApproveButtonText("Add");
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
ret = fileChooser.showOpenDialog(frame);
if(ret == JFileChooser.APPROVE_OPTION){
outputPanel.setTextTextFieldOutput1(fileChooser.getSelectedFile().getPath());
}
}
public void buttonOutput2(){
int ret;
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Select a directory");
fileChooser.setApproveButtonText("Add");
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
ret = fileChooser.showOpenDialog(frame);
if(ret == JFileChooser.APPROVE_OPTION){
outputPanel.setTextTextFieldOutput2(fileChooser.getSelectedFile().getPath());
}
}
public void setFrame(JFrame f){
frame = f;
}
public void setProgramPanel(ProgramPanel p){
programPanel = p;
}
public void setInputPanel(InputPanel p){
inputPanel = p;
}
public void setProcessingPanel(ProcessingPanel p){
processingPanel = p;
}
public void setOutputPanel(OutputPanel p){
outputPanel = p;
}
public void textFieldAddress0(String s){
int i;
try{
i = Integer.parseInt(s);
if(i <= 0 || i > 255){
inputPanel.setTextTextFieldAddress0("", true);
}
else{
inputPanel.setTextTextFieldAddress0(null, false);
}
}
catch(NumberFormatException e){
inputPanel.setTextTextFieldAddress0("", true);
}
}
public void textFieldAddress1(String s){
int i;
try{
i = Integer.parseInt(s);
if(i < 0 || i > 255){
inputPanel.setTextTextFieldAddress1("", true);
}
else{
inputPanel.setTextTextFieldAddress1(null, false);
}
}
catch(NumberFormatException e){
inputPanel.setTextTextFieldAddress1("", true);
}
}
public void textFieldAddress2(String s){
int i;
try{
i = Integer.parseInt(s);
if(i < 0 || i > 255){
inputPanel.setTextTextFieldAddress2("", true);
}
else{
inputPanel.setTextTextFieldAddress2(null, false);
}
}
catch(NumberFormatException e){
inputPanel.setTextTextFieldAddress2("", true);
}
}
public void textFieldAddress3(String s){
int i;
try{
i = Integer.parseInt(s);
if(i <= 0 || i > 255){
inputPanel.setTextTextFieldAddress3("", true);
}
else{
inputPanel.setTextTextFieldAddress3(null, false);
}
}
catch(NumberFormatException e){
inputPanel.setTextTextFieldAddress3("", true);
}
}
public void textFieldAddressPort(String s){
int i;
try{
i = Integer.parseInt(s);
if(i <= 0 || i > 65535){
inputPanel.setTextTextFieldAddressPort("", true);
}
else{
inputPanel.setTextTextFieldAddressPort(null, false);
}
}
catch(NumberFormatException e){
inputPanel.setTextTextFieldAddressPort("", true);
}
}
public void radButtonDSF(){
if(processingPanel.getOption(ProcessingPanel.OPTION_STEREO).enabled == false || processingPanel.getOption(ProcessingPanel.OPTION_MULTI).enabled == false){
processingPanel.setOption(ProcessingPanel.OPTION_STEREO, checkBoxState_selected_enabled);
processingPanel.setOption(ProcessingPanel.OPTION_MULTI, checkBoxState_unselected_enabled);
}
processingPanel.setOption(ProcessingPanel.OPTION_DECOMPRESS, checkBoxState_selected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_SELECTTRACKS, checkBoxState_unselected_enabled);
processingPanel.setEnabledTextFieldTracks(false);
processingPanel.setOption(ProcessingPanel.OPTION_NOPAD, checkBoxState_unselected_enabled);
processingPanel.setOption(ProcessingPanel.OPTION_CUE, checkBoxState_unselected_enabled);
outputPanel.setEnabledOutput1(true, "Output directory ");
outputPanel.setEnabledOutput2(false, "");
}
public void radButtonDSDIFF(){
if(processingPanel.getOption(ProcessingPanel.OPTION_STEREO).enabled == false || processingPanel.getOption(ProcessingPanel.OPTION_MULTI).enabled == false){
processingPanel.setOption(ProcessingPanel.OPTION_STEREO, checkBoxState_selected_enabled);
processingPanel.setOption(ProcessingPanel.OPTION_MULTI, checkBoxState_unselected_enabled);
}
if(processingPanel.getOption(ProcessingPanel.OPTION_DECOMPRESS).selected){
processingPanel.setOption(ProcessingPanel.OPTION_DECOMPRESS, checkBoxState_selected_enabled);
}
else{
processingPanel.setOption(ProcessingPanel.OPTION_DECOMPRESS, checkBoxState_unselected_enabled);
}
processingPanel.setOption(ProcessingPanel.OPTION_SELECTTRACKS, checkBoxState_unselected_enabled);
processingPanel.setEnabledTextFieldTracks(false);
processingPanel.setOption(ProcessingPanel.OPTION_NOPAD, checkBoxState_unselected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_CUE, checkBoxState_unselected_enabled);
outputPanel.setEnabledOutput1(true, "Output directory ");
outputPanel.setEnabledOutput2(false, "");
}
public void radButtonDSDIFFEM(){
if(processingPanel.getOption(ProcessingPanel.OPTION_STEREO).enabled == false || processingPanel.getOption(ProcessingPanel.OPTION_MULTI).enabled == false){
processingPanel.setOption(ProcessingPanel.OPTION_STEREO, checkBoxState_selected_enabled);
processingPanel.setOption(ProcessingPanel.OPTION_MULTI, checkBoxState_unselected_enabled);
}
if(processingPanel.getOption(ProcessingPanel.OPTION_DECOMPRESS).selected){
processingPanel.setOption(ProcessingPanel.OPTION_DECOMPRESS, checkBoxState_selected_enabled);
}
else{
processingPanel.setOption(ProcessingPanel.OPTION_DECOMPRESS, checkBoxState_unselected_enabled);
}
processingPanel.setOption(ProcessingPanel.OPTION_SELECTTRACKS, checkBoxState_unselected_disabled);
processingPanel.setEnabledTextFieldTracks(false);
processingPanel.setOption(ProcessingPanel.OPTION_NOPAD, checkBoxState_unselected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_CUE, checkBoxState_selected_disabled);
outputPanel.setEnabledOutput1(true, "Output directory ");
outputPanel.setEnabledOutput2(false, "");
}
public void radButtonISO(){
processingPanel.setOption(ProcessingPanel.OPTION_STEREO, checkBoxState_unselected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_MULTI, checkBoxState_unselected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_DECOMPRESS, checkBoxState_unselected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_SELECTTRACKS, checkBoxState_unselected_disabled);
processingPanel.setEnabledTextFieldTracks(false);
processingPanel.setOption(ProcessingPanel.OPTION_NOPAD, checkBoxState_unselected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_CUE, checkBoxState_unselected_enabled);
outputPanel.setEnabledOutput1(true, "Output directory ");
outputPanel.setEnabledOutput2(false, "");
}
public void radButtonISO_DSF(){
if(processingPanel.getOption(ProcessingPanel.OPTION_STEREO).enabled == false || processingPanel.getOption(ProcessingPanel.OPTION_MULTI).enabled == false){
processingPanel.setOption(ProcessingPanel.OPTION_STEREO, checkBoxState_selected_enabled);
processingPanel.setOption(ProcessingPanel.OPTION_MULTI, checkBoxState_unselected_enabled);
}
processingPanel.setOption(ProcessingPanel.OPTION_DECOMPRESS, checkBoxState_selected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_SELECTTRACKS, checkBoxState_unselected_enabled);
processingPanel.setEnabledTextFieldTracks(false);
processingPanel.setOption(ProcessingPanel.OPTION_NOPAD, checkBoxState_unselected_enabled);
processingPanel.setOption(ProcessingPanel.OPTION_CUE, checkBoxState_unselected_enabled);
outputPanel.setEnabledOutput1(true, "ISO output directory ");
outputPanel.setEnabledOutput2(true, "DSF output directory ");
}
public void radButtonISO_DSDIFF(){
if(processingPanel.getOption(ProcessingPanel.OPTION_STEREO).enabled == false || processingPanel.getOption(ProcessingPanel.OPTION_MULTI).enabled == false){
processingPanel.setOption(ProcessingPanel.OPTION_STEREO, checkBoxState_selected_enabled);
processingPanel.setOption(ProcessingPanel.OPTION_MULTI, checkBoxState_unselected_enabled);
}
processingPanel.setOption(ProcessingPanel.OPTION_DECOMPRESS, checkBoxState_unselected_enabled);
processingPanel.setOption(ProcessingPanel.OPTION_SELECTTRACKS, checkBoxState_unselected_enabled);
processingPanel.setEnabledTextFieldTracks(false);
processingPanel.setOption(ProcessingPanel.OPTION_NOPAD, checkBoxState_unselected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_CUE, checkBoxState_unselected_enabled);
outputPanel.setEnabledOutput1(true, "ISO output directory ");
outputPanel.setEnabledOutput2(true, "DSDIFF output directory ");
}
public void radButtonNone(){
processingPanel.setOption(ProcessingPanel.OPTION_STEREO, checkBoxState_unselected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_MULTI, checkBoxState_unselected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_DECOMPRESS, checkBoxState_unselected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_SELECTTRACKS, checkBoxState_unselected_disabled);
processingPanel.setEnabledTextFieldTracks(false);
processingPanel.setOption(ProcessingPanel.OPTION_NOPAD, checkBoxState_unselected_disabled);
processingPanel.setOption(ProcessingPanel.OPTION_CUE, checkBoxState_unselected_enabled);
processingPanel.setOption(ProcessingPanel.OPTION_PRINT, checkBoxState_selected_enabled);
outputPanel.setEnabledOutput1(false, "Output directory ");
outputPanel.setEnabledOutput2(false, "");
}
public void checkBoxStereo(CheckBoxState s){
// Make sure stereo or multi is checked
if(s.selected == false){
processingPanel.setOption(ProcessingPanel.OPTION_MULTI, checkBoxState_selected_enabled);
}
}
public void checkBoxMulti(CheckBoxState s){
// Make sure stereo or multi is checked
if(s.selected == false){
processingPanel.setOption(ProcessingPanel.OPTION_STEREO, checkBoxState_selected_enabled);
}
}
public void checkBoxSelectTracks(CheckBoxState s){
if(s.selected){
processingPanel.setEnabledTextFieldTracks(true);
processingPanel.setOption(ProcessingPanel.OPTION_NOPAD, checkBoxState_unselected_disabled);
}
else{
processingPanel.setEnabledTextFieldTracks(false);
if(processingPanel.getRadButtonState(ProcessingPanel.PROCESS_DSF) || processingPanel.getRadButtonState(ProcessingPanel.PROCESS_ISO_DSF)){
processingPanel.setOption(ProcessingPanel.OPTION_NOPAD, checkBoxState_unselected_enabled);
}
}
}
public void checkBoxNoPad(CheckBoxState s){
if(s.selected){
processingPanel.setOption(ProcessingPanel.OPTION_SELECTTRACKS, checkBoxState_unselected_disabled);
processingPanel.setEnabledTextFieldTracks(false);
}
else{
processingPanel.setOption(ProcessingPanel.OPTION_SELECTTRACKS, checkBoxState_unselected_enabled);
}
}
public void checkBoxCue(CheckBoxState s){
if(processingPanel.getRadButtonState(ProcessingPanel.PROCESS_NONE)){
CheckBoxState checkBoxState_print = new CheckBoxState();
// Make sure stereo or multi is checked
if(s.selected == false){
processingPanel.setSelectedCheckBoxPrint(checkBoxState_selected_enabled);
}
outputPanel.setEnabledOutput1(s.selected, "Output directory");
}
}
public void checkBoxPrint(CheckBoxState s){
if(processingPanel.getRadButtonState(ProcessingPanel.PROCESS_NONE)){
if(s.selected == false){
processingPanel.setSelectedCheckBoxCue(checkBoxState_selected_enabled);
outputPanel.setEnabledOutput1(true, "Output directory");
}
}
}
public void radButton_server(){
inputPanel.setEnabledTextFieldsAddress(true);
inputPanel.setEnabledTextFieldPath(false);
inputPanel.setEnabledButtonBrowse(false);
inputPanel.setEnabledButtonPing(true);
inputPanel.setEnabledButtonTest(true);
inputPanel.setEnabledListFiles(false);
inputPanel.setEnabledButtonAdd(false);
inputPanel.setEnabledButtonRemove(false);
}
public void radButton_file(){
inputPanel.setEnabledTextFieldsAddress(false);
inputPanel.setEnabledTextFieldPath(true);
inputPanel.setEnabledButtonBrowse(true);
inputPanel.setEnabledButtonPing(false);
inputPanel.setEnabledButtonTest(false);
inputPanel.setEnabledListFiles(false);
inputPanel.setEnabledButtonAdd(false);
inputPanel.setEnabledButtonRemove(false);
}
public void radButton_files(){
inputPanel.setEnabledTextFieldsAddress(false);
inputPanel.setEnabledTextFieldPath(false);
inputPanel.setEnabledButtonBrowse(false);
inputPanel.setEnabledButtonPing(false);
inputPanel.setEnabledButtonTest(false);
inputPanel.setEnabledListFiles(true);
inputPanel.setEnabledButtonAdd(true);
inputPanel.setEnabledButtonRemove(true);
}
public void buttonAdd(DefaultListModel<String> l){
}
public void buttonRemove(int [] i){
inputPanel.removeFiles(i);
}
public void buttonProgramTest(){
doProgramTest(programPanel.getTextTextFieldProgram());
}
public void buttonRun(){
doRun();
}
public void buttonStop(){
doExecStop();
}
public void killExec(){
doExecStop();
}
public void checkBoxOutputdir1(boolean s){
outputPanel.setEnabledTextFieldOutput1(s);
outputPanel.setEnabledButtonOutput1(s);
}
public void checkBoxOutputdir2(boolean s){
outputPanel.setEnabledTextFieldOutput2(s);
outputPanel.setEnabledButtonOutput2(s);
}
public void buttonPing(){
doPing(getAddress());
}
public void buttonServerTest(){
String sAddress, sPort;
sAddress = getAddress();
sPort = getPort();
if(sAddress == null || sPort == null){
printLog(String.format("[ERROR] Incomplete server IP address or port."));
return;
}
doTest(sAddress, sPort);
}
private void doRun(){
execThread = new ExecThread(this);
String stringProgram = programPanel.getTextTextFieldProgram();
File fileProgram = new File(stringProgram);
CheckBoxState checkBoxState;
// Check the sacd_extract executable
if(!fileProgram.canExecute()){
printLog(String.format("[ERROR] %s doesn't exist or not executable.", stringProgram));
return;
}
// Check the input
if(inputPanel.getRadButtonStateFiles()){
ArrayList<String> files;
files = inputPanel.getFiles();
boolean go = true;
if(files.size() < 1){
printLog("[ERROR] Input file list is empty.");
return;
}
for(String s : files){
File f = new File(s);
if(!f.canRead()){
printLog(String.format("[ERROR] Input file \"%s\" doesn't exist or is not readable.", s));
go = false;
}
}
if(!go){
return;
}
}
if(inputPanel.getRadButtonStateFile()){
String stringFile = inputPanel.getTextTextFieldPath();
File file = new File(stringFile);
if(!file.canRead()){
printLog(String.format("[ERROR] Input file \"%s\" doesn't exist or is not readable.", stringFile));
return;
}
}
if(inputPanel.getRadButtonStateServer()){
if(getAddress() == null || getPort() == null){
printLog(String.format("[ERROR] Incomplete server IP address or port."));
return;
}
}
// Check the output directories
checkBoxState = outputPanel.getCheckBoxStateOutput1();
if(checkBoxState.enabled && checkBoxState.selected){
String fileString = outputPanel.getTextOutput1();
File f = new File(fileString);
if(!f.canWrite()){
printLog(String.format("[ERROR] Output directory \"%s\" doesn't exist or is not writable.", fileString));
return;
}
}
checkBoxState = outputPanel.getCheckBoxStateOutput2();
if(checkBoxState.enabled && checkBoxState.selected){
String fileString = outputPanel.getTextOutput2();
File f = new File(fileString);
if(!f.canWrite()){
printLog(String.format("[ERROR] Output directory \"%s\" doesn't exist or is not writable.", fileString));
return;
}
}
execThread.setTextArea(outputPanel.textArea);
ExecButtonSetEnabled(false);
execThread.setCommands(getCommands());
execThread.start();
}
private void doExecStop(){
if(execThread != null){
if(execThread.isAlive()){
execThread.requestStop();
try{
execThread.join();
}
catch(Exception e){
}
}
}
}
private void doProgramTest(String program){
execThread = new ExecThread(this);
ArrayList<String> cmd = new ArrayList<String>(Arrays.asList(program, "-v"));
String stringProgram = programPanel.getTextTextFieldProgram();
File fileProgram = new File(stringProgram);
// Check the sacd_extract executable
if(!fileProgram.canExecute()){
printLog(String.format("[ERROR] %s doesn't exist or not executable.", stringProgram));
return;
}
ExecButtonSetEnabled(false);
execThread.setCommand(cmd);
execThread.start();
}
private void doTest(String address, String port){
Socket socket;
SocketAddress sockaddr;
try{
socket = new Socket();
sockaddr = new InetSocketAddress(InetAddress.getByName(address), Integer.parseInt(port));
socket.connect(sockaddr, 1500);
socket.close();
printLog(String.format("[SUCCESS] Port %s of %s is accessible.", port, address));
}
catch(Exception e){
printLog(String.format("[FAILURE] Port %s of %s is inaccessible.", port, address));
}
}
private void doPing(String address){
execThread = new ExecThread(this);
ArrayList<String> cmd;
if(OSDetect.isWindows()){
cmd = new ArrayList<String>(Arrays.asList("ping", "-n", "3", "-w", "1", address));
}
else{
cmd = new ArrayList<String>(Arrays.asList("ping", "-c", "3", "-W", "1", address));
}
if(getAddress() == null){
printLog(String.format("[ERROR] Incomplete server IP address."));
return;
}
ExecButtonSetEnabled(false);
execThread.setCommand(cmd);
execThread.start();
}
private String getAddress(){
int i;
String stringAddress0 = inputPanel.getTextTextFieldAddress0();
String stringAddress1 = inputPanel.getTextTextFieldAddress1();
String stringAddress2 = inputPanel.getTextTextFieldAddress2();
String stringAddress3 = inputPanel.getTextTextFieldAddress3();
try{
i = Integer.parseInt(stringAddress0);
if(i <= 0 || i > 255){
return null;
}
i = Integer.parseInt(stringAddress1);
if(i < 0 || i > 255){
return null;
}
i = Integer.parseInt(stringAddress2);
if(i < 0 || i > 255){
return null;
}
i = Integer.parseInt(stringAddress3);
if(i <= 0 || i > 255){
return null;
}
}
catch(NumberFormatException e){
return null;
}
return stringAddress0 + "." + stringAddress1 + "." + stringAddress2 + "." + stringAddress3;
}
private String getPort(){
int i;
String stringPort = inputPanel.getTextTextFieldAddressPort();
try{
i = Integer.parseInt(stringPort);
if(i <= 0 || i > 65535){
return null;
}
}
catch(NumberFormatException e){
return null;
}
return stringPort;
}
private ArrayList<ArrayList<String>> getCommands(){
ArrayList<ArrayList<String>> cmds = new ArrayList<ArrayList<String>>();
if(inputPanel.getRadButtonStateFiles()){
// Multiple files
for(String s : inputPanel.getFiles()){
cmds.add(getCommand(s));
}
}
else{
// Single file or IP address
cmds.add(getCommand(null));
}
return cmds;
}
private ArrayList<String> getCommand(String extfile){
String addressPort;
String program;
String str;
ArrayList<String> cmd = new ArrayList<String>();
CheckBoxState checkBoxState;
boolean stereo, multi, decompress, selectTracks, nopad, cue, print;
int process = ProcessingPanel.PROCESS_NONE;
String inputFile;
boolean server, files;
String output1Text, output2Text;
boolean output1Enabled, output2Enabled;
program = programPanel.getTextTextFieldProgram();
addressPort = inputPanel.getTextTextFieldAddress0() + "." + inputPanel.getTextTextFieldAddress1() + "." + inputPanel.getTextTextFieldAddress2() + "." + inputPanel.getTextTextFieldAddress3() + ":" + inputPanel.getTextTextFieldAddressPort();
inputFile = inputPanel.getTextTextFieldPath();
server = inputPanel.getRadButtonStateServer();
files = inputPanel.getRadButtonStateFiles();
if(processingPanel.getRadButtonState(ProcessingPanel.PROCESS_DSF)){
process = ProcessingPanel.PROCESS_DSF;
}
if(processingPanel.getRadButtonState(ProcessingPanel.PROCESS_DSDIFF)){
process = ProcessingPanel.PROCESS_DSDIFF;
}
if(processingPanel.getRadButtonState(ProcessingPanel.PROCESS_DSDIFFEM)){
process = ProcessingPanel.PROCESS_DSDIFFEM;
}
if(processingPanel.getRadButtonState(ProcessingPanel.PROCESS_ISO)){
process = ProcessingPanel.PROCESS_ISO;
}
if(processingPanel.getRadButtonState(ProcessingPanel.PROCESS_ISO_DSF)){
process = ProcessingPanel.PROCESS_ISO_DSF;
}
if(processingPanel.getRadButtonState(ProcessingPanel.PROCESS_ISO_DSDIFF)){
process = ProcessingPanel.PROCESS_ISO_DSDIFF;
}
if(processingPanel.getRadButtonState(ProcessingPanel.PROCESS_NONE)){
process = ProcessingPanel.PROCESS_NONE;
}
checkBoxState = processingPanel.getOption(ProcessingPanel.OPTION_STEREO); stereo = checkBoxState.selected;
checkBoxState = processingPanel.getOption(ProcessingPanel.OPTION_MULTI); multi = checkBoxState.selected;
checkBoxState = processingPanel.getOption(ProcessingPanel.OPTION_DECOMPRESS); decompress = checkBoxState.selected;
checkBoxState = processingPanel.getOption(ProcessingPanel.OPTION_SELECTTRACKS); selectTracks = checkBoxState.selected;
checkBoxState = processingPanel.getOption(ProcessingPanel.OPTION_NOPAD); nopad = checkBoxState.selected;
checkBoxState = processingPanel.getOption(ProcessingPanel.OPTION_CUE); cue = checkBoxState.selected;
checkBoxState = processingPanel.getOption(ProcessingPanel.OPTION_PRINT); print = checkBoxState.selected;
checkBoxState = outputPanel.getCheckBoxStateOutput1(); output1Enabled = checkBoxState.selected;
output1Text = outputPanel.getTextOutput1();
output2Text = outputPanel.getTextOutput2();
checkBoxState = outputPanel.getCheckBoxStateOutput2(); output2Enabled = checkBoxState.selected;
cmd.add(program); cmd.add("-i");
if(server){
cmd.add(addressPort);
}
else if(files){
cmd.add(extfile);
}
else{
cmd.add(inputFile);
}
switch(process){
case ProcessingPanel.PROCESS_DSF:
cmd.add("-s");
if(nopad){
cmd.add("-z");
}
break;
case ProcessingPanel.PROCESS_DSDIFF:
cmd.add("-p");
if(decompress){
cmd.add("-c");
}
break;
case ProcessingPanel.PROCESS_DSDIFFEM:
cmd.add("-e");
if(decompress){
cmd.add("-c");
}
break;
case ProcessingPanel.PROCESS_ISO:
cmd.add("-I");
break;
case ProcessingPanel.PROCESS_ISO_DSF:
cmd.add("-w"); cmd.add("-I"); cmd.add("-s");
if(nopad){
cmd.add("-z");
}
break;
case ProcessingPanel.PROCESS_ISO_DSDIFF:
cmd.add("-w"); cmd.add("-I"); cmd.add("-p");
if(decompress){
cmd.add("-c");
}
break;
case ProcessingPanel.PROCESS_NONE:
break;
}
if(stereo){
cmd.add("-2");
}
if(multi){
cmd.add("-m");
}
if(cue){
cmd.add("-C");
}
if(print){
cmd.add("-P");
}
if(selectTracks){
cmd.add("-t");
cmd.add(processingPanel.getTextTextFieldTracks());
}
if(output1Enabled){
cmd.add("-o");
cmd.add(output1Text);
}
if(output2Enabled){
cmd.add("-y");
cmd.add(output2Text);
}
return cmd;
}
public void initGui(){
}
public GuiControl(){
}
}