11package com .xwintop .xJavaFxTool .controller ;
22
3- import com .xwintop .xJavaFxTool .common .logback .ConsoleLogAppender ;
43import com .xwintop .xJavaFxTool .controller .index .PluginManageController ;
54import com .xwintop .xJavaFxTool .model .ToolFxmlLoaderConfiguration ;
65import com .xwintop .xJavaFxTool .services .IndexService ;
1514import javafx .beans .value .ChangeListener ;
1615import javafx .beans .value .ObservableValue ;
1716import javafx .event .ActionEvent ;
18- import javafx .event .Event ;
1917import javafx .event .EventHandler ;
2018import javafx .fxml .FXML ;
2119import javafx .fxml .FXMLLoader ;
22- import javafx .scene .control .*;
20+ import javafx .scene .control .ContextMenu ;
21+ import javafx .scene .control .Menu ;
22+ import javafx .scene .control .MenuItem ;
2323import javafx .scene .image .Image ;
2424import javafx .scene .image .ImageView ;
25- import javafx .scene .layout .BorderPane ;
26- import javafx .scene .web .WebEngine ;
27- import javafx .scene .web .WebView ;
28- import javafx .stage .Stage ;
25+ import lombok .Getter ;
26+ import lombok .Setter ;
2927import lombok .extern .slf4j .Slf4j ;
3028import org .apache .commons .lang .StringUtils ;
3129import org .apache .commons .lang3 .time .DateFormatUtils ;
4038 * @date: 2017年7月20日 下午1:50:00
4139 */
4240@ Slf4j
41+ @ Getter
42+ @ Setter
4343public class IndexController extends IndexView {
4444 private Map <String , Menu > menuMap = new HashMap <String , Menu >();
4545 private Map <String , MenuItem > menuItemMap = new HashMap <String , MenuItem >();
46- private IndexService indexService = new IndexService ();
46+ private IndexService indexService = new IndexService (this );
4747 private ContextMenu contextMenu = new ContextMenu ();
4848
4949 public static FXMLLoader getFXMLLoader () {
@@ -119,19 +119,19 @@ private void initView() {
119119 }
120120 if ("Node" .equals (toolConfig .getControllerType ())) {
121121 menuItem .setOnAction ((ActionEvent event ) -> {
122- addContent (menuItem .getText (), toolConfig .getUrl (), toolConfig .getResourceBundleName (),
122+ indexService . addContent (menuItem .getText (), toolConfig .getUrl (), toolConfig .getResourceBundleName (),
123123 toolConfig .getIconPath ());
124124 });
125125 if (toolConfig .getIsDefaultShow ()) {
126- addContent (menuItem .getText (), toolConfig .getUrl (), toolConfig .getResourceBundleName (),
126+ indexService . addContent (menuItem .getText (), toolConfig .getUrl (), toolConfig .getResourceBundleName (),
127127 toolConfig .getIconPath ());
128128 }
129129 } else if ("WebView" .equals (toolConfig .getControllerType ())) {
130130 menuItem .setOnAction ((ActionEvent event ) -> {
131- addWebView (menuItem .getText (), toolConfig .getUrl (), toolConfig .getIconPath ());
131+ indexService . addWebView (menuItem .getText (), toolConfig .getUrl (), toolConfig .getIconPath ());
132132 });
133133 if (toolConfig .getIsDefaultShow ()) {
134- addWebView (menuItem .getText (), toolConfig .getUrl (), toolConfig .getIconPath ());
134+ indexService . addWebView (menuItem .getText (), toolConfig .getUrl (), toolConfig .getIconPath ());
135135 }
136136 }
137137 menuMap .get (toolConfig .getMenuParentId ()).getItems ().add (menuItem );
@@ -158,8 +158,6 @@ public void handle(ActionEvent arg0) {
158158 }
159159
160160 private void initService () {
161- indexService .setBundle (bundle );
162- indexService .setMenuItemMap (menuItemMap );
163161 }
164162
165163 public void selectAction (String selectText ) {
@@ -189,104 +187,12 @@ private void openAllTabAction(ActionEvent event) {
189187
190188 @ FXML
191189 private void addNodepadAction (ActionEvent event ) {
192- TextArea textArea = new TextArea ();
193- textArea .setFocusTraversable (true );
194- if (singleWindowBootCheckBox .isSelected ()) {
195- JavaFxViewUtil .getNewStage (this .bundle .getString ("addNodepad" ), null , textArea );
196- } else {
197- Tab tab = new Tab (this .bundle .getString ("addNodepad" ));
198- tab .setContent (textArea );
199- tabPaneMain .getTabs ().add (tab );
200- if (event != null ) {
201- tabPaneMain .getSelectionModel ().select (tab );
202- }
203- }
190+ indexService .addNodepadAction (event );
204191 }
205192
206193 @ FXML
207194 private void addLogConsoleAction (ActionEvent event ) {
208- TextArea textArea = new TextArea ();
209- textArea .setFocusTraversable (true );
210- ConsoleLogAppender .textAreaList .add (textArea );
211- if (singleWindowBootCheckBox .isSelected ()) {
212- Stage newStage = JavaFxViewUtil .getNewStage (this .bundle .getString ("addLogConsole" ), null , textArea );
213- newStage .setOnCloseRequest (event1 -> {
214- ConsoleLogAppender .textAreaList .remove (textArea );
215- });
216- } else {
217- Tab tab = new Tab (this .bundle .getString ("addLogConsole" ));
218- tab .setContent (textArea );
219- tabPaneMain .getTabs ().add (tab );
220- if (event != null ) {
221- tabPaneMain .getSelectionModel ().select (tab );
222- }
223- tab .setOnCloseRequest ((Event event1 ) -> {
224- ConsoleLogAppender .textAreaList .remove (textArea );
225- });
226- }
227- }
228-
229- /**
230- * @Title: addContent
231- * @Description: 添加Content内容
232- */
233- private void addContent (String title , String url , String resourceBundleName , String iconPath ) {
234- try {
235- FXMLLoader generatingCodeFXMLLoader = new FXMLLoader (getClass ().getResource (url ));
236- if (StringUtils .isNotEmpty (resourceBundleName )) {
237- ResourceBundle resourceBundle = ResourceBundle .getBundle (resourceBundleName , Config .defaultLocale );
238- generatingCodeFXMLLoader .setResources (resourceBundle );
239- }
240- if (singleWindowBootCheckBox .isSelected ()) {
241- JavaFxViewUtil .getNewStage (title , iconPath , generatingCodeFXMLLoader );
242- return ;
243- }
244- Tab tab = new Tab (title );
245- if (StringUtils .isNotEmpty (iconPath )) {
246- ImageView imageView = new ImageView (new Image (iconPath ));
247- imageView .setFitHeight (18 );
248- imageView .setFitWidth (18 );
249- tab .setGraphic (imageView );
250- }
251-
252- tab .setContent (generatingCodeFXMLLoader .load ());
253- tabPaneMain .getTabs ().add (tab );
254- tabPaneMain .getSelectionModel ().select (tab );
255-
256- tab .setOnCloseRequest ((Event event ) -> {
257- JavaFxViewUtil .setControllerOnCloseRequest (generatingCodeFXMLLoader .getController (), event );
258- });
259- } catch (Exception e ) {
260- e .printStackTrace ();
261- }
262- }
263-
264- /**
265- * @Title: addWebView
266- * @Description: 添加WebView视图
267- */
268- private void addWebView (String title , String url , String iconPath ) {
269- WebView browser = new WebView ();
270- WebEngine webEngine = browser .getEngine ();
271- if (url .startsWith ("http" )) {
272- webEngine .load (url );
273- } else {
274- webEngine .load (IndexController .class .getResource (url ).toExternalForm ());
275- }
276- if (singleWindowBootCheckBox .isSelected ()) {
277- JavaFxViewUtil .getNewStage (title , iconPath , new BorderPane (browser ));
278- return ;
279- }
280- Tab tab = new Tab (title );
281- if (StringUtils .isNotEmpty (iconPath )) {
282- ImageView imageView = new ImageView (new Image (iconPath ));
283- imageView .setFitHeight (18 );
284- imageView .setFitWidth (18 );
285- tab .setGraphic (imageView );
286- }
287- tab .setContent (browser );
288- tabPaneMain .getTabs ().add (tab );
289- tabPaneMain .getSelectionModel ().select (tab );
195+ indexService .addLogConsoleAction (event );
290196 }
291197
292198 @ FXML
0 commit comments