diff options
Diffstat (limited to 'src/toolsconfig/ToolsRegistry.java')
-rw-r--r-- | src/toolsconfig/ToolsRegistry.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/toolsconfig/ToolsRegistry.java b/src/toolsconfig/ToolsRegistry.java new file mode 100644 index 0000000..a227c85 --- /dev/null +++ b/src/toolsconfig/ToolsRegistry.java | |||
@@ -0,0 +1,34 @@ | |||
1 | package toolsconfig; | ||
2 | |||
3 | import java.util.HashMap; | ||
4 | import java.util.function.BiConsumer; | ||
5 | import javax.swing.JOptionPane; | ||
6 | |||
7 | public class ToolsRegistry { | ||
8 | private static final HashMap<String, ToolsConfig> tools = | ||
9 | new HashMap<String, ToolsConfig>(); | ||
10 | |||
11 | static public void registerTool(String name, ToolsConfig tool) { | ||
12 | tools.put(name, tool); | ||
13 | } | ||
14 | |||
15 | static public ToolsConfig getTool(String name) { | ||
16 | return tools.get(name); | ||
17 | } | ||
18 | |||
19 | public static void executeTool(String name, String src) { | ||
20 | ToolsConfig tool = tools.get(name); | ||
21 | if (tool != null && tool.checkInit()) { | ||
22 | tool.execute(src); | ||
23 | } else if (tool == null) { | ||
24 | JOptionPane.showMessageDialog(null, "Error: 工具代码未设置", "提示", | ||
25 | 2); | ||
26 | } else { | ||
27 | JOptionPane.showMessageDialog(null, "Error: 参数错误", "提示", 2); | ||
28 | } | ||
29 | } | ||
30 | |||
31 | public static void forEach(BiConsumer<String, ToolsConfig> action) { | ||
32 | tools.forEach(action); | ||
33 | } | ||
34 | } | ||