OSDN Git Service

Merge branch 'develop' into release/v3.0.0
[delesterandomselector/DelesteRandomSelector.git] / src / com / ranfa / main / DelesteRandomSelector.java
index 935842b..bbdcb8e 100644 (file)
@@ -33,7 +33,9 @@ import com.jgoodies.forms.layout.FormLayout;
 import com.jgoodies.forms.layout.FormSpecs;
 import com.jgoodies.forms.layout.RowSpec;
 import com.ranfa.lib.CheckVersion;
+import com.ranfa.lib.Easter;
 import com.ranfa.lib.EstimateAlbumTypeCycle;
+import com.ranfa.lib.ManualUpdateThreadImpl;
 import com.ranfa.lib.Scraping;
 import com.ranfa.lib.SettingJSONProperty;
 import com.ranfa.lib.Settings;
@@ -41,7 +43,7 @@ import com.ranfa.lib.Song;
 import com.ranfa.lib.TwitterIntegration;
 import com.ranfa.lib.Version;
 
-@Version(major = 2, minor = 0, patch = 3)
+@Version(major = 3, minor = 0, patch = 0)
 public class DelesteRandomSelector extends JFrame {
 
        private static ArrayList<Song> selectedSongsList = new ArrayList<>();
@@ -74,6 +76,10 @@ public class DelesteRandomSelector extends JFrame {
        private CompletableFuture<Void> albumTypeEstimateFuture = null;
        private String albumType = Messages.MSGAlbumTypeBeingCalculated.toString();
        private Logger logger = LoggerFactory.getLogger(DelesteRandomSelector.class);
+       private ManualUpdateThreadImpl impl;
+       private Thread manualUpdateThread;
+       private JButton btnManualUpdate;
+       private Easter easter;
 
        /**
         * Launch the application.
@@ -148,7 +154,7 @@ public class DelesteRandomSelector extends JFrame {
                };
                Runnable setEnabled = () -> {
                        try {
-                               Thread.sleep(1000);
+                               Thread.sleep(3 * 1000L);
                        } catch (InterruptedException e1) {
                                this.logger.error("Thread has been interrupted during waiting cooldown.", e1);
                        }
@@ -161,10 +167,12 @@ public class DelesteRandomSelector extends JFrame {
                        CompletableFuture<Void> updatedFuture = getWholeDataFuture.thenAcceptBothAsync(getFromJsonFuture, updateConsumer, es);
                        updatedFuture.thenRunAsync(setEnabled, es);
                }
+               this.easter = new Easter();
+               this.setTitle(this.easter.getTodaysBirth());
                this.logger.debug("Version: {}", CheckVersion.getVersion());
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-               this.setBounds(100, 100, this.property.getWindowWidth(), this.property.getWindowHeight());
-               // this.setBounds(100, 100, 640, 360);
+               // this.setBounds(100, 100, this.property.getWindowWidth(), this.property.getWindowHeight());
+               this.setBounds(100, 100, 640, 360);
                this.contentPane = new JPanel();
                this.contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                this.setContentPane(this.contentPane);
@@ -269,6 +277,11 @@ public class DelesteRandomSelector extends JFrame {
                this.btnImport = new JButton(Messages.MSGUpdatingDatabase.toString());
                this.btnImport.setEnabled(false);
                this.btnImport.addActionListener(e -> {
+                       if(this.impl != null) {
+                               if(!this.impl.getFlag()) {
+                                       JOptionPane.showMessageDialog(null, Messages.MSGManualUpdateNotCompleteYet.toString());
+                               }
+                       }
                        ArrayList<Song> fromJson = Scraping.getFromJson();
                        ArrayList<Song> specificlevelList = Scraping.getSpecificLevelSongs(fromJson, (Integer)DelesteRandomSelector.this.spinnerLevel.getValue(), DelesteRandomSelector.this.checkLessLv.isSelected(), DelesteRandomSelector.this.checkMoreLv.isSelected());
                        ArrayList<Song> specificDifficultyList = Scraping.getSpecificDifficultySongs(specificlevelList, DelesteRandomSelector.this.comboDifficultySelect.getSelectedItem().toString());
@@ -351,12 +364,21 @@ public class DelesteRandomSelector extends JFrame {
                                DelesteRandomSelector.this.logger.info("seems to reject the permission.it should need try again.");
                        }
                });
+
+               this.btnManualUpdate = new JButton(Messages.MSGManualUpdate.toString());
+               this.btnManualUpdate.addActionListener(e -> {
+                       this.impl = new ManualUpdateThreadImpl();
+                       es.submit(this.impl);
+               });
+               this.panelEast.add(this.btnManualUpdate, "1, 9");
                this.panelEast.add(this.btnTwitterIntegration, "1, 11");
 
                this.btnExit = new JButton(Messages.MSGTerminate.toString());
                this.btnExit.addActionListener(e -> {
-                       if(DelesteRandomSelector.this.softwareUpdateFuture.isDone() || DelesteRandomSelector.this.albumTypeEstimateFuture.isDone()) {
-                               DelesteRandomSelector.this.logger.info("Requested Exit by Button");
+                       if(DelesteRandomSelector.this.softwareUpdateFuture.isDone() || DelesteRandomSelector.this.albumTypeEstimateFuture.isDone() || !this.impl.getFlag()) {
+                               DelesteRandomSelector.this.logger.info("Requested Exit by Button.");
+                               this.logger.info("Shut down thread pool.");
+                               es.shutdown();
                                System.exit(0);
                        } else {
                                JOptionPane.showMessageDialog(null, Messages.MSGInternalYpdateNotDoneYet.toString());