-
Notifications
You must be signed in to change notification settings - Fork 23
为I18n mod添加下载窗口 #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
502y
wants to merge
6
commits into
CFPAOrg:main
Choose a base branch
from
502y:downloading_windows
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
为I18n mod添加下载窗口 #48
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dfa65d7
feat(GUI): 初步实现下载GUI
502y bdf235a
feat(GUI): Server Safe mod
502y 957c3ef
fix: 运行时异常保留窗口
502y 6d59f3a
feat(GUI): add log to shutdown button
502y ffe7bc9
Apply suggestions from code review
502y 5a688d2
reformat code
502y File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| package i18nupdatemod.core; | ||
|
|
||
| import i18nupdatemod.I18nUpdateMod; | ||
| import i18nupdatemod.entity.LoadStage; | ||
| import i18nupdatemod.util.Log; | ||
|
|
||
| import javax.swing.*; | ||
| import java.awt.*; | ||
| import java.awt.event.ActionEvent; | ||
| import java.awt.event.WindowAdapter; | ||
| import java.awt.event.WindowEvent; | ||
| import java.net.URL; | ||
|
|
||
| public class LoadDetailUI { | ||
| private static volatile LoadDetailUI instance; | ||
| private final JFrame frame; | ||
| private final JProgressBar statusBar; | ||
| private final JTextArea logArea; | ||
| private final boolean useGUI; | ||
|
|
||
| private LoadDetailUI() { | ||
| useGUI = !Boolean.parseBoolean(System.getProperty("java.awt.headless", "false")); | ||
|
|
||
| if (!useGUI) { | ||
| frame = null; | ||
| statusBar = null; | ||
| logArea = null; | ||
| return; | ||
| } | ||
|
|
||
| frame = new JFrame(); | ||
| frame.setTitle("I18nUpdateMod-资源包下载进度"); | ||
| frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); | ||
| frame.setSize(854, 480); | ||
| frame.setLocationRelativeTo(null); | ||
| frame.setLayout(new BorderLayout()); | ||
| frame.addWindowListener(new WindowAdapter() { | ||
| @Override | ||
| public void windowClosing(WindowEvent e) { | ||
| shutdown(); | ||
| } | ||
| }); | ||
|
|
||
|
|
||
| URL iconURL = getClass().getResource("/icons/CFPA.png"); | ||
| if (iconURL != null) { | ||
| Image icon = Toolkit.getDefaultToolkit().getImage(iconURL); | ||
| frame.setIconImage(icon); | ||
| } | ||
|
|
||
| // 主面板 | ||
| JPanel panel = new JPanel(); | ||
| panel.setBackground(new Color(220, 220, 220)); | ||
| panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); | ||
| panel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); | ||
|
|
||
| // 状态栏 | ||
| statusBar = new JProgressBar(); | ||
| statusBar.setString(LoadStage.getDescription(LoadStage.INIT)); | ||
| statusBar.setStringPainted(true); | ||
| statusBar.setMaximum(LoadStage.values().length - 1); | ||
| statusBar.setValue(0); | ||
| statusBar.setForeground(new Color(102, 255, 102)); | ||
| panel.add(statusBar); | ||
| panel.add(Box.createVerticalStrut(10)); | ||
|
|
||
| // 日志输出区 | ||
| logArea = new JTextArea(6, 30); | ||
| logArea.setEditable(false); | ||
| logArea.setFont(new Font("Monospaced", Font.PLAIN, 13)); | ||
| JScrollPane scrollPane = new JScrollPane(logArea); | ||
| scrollPane.setBorder(BorderFactory.createLineBorder(Color.GRAY)); | ||
| panel.add(scrollPane); | ||
| panel.add(Box.createVerticalStrut(10)); | ||
|
|
||
| // 提示文字 | ||
| JLabel tip = new JLabel("如遇到进度卡住,可以点击下方按钮/关闭此窗口停止此次下载。"); | ||
| tip.setAlignmentX(Component.CENTER_ALIGNMENT); | ||
| panel.add(tip); | ||
| panel.add(Box.createVerticalStrut(10)); | ||
|
|
||
| // 停止按钮 | ||
| JButton stopButton = new JButton("停止此次下载"); | ||
| stopButton.setFocusPainted(false); | ||
| stopButton.setBackground(Color.WHITE); | ||
| stopButton.setAlignmentX(Component.CENTER_ALIGNMENT); | ||
| stopButton.addActionListener((ActionEvent e) -> shutdown()); | ||
| panel.add(stopButton); | ||
|
|
||
| frame.add(panel, BorderLayout.CENTER); | ||
| } | ||
|
|
||
| public static LoadDetailUI getInstance() { | ||
| if (instance == null) { | ||
| synchronized (LoadDetailUI.class) { | ||
| if (instance == null) { | ||
| instance = new LoadDetailUI(); | ||
| } | ||
| } | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
| public static void show() { | ||
| LoadDetailUI gui = getInstance(); | ||
| if (!gui.useGUI || gui.frame == null) { | ||
| return; | ||
| } | ||
| SwingUtilities.invokeLater(() -> gui.frame.setVisible(true)); | ||
| } | ||
|
|
||
| public static void hide() { | ||
| LoadDetailUI gui = getInstance(); | ||
| if (!gui.useGUI || gui.frame == null) { | ||
| return; | ||
| } | ||
| SwingUtilities.invokeLater(() -> gui.frame.setVisible(false)); | ||
| } | ||
|
|
||
| private void shutdown() { | ||
| I18nUpdateMod.shouldShutdown = true; | ||
| Log.info("User shutdown task"); | ||
| if (!useGUI) { | ||
| return; | ||
| } | ||
| hide(); | ||
| } | ||
|
|
||
| public static void setStage(LoadStage stage) { | ||
| LoadDetailUI gui = getInstance(); | ||
| if (!gui.useGUI || gui.statusBar == null || gui.logArea == null) { | ||
| return; | ||
| } | ||
| SwingUtilities.invokeLater(() -> { | ||
| gui.statusBar.setString(LoadStage.getDescription(stage)); | ||
| gui.statusBar.setValue(stage.getValue()); | ||
| gui.logArea.append("当前阶段: " + LoadStage.getDescription(stage) + "\n"); | ||
| gui.logArea.setCaretPosition(gui.logArea.getDocument().getLength()); | ||
| }); | ||
| } | ||
|
|
||
| public static void appendLog(String log) { | ||
| LoadDetailUI gui = getInstance(); | ||
| if (!gui.useGUI || gui.logArea == null) { | ||
| return; | ||
| } | ||
| SwingUtilities.invokeLater(() -> { | ||
| gui.logArea.append(log + "\n"); | ||
| gui.logArea.setCaretPosition(gui.logArea.getDocument().getLength()); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package i18nupdatemod.entity; | ||
|
|
||
| public enum LoadStage { | ||
| INIT(0), | ||
| DOWNLOAD_ASSET(1), | ||
| CONVERT_RESOURCE_PACK(2), | ||
| APPLY_RESOURCE_PACK(3), | ||
| FINISH(4); | ||
|
|
||
| private final int value; | ||
|
|
||
| LoadStage(int value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public int getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public static String getDescription(LoadStage stage) { | ||
| switch (stage) { | ||
| case INIT: | ||
| return "初始化"; | ||
| case DOWNLOAD_ASSET: | ||
| return "更新资源包"; | ||
| case CONVERT_RESOURCE_PACK: | ||
| return "转换资源包"; | ||
| case APPLY_RESOURCE_PACK: | ||
| return "应用资源包"; | ||
| case FINISH: | ||
| return "完成"; | ||
| default: | ||
| return "未知"; | ||
| } | ||
| } | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.