美文网首页
IDEA 插件开发-下载原生进度条

IDEA 插件开发-下载原生进度条

作者: kongjn | 来源:发表于2022-06-21 17:42 被阅读0次

分享几种IDEA 插件开发时原生下载方式和进度条自定义方法。

下载文件到本地

DownloadableFileService fileService = DownloadableFileService.getInstance();

        String filename = FilenameUtils.getName(URL);
        DownloadableFileDescription fileDescription = fileService.createFileDescription(URL, filename);
        List<DownloadableFileDescription> fileDescriptions = new ArrayList<>();
        fileDescriptions.add(fileDescription);
        //同步下载,下载期间无法操作IDE
        fileService.createDownloader(fileDescriptions, "")
                .downloadFilesWithProgress(TARGET_PATH, project, null);

        //异步下载,下载期间可以操作IDE
        fileService .createDownloader(fileDescriptions, "")
                .downloadWithBackgroundProgress(TARGET_PATH, project);
异步后台下载 同步前台下载

进度条自定义

ProgressManager.getInstance().run(new Task.Backgroundable(project, "TitleKKKKK"){
            public void run(@NotNull ProgressIndicator progressIndicator) {

                // start your process

                // Set the progress bar percentage and text
                progressIndicator.setFraction(0.10);
                progressIndicator.setText("90% to finish");

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                // 50% done
                progressIndicator.setFraction(0.50);
                progressIndicator.setText("50% to finish");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                // Finished
                progressIndicator.setFraction(1.0);
                progressIndicator.setText("finished");

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }});
进度条自定义

相关文章

网友评论

      本文标题:IDEA 插件开发-下载原生进度条

      本文链接:https://www.haomeiwen.com/subject/undevrtx.html