|
1 | | -package com.xwintop.xJavaFxTool.services; |
2 | | - |
3 | | -import com.xwintop.xJavaFxTool.common.logback.ConsoleLogAppender; |
4 | | -import com.xwintop.xJavaFxTool.controller.IndexController; |
5 | | -import com.xwintop.xJavaFxTool.utils.Config; |
6 | | -import com.xwintop.xcore.util.ConfigureUtil; |
7 | | -import com.xwintop.xcore.util.javafx.AlertUtil; |
8 | | -import com.xwintop.xcore.util.javafx.JavaFxViewUtil; |
9 | | -import javafx.event.ActionEvent; |
10 | | -import javafx.event.Event; |
11 | | -import javafx.fxml.FXMLLoader; |
12 | | -import javafx.scene.control.ContextMenu; |
13 | | -import javafx.scene.control.MenuItem; |
14 | | -import javafx.scene.control.Tab; |
15 | | -import javafx.scene.control.TextArea; |
16 | | -import javafx.scene.image.Image; |
17 | | -import javafx.scene.image.ImageView; |
18 | | -import javafx.scene.layout.BorderPane; |
19 | | -import javafx.scene.web.WebEngine; |
20 | | -import javafx.scene.web.WebView; |
21 | | -import javafx.stage.Stage; |
22 | | -import lombok.Setter; |
23 | | -import org.apache.commons.configuration.PropertiesConfiguration; |
24 | | -import org.apache.commons.io.FileUtils; |
25 | | -import org.apache.commons.lang3.StringUtils; |
26 | | - |
27 | | -import java.io.File; |
28 | | -import java.util.Locale; |
29 | | -import java.util.ResourceBundle; |
30 | | - |
31 | | -@Setter |
32 | | -public class IndexService { |
33 | | - private IndexController indexController; |
34 | | - |
35 | | - public IndexService(IndexController indexController) { |
36 | | - this.indexController = indexController; |
37 | | - } |
38 | | - |
39 | | - public void setLanguageAction(String languageType) throws Exception { |
40 | | - File file = ConfigureUtil.getConfigureFile("systemConfigure.properties"); |
41 | | - FileUtils.touch(file); |
42 | | - PropertiesConfiguration xmlConfigure = new PropertiesConfiguration(file); |
43 | | - if ("简体中文".equals(languageType)) { |
44 | | - xmlConfigure.setProperty("Locale", Locale.SIMPLIFIED_CHINESE); |
45 | | - } else if ("English".equals(languageType)) { |
46 | | - xmlConfigure.setProperty("Locale", Locale.US); |
47 | | - } |
48 | | - xmlConfigure.save(); |
49 | | - AlertUtil.showInfoAlert(indexController.getBundle().getString("SetLanguageText")); |
50 | | - } |
51 | | - |
52 | | - public ContextMenu getSelectContextMenu(String selectText) { |
53 | | - selectText = selectText.toLowerCase(); |
54 | | - ContextMenu contextMenu = new ContextMenu(); |
55 | | - for (MenuItem menuItem : indexController.getMenuItemMap().values()) { |
56 | | - if (menuItem.getText().toLowerCase().contains(selectText)) { |
57 | | - MenuItem menu_tab = new MenuItem(menuItem.getText(), menuItem.getGraphic()); |
58 | | - menu_tab.setOnAction(event1 -> { |
59 | | - menuItem.fire(); |
60 | | - }); |
61 | | - contextMenu.getItems().add(menu_tab); |
62 | | - } |
63 | | - } |
64 | | - return contextMenu; |
65 | | - } |
66 | | - |
67 | | - public void addNodepadAction(ActionEvent event) { |
68 | | - TextArea textArea = new TextArea(); |
69 | | - textArea.setFocusTraversable(true); |
70 | | - if (indexController.getSingleWindowBootCheckBox().isSelected()) { |
71 | | - JavaFxViewUtil.getNewStage(indexController.getBundle().getString("addNodepad"), null, textArea); |
72 | | - } else { |
73 | | - Tab tab = new Tab(indexController.getBundle().getString("addNodepad")); |
74 | | - tab.setContent(textArea); |
75 | | - indexController.getTabPaneMain().getTabs().add(tab); |
76 | | - if (event != null) { |
77 | | - indexController.getTabPaneMain().getSelectionModel().select(tab); |
78 | | - } |
79 | | - } |
80 | | - } |
81 | | - |
82 | | - public void addLogConsoleAction(ActionEvent event) { |
83 | | - TextArea textArea = new TextArea(); |
84 | | - textArea.setFocusTraversable(true); |
85 | | - ConsoleLogAppender.textAreaList.add(textArea); |
86 | | - if (indexController.getSingleWindowBootCheckBox().isSelected()) { |
87 | | - Stage newStage = JavaFxViewUtil.getNewStage(indexController.getBundle().getString("addLogConsole"), null, textArea); |
88 | | - newStage.setOnCloseRequest(event1 -> { |
89 | | - ConsoleLogAppender.textAreaList.remove(textArea); |
90 | | - }); |
91 | | - } else { |
92 | | - Tab tab = new Tab(indexController.getBundle().getString("addLogConsole")); |
93 | | - tab.setContent(textArea); |
94 | | - indexController.getTabPaneMain().getTabs().add(tab); |
95 | | - if (event != null) { |
96 | | - indexController.getTabPaneMain().getSelectionModel().select(tab); |
97 | | - } |
98 | | - tab.setOnCloseRequest((Event event1) -> { |
99 | | - ConsoleLogAppender.textAreaList.remove(textArea); |
100 | | - }); |
101 | | - } |
102 | | - } |
103 | | - |
104 | | - /** |
105 | | - * @Title: addContent |
106 | | - * @Description: 添加Content内容 |
107 | | - */ |
108 | | - public void addContent(String title, String url, String resourceBundleName, String iconPath) { |
109 | | - try { |
110 | | - FXMLLoader generatingCodeFXMLLoader = new FXMLLoader(getClass().getResource(url)); |
111 | | - if (StringUtils.isNotEmpty(resourceBundleName)) { |
112 | | - ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceBundleName, Config.defaultLocale); |
113 | | - generatingCodeFXMLLoader.setResources(resourceBundle); |
114 | | - } |
115 | | - if (indexController.getSingleWindowBootCheckBox().isSelected()) { |
116 | | - JavaFxViewUtil.getNewStage(title, iconPath, generatingCodeFXMLLoader); |
117 | | - return; |
118 | | - } |
119 | | - Tab tab = new Tab(title); |
120 | | - if (StringUtils.isNotEmpty(iconPath)) { |
121 | | - ImageView imageView = new ImageView(new Image(iconPath)); |
122 | | - imageView.setFitHeight(18); |
123 | | - imageView.setFitWidth(18); |
124 | | - tab.setGraphic(imageView); |
125 | | - } |
126 | | - |
127 | | - tab.setContent(generatingCodeFXMLLoader.load()); |
128 | | - indexController.getTabPaneMain().getTabs().add(tab); |
129 | | - indexController.getTabPaneMain().getSelectionModel().select(tab); |
130 | | - |
131 | | - tab.setOnCloseRequest((Event event) -> { |
132 | | - JavaFxViewUtil.setControllerOnCloseRequest(generatingCodeFXMLLoader.getController(), event); |
133 | | - }); |
134 | | - } catch (Exception e) { |
135 | | - e.printStackTrace(); |
136 | | - } |
137 | | - } |
138 | | - |
139 | | - /** |
140 | | - * @Title: addWebView |
141 | | - * @Description: 添加WebView视图 |
142 | | - */ |
143 | | - public void addWebView(String title, String url, String iconPath) { |
144 | | - WebView browser = new WebView(); |
145 | | - WebEngine webEngine = browser.getEngine(); |
146 | | - if (url.startsWith("http")) { |
147 | | - webEngine.load(url); |
148 | | - } else { |
149 | | - webEngine.load(IndexController.class.getResource(url).toExternalForm()); |
150 | | - } |
151 | | - if (indexController.getSingleWindowBootCheckBox().isSelected()) { |
152 | | - JavaFxViewUtil.getNewStage(title, iconPath, new BorderPane(browser)); |
153 | | - return; |
154 | | - } |
155 | | - Tab tab = new Tab(title); |
156 | | - if (StringUtils.isNotEmpty(iconPath)) { |
157 | | - ImageView imageView = new ImageView(new Image(iconPath)); |
158 | | - imageView.setFitHeight(18); |
159 | | - imageView.setFitWidth(18); |
160 | | - tab.setGraphic(imageView); |
161 | | - } |
162 | | - tab.setContent(browser); |
163 | | - indexController.getTabPaneMain().getTabs().add(tab); |
164 | | - indexController.getTabPaneMain().getSelectionModel().select(tab); |
165 | | - } |
166 | | -} |
| 1 | +package com.xwintop.xJavaFxTool.services; |
| 2 | + |
| 3 | +import com.xwintop.xJavaFxTool.common.logback.ConsoleLogAppender; |
| 4 | +import com.xwintop.xJavaFxTool.controller.IndexController; |
| 5 | +import com.xwintop.xJavaFxTool.utils.Config; |
| 6 | +import com.xwintop.xJavaFxTool.utils.FxmlUtils; |
| 7 | +import com.xwintop.xcore.util.ConfigureUtil; |
| 8 | +import com.xwintop.xcore.util.javafx.AlertUtil; |
| 9 | +import com.xwintop.xcore.util.javafx.JavaFxViewUtil; |
| 10 | +import java.io.File; |
| 11 | +import java.util.Locale; |
| 12 | +import java.util.ResourceBundle; |
| 13 | +import javafx.event.ActionEvent; |
| 14 | +import javafx.event.Event; |
| 15 | +import javafx.fxml.FXMLLoader; |
| 16 | +import javafx.scene.Parent; |
| 17 | +import javafx.scene.control.ContextMenu; |
| 18 | +import javafx.scene.control.MenuItem; |
| 19 | +import javafx.scene.control.Tab; |
| 20 | +import javafx.scene.control.TextArea; |
| 21 | +import javafx.scene.image.Image; |
| 22 | +import javafx.scene.image.ImageView; |
| 23 | +import javafx.scene.layout.BorderPane; |
| 24 | +import javafx.scene.web.WebEngine; |
| 25 | +import javafx.scene.web.WebView; |
| 26 | +import javafx.stage.Stage; |
| 27 | +import lombok.Setter; |
| 28 | +import org.apache.commons.configuration.PropertiesConfiguration; |
| 29 | +import org.apache.commons.io.FileUtils; |
| 30 | +import org.apache.commons.lang3.StringUtils; |
| 31 | + |
| 32 | +@Setter |
| 33 | +public class IndexService { |
| 34 | + private IndexController indexController; |
| 35 | + |
| 36 | + public IndexService(IndexController indexController) { |
| 37 | + this.indexController = indexController; |
| 38 | + } |
| 39 | + |
| 40 | + public void setLanguageAction(String languageType) throws Exception { |
| 41 | + File file = ConfigureUtil.getConfigureFile("systemConfigure.properties"); |
| 42 | + FileUtils.touch(file); |
| 43 | + PropertiesConfiguration xmlConfigure = new PropertiesConfiguration(file); |
| 44 | + if ("简体中文".equals(languageType)) { |
| 45 | + xmlConfigure.setProperty("Locale", Locale.SIMPLIFIED_CHINESE); |
| 46 | + } else if ("English".equals(languageType)) { |
| 47 | + xmlConfigure.setProperty("Locale", Locale.US); |
| 48 | + } |
| 49 | + xmlConfigure.save(); |
| 50 | + AlertUtil.showInfoAlert(indexController.getBundle().getString("SetLanguageText")); |
| 51 | + } |
| 52 | + |
| 53 | + public ContextMenu getSelectContextMenu(String selectText) { |
| 54 | + selectText = selectText.toLowerCase(); |
| 55 | + ContextMenu contextMenu = new ContextMenu(); |
| 56 | + for (MenuItem menuItem : indexController.getMenuItemMap().values()) { |
| 57 | + if (menuItem.getText().toLowerCase().contains(selectText)) { |
| 58 | + MenuItem menu_tab = new MenuItem(menuItem.getText(), menuItem.getGraphic()); |
| 59 | + menu_tab.setOnAction(event1 -> { |
| 60 | + menuItem.fire(); |
| 61 | + }); |
| 62 | + contextMenu.getItems().add(menu_tab); |
| 63 | + } |
| 64 | + } |
| 65 | + return contextMenu; |
| 66 | + } |
| 67 | + |
| 68 | + public void addNodepadAction(ActionEvent event) { |
| 69 | + Parent notepad = FxmlUtils.load("/com/xwintop/xJavaFxTool/fxmlView/notepad.fxml"); |
| 70 | + if (indexController.getSingleWindowBootCheckBox().isSelected()) { |
| 71 | + JavaFxViewUtil.getNewStage(indexController.getBundle().getString("addNodepad"), null, notepad); |
| 72 | + } else { |
| 73 | + Tab tab = new Tab(indexController.getBundle().getString("addNodepad")); |
| 74 | + tab.setContent(notepad); |
| 75 | + indexController.getTabPaneMain().getTabs().add(tab); |
| 76 | + if (event != null) { |
| 77 | + indexController.getTabPaneMain().getSelectionModel().select(tab); |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + public void addLogConsoleAction(ActionEvent event) { |
| 83 | + TextArea textArea = new TextArea(); |
| 84 | + textArea.setFocusTraversable(true); |
| 85 | + ConsoleLogAppender.textAreaList.add(textArea); |
| 86 | + if (indexController.getSingleWindowBootCheckBox().isSelected()) { |
| 87 | + Stage newStage = JavaFxViewUtil.getNewStage(indexController.getBundle().getString("addLogConsole"), null, textArea); |
| 88 | + newStage.setOnCloseRequest(event1 -> { |
| 89 | + ConsoleLogAppender.textAreaList.remove(textArea); |
| 90 | + }); |
| 91 | + } else { |
| 92 | + Tab tab = new Tab(indexController.getBundle().getString("addLogConsole")); |
| 93 | + tab.setContent(textArea); |
| 94 | + indexController.getTabPaneMain().getTabs().add(tab); |
| 95 | + if (event != null) { |
| 96 | + indexController.getTabPaneMain().getSelectionModel().select(tab); |
| 97 | + } |
| 98 | + tab.setOnCloseRequest((Event event1) -> { |
| 99 | + ConsoleLogAppender.textAreaList.remove(textArea); |
| 100 | + }); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * @Title: addContent |
| 106 | + * @Description: 添加Content内容 |
| 107 | + */ |
| 108 | + public void addContent(String title, String url, String resourceBundleName, String iconPath) { |
| 109 | + try { |
| 110 | + FXMLLoader generatingCodeFXMLLoader = new FXMLLoader(getClass().getResource(url)); |
| 111 | + if (StringUtils.isNotEmpty(resourceBundleName)) { |
| 112 | + ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceBundleName, Config.defaultLocale); |
| 113 | + generatingCodeFXMLLoader.setResources(resourceBundle); |
| 114 | + } |
| 115 | + if (indexController.getSingleWindowBootCheckBox().isSelected()) { |
| 116 | + JavaFxViewUtil.getNewStage(title, iconPath, generatingCodeFXMLLoader); |
| 117 | + return; |
| 118 | + } |
| 119 | + Tab tab = new Tab(title); |
| 120 | + if (StringUtils.isNotEmpty(iconPath)) { |
| 121 | + ImageView imageView = new ImageView(new Image(iconPath)); |
| 122 | + imageView.setFitHeight(18); |
| 123 | + imageView.setFitWidth(18); |
| 124 | + tab.setGraphic(imageView); |
| 125 | + } |
| 126 | + |
| 127 | + tab.setContent(generatingCodeFXMLLoader.load()); |
| 128 | + indexController.getTabPaneMain().getTabs().add(tab); |
| 129 | + indexController.getTabPaneMain().getSelectionModel().select(tab); |
| 130 | + |
| 131 | + tab.setOnCloseRequest((Event event) -> { |
| 132 | + JavaFxViewUtil.setControllerOnCloseRequest(generatingCodeFXMLLoader.getController(), event); |
| 133 | + }); |
| 134 | + } catch (Exception e) { |
| 135 | + e.printStackTrace(); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * @Title: addWebView |
| 141 | + * @Description: 添加WebView视图 |
| 142 | + */ |
| 143 | + public void addWebView(String title, String url, String iconPath) { |
| 144 | + WebView browser = new WebView(); |
| 145 | + WebEngine webEngine = browser.getEngine(); |
| 146 | + if (url.startsWith("http")) { |
| 147 | + webEngine.load(url); |
| 148 | + } else { |
| 149 | + webEngine.load(IndexController.class.getResource(url).toExternalForm()); |
| 150 | + } |
| 151 | + if (indexController.getSingleWindowBootCheckBox().isSelected()) { |
| 152 | + JavaFxViewUtil.getNewStage(title, iconPath, new BorderPane(browser)); |
| 153 | + return; |
| 154 | + } |
| 155 | + Tab tab = new Tab(title); |
| 156 | + if (StringUtils.isNotEmpty(iconPath)) { |
| 157 | + ImageView imageView = new ImageView(new Image(iconPath)); |
| 158 | + imageView.setFitHeight(18); |
| 159 | + imageView.setFitWidth(18); |
| 160 | + tab.setGraphic(imageView); |
| 161 | + } |
| 162 | + tab.setContent(browser); |
| 163 | + indexController.getTabPaneMain().getTabs().add(tab); |
| 164 | + indexController.getTabPaneMain().getSelectionModel().select(tab); |
| 165 | + } |
| 166 | +} |
0 commit comments