This repository has been archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
UIFrame.java
1277 lines (1101 loc) · 55.9 KB
/
UIFrame.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
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Any modification, copies of sections of this file must be attached with this
* license and shown clearly in the developer's project. The code can be used
* as long as you state clearly you do not own it. Any violation might result in
* a take-down.
*
* MIT License
*
* Copyright (c) 2016, 2017 Anthony Law
*
* 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.
*******************************************************************************/
package com.github.mob41.osumer.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Desktop;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Calendar;
import javax.imageio.ImageIO;
import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.Timer;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileFilter;
import com.github.mob41.organdebug.exceptions.DebuggableException;
import com.github.mob41.osumer.Config;
import com.github.mob41.osumer.Osumer;
import com.github.mob41.osumer.exceptions.NoBuildsForVersionException;
import com.github.mob41.osumer.exceptions.NoSuchBuildNumberException;
import com.github.mob41.osumer.exceptions.NoSuchVersionException;
import com.github.mob41.osumer.io.legacy.URLDownloader;
import com.github.mob41.osumer.io.queue.Queue;
import com.github.mob41.osumer.io.queue.QueueAction;
import com.github.mob41.osumer.io.queue.QueueManager;
import com.github.mob41.osumer.io.queue.actions.AfterSoundAction;
import com.github.mob41.osumer.io.queue.actions.BeatmapImportAction;
import com.github.mob41.osumer.io.queue.actions.BeforeSoundAction;
import com.github.mob41.osumer.io.queue.actions.CustomImportAction;
import com.github.mob41.osumer.io.queue.actions.UpdaterRunAction;
import com.github.mob41.osumer.sock.SockThread;
import com.github.mob41.osumer.updater.UpdateInfo;
import com.github.mob41.osumer.updater.Updater;
import com.github.mob41.osums.io.beatmap.OsuBeatmap;
import com.github.mob41.osums.io.beatmap.OsuDownloader;
import com.github.mob41.osums.io.beatmap.Osums;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.border.TitledBorder;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
public class UIFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = -4742856302707419966L;
private boolean daemonMode = false;
private final QueueManager mgr;
private final Updater updater;
private final Osums osu;
private final SockThread sockThread;
private final Config config;
private final TrayIcon icon;
private final Timer timer;
private File selectedFile = null;
private File selectedFolder = null;
private JPanel contentPane;
private QueueCellTableModel tableModel;
private JTable table;
private JTextField beatmapField;
private JCheckBox chckbxShowBeatmapPreview;
private boolean checkingUpdate = false;
private String targetFile = "";
private String targetFolder = "";
/**
* Create the frame.
*/
public UIFrame(Config config, QueueManager mgr, TrayIcon icon) {
this.icon = icon;
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent arg0) {
if (daemonMode) {
setVisible(false);
icon.displayMessage("osumer2", "osumer2 is now running in background.", TrayIcon.MessageType.INFO);
} else {
dispose();
System.exit(0);
return;
}
}
});
this.mgr = mgr;
this.config = config;
this.osu = new Osums();
this.updater = new Updater(config);
setLocationRelativeTo(null);
//TODO: Remove this once new parser implemented
if (!config.isLegacyDisableOldSiteBeatmapRedirectingStartupNotification() || !config.isLegacyEnableOldSiteBeatmapRedirecting()) {
//Blocking thread if not enabled
Legacy_OldSiteParsingDialog dialog = new Legacy_OldSiteParsingDialog();
dialog.setLocationRelativeTo(this);
if (!config.isLegacyEnableOldSiteBeatmapRedirecting()) {
dialog.setModal(true);
dialog.setVisible(true);
} else {
new Thread() {
public void run() {
dialog.setModal(true);
dialog.setVisible(true);
}
}.start();
}
}
mgr.startQueuing();
setTitle("osumer");
setIconImage(Toolkit.getDefaultToolkit()
.getImage(UIFrame.class.getResource("/com/github/mob41/osumer/ui/osumerIcon_32px.png")));
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setBounds(100, 100, 883, 578);
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu mnOsumer2 = new JMenu("osumer2");
menuBar.add(mnOsumer2);
JMenuItem mntmViewDumps = new JMenuItem("View dumps");
mntmViewDumps.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ViewDumpDialog dialog = new ViewDumpDialog();
dialog.setModal(true);
dialog.setVisible(true);
}
});
JMenuItem mntmGcCall = new JMenuItem("GC Call");
mntmGcCall.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.gc();
Runtime.getRuntime().gc();
}
});
mnOsumer2.add(mntmGcCall);
mnOsumer2.add(mntmViewDumps);
JMenuItem mntmPreferences = new JMenuItem("Preferences");
mntmPreferences.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
PreferenceDialog dialog = new PreferenceDialog(config, UIFrame.this);
dialog.setLocationRelativeTo(UIFrame.this);
dialog.setModal(true);
dialog.setVisible(true);
}
});
JMenuItem mntmViewConfigurationLocation = new JMenuItem("Open configuration location");
mntmViewConfigurationLocation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Desktop.getDesktop().open(new File(System.getenv("LOCALAPPDATA") + "\\osumerExpress"));
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
mnOsumer2.add(mntmViewConfigurationLocation);
mnOsumer2.add(mntmPreferences);
JSeparator separator = new JSeparator();
mnOsumer2.add(separator);
JMenuItem mntmExit = new JMenuItem("Exit");
mntmExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (daemonMode) {
int option = JOptionPane.showOptionDialog(UIFrame.this,
"This application is running in daemon mode.\nExiting might slow down the osumerExpress background download speed.\n\nAre you sure? Or you may prefer running in background.",
"Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null,
new String[] { "Yes", "No", "Run in Background" }, JOptionPane.NO_OPTION);
if (option == JOptionPane.NO_OPTION || option == JOptionPane.CLOSED_OPTION) {
return;
} else if (option == 2) {
setVisible(false);
icon.displayMessage("osumer2", "osumer2 is now running in background.",
TrayIcon.MessageType.INFO);
return;
}
}
dispose();
System.exit(0);
return;
}
});
JMenuItem mntmCheckForUpdates = new JMenuItem("Check for updates");
mntmCheckForUpdates.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
checkUpdate();
}
});
mnOsumer2.add(mntmCheckForUpdates);
JSeparator separator_1 = new JSeparator();
mnOsumer2.add(separator_1);
mnOsumer2.add(mntmExit);
JMenu mnQueue = new JMenu("Queue");
menuBar.add(mnQueue);
JMenuItem mntmRefreshQueueList = new JMenuItem("Refresh queue list");
mntmRefreshQueueList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
tableModel.fireTableDataChanged();
}
});
JMenuItem mntmAddLegacyQueue = new JMenuItem("Add legacy queue");
mntmAddLegacyQueue.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String input = JOptionPane.showInputDialog("Specify URL to download:");
URL url = null;
try {
url = new URL(input);
} catch (MalformedURLException e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this, "Error: Invalid URL", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
mgr.addQueue(new Queue("Legacy download",
new URLDownloader("C:\\Users\\Anthony\\Desktop\\Unknown", "legacy.test", url), null, null,
null));
tableModel.fireTableDataChanged();
}
});
mnQueue.add(mntmAddLegacyQueue);
JMenuItem mntmEditQueues = new JMenuItem("Edit queues");
mntmEditQueues.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EditQueueDialog dialog = new EditQueueDialog(mgr);
dialog.setModal(true);
dialog.setVisible(true);
}
});
mnQueue.add(mntmEditQueues);
mnQueue.add(mntmRefreshQueueList);
JMenu mnAbout = new JMenu("About");
menuBar.add(mnAbout);
JMenuItem mntmGithubProject = new JMenuItem("GitHub Project");
mntmGithubProject.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Desktop.getDesktop().browse(new URL("https://github.com/mob41/osumer").toURI());
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
mnAbout.add(mntmGithubProject);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
JLabel lblImg = new JLabel("");
lblImg.setIcon(new ImageIcon(UIFrame.class.getResource("/com/github/mob41/osumer/ui/osumerIcon_64px.png")));
JLabel lblTitle = new JLabel("osumer2");
lblTitle.setVerticalAlignment(SwingConstants.BOTTOM);
lblTitle.setFont(new Font("Tahoma", Font.PLAIN, 27));
tab = new JTabbedPane(JTabbedPane.TOP);
JLabel lblCopyright = new JLabel("Copyright (c) 2016-2018 Anthony Law. Licensed under MIT License.");
lblCopyright.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblCopyright.setHorizontalAlignment(SwingConstants.CENTER);
JLabel label = new JLabel("");
JLabel lblTheEasiestExpress = new JLabel("The easiest, express way to obtain beatmaps");
lblTheEasiestExpress.setHorizontalAlignment(SwingConstants.LEFT);
lblTheEasiestExpress.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblUpdateStatus = new JLabel("");
lblUpdateStatus.setHorizontalAlignment(SwingConstants.RIGHT);
lblUpdateStatus.setFont(new Font("Tahoma", Font.PLAIN, 12));
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(tab)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblImg)
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblTheEasiestExpress)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblUpdateStatus, GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE))
.addGroup(gl_contentPane.createSequentialGroup()
.addGap(255)
.addComponent(label))
.addComponent(lblTitle, GroupLayout.DEFAULT_SIZE, 691, Short.MAX_VALUE)))
.addComponent(lblCopyright, GroupLayout.DEFAULT_SIZE, 761, Short.MAX_VALUE))
.addGap(0))
);
gl_contentPane.setVerticalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addContainerGap()
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(lblTitle)
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
.addComponent(lblUpdateStatus, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lblTheEasiestExpress, GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.addComponent(label)))
.addComponent(lblImg))
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(tab, GroupLayout.PREFERRED_SIZE, 366, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(lblCopyright))
);
JPanel panel = new JPanel();
tab.addTab("Quick start", null, panel, null);
JLabel lblBeatmapUrl = new JLabel("Beatmap URL:");
lblBeatmapUrl.setFont(new Font("Tahoma", Font.PLAIN, 21));
beatmapField = new JTextField();
beatmapField.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent arg0) {
String text = beatmapField.getText();
if (Osums.isVaildBeatMapUrl(text)){
beatmapField.setBackground(Color.WHITE);
beatmapField.setForeground(Color.BLACK);
} else {
beatmapField.setBackground(Color.PINK);
beatmapField.setForeground(Color.WHITE);
}
}
});
beatmapField.setFont(new Font("Tahoma", Font.PLAIN, 18));
beatmapField.setColumns(10);
JButton btnAddToQueue = new JButton("Add to queue");
btnAddToQueue.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!Osums.isVaildBeatMapUrl(beatmapField.getText())){
JOptionPane.showMessageDialog(UIFrame.this, "Please enter a valid song/beatmap URL.", "Error", JOptionPane.WARNING_MESSAGE);
return;
}
addBtQueue(beatmapField.getText(), chckbxShowBeatmapPreview.isSelected());
}
});
btnAddToQueue.setFont(new Font("Tahoma", Font.PLAIN, 15));
JLabel lblSpecifyYourDesired = new JLabel(
"Specify your desired osu! beatmap URL to download. (e.g. http://osu.ppy.sh/s/320118)");
lblSpecifyYourDesired.setFont(new Font("Tahoma", Font.PLAIN, 12));
JLabel lblNewWebpageUrls = new JLabel(
"New web links with more than 6 digits (e.g. https://osu.ppy.sh/b/1483372) are currently not supported.");
lblNewWebpageUrls.setFont(new Font("Tahoma", Font.PLAIN, 12));
ButtonGroup dwnSelectionBtnGp = new ButtonGroup();
JButton btnOsumerPreferences = new JButton("osumer2 Preferences");
btnOsumerPreferences.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PreferenceDialog dialog = new PreferenceDialog(config, UIFrame.this);
dialog.setLocationRelativeTo(UIFrame.this);
dialog.setModal(true);
dialog.setVisible(true);
}
});
btnOsumerPreferences.setFont(new Font("Tahoma", Font.PLAIN, 18));
chckbxShowBeatmapPreview = new JCheckBox("Show beatmap preview");
chckbxShowBeatmapPreview.setSelected(true);
chckbxShowBeatmapPreview.setFont(new Font("Tahoma", Font.PLAIN, 12));
JButton btnDownloadAList = new JButton("Download a list of beatmaps");
btnDownloadAList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MultiDownloadDialog d = new MultiDownloadDialog(UIFrame.this);
d.setLocationRelativeTo(UIFrame.this);
d.setModal(true);
d.setVisible(true);
}
});
btnDownloadAList.setFont(new Font("Tahoma", Font.PLAIN, 18));
JPanel panel_1 = new JPanel();
panel_1.setBorder(new TitledBorder(null, "Beatmap Import Actions", TitledBorder.LEADING, TitledBorder.TOP, null, null));
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
.addComponent(lblSpecifyYourDesired, GroupLayout.DEFAULT_SIZE, 822, Short.MAX_VALUE)
.addGroup(gl_panel.createSequentialGroup()
.addComponent(lblBeatmapUrl)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(beatmapField, GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnAddToQueue, GroupLayout.PREFERRED_SIZE, 151, GroupLayout.PREFERRED_SIZE))
.addComponent(lblNewWebpageUrls, GroupLayout.DEFAULT_SIZE, 822, Short.MAX_VALUE))
.addContainerGap())
.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
.addComponent(btnDownloadAList, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 822, Short.MAX_VALUE)
.addComponent(btnOsumerPreferences, GroupLayout.DEFAULT_SIZE, 822, Short.MAX_VALUE))
.addContainerGap())
.addGroup(gl_panel.createSequentialGroup()
.addComponent(panel_1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())))
.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
.addGap(10)
.addComponent(chckbxShowBeatmapPreview, GroupLayout.DEFAULT_SIZE, 826, Short.MAX_VALUE)
.addContainerGap())
);
gl_panel.setVerticalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
.addComponent(btnAddToQueue, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
.addComponent(beatmapField, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(lblBeatmapUrl, Alignment.LEADING))
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblSpecifyYourDesired)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(lblNewWebpageUrls)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 145, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(chckbxShowBeatmapPreview)
.addGap(33)
.addComponent(btnOsumerPreferences)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnDownloadAList, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
rdbtnUseDefaultSettings = new JRadioButton("Use default settings in Preferences");
rdbtnUseDefaultSettings.setSelected(true);
rdbtnDownloadAndImport = new JRadioButton("Download and Import (Recommended)");
rdbtnDownloadToOsu = new JRadioButton("Download to osu! Song folder (Press F5 in osu! to load)");
rdbtnDownloadToFile = new JRadioButton("Download to file");
rdbtnDownloadToFolder = new JRadioButton("Download to folder");
ButtonGroup downloadSettingsGroup = new ButtonGroup();
downloadSettingsGroup.add(rdbtnUseDefaultSettings);
downloadSettingsGroup.add(rdbtnDownloadAndImport);
downloadSettingsGroup.add(rdbtnDownloadToOsu);
downloadSettingsGroup.add(rdbtnDownloadToFile);
downloadSettingsGroup.add(rdbtnDownloadToFolder);
JButton btnSelectFile = new JButton("Select file");
btnSelectFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser c = new JFileChooser();
c.setFileSelectionMode(JFileChooser.FILES_ONLY);
File file = new File(targetFile);
c.setSelectedFile(file);
int opt = c.showSaveDialog(UIFrame.this);
if (opt == JFileChooser.APPROVE_OPTION) {
File sf = c.getSelectedFile();
targetFile = sf.getAbsolutePath();
}
}
});
JButton btnSelectFolder = new JButton("Select folder");
btnSelectFolder.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser c = new JFileChooser();
c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
File file = new File(targetFolder);
c.setSelectedFile(file);
int opt = c.showSaveDialog(UIFrame.this);
if (opt == JFileChooser.APPROVE_OPTION) {
File sf = c.getSelectedFile();
targetFolder = sf.getAbsolutePath();
}
}
});
GroupLayout gl_panel_1 = new GroupLayout(panel_1);
gl_panel_1.setHorizontalGroup(
gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
.addComponent(rdbtnUseDefaultSettings)
.addComponent(rdbtnDownloadAndImport)
.addComponent(rdbtnDownloadToOsu)
.addGroup(gl_panel_1.createSequentialGroup()
.addComponent(rdbtnDownloadToFile)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnSelectFile))
.addGroup(gl_panel_1.createSequentialGroup()
.addComponent(rdbtnDownloadToFolder)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnSelectFolder)))
.addContainerGap(529, Short.MAX_VALUE))
);
gl_panel_1.setVerticalGroup(
gl_panel_1.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel_1.createSequentialGroup()
.addComponent(rdbtnUseDefaultSettings)
.addComponent(rdbtnDownloadAndImport)
.addComponent(rdbtnDownloadToOsu)
.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
.addComponent(rdbtnDownloadToFile)
.addComponent(btnSelectFile))
.addGroup(gl_panel_1.createParallelGroup(Alignment.BASELINE)
.addComponent(rdbtnDownloadToFolder)
.addComponent(btnSelectFolder)))
);
panel_1.setLayout(gl_panel_1);
panel.setLayout(gl_panel);
JPanel queuePanel = new JPanel();
tab.addTab("Queue", null, queuePanel, null);
queuePanel.setLayout(new BorderLayout(0, 0));
JScrollPane scrollPane = new JScrollPane();
queuePanel.add(scrollPane, BorderLayout.CENTER);
tableModel = new QueueCellTableModel(mgr);
table = new JTable(tableModel);
table.setDefaultRenderer(Queue.class, new QueueCellRenderer(tableModel));
table.setDefaultEditor(Queue.class, new QueueCellEditor(tableModel));
table.setRowHeight(153);
timer = new Timer(100, new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
tableModel.fireTableDataChanged();
}
});
timer.start();
JPopupMenu popupMenu = new JPopupMenu();
JMenuItem mntmStart = new JMenuItem("Start");
popupMenu.add(mntmStart);
JMenuItem mntmPause = new JMenuItem("Pause");
popupMenu.add(mntmPause);
JMenuItem mntmResume = new JMenuItem("Resume");
popupMenu.add(mntmResume);
JMenuItem mntmCancel = new JMenuItem("Cancel");
mntmCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int index = table.getSelectedRow();
if (index != -1) {
Queue queue = (Queue) table.getValueAt(index, 0);
mgr.removeQueue(queue);
tableModel.fireTableDataChanged();
}
}
});
popupMenu.add(mntmCancel);
// timer.start();
scrollPane.setViewportView(table);
contentPane.setLayout(gl_contentPane);
JPanel panel_2 = new JPanel();
tab.addTab("Manage beatmaps", null, panel_2, null);
tab.setEnabledAt(2, false);
tab.add("Search beatmaps", new BeatmapSearchPanel(this, osu));
this.sockThread = new SockThread(this);
sockThread.start();
EventQueue.invokeLater(new Runnable() {
public void run() {
checkUpdate();
if (config.isShowGettingStartedOnStartup()) {
GettingStartedDialog gsd = new GettingStartedDialog();
gsd.setLocationRelativeTo(UIFrame.this);
gsd.setModal(true);
gsd.setVisible(true);
}
}
});
}
public Config getConfig() {
return config;
}
public Osums getOsums() {
return osu;
}
public JTabbedPane getTab() {
return tab;
}
public QueueManager getQueueManager() {
return mgr;
}
private OsuBeatmap map = null;
private BufferedImage thumb = null;
private ProgressDialog pbd = null;
private JTabbedPane tab;
private JLabel lblUpdateStatus;
private JRadioButton rdbtnUseDefaultSettings;
private JRadioButton rdbtnDownloadAndImport;
private JRadioButton rdbtnDownloadToOsu;
private JRadioButton rdbtnDownloadToFile;
private JRadioButton rdbtnDownloadToFolder;
public boolean addBtQueue(String url, boolean preview) {
return addBtQueue(url, preview, true, null, null);
}
public boolean addQuietBtQueue(String url) {
if (config.getCheckUpdateFreq() == Config.CHECK_UPDATE_FREQ_EVERY_ACT) {
checkUpdate();
}
String user = config.getUser();
String pass = config.getPass();
if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
LoginPanel loginPanel = new LoginPanel();
int option = JOptionPane.showOptionDialog(UIFrame.this, loginPanel, "Login to osu!",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null,
JOptionPane.CANCEL_OPTION);
if (option == JOptionPane.OK_OPTION) {
if (loginPanel.getUsername().isEmpty() || loginPanel.getPassword().isEmpty()) {
JOptionPane.showMessageDialog(UIFrame.this, "Username or password cannot be empty.",
"Error", JOptionPane.ERROR_MESSAGE);
return false;
}
user = loginPanel.getUsername();
pass = loginPanel.getPassword();
} else {
return false;
}
}
try {
osu.login(user, pass);
} catch (DebuggableException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this, "Error logging in:\n" + e.getDump().getMessage(),
"Error", JOptionPane.ERROR_MESSAGE);
return false;
}
String modBUrl = config.isLegacyEnableOldSiteBeatmapRedirecting() ? url.replace("osu.ppy.sh", "old.ppy.sh") : url;
try {
map = osu.getBeatmapInfo(modBUrl);
} catch (DebuggableException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this,
"Error getting beatmap info:\n" + e.getDump().getMessage(), "Error",
JOptionPane.ERROR_MESSAGE);
return false;
}
String modUrl = map.getThumbUrl();
URL thumbUrl = null;
try {
thumbUrl = new URL("http:" + modUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
return false;
}
URLConnection conn = null;
try {
conn = thumbUrl.openConnection();
} catch (IOException e) {
e.printStackTrace();
return false;
}
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
try {
thumb = ImageIO.read(conn.getInputStream());
} catch (IOException e) {
e.printStackTrace();
thumb = null;
}
URL downloadUrl = null;
try {
downloadUrl = new URL("http://osu.ppy.sh" + map.getDwnUrl());
} catch (MalformedURLException e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this, "Error validating download URL:\n" + e1, "Error",
JOptionPane.ERROR_MESSAGE);
return false;
}
String tmpdir = System.getProperty("java.io.tmpdir");
final String mapName = map.getName();
OsuDownloader dwn = new OsuDownloader(tmpdir,
map.getDwnUrl().substring(3, map.getDwnUrl().length()) + " " + map.getName(), osu, downloadUrl);
QueueAction importAction;
if (rdbtnUseDefaultSettings.isSelected()) {
importAction = new BeatmapImportAction(config);
} else {
int action = -1;
String targetFileOrFolder = null;
if (rdbtnDownloadAndImport.isSelected()) {
action = 0;
} else if (rdbtnDownloadToOsu.isSelected()) {
action = 1;
} else if (rdbtnDownloadToFile.isSelected()) {
action = 2;
targetFileOrFolder = targetFile;
} else if (rdbtnDownloadToFolder.isSelected()) {
action = 3;
targetFileOrFolder = targetFolder;
}
importAction = new CustomImportAction(action, targetFileOrFolder);
}
QueueAction[] beforeActions = new QueueAction[] {
new BeforeSoundAction(config)
};
QueueAction[] afterActions = new QueueAction[] {
new AfterSoundAction(config),
new QueueAction(){
@Override
public void run(Queue queue) {
icon.displayMessage("Download completed for \"" + mapName + "\"", "This osumer queue has completed downloading.", TrayIcon.MessageType.INFO);
}
},
importAction
};
boolean added = mgr.addQueue(new Queue(map.getName(), dwn, thumb, beforeActions, afterActions));
if (added){
icon.displayMessage("Downloading \"" + mapName + "\"", "osumerExpress is downloading the requested beatmap!", TrayIcon.MessageType.INFO);
} else {
icon.displayMessage("Could not add \"" + mapName + "\" to queue", "It has already in queue/downloading or completed.", TrayIcon.MessageType.INFO);
}
tableModel.fireTableDataChanged();
return true;
}
public boolean addBtQueue(String url, boolean preview, boolean changeTab, QueueAction[] beforeActions, QueueAction[] afterActions) {
if (config.getCheckUpdateFreq() == Config.CHECK_UPDATE_FREQ_EVERY_ACT) {
checkUpdate();
}
map = null;
thumb = null;
pbd = new ProgressDialog();
new Thread() {
public void run() {
pbd.getProgressBar().setIndeterminate(true);
pbd.getLabel().setText("Status: Getting configuration...");
String user = config.getUser();
String pass = config.getPass();
if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
pbd.getLabel().setText("Status: Prompting username and password...");
LoginPanel loginPanel = new LoginPanel();
int option = JOptionPane.showOptionDialog(UIFrame.this, loginPanel, "Login to osu!",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null,
JOptionPane.CANCEL_OPTION);
if (option == JOptionPane.OK_OPTION) {
if (loginPanel.getUsername().isEmpty() || loginPanel.getPassword().isEmpty()) {
JOptionPane.showMessageDialog(UIFrame.this, "Username or password cannot be empty.",
"Error", JOptionPane.ERROR_MESSAGE);
pbd.dispose();
return;
}
user = loginPanel.getUsername();
pass = loginPanel.getPassword();
} else {
pbd.dispose();
return;
}
}
pbd.getLabel().setText("Status: Logging in...");
try {
osu.login(user, pass);
} catch (DebuggableException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this, "Error logging in:\n" + e.getDump().getMessage(),
"Error", JOptionPane.ERROR_MESSAGE);
pbd.dispose();
return;
}
String modUrl = config.isLegacyEnableOldSiteBeatmapRedirecting() ? url.replace("osu.ppy.sh", "old.ppy.sh") : url;
pbd.getLabel().setText("Status: Obtaining beatmap information...");
try {
map = osu.getBeatmapInfo(modUrl);
} catch (DebuggableException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this,
"Error getting beatmap info:\n" + e.getDump().getMessage(), "Error",
JOptionPane.ERROR_MESSAGE);
pbd.dispose();
return;
}
pbd.dispose();
pbd = null;
}
}.start();
pbd.setLocationRelativeTo(UIFrame.this);
pbd.setModal(true);
pbd.setVisible(true);
if (map == null) {
return false;
}
boolean stillDwn = true;
if (preview) {
BeatmapPreviewDialog bpd = new BeatmapPreviewDialog(map);
bpd.setLocationRelativeTo(UIFrame.this);
bpd.setModal(true);
bpd.setVisible(true);
stillDwn = bpd.isSelectedYes();
thumb = bpd.getDownloadedImage();
}
if (thumb == null) {
pbd = new ProgressDialog();
new Thread() {
public void run() {
pbd.getProgressBar().setIndeterminate(true);
pbd.getLabel().setText("Status: Downloading thumb image...");
URL url = null;
try {
url = new URL("http:" + map.getThumbUrl());
} catch (MalformedURLException e) {
e.printStackTrace();
pbd.dispose();
return;
}
URLConnection conn = null;
try {
conn = url.openConnection();
} catch (IOException e) {
e.printStackTrace();
pbd.dispose();
return;
}
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
try {
thumb = ImageIO.read(conn.getInputStream());
} catch (IOException e) {
e.printStackTrace();
pbd.dispose();
return;
}
pbd.dispose();
}
}.start();
pbd.setLocationRelativeTo(UIFrame.this);
pbd.setModal(true);