From ee9b4428a8ea3c899ca6181e762a0089e9a34769 Mon Sep 17 00:00:00 2001 From: "Notmoo-PC\\Notmoo" Date: Thu, 2 Nov 2017 14:06:53 +0100 Subject: [PATCH] =?UTF-8?q?Module=20Client=20:=20correction=20du=20bug=20d?= =?UTF-8?q?e=20mise=20=C3=A0=20jour=20des=20=C3=A9l=C3=A9ments;=20ajout=20?= =?UTF-8?q?des=20clss/interfaces=20IFXFrame,=20FrameManager=20et=20FrameSc?= =?UTF-8?q?ene?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/pqt/client/Main.java | 53 +------------- .../java/com/pqt/client/gui/FrameManager.java | 71 +++++++++++++++++++ .../java/com/pqt/client/gui/FrameScene.java | 23 ++++++ .../pqt/client/gui/main_frame/MainFrame.java | 6 +- .../components/generics/frames/IFXFrame.java | 7 ++ .../gui/startup_frame/StartupFrame.java | 11 ++- 6 files changed, 117 insertions(+), 54 deletions(-) create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/FrameManager.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/FrameScene.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/generics/frames/IFXFrame.java diff --git a/Workspace/client/src/main/java/com/pqt/client/Main.java b/Workspace/client/src/main/java/com/pqt/client/Main.java index 9582e9c3..dfe7bf16 100644 --- a/Workspace/client/src/main/java/com/pqt/client/Main.java +++ b/Workspace/client/src/main/java/com/pqt/client/Main.java @@ -1,5 +1,6 @@ package com.pqt.client; +import com.pqt.client.gui.FrameManager; import com.pqt.client.gui.main_frame.MainFrame; import com.pqt.client.gui.main_frame.listeners.IMainFrameModelListener; import com.pqt.client.gui.modules.account_screen.AccountScreen; @@ -26,56 +27,6 @@ public class Main extends Application{ @Override public void start(Stage primaryStage) throws Exception { - - ClientBackEndModuleManager moduleManager = new ClientBackEndModuleManager(null); - - - MainFrame mainFrame = new MainFrame(moduleManager.getAccountService()); - mainFrame.addModule(new SaleScreen(moduleManager.getAccountService(), moduleManager.getStockService(), moduleManager.getSaleService()), true); - mainFrame.addModule(new StockScreen(moduleManager.getStockService(), moduleManager.getAccountService())); - mainFrame.addModule(new StatScreen(moduleManager.getStatService())); - mainFrame.addModule(new AccountScreen(moduleManager.getAccountService())); - Scene mainFrameScene = initScene(mainFrame.getPane()); - - StartupFrame startupFrame = new StartupFrame(moduleManager.getAccountService(), moduleManager.getNetworkService()); - Scene startupFrameScene = initScene(startupFrame.getPane()); - - mainFrame.addFrameModelListener(getMainFrameListener(primaryStage, startupFrameScene)); - startupFrame.addFrameModelListener(getStartupFrameListener(primaryStage, mainFrameScene)); - - ToastFactory.init(primaryStage); - primaryStage.setTitle(GUIStringTool.getAppTitle()); - primaryStage.setScene(startupFrameScene); - primaryStage.show(); - } - - private Scene initScene(Pane pane){ - Scene scene = new Scene(pane); - scene.getStylesheets().clear(); - scene.getStylesheets().addAll(getClass().getResource(GUICssTool.getCssFilePath()).toExternalForm()); - - return scene; - } - - private IStartupFrameModelListener getStartupFrameListener(Stage primaryStage, Scene sceneToDisplay){ - return () -> { - Platform.runLater(()->trySwitchScene(primaryStage, sceneToDisplay, true)); - }; - } - - - private IMainFrameModelListener getMainFrameListener(Stage primaryStage, Scene sceneToDisplay){ - return () -> trySwitchScene(primaryStage, sceneToDisplay, false); - } - - private void trySwitchScene(Stage primaryStage, Scene sceneToDisplay, boolean maximize){ - if(sceneToDisplay!=null) { - primaryStage.hide(); - primaryStage.setScene(sceneToDisplay); - primaryStage.setMaximized(maximize); - primaryStage.show(); - }else{ - Platform.exit(); - } + new FrameManager(primaryStage).show(); } } diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/FrameManager.java b/Workspace/client/src/main/java/com/pqt/client/gui/FrameManager.java new file mode 100644 index 00000000..47ed07f6 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/FrameManager.java @@ -0,0 +1,71 @@ +package com.pqt.client.gui; + +import com.pqt.client.gui.main_frame.MainFrame; +import com.pqt.client.gui.main_frame.listeners.IMainFrameModelListener; +import com.pqt.client.gui.modules.account_screen.AccountScreen; +import com.pqt.client.gui.modules.sale_screen.SaleScreen; +import com.pqt.client.gui.modules.stat_screen.StatScreen; +import com.pqt.client.gui.modules.stock_screen.StockScreen; +import com.pqt.client.gui.ressources.components.generics.toast.ToastFactory; +import com.pqt.client.gui.ressources.strings.GUIStringTool; +import com.pqt.client.gui.startup_frame.StartupFrame; +import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener; +import com.pqt.client.module.ClientBackEndModuleManager; +import javafx.application.Platform; +import javafx.stage.Stage; + +public class FrameManager { + + private FrameScene mainFrameScene; + private FrameScene startupFrameScene; + private Stage stage; + + public FrameManager(Stage stage) { + this.stage = stage; + + ClientBackEndModuleManager moduleManager = new ClientBackEndModuleManager(null); + + MainFrame mainFrame = new MainFrame(moduleManager.getAccountService()); + mainFrame.addModule(new SaleScreen(moduleManager.getAccountService(), moduleManager.getStockService(), moduleManager.getSaleService()), true); + mainFrame.addModule(new StockScreen(moduleManager.getStockService(), moduleManager.getAccountService())); + mainFrame.addModule(new StatScreen(moduleManager.getStatService())); + mainFrame.addModule(new AccountScreen(moduleManager.getAccountService())); + mainFrameScene = new FrameScene(mainFrame); + + StartupFrame startupFrame = new StartupFrame(moduleManager.getAccountService(), moduleManager.getNetworkService()); + startupFrameScene = new FrameScene(startupFrame); + + mainFrame.addFrameModelListener(getMainFrameListener()); + startupFrame.addFrameModelListener(getStartupFrameListener()); + + ToastFactory.init(this.stage); + this.stage.setTitle(GUIStringTool.getAppTitle()); + this.stage.setScene(startupFrameScene); + this.stage.show(); + } + + public void show(){ + stage.show(); + } + + private IStartupFrameModelListener getStartupFrameListener(){ + return () -> Platform.runLater(()->trySwitchScene(stage, mainFrameScene, true)); + } + + + private IMainFrameModelListener getMainFrameListener(){ + return () -> Platform.runLater(()->trySwitchScene(stage, startupFrameScene, false)); + } + + private void trySwitchScene(Stage stage, FrameScene sceneToDisplay, boolean maximize){ + if(sceneToDisplay!=null) { + stage.hide(); + stage.setScene(sceneToDisplay); + stage.setMaximized(maximize); + stage.show(); + sceneToDisplay.requestFrameUpdate(); + }else{ + Platform.exit(); + } + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/FrameScene.java b/Workspace/client/src/main/java/com/pqt/client/gui/FrameScene.java new file mode 100644 index 00000000..e376eb7b --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/FrameScene.java @@ -0,0 +1,23 @@ +package com.pqt.client.gui; + +import com.pqt.client.gui.ressources.components.generics.frames.IFXFrame; +import com.pqt.client.gui.ressources.css.GUICssTool; +import javafx.scene.Scene; + +public class FrameScene extends Scene { + + private IFXFrame frame; + + public FrameScene(IFXFrame frame) { + super(frame.getPane()); + + this.frame = frame; + + getStylesheets().clear(); + getStylesheets().addAll(getClass().getResource(GUICssTool.getCssFilePath()).toExternalForm()); + } + + public void requestFrameUpdate(){ + frame.requestFrameUpdate(); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrame.java b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrame.java index bccfbce8..8c75b428 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrame.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/main_frame/MainFrame.java @@ -3,11 +3,12 @@ package com.pqt.client.gui.main_frame; import com.pqt.client.gui.main_frame.listeners.IMainFrameModelListener; import com.pqt.client.gui.modules.IGuiModule; import com.pqt.client.gui.ressources.components.generics.IFXComponent; +import com.pqt.client.gui.ressources.components.generics.frames.IFXFrame; import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener; import com.pqt.client.module.account.AccountService; import javafx.scene.layout.Pane; -public class MainFrame implements IFXComponent { +public class MainFrame implements IFXFrame { private MainFrameView view; private MainFrameController ctrl; @@ -35,6 +36,9 @@ public class MainFrame implements IFXComponent { model.addListener(l); } + public void requestFrameUpdate(){ + ctrl.updateView(); + } @Override public Pane getPane() { return view.getPane(); diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/generics/frames/IFXFrame.java b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/generics/frames/IFXFrame.java new file mode 100644 index 00000000..dd8d85ef --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/gui/ressources/components/generics/frames/IFXFrame.java @@ -0,0 +1,7 @@ +package com.pqt.client.gui.ressources.components.generics.frames; + +import com.pqt.client.gui.ressources.components.generics.IFXComponent; + +public interface IFXFrame extends IFXComponent{ + void requestFrameUpdate(); +} diff --git a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrame.java b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrame.java index 29e2c7e0..4b06345a 100644 --- a/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrame.java +++ b/Workspace/client/src/main/java/com/pqt/client/gui/startup_frame/StartupFrame.java @@ -1,19 +1,21 @@ package com.pqt.client.gui.startup_frame; import com.pqt.client.gui.ressources.components.generics.IFXComponent; +import com.pqt.client.gui.ressources.components.generics.frames.IFXFrame; import com.pqt.client.gui.startup_frame.listeners.frame.IStartupFrameModelListener; import com.pqt.client.module.account.AccountService; import com.pqt.client.module.network.NetworkService; import javafx.scene.layout.Pane; -public class StartupFrame implements IFXComponent{ +public class StartupFrame implements IFXFrame{ private StartupFrameView view; + private StartupFrameController ctrl; private StartupFrameModel model; public StartupFrame(AccountService accountService, NetworkService networkService) { model = new StartupFrameModel(accountService, networkService); - StartupFrameController ctrl = new StartupFrameController(model); + ctrl = new StartupFrameController(model); model.addListener(ctrl); view = new StartupFrameView(ctrl); @@ -29,4 +31,9 @@ public class StartupFrame implements IFXComponent{ public Pane getPane() { return view.getPane(); } + + @Override + public void requestFrameUpdate() { + ctrl.updateView(); + } }