Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 6fe7be6

Browse files
committed
重构弹窗部分
1 parent 21cac85 commit 6fe7be6

File tree

8 files changed

+227
-216
lines changed

8 files changed

+227
-216
lines changed

src/main/java/org/code4everything/qiniu/QiniuApplication.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.code4everything.qiniu.model.ConfigBean;
1616
import org.code4everything.qiniu.model.FileInfo;
1717
import org.code4everything.qiniu.util.ConfigUtils;
18-
import org.code4everything.qiniu.view.Dialogs;
18+
import org.code4everything.qiniu.util.DialogUtils;
1919

2020
import java.util.Optional;
2121
import java.util.concurrent.LinkedBlockingQueue;
@@ -80,7 +80,7 @@ public void start(Stage stage) {
8080
stage.setScene(scene);
8181
} catch (Exception e) {
8282
LOGGER.error("init stage error: " + e.getMessage());
83-
Dialogs.showFatalError(QiniuValueConsts.INIT_APP_ERROR_HEADER, e);
83+
DialogUtils.showFatalError(QiniuValueConsts.INIT_APP_ERROR_HEADER, e);
8484
}
8585
// 设置图标
8686
stage.getIcons().add(new Image(getClass().getResourceAsStream("/image/qiniu.png")));
@@ -90,7 +90,7 @@ public void start(Stage stage) {
9090
// 判断是否有文件在上传下载
9191
MainWindowController main = MainWindowController.getInstance();
9292
if (main.downloadProgress.isVisible() || main.uploadProgress.isVisible()) {
93-
Optional<ButtonType> result = Dialogs.showConfirmation(QiniuValueConsts.UPLOADING_OR_DOWNLOADING);
93+
Optional<ButtonType> result = DialogUtils.showConfirmation(QiniuValueConsts.UPLOADING_OR_DOWNLOADING);
9494
if (result.isPresent() && result.get() != ButtonType.OK) {
9595
// 取消退出事件
9696
event.consume();

src/main/java/org/code4everything/qiniu/api/QiManager.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.code4everything.qiniu.controller.MainWindowController;
2323
import org.code4everything.qiniu.model.FileInfo;
2424
import org.code4everything.qiniu.util.QiniuUtils;
25-
import org.code4everything.qiniu.view.Dialogs;
25+
import org.code4everything.qiniu.util.DialogUtils;
2626

2727
import java.io.UnsupportedEncodingException;
2828
import java.net.URLEncoder;
@@ -65,7 +65,7 @@ public Series<String, Long> getBucketBandwidth(String[] domains, String fromDate
6565
bandwidthResult = SdkConfigurer.getCdnManager().getBandwidthData(domains, fromDate, toDate, "day");
6666
} catch (QiniuException e) {
6767
logger.error("get bucket bandwidth error, message: " + e.getMessage());
68-
Platform.runLater(() -> Dialogs.showException(QiniuValueConsts.BUCKET_BAND_ERROR, e));
68+
Platform.runLater(() -> DialogUtils.showException(QiniuValueConsts.BUCKET_BAND_ERROR, e));
6969
}
7070
Series<String, Long> bandSer = new Series<>();
7171
bandSer.setName(QiniuValueConsts.BUCKET_BANDWIDTH_COUNT.replaceAll("[A-Z]+", countUnit));
@@ -125,7 +125,7 @@ public Series<String, Long> getBucketFlux(String[] domains, String fromDate, Str
125125
fluxResult = SdkConfigurer.getCdnManager().getFluxData(domains, fromDate, toDate, "day");
126126
} catch (QiniuException e) {
127127
logger.error("get bucket flux error, message: " + e.getMessage());
128-
Platform.runLater(() -> Dialogs.showException(QiniuValueConsts.BUCKET_FLUX_ERROR, e));
128+
Platform.runLater(() -> DialogUtils.showException(QiniuValueConsts.BUCKET_FLUX_ERROR, e));
129129
}
130130
Series<String, Long> fluxSer = new Series<>();
131131
fluxSer.setName(QiniuValueConsts.BUCKET_FLUX_COUNT.replaceAll("[A-Z]+", countUnit));
@@ -174,7 +174,7 @@ public void downloadCdnLog(String logDate) {
174174
}
175175
} catch (QiniuException e) {
176176
logger.error("get cdn log url error, message: " + e.getMessage());
177-
Dialogs.showException(e);
177+
DialogUtils.showException(e);
178178
}
179179
}
180180
}
@@ -203,7 +203,7 @@ private void refreshFile(String[] files) {
203203
logger.info("refresh files success");
204204
} catch (QiniuException e) {
205205
logger.error("refresh files error, message: " + e.getMessage());
206-
Dialogs.showException(e);
206+
DialogUtils.showException(e);
207207
}
208208
}
209209

@@ -248,7 +248,7 @@ public void updateFile(String bucket, String key) {
248248
logger.info(log + "' success");
249249
} catch (QiniuException e) {
250250
logger.error(log + "' error, message: " + e.getMessage());
251-
Dialogs.showException(QiniuValueConsts.UPDATE_ERROR, e);
251+
DialogUtils.showException(QiniuValueConsts.UPDATE_ERROR, e);
252252
}
253253
}
254254

@@ -262,7 +262,7 @@ public void setFileLife(String bucket, String key, int days) {
262262
logger.info(log + "success");
263263
} catch (QiniuException e) {
264264
logger.error(log + "error, message: " + e.getMessage());
265-
Dialogs.showException(QiniuValueConsts.MOVE_OR_RENAME_ERROR, e);
265+
DialogUtils.showException(QiniuValueConsts.MOVE_OR_RENAME_ERROR, e);
266266
}
267267
}
268268

@@ -298,7 +298,7 @@ public boolean moveOrCopyFile(String fromBucket, String fromKey, String toBucket
298298
return true;
299299
} catch (QiniuException e) {
300300
logger.error(log + " failed, message: " + e.getMessage());
301-
Dialogs.showException(QiniuValueConsts.MOVE_OR_RENAME_ERROR, e);
301+
DialogUtils.showException(QiniuValueConsts.MOVE_OR_RENAME_ERROR, e);
302302
return false;
303303
}
304304
}
@@ -317,7 +317,7 @@ public boolean changeType(String fileName, String newType, String bucket) {
317317
return true;
318318
} catch (QiniuException e) {
319319
logger.error(log + "' failed, message: " + e.getMessage());
320-
Dialogs.showException(QiniuValueConsts.CHANGE_FILE_TYPE_ERROR, e);
320+
DialogUtils.showException(QiniuValueConsts.CHANGE_FILE_TYPE_ERROR, e);
321321
return false;
322322
}
323323
}
@@ -359,11 +359,11 @@ public void deleteFiles(ObservableList<FileInfo> fileInfos, String bucket) {
359359
}
360360
} else {
361361
logger.error("delete file '" + file + "' failed, message: " + status.data.error);
362-
Dialogs.showError("删除文件:" + file + " 失败");
362+
DialogUtils.showError("删除文件:" + file + " 失败");
363363
}
364364
}
365365
} catch (QiniuException e) {
366-
Dialogs.showException(QiniuValueConsts.DELETE_ERROR, e);
366+
DialogUtils.showException(QiniuValueConsts.DELETE_ERROR, e);
367367
}
368368
MainWindowController.getInstance().setBucketCount();
369369
}
@@ -402,7 +402,7 @@ public void listFileOfBucket() {
402402

403403
private void urlError(Exception e) {
404404
logger.error("generate url error: " + e.getMessage());
405-
Dialogs.showException(QiniuValueConsts.GENERATE_URL_ERROR, e);
405+
DialogUtils.showException(QiniuValueConsts.GENERATE_URL_ERROR, e);
406406
}
407407

408408
public enum FileAction {

src/main/java/org/code4everything/qiniu/api/config/SdkConfigurer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.apache.log4j.Logger;
1313
import org.code4everything.qiniu.constant.QiniuValueConsts;
1414
import org.code4everything.qiniu.util.QiniuUtils;
15-
import org.code4everything.qiniu.view.Dialogs;
15+
import org.code4everything.qiniu.util.DialogUtils;
1616

1717
import java.io.IOException;
1818
import java.nio.file.Paths;
@@ -77,7 +77,7 @@ public static void createAuth(String accessKey, String secretKey) {
7777
public static boolean configUploadEnv(String zone, String bucket) {
7878
if (!QiniuUtils.checkNet()) {
7979
Platform.runLater(() -> {
80-
Dialogs.showError(QiniuValueConsts.NET_ERROR);
80+
DialogUtils.showError(QiniuValueConsts.NET_ERROR);
8181
System.exit(0);
8282
});
8383
return false;

src/main/java/org/code4everything/qiniu/controller/MainWindowController.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
import org.code4everything.qiniu.constant.QiniuValueConsts;
2929
import org.code4everything.qiniu.model.FileInfo;
3030
import org.code4everything.qiniu.util.ConfigUtils;
31+
import org.code4everything.qiniu.util.DialogUtils;
32+
import org.code4everything.qiniu.util.QiniuDialog;
3133
import org.code4everything.qiniu.util.QiniuUtils;
32-
import org.code4everything.qiniu.view.Dialogs;
3334

3435
import java.awt.*;
3536
import java.io.File;
@@ -358,7 +359,7 @@ private void drawChart(boolean fluxUnitChange, boolean bandUnitChange) {
358359
* 日志下载,cdn相关
359360
*/
360361
public void downloadCdnLog() {
361-
String date = Dialogs.showInputDialog(null, QiniuValueConsts.INPUT_LOG_DATE,
362+
String date = DialogUtils.showInputDialog(null, QiniuValueConsts.INPUT_LOG_DATE,
362363
Formatter.dateToString(new Date()));
363364
new QiManager().downloadCdnLog(date);
364365
}
@@ -375,7 +376,7 @@ public void refreshFile() {
375376
* 通过链接下载其他的网络文件
376377
*/
377378
public void downloadFromURL() {
378-
String url = Dialogs.showInputDialog(null, QiniuValueConsts.DOWNLOAD_URL, "http://example.com");
379+
String url = DialogUtils.showInputDialog(null, QiniuValueConsts.DOWNLOAD_URL, "http://example.com");
379380
QiniuUtils.download(url);
380381
}
381382

@@ -443,7 +444,7 @@ public void updateFile() {
443444
public void setLife() {
444445
ObservableList<FileInfo> selectedItems = resTable.getSelectionModel().getSelectedItems();
445446
if (Checker.isNotEmpty(selectedItems)) {
446-
String lifeStr = Dialogs.showInputDialog(null, QiniuValueConsts.FILE_LIFE,
447+
String lifeStr = DialogUtils.showInputDialog(null, QiniuValueConsts.FILE_LIFE,
447448
QiniuValueConsts.DEFAULT_FILE_LIFE);
448449
if (Checker.isNumber(lifeStr)) {
449450
int life = Formatter.stringToInt(lifeStr);
@@ -466,9 +467,9 @@ public void showFileMovableDialog() {
466467
// 没有选择文件,结束方法
467468
return;
468469
} else if (selectedItems.size() > 1) {
469-
pair = new Dialogs().showFileMovableDialog(bucket, "", false);
470+
pair = new QiniuDialog().showFileMovableDialog(bucket, "", false);
470471
} else {
471-
pair = new Dialogs().showFileMovableDialog(bucket, selectedItems.get(0).getName(), true);
472+
pair = new QiniuDialog().showFileMovableDialog(bucket, selectedItems.get(0).getName(), true);
472473
}
473474
if (Checker.isNotNull(pair)) {
474475
boolean useNewKey = Checker.isNotEmpty(pair.getValue()[1]);
@@ -563,11 +564,11 @@ public void setBucketCount() {
563564
*/
564565
public void refreshResTable() {
565566
if (!QiniuUtils.checkNet()) {
566-
Dialogs.showWarning(QiniuValueConsts.NET_ERROR);
567+
DialogUtils.showWarning(QiniuValueConsts.NET_ERROR);
567568
return;
568569
}
569570
setResTableData();
570-
Dialogs.showInformation(QiniuValueConsts.REFRESH_SUCCESS);
571+
DialogUtils.showInformation(QiniuValueConsts.REFRESH_SUCCESS);
571572
}
572573

573574
/**
@@ -666,7 +667,7 @@ private void setFiles(File[] files, boolean checkRecursive) {
666667
public void uploadFile() {
667668
if (Checker.isEmpty(zoneText.getText()) || Checker.isEmpty(selectedFileTextArea.getText())) {
668669
// 没有选择存储空间或文件,不能上传文件
669-
Dialogs.showWarning(QiniuValueConsts.NEED_CHOOSE_BUCKET_OR_FILE);
670+
DialogUtils.showWarning(QiniuValueConsts.NEED_CHOOSE_BUCKET_OR_FILE);
670671
return;
671672
}
672673
// 新建一个上传文件的线程
@@ -732,7 +733,7 @@ public void uploadFile() {
732733
} catch (QiniuException e) {
733734
status = Formatter.datetimeToString(new Date()) + "\terror\t" + path;
734735
logger.error("upload error, message: " + e.getMessage());
735-
Platform.runLater(() -> Dialogs.showException(QiniuValueConsts.UPLOAD_ERROR, e));
736+
Platform.runLater(() -> DialogUtils.showException(QiniuValueConsts.UPLOAD_ERROR, e));
736737
}
737738
Platform.runLater(() -> {
738739
uploadStatusTextArea.deleteText(0, end);
@@ -777,7 +778,7 @@ private void savePrefix(String key) {
777778
public void openConfigFile() {
778779
try {
779780
Desktop.getDesktop().open(new File(QiniuValueConsts.CONFIG_PATH));
780-
Optional<ButtonType> result = Dialogs.showConfirmation(QiniuValueConsts.RELOAD_CONFIG);
781+
Optional<ButtonType> result = DialogUtils.showConfirmation(QiniuValueConsts.RELOAD_CONFIG);
781782
if (result.isPresent() && result.get() == ButtonType.OK) {
782783
// 重新载入配置文件
783784
bucketChoiceCombo.getItems().clear();
@@ -786,18 +787,18 @@ public void openConfigFile() {
786787
}
787788
} catch (IOException e) {
788789
logger.error("open config file error, message -> " + e.getMessage());
789-
Dialogs.showException(QiniuValueConsts.OPEN_FILE_ERROR, e);
790+
DialogUtils.showException(QiniuValueConsts.OPEN_FILE_ERROR, e);
790791
} catch (Exception e) {
791792
logger.error("can't open config file, message -> " + e.getMessage());
792-
Dialogs.showException(QiniuValueConsts.OPEN_FILE_ERROR, e);
793+
DialogUtils.showException(QiniuValueConsts.OPEN_FILE_ERROR, e);
793794
}
794795
}
795796

796797
/**
797798
* 重置Key
798799
*/
799800
public void resetKey() {
800-
boolean ok = new Dialogs().showInputKeyDialog();
801+
boolean ok = new QiniuDialog().showInputKeyDialog();
801802
if (ok && Checker.isNotEmpty(zoneText.getText())) {
802803
SdkConfigurer.configUploadEnv(zoneText.getText(), bucketChoiceCombo.getValue());
803804
}
@@ -808,7 +809,7 @@ public void resetKey() {
808809
*/
809810
public void showBucketAddableDialog() {
810811
logger.info("show bucket addable dialog");
811-
new Dialogs().showBucketAddableDialog();
812+
new QiniuDialog().showBucketAddableDialog();
812813
}
813814

814815
public enum DownloadWay {

src/main/java/org/code4everything/qiniu/util/ConfigUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public static void loadConfig() {
7070
QiniuApplication.setConfigBean(configBean);
7171
}
7272

73+
/**
74+
* 写配置文件
75+
*/
7376
public static void writeConfig() {
7477
FileUtil.writeUtf8String(JSONObject.toJSONString(QiniuApplication.getConfigBean(), true), CONFIG_PATH);
7578
}

0 commit comments

Comments
 (0)