・TodoDataクラスを追加
・フォームで選択したTODOによって、処理を変化させるように修正
| @@ -35,6 +35,7 @@ | ||
| 35 | 35 | private final SongDataList songData; |
| 36 | 36 | private final ResultDataList resultData; |
| 37 | 37 | private final ResultData2List resultData2; |
| 38 | + private final TodoData todoData; | |
| 38 | 39 | |
| 39 | 40 | /** |
| 40 | 41 | * コンストラクタ |
| @@ -44,7 +45,7 @@ | ||
| 44 | 45 | * @param songData |
| 45 | 46 | * @param resultData |
| 46 | 47 | */ |
| 47 | - public DownloadThread(JButton button, JTextArea textArea, ConfigData configData, SongDataList songData, ResultDataList resultData, ResultData2List resultData2) { | |
| 48 | + public DownloadThread(JButton button, JTextArea textArea, ConfigData configData, SongDataList songData, ResultDataList resultData, ResultData2List resultData2, TodoData todoData) { | |
| 48 | 49 | if ((button == null) || (textArea == null) || (configData == null) |
| 49 | 50 | || (songData == null) || (resultData == null) || (resultData2 == null)) { |
| 50 | 51 | throw new NullPointerException("DownloadThread.DownloadThread"); |
| @@ -56,6 +57,7 @@ | ||
| 56 | 57 | this.songData = songData; |
| 57 | 58 | this.resultData = resultData; |
| 58 | 59 | this.resultData2 = resultData2; |
| 60 | + this.todoData = todoData; | |
| 59 | 61 | |
| 60 | 62 | button.setEnabled(false); |
| 61 | 63 | } |
| @@ -91,7 +93,7 @@ | ||
| 91 | 93 | TextDownloader downloader = new TextDownloader( |
| 92 | 94 | this.configData.getConnectTimeout(), this.configData.getReadTimeout(), this.configData.getProxy()); |
| 93 | 95 | |
| 94 | - // ログイン | |
| 96 | + // ログインページに接続する | |
| 95 | 97 | this.publish("ログインページに接続します。\n"); |
| 96 | 98 | source = this.getLoginPageSource(downloader); |
| 97 | 99 |
| @@ -101,6 +103,7 @@ | ||
| 101 | 103 | return null; |
| 102 | 104 | } |
| 103 | 105 | |
| 106 | + // ログインに成功したかどうか調べる | |
| 104 | 107 | if (!this.isLogin(source)) { |
| 105 | 108 | this.publish("エラー:ログインに失敗しました。\n"); |
| 106 | 109 | this.publish("エラー:処理を中断しました。\n"); |
| @@ -114,44 +117,50 @@ | ||
| 114 | 117 | return null; |
| 115 | 118 | } |
| 116 | 119 | |
| 117 | - // 精密採点ページ取得 | |
| 118 | - for (int page = 1; page <= 10; page++) { | |
| 119 | - this.publish("精密採点の" + page + "ページ目に接続します。\n"); | |
| 120 | - source = this.getSeimitsuPageSource(downloader, page); | |
| 121 | - | |
| 122 | - // キャンセル判定 | |
| 123 | - if (this.isCancelled()) { | |
| 124 | - this.publish("エラー:処理を中断しました。\n"); | |
| 125 | - return null; | |
| 120 | + if (this.todoData.isDownloadSeimitsu()) { | |
| 121 | + for (int page = 1; page <= 10; page++) { | |
| 122 | + // 精密採点ページに接続する | |
| 123 | + this.publish("精密採点の" + page + "ページ目に接続します。\n"); | |
| 124 | + source = this.getSeimitsuPageSource(downloader, page); | |
| 125 | + | |
| 126 | + // キャンセル判定 | |
| 127 | + if (this.isCancelled()) { | |
| 128 | + this.publish("エラー:処理を中断しました。\n"); | |
| 129 | + return null; | |
| 130 | + } | |
| 131 | + | |
| 132 | + // 精密採点のソースを解析してデータに追加する | |
| 133 | + this.updateResultData(source, page); | |
| 134 | + | |
| 135 | + // キャンセル判定 | |
| 136 | + if (this.isCancelled()) { | |
| 137 | + this.publish("エラー:処理を中断しました。\n"); | |
| 138 | + return null; | |
| 139 | + } | |
| 126 | 140 | } |
| 127 | - | |
| 128 | - this.updateResultData(source, page); | |
| 129 | - | |
| 130 | - // キャンセル判定 | |
| 131 | - if (this.isCancelled()) { | |
| 132 | - this.publish("エラー:処理を中断しました。\n"); | |
| 133 | - return null; | |
| 134 | - } | |
| 135 | 141 | } |
| 136 | 142 | |
| 137 | - // 精密採点IIページ取得 | |
| 138 | - for (int page = 1; page <= 10; page++) { | |
| 139 | - this.publish("精密採点IIの" + page + "ページ目に接続します。\n"); | |
| 140 | - source = this.getSeimitsu2PageSource(downloader, page); | |
| 141 | - | |
| 142 | - // キャンセル判定 | |
| 143 | - if (this.isCancelled()) { | |
| 144 | - this.publish("エラー:処理を中断しました。\n"); | |
| 145 | - return null; | |
| 143 | + if (this.todoData.isDownloadSeimitsu2()) { | |
| 144 | + for (int page = 1; page <= 10; page++) { | |
| 145 | + // 精密採点IIページに接続する | |
| 146 | + this.publish("精密採点IIの" + page + "ページ目に接続します。\n"); | |
| 147 | + source = this.getSeimitsu2PageSource(downloader, page); | |
| 148 | + | |
| 149 | + // キャンセル判定 | |
| 150 | + if (this.isCancelled()) { | |
| 151 | + this.publish("エラー:処理を中断しました。\n"); | |
| 152 | + return null; | |
| 153 | + } | |
| 154 | + | |
| 155 | + // 精密採点IIのソースを解析して、データに追加する | |
| 156 | + this.updateResultData2(source, page); | |
| 157 | + | |
| 158 | + // キャンセル判定 | |
| 159 | + if (this.isCancelled()) { | |
| 160 | + this.publish("エラー:処理を中断しました。\n"); | |
| 161 | + return null; | |
| 162 | + } | |
| 146 | 163 | } |
| 147 | - | |
| 148 | - this.updateResultData2(source, page); | |
| 149 | - | |
| 150 | - // キャンセル判定 | |
| 151 | - if (this.isCancelled()) { | |
| 152 | - this.publish("エラー:処理を中断しました。\n"); | |
| 153 | - return null; | |
| 154 | - } | |
| 155 | 164 | } |
| 156 | 165 | } catch (Exception e) { |
| 157 | 166 | this.publish("エラー:例外が発生しました。\n"); |
| @@ -0,0 +1,30 @@ | ||
| 1 | +/* | |
| 2 | + * To change this template, choose Tools | Templates | |
| 3 | + * and open the template in the editor. | |
| 4 | + */ | |
| 5 | + | |
| 6 | +package jp.sourceforge.damstation_dl; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * | |
| 10 | + * @author d | |
| 11 | + */ | |
| 12 | +public class TodoData { | |
| 13 | + private boolean downloadSeimitsu; | |
| 14 | + private boolean downloadSeimitsu2; | |
| 15 | + | |
| 16 | + public TodoData (boolean downloadSeimitsu, boolean downloadSeimitsu2) { | |
| 17 | + this.downloadSeimitsu = downloadSeimitsu; | |
| 18 | + this.downloadSeimitsu2 = downloadSeimitsu2; | |
| 19 | + } | |
| 20 | + | |
| 21 | + public boolean isDownloadSeimitsu() { | |
| 22 | + return downloadSeimitsu; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public boolean isDownloadSeimitsu2() { | |
| 26 | + return downloadSeimitsu2; | |
| 27 | + } | |
| 28 | + | |
| 29 | + | |
| 30 | +} |
| @@ -40,6 +40,7 @@ | ||
| 40 | 40 | cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); // ALLじゃないと動かない… |
| 41 | 41 | CookieHandler.setDefault(cookieManager); |
| 42 | 42 | |
| 43 | + // 各種データの初期化 | |
| 43 | 44 | this.configData = new ConfigData(GlobalData.CONFIG_FILE_IN); |
| 44 | 45 | this.songData = new SongDataList(GlobalData.SONG_FILE_IN); |
| 45 | 46 | this.resultData = new ResultDataList(GlobalData.RESULT_FILE_IN); |
| @@ -95,8 +96,9 @@ | ||
| 95 | 96 | jTodoSeimitsu2CheckBox.setBackground(java.awt.Color.white); |
| 96 | 97 | jTodoSeimitsu2CheckBox.setText("精密採点II"); |
| 97 | 98 | |
| 98 | - jTodoFixSongDataCheckBox.setBackground(java.awt.Color.yellow); | |
| 99 | + jTodoFixSongDataCheckBox.setBackground(java.awt.Color.gray); | |
| 99 | 100 | jTodoFixSongDataCheckBox.setText("曲データ修正"); |
| 101 | + jTodoFixSongDataCheckBox.setEnabled(false); | |
| 100 | 102 | |
| 101 | 103 | javax.swing.GroupLayout jTodoPanelLayout = new javax.swing.GroupLayout(jTodoPanel); |
| 102 | 104 | jTodoPanel.setLayout(jTodoPanelLayout); |
| @@ -149,8 +151,6 @@ | ||
| 149 | 151 | } |
| 150 | 152 | }); |
| 151 | 153 | |
| 152 | - jPasswordField.setEchoChar('\uff0a'); | |
| 153 | - | |
| 154 | 154 | javax.swing.GroupLayout jConfigPanelLayout = new javax.swing.GroupLayout(jConfigPanel); |
| 155 | 155 | jConfigPanel.setLayout(jConfigPanelLayout); |
| 156 | 156 | jConfigPanelLayout.setHorizontalGroup( |
| @@ -220,16 +220,44 @@ | ||
| 220 | 220 | pack(); |
| 221 | 221 | }// </editor-fold>//GEN-END:initComponents |
| 222 | 222 | |
| 223 | + /** | |
| 224 | + * 開始ボタンを押した時の動作 | |
| 225 | + * @param evt | |
| 226 | + */ | |
| 223 | 227 | private void jStartButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jStartButtonActionPerformed |
| 228 | + // SwingWorkerが実行中でない時は処理を開始させる | |
| 224 | 229 | if((this.thread == null) || this.thread.isDone()) { |
| 230 | + // カード番号とパスワード取得 | |
| 225 | 231 | this.getFieldValue(); |
| 226 | - this.thread = new DownloadThread(this.jStartButton, this.jTextArea, this.configData, this.songData, this.resultData, this.resultData2); | |
| 232 | + | |
| 233 | + // TODOの状態を取得 | |
| 234 | + TodoData todoData = new TodoData( | |
| 235 | + this.jTodoSeimitsuCheckBox.isSelected(), | |
| 236 | + this.jTodoSeimitsu2CheckBox.isSelected() | |
| 237 | + ); | |
| 238 | + | |
| 239 | + // SwingWorker動作開始 | |
| 240 | + this.thread = new DownloadThread( | |
| 241 | + this.jStartButton, | |
| 242 | + this.jTextArea, | |
| 243 | + this.configData, | |
| 244 | + this.songData, | |
| 245 | + this.resultData, | |
| 246 | + this.resultData2, | |
| 247 | + todoData | |
| 248 | + ); | |
| 227 | 249 | this.thread.execute(); |
| 228 | 250 | } |
| 229 | 251 | }//GEN-LAST:event_jStartButtonActionPerformed |
| 230 | 252 | |
| 253 | + /** | |
| 254 | + * 中止ボタンを押した時の動作 | |
| 255 | + * @param evt | |
| 256 | + */ | |
| 231 | 257 | private void jStopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jStopButtonActionPerformed |
| 258 | + // SwingWorkerが実行中の時は中止させる | |
| 232 | 259 | if((this.thread != null) && !this.thread.isDone()) { |
| 260 | + // 中止 | |
| 233 | 261 | this.thread.cancel(true); |
| 234 | 262 | } |
| 235 | 263 | }//GEN-LAST:event_jStopButtonActionPerformed |
| @@ -320,11 +348,17 @@ | ||
| 320 | 348 | }); |
| 321 | 349 | } |
| 322 | 350 | |
| 351 | + /** | |
| 352 | + * カード番号とパスワードをフォームにセットする | |
| 353 | + */ | |
| 323 | 354 | private void setFieldValue() { |
| 324 | 355 | this.jCardNumberField.setText(this.configData.getCardNumber()); |
| 325 | 356 | this.jPasswordField.setText(PasswordUtility.decode(this.configData.getPassword())); |
| 326 | 357 | } |
| 327 | 358 | |
| 359 | + /** | |
| 360 | + * カード番号とパスワードをフォームから取得する | |
| 361 | + */ | |
| 328 | 362 | private void getFieldValue() { |
| 329 | 363 | this.configData.setCardNumber(this.jCardNumberField.getText()); |
| 330 | 364 | this.configData.setPassword(PasswordUtility.encode(new String(this.jPasswordField.getPassword()))); |